@epicdm/flowstate-mcp-gateway 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs ADDED
@@ -0,0 +1,372 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/server.ts
4
+ import express from "express";
5
+ import cors from "cors";
6
+ import { FlowStateMCPServer } from "@epicdm/flowstate-mcp";
7
+
8
+ // src/InMemoryTransport.ts
9
+ import { EventEmitter } from "events";
10
+ var InMemoryTransport = class {
11
+ sessionId;
12
+ onclose;
13
+ onerror;
14
+ onmessage;
15
+ started = false;
16
+ emitter = new EventEmitter();
17
+ responseHandlers = /* @__PURE__ */ new Map();
18
+ async start() {
19
+ this.started = true;
20
+ this.sessionId = `inmemory-${Date.now()}-${Math.random().toString(36).substring(7)}`;
21
+ }
22
+ async send(message) {
23
+ if (!this.started) {
24
+ throw new Error("Transport not started");
25
+ }
26
+ if ("result" in message || "error" in message) {
27
+ const response = message;
28
+ const handler = this.responseHandlers.get(response.id);
29
+ if (handler) {
30
+ handler(message);
31
+ this.responseHandlers.delete(response.id);
32
+ }
33
+ }
34
+ }
35
+ async close() {
36
+ this.started = false;
37
+ this.responseHandlers.clear();
38
+ this.onclose?.();
39
+ }
40
+ setProtocolVersion(version) {
41
+ }
42
+ /**
43
+ * Send a request and wait for response
44
+ * Used by the gateway to make programmatic requests
45
+ */
46
+ async sendRequest(request) {
47
+ if (!this.started) {
48
+ throw new Error("Transport not started");
49
+ }
50
+ return new Promise((resolve2, reject) => {
51
+ const req = request;
52
+ const timeout = setTimeout(() => {
53
+ this.responseHandlers.delete(req.id);
54
+ reject(new Error("Request timeout"));
55
+ }, 6e4);
56
+ this.responseHandlers.set(req.id, (response) => {
57
+ clearTimeout(timeout);
58
+ resolve2(response);
59
+ });
60
+ if (this.onmessage) {
61
+ this.onmessage(request);
62
+ } else {
63
+ reject(new Error("Transport not connected to server"));
64
+ }
65
+ });
66
+ }
67
+ };
68
+
69
+ // src/server.ts
70
+ var MCPGatewayServer = class {
71
+ app;
72
+ mcpServer;
73
+ config;
74
+ isInitialized = false;
75
+ httpServer;
76
+ transport;
77
+ constructor(config2) {
78
+ this.config = config2;
79
+ this.app = express();
80
+ this.mcpServer = new FlowStateMCPServer({
81
+ rxdbServerUrl: config2.rxdbServerUrl,
82
+ domainId: config2.domainId,
83
+ projectPath: config2.projectPath || process.cwd(),
84
+ ...config2.userId && { userId: config2.userId },
85
+ ...config2.orgId && { orgId: config2.orgId }
86
+ });
87
+ this.setupMiddleware();
88
+ this.setupRoutes();
89
+ }
90
+ /**
91
+ * Get list of tools from MCP server
92
+ *
93
+ * WARNING: This method accesses internal MCP server API via type casting.
94
+ * This is necessary because FlowStateMCPServer doesn't expose a public method
95
+ * for listing tools. The underlying server.request() method is used directly.
96
+ *
97
+ * RISKS:
98
+ * - Internal API may change without notice in future versions
99
+ * - Type casting bypasses TypeScript safety checks
100
+ * - May break if FlowStateMCPServer implementation changes
101
+ *
102
+ * TODO: Consider requesting a public API method in FlowStateMCPServer
103
+ * for listing and calling tools to avoid internal API access.
104
+ */
105
+ async listTools() {
106
+ if (!this.transport) {
107
+ return [];
108
+ }
109
+ const request = {
110
+ jsonrpc: "2.0",
111
+ id: Date.now(),
112
+ method: "tools/list"
113
+ };
114
+ const response = await this.transport.sendRequest(request);
115
+ if ("error" in response) {
116
+ throw new Error(response.error.message || "Failed to list tools");
117
+ }
118
+ return response.result?.tools || [];
119
+ }
120
+ /**
121
+ * Call a tool on the MCP server
122
+ *
123
+ * WARNING: This method accesses internal MCP server API via type casting.
124
+ * This is necessary because FlowStateMCPServer doesn't expose a public method
125
+ * for calling tools. The underlying server.request() method is used directly.
126
+ *
127
+ * RISKS:
128
+ * - Internal API may change without notice in future versions
129
+ * - Type casting bypasses TypeScript safety checks
130
+ * - May break if FlowStateMCPServer implementation changes
131
+ *
132
+ * TODO: Consider requesting a public API method in FlowStateMCPServer
133
+ * for listing and calling tools to avoid internal API access.
134
+ *
135
+ * NOTE: The MCP SDK's server.request() method appears to require the request
136
+ * object to be passed twice (once as the request, once as params). This seems
137
+ * to be how the underlying MCP SDK expects the call to be structured based on
138
+ * the protocol specification.
139
+ */
140
+ async callTool(toolName, args) {
141
+ if (!this.transport) {
142
+ throw new Error("MCP server not available");
143
+ }
144
+ const request = {
145
+ jsonrpc: "2.0",
146
+ id: Date.now(),
147
+ method: "tools/call",
148
+ params: {
149
+ name: toolName,
150
+ arguments: args
151
+ }
152
+ };
153
+ const response = await this.transport.sendRequest(request);
154
+ if ("error" in response) {
155
+ throw new Error(response.error.message || "Failed to call tool");
156
+ }
157
+ return response.result?.content?.[0]?.text || response.result;
158
+ }
159
+ setupMiddleware() {
160
+ this.app.use(
161
+ cors({
162
+ origin: this.config.corsOrigins || "*",
163
+ methods: ["GET", "POST", "OPTIONS"],
164
+ allowedHeaders: ["Content-Type", "Authorization"]
165
+ })
166
+ );
167
+ this.app.use(express.json());
168
+ this.app.use(express.urlencoded({ extended: true }));
169
+ this.app.use((req, res, next) => {
170
+ console.log(`${(/* @__PURE__ */ new Date()).toISOString()} ${req.method} ${req.path}`);
171
+ next();
172
+ });
173
+ }
174
+ /**
175
+ * Extract and forward auth token from request to MCP server
176
+ *
177
+ * This enables per-request auth so each API call can use its own token,
178
+ * rather than relying on the initial config token.
179
+ */
180
+ updateAuthFromRequest(req) {
181
+ const authHeader = req.headers["authorization"];
182
+ if (!authHeader) {
183
+ console.log("[MCP Gateway] No Authorization header in request");
184
+ return;
185
+ }
186
+ const token = authHeader.toString().replace("Bearer ", "");
187
+ if (!token) {
188
+ console.log("[MCP Gateway] Empty token after Bearer prefix removal");
189
+ return;
190
+ }
191
+ if (!token.startsWith("eyJ") && !token.startsWith("epic_")) {
192
+ console.log(`[MCP Gateway] Invalid token format (starts with: ${token.substring(0, 10)}...)`);
193
+ return;
194
+ }
195
+ try {
196
+ ;
197
+ this.mcpServer.config.authToken = token;
198
+ console.log("[MCP Gateway] Auth token updated from request");
199
+ } catch (error) {
200
+ console.error("[MCP Gateway] Failed to update auth config:", error);
201
+ }
202
+ }
203
+ setupRoutes() {
204
+ this.app.get("/health", (req, res) => {
205
+ res.json({
206
+ status: "ok",
207
+ initialized: this.isInitialized,
208
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
209
+ });
210
+ });
211
+ this.app.get("/mcp/tools", async (req, res) => {
212
+ try {
213
+ if (!this.isInitialized) {
214
+ return res.status(503).json({
215
+ error: "Server not initialized"
216
+ });
217
+ }
218
+ this.updateAuthFromRequest(req);
219
+ const tools = await this.listTools();
220
+ res.json({ tools });
221
+ } catch (error) {
222
+ console.error("Error listing tools:", error);
223
+ res.status(500).json({
224
+ error: error instanceof Error ? error.message : "Unknown error"
225
+ });
226
+ }
227
+ });
228
+ this.app.post("/mcp/tools/call", async (req, res) => {
229
+ try {
230
+ if (!this.isInitialized) {
231
+ return res.status(503).json({
232
+ success: false,
233
+ error: "Server not initialized"
234
+ });
235
+ }
236
+ this.updateAuthFromRequest(req);
237
+ const { toolName, arguments: args } = req.body;
238
+ if (!toolName) {
239
+ return res.status(400).json({
240
+ success: false,
241
+ error: "toolName is required"
242
+ });
243
+ }
244
+ const result = await this.callTool(toolName, args || {});
245
+ const response = {
246
+ success: true,
247
+ result
248
+ };
249
+ res.json(response);
250
+ } catch (error) {
251
+ console.error("Error calling tool:", error);
252
+ const response = {
253
+ success: false,
254
+ error: error instanceof Error ? error.message : "Unknown error"
255
+ };
256
+ res.status(500).json(response);
257
+ }
258
+ });
259
+ }
260
+ async initialize() {
261
+ await this.mcpServer.initialize();
262
+ this.transport = new InMemoryTransport();
263
+ const server = this.mcpServer.server;
264
+ if (server) {
265
+ await server.connect(this.transport);
266
+ }
267
+ this.isInitialized = true;
268
+ console.log("MCP Gateway initialized");
269
+ }
270
+ async start() {
271
+ await this.initialize();
272
+ return new Promise((resolve2) => {
273
+ this.httpServer = this.app.listen(this.config.port, this.config.host, () => {
274
+ console.log(`MCP Gateway listening on http://${this.config.host}:${this.config.port}`);
275
+ resolve2();
276
+ });
277
+ });
278
+ }
279
+ async close() {
280
+ if (this.httpServer) {
281
+ await new Promise((resolve2, reject) => {
282
+ this.httpServer.close((err) => {
283
+ if (err) {
284
+ console.error("Error closing HTTP server:", err);
285
+ reject(err);
286
+ } else {
287
+ console.log("HTTP server closed");
288
+ resolve2();
289
+ }
290
+ });
291
+ });
292
+ }
293
+ await this.mcpServer.close();
294
+ console.log("MCP Gateway closed");
295
+ }
296
+ };
297
+
298
+ // src/cli.ts
299
+ import { config } from "dotenv";
300
+ import { resolve } from "path";
301
+ config({ path: resolve(process.cwd(), ".env") });
302
+ var isShuttingDown = false;
303
+ process.on("unhandledRejection", (reason, promise) => {
304
+ console.error("Unhandled Rejection at:", promise, "reason:", reason);
305
+ process.exit(1);
306
+ });
307
+ process.on("uncaughtException", (error) => {
308
+ console.error("Uncaught Exception:", error);
309
+ process.exit(1);
310
+ });
311
+ async function main() {
312
+ const gatewayConfig = {
313
+ port: parseInt(process.env.MCP_GATEWAY_PORT || "7081", 10),
314
+ host: process.env.MCP_GATEWAY_HOST || "0.0.0.0",
315
+ rxdbServerUrl: process.env.RXDB_SERVER_URL || "",
316
+ authToken: process.env.RXDB_AUTH_TOKEN || "",
317
+ domainId: process.env.RXDB_DOMAIN_ID || "",
318
+ projectPath: process.env.PROJECT_PATH,
319
+ userId: process.env.USER_ID,
320
+ orgId: process.env.ORG_ID,
321
+ corsOrigins: process.env.CORS_ORIGINS?.split(",")
322
+ };
323
+ if (!gatewayConfig.rxdbServerUrl) {
324
+ console.error("ERROR: RXDB_SERVER_URL is required");
325
+ process.exit(1);
326
+ }
327
+ if (!gatewayConfig.authToken) {
328
+ console.error("ERROR: RXDB_AUTH_TOKEN is required");
329
+ process.exit(1);
330
+ }
331
+ if (!gatewayConfig.domainId) {
332
+ console.error("ERROR: RXDB_DOMAIN_ID is required");
333
+ process.exit(1);
334
+ }
335
+ console.log("MCP Gateway starting with configuration:");
336
+ console.log(` Port: ${gatewayConfig.port}`);
337
+ console.log(` Host: ${gatewayConfig.host}`);
338
+ console.log(` RxDB Server URL: ${gatewayConfig.rxdbServerUrl}`);
339
+ console.log(` Domain ID: ${gatewayConfig.domainId}`);
340
+ console.log(` Project Path: ${gatewayConfig.projectPath || "not set"}`);
341
+ console.log(` User ID: ${gatewayConfig.userId || "not set"}`);
342
+ console.log(` Org ID: ${gatewayConfig.orgId || "not set"}`);
343
+ console.log(` CORS Origins: ${gatewayConfig.corsOrigins?.join(", ") || "not set"}`);
344
+ const server = new MCPGatewayServer(gatewayConfig);
345
+ const gracefulShutdown = async (signal) => {
346
+ if (isShuttingDown) {
347
+ console.log("Shutdown already in progress, ignoring signal:", signal);
348
+ return;
349
+ }
350
+ isShuttingDown = true;
351
+ console.log(`
352
+ Received ${signal}, shutting down gracefully...`);
353
+ try {
354
+ await server.close();
355
+ console.log("Server closed successfully");
356
+ process.exit(0);
357
+ } catch (error) {
358
+ console.error("Error during shutdown:", error);
359
+ process.exit(1);
360
+ }
361
+ };
362
+ process.on("SIGINT", () => gracefulShutdown("SIGINT"));
363
+ process.on("SIGTERM", () => gracefulShutdown("SIGTERM"));
364
+ try {
365
+ await server.start();
366
+ } catch (error) {
367
+ console.error("Failed to start MCP Gateway:", error);
368
+ process.exit(1);
369
+ }
370
+ }
371
+ main();
372
+ //# sourceMappingURL=cli.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server.ts","../src/InMemoryTransport.ts","../src/cli.ts"],"sourcesContent":["// Copyright 2026 Epic Digital Interactive Media LLC\n// SPDX-License-Identifier: Apache-2.0\n\nimport express, { Express, Request, Response } from 'express'\nimport cors from 'cors'\nimport { FlowStateMCPServer } from '@epicdm/flowstate-mcp'\nimport { InMemoryTransport } from './InMemoryTransport'\nimport type { MCPGatewayConfig, ToolCallRequest, ToolCallResponse } from './types'\n\nexport class MCPGatewayServer {\n private app: Express\n private mcpServer: FlowStateMCPServer\n private config: MCPGatewayConfig\n private isInitialized = false\n private httpServer?: ReturnType<Express['listen']>\n private transport?: InMemoryTransport\n\n constructor(config: MCPGatewayConfig) {\n this.config = config\n this.app = express()\n\n // Initialize MCP Server\n this.mcpServer = new FlowStateMCPServer({\n rxdbServerUrl: config.rxdbServerUrl,\n domainId: config.domainId,\n projectPath: config.projectPath || process.cwd(),\n ...(config.userId && { userId: config.userId }),\n ...(config.orgId && { orgId: config.orgId }),\n } as any)\n\n this.setupMiddleware()\n this.setupRoutes()\n }\n\n /**\n * Get list of tools from MCP server\n *\n * WARNING: This method accesses internal MCP server API via type casting.\n * This is necessary because FlowStateMCPServer doesn't expose a public method\n * for listing tools. The underlying server.request() method is used directly.\n *\n * RISKS:\n * - Internal API may change without notice in future versions\n * - Type casting bypasses TypeScript safety checks\n * - May break if FlowStateMCPServer implementation changes\n *\n * TODO: Consider requesting a public API method in FlowStateMCPServer\n * for listing and calling tools to avoid internal API access.\n */\n private async listTools(): Promise<any[]> {\n if (!this.transport) {\n return []\n }\n\n // Send request through transport\n const request = {\n jsonrpc: '2.0' as const,\n id: Date.now(),\n method: 'tools/list' as const,\n }\n\n const response: any = await this.transport.sendRequest(request)\n\n if ('error' in response) {\n throw new Error(response.error.message || 'Failed to list tools')\n }\n\n return response.result?.tools || []\n }\n\n /**\n * Call a tool on the MCP server\n *\n * WARNING: This method accesses internal MCP server API via type casting.\n * This is necessary because FlowStateMCPServer doesn't expose a public method\n * for calling tools. The underlying server.request() method is used directly.\n *\n * RISKS:\n * - Internal API may change without notice in future versions\n * - Type casting bypasses TypeScript safety checks\n * - May break if FlowStateMCPServer implementation changes\n *\n * TODO: Consider requesting a public API method in FlowStateMCPServer\n * for listing and calling tools to avoid internal API access.\n *\n * NOTE: The MCP SDK's server.request() method appears to require the request\n * object to be passed twice (once as the request, once as params). This seems\n * to be how the underlying MCP SDK expects the call to be structured based on\n * the protocol specification.\n */\n private async callTool(toolName: string, args: Record<string, any>): Promise<any> {\n if (!this.transport) {\n throw new Error('MCP server not available')\n }\n\n // Send request through transport\n const request = {\n jsonrpc: '2.0' as const,\n id: Date.now(),\n method: 'tools/call' as const,\n params: {\n name: toolName,\n arguments: args,\n },\n }\n\n const response: any = await this.transport.sendRequest(request)\n\n if ('error' in response) {\n throw new Error(response.error.message || 'Failed to call tool')\n }\n\n return response.result?.content?.[0]?.text || response.result\n }\n\n private setupMiddleware(): void {\n // CORS\n this.app.use(\n cors({\n origin: this.config.corsOrigins || '*',\n methods: ['GET', 'POST', 'OPTIONS'],\n allowedHeaders: ['Content-Type', 'Authorization'],\n })\n )\n\n // Body parsing\n this.app.use(express.json())\n this.app.use(express.urlencoded({ extended: true }))\n\n // Request logging\n this.app.use((req, res, next) => {\n console.log(`${new Date().toISOString()} ${req.method} ${req.path}`)\n next()\n })\n }\n\n /**\n * Extract and forward auth token from request to MCP server\n *\n * This enables per-request auth so each API call can use its own token,\n * rather than relying on the initial config token.\n */\n private updateAuthFromRequest(req: Request): void {\n const authHeader = req.headers['authorization']\n if (!authHeader) {\n console.log('[MCP Gateway] No Authorization header in request')\n return\n }\n\n const token = authHeader.toString().replace('Bearer ', '')\n if (!token) {\n console.log('[MCP Gateway] Empty token after Bearer prefix removal')\n return\n }\n\n // Only accept valid-looking tokens (JWT or API tokens)\n if (!token.startsWith('eyJ') && !token.startsWith('epic_')) {\n console.log(`[MCP Gateway] Invalid token format (starts with: ${token.substring(0, 10)}...)`)\n return\n }\n\n try {\n ;(this.mcpServer as any).config.authToken = token\n console.log('[MCP Gateway] Auth token updated from request')\n } catch (error) {\n console.error('[MCP Gateway] Failed to update auth config:', error)\n }\n }\n\n private setupRoutes(): void {\n // Health check\n this.app.get('/health', (req: Request, res: Response) => {\n res.json({\n status: 'ok',\n initialized: this.isInitialized,\n timestamp: new Date().toISOString(),\n })\n })\n\n // List available tools\n this.app.get('/mcp/tools', async (req: Request, res: Response) => {\n try {\n if (!this.isInitialized) {\n return res.status(503).json({\n error: 'Server not initialized',\n })\n }\n\n // Forward per-request auth to MCP server\n this.updateAuthFromRequest(req)\n\n const tools = await this.listTools()\n res.json({ tools })\n } catch (error) {\n console.error('Error listing tools:', error)\n res.status(500).json({\n error: error instanceof Error ? error.message : 'Unknown error',\n })\n }\n })\n\n // Execute a tool\n this.app.post('/mcp/tools/call', async (req: Request, res: Response) => {\n try {\n if (!this.isInitialized) {\n return res.status(503).json({\n success: false,\n error: 'Server not initialized',\n })\n }\n\n // Forward per-request auth to MCP server\n this.updateAuthFromRequest(req)\n\n const { toolName, arguments: args } = req.body as ToolCallRequest\n\n if (!toolName) {\n return res.status(400).json({\n success: false,\n error: 'toolName is required',\n })\n }\n\n const result = await this.callTool(toolName, args || {})\n\n const response: ToolCallResponse = {\n success: true,\n result,\n }\n\n res.json(response)\n } catch (error) {\n console.error('Error calling tool:', error)\n const response: ToolCallResponse = {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error',\n }\n res.status(500).json(response)\n }\n })\n }\n\n async initialize(): Promise<void> {\n await this.mcpServer.initialize()\n\n // Connect the MCP server to an in-memory transport\n // This is required for the MCP SDK to handle requests\n this.transport = new InMemoryTransport()\n const server = (this.mcpServer as any).server\n if (server) {\n await server.connect(this.transport)\n }\n\n this.isInitialized = true\n console.log('MCP Gateway initialized')\n }\n\n async start(): Promise<void> {\n await this.initialize()\n\n return new Promise(resolve => {\n this.httpServer = this.app.listen(this.config.port, this.config.host, () => {\n console.log(`MCP Gateway listening on http://${this.config.host}:${this.config.port}`)\n resolve()\n })\n })\n }\n\n async close(): Promise<void> {\n // Close HTTP server first\n if (this.httpServer) {\n await new Promise<void>((resolve, reject) => {\n this.httpServer!.close(err => {\n if (err) {\n console.error('Error closing HTTP server:', err)\n reject(err)\n } else {\n console.log('HTTP server closed')\n resolve()\n }\n })\n })\n }\n\n // Then close MCP server\n await this.mcpServer.close()\n console.log('MCP Gateway closed')\n }\n}\n","// Copyright 2026 Epic Digital Interactive Media LLC\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';\nimport type { JSONRPCMessage, JSONRPCRequest, JSONRPCResponse, JSONRPCErrorResponse } from '@modelcontextprotocol/sdk/types.js';\nimport { EventEmitter } from 'events';\n\n/**\n * In-Memory Transport for programmatic MCP server usage\n *\n * This transport creates a bidirectional message channel that allows\n * the MCP server to be used programmatically without stdio/SSE.\n */\nexport class InMemoryTransport implements Transport {\n sessionId?: string;\n onclose?: () => void;\n onerror?: (error: Error) => void;\n onmessage?: (message: JSONRPCMessage) => void;\n\n private started = false;\n private emitter = new EventEmitter();\n private responseHandlers = new Map<string | number, (response: JSONRPCMessage) => void>();\n\n async start(): Promise<void> {\n this.started = true;\n this.sessionId = `inmemory-${Date.now()}-${Math.random().toString(36).substring(7)}`;\n }\n\n async send(message: JSONRPCMessage): Promise<void> {\n if (!this.started) {\n throw new Error('Transport not started');\n }\n\n // If this is a response (has 'result' or 'error' and 'id')\n if ('result' in message || 'error' in message) {\n const response = message as JSONRPCResponse | JSONRPCErrorResponse;\n const handler = this.responseHandlers.get(response.id!);\n if (handler) {\n handler(message);\n this.responseHandlers.delete(response.id!);\n }\n }\n }\n\n async close(): Promise<void> {\n this.started = false;\n this.responseHandlers.clear();\n this.onclose?.();\n }\n\n setProtocolVersion?(version: string): void {\n // No-op for in-memory transport\n }\n\n /**\n * Send a request and wait for response\n * Used by the gateway to make programmatic requests\n */\n async sendRequest(request: JSONRPCMessage): Promise<JSONRPCMessage> {\n if (!this.started) {\n throw new Error('Transport not started');\n }\n\n return new Promise((resolve, reject) => {\n const req = request as JSONRPCRequest;\n const timeout = setTimeout(() => {\n this.responseHandlers.delete(req.id);\n reject(new Error('Request timeout'));\n }, 60000);\n\n this.responseHandlers.set(req.id, (response) => {\n clearTimeout(timeout);\n resolve(response);\n });\n\n // Route request to server's message handler\n if (this.onmessage) {\n this.onmessage(request);\n } else {\n reject(new Error('Transport not connected to server'));\n }\n });\n }\n}\n","#!/usr/bin/env node\n// Copyright 2026 Epic Digital Interactive Media LLC\n// SPDX-License-Identifier: Apache-2.0\n\nimport { MCPGatewayServer } from './server';\nimport { config } from 'dotenv';\nimport { resolve } from 'path';\n\n// Load environment variables\nconfig({ path: resolve(process.cwd(), '.env') });\n\n// Shutdown guard to prevent race conditions\nlet isShuttingDown = false;\n\n// Global error handlers\nprocess.on('unhandledRejection', (reason, promise) => {\n console.error('Unhandled Rejection at:', promise, 'reason:', reason);\n process.exit(1);\n});\n\nprocess.on('uncaughtException', (error) => {\n console.error('Uncaught Exception:', error);\n process.exit(1);\n});\n\nasync function main() {\n const gatewayConfig = {\n port: parseInt(process.env.MCP_GATEWAY_PORT || '7081', 10),\n host: process.env.MCP_GATEWAY_HOST || '0.0.0.0',\n rxdbServerUrl: process.env.RXDB_SERVER_URL || '',\n authToken: process.env.RXDB_AUTH_TOKEN || '',\n domainId: process.env.RXDB_DOMAIN_ID || '',\n projectPath: process.env.PROJECT_PATH,\n userId: process.env.USER_ID,\n orgId: process.env.ORG_ID,\n corsOrigins: process.env.CORS_ORIGINS?.split(','),\n };\n\n // Validate required config\n if (!gatewayConfig.rxdbServerUrl) {\n console.error('ERROR: RXDB_SERVER_URL is required');\n process.exit(1);\n }\n if (!gatewayConfig.authToken) {\n console.error('ERROR: RXDB_AUTH_TOKEN is required');\n process.exit(1);\n }\n if (!gatewayConfig.domainId) {\n console.error('ERROR: RXDB_DOMAIN_ID is required');\n process.exit(1);\n }\n\n // Log non-sensitive configuration on startup\n console.log('MCP Gateway starting with configuration:');\n console.log(` Port: ${gatewayConfig.port}`);\n console.log(` Host: ${gatewayConfig.host}`);\n console.log(` RxDB Server URL: ${gatewayConfig.rxdbServerUrl}`);\n console.log(` Domain ID: ${gatewayConfig.domainId}`);\n console.log(` Project Path: ${gatewayConfig.projectPath || 'not set'}`);\n console.log(` User ID: ${gatewayConfig.userId || 'not set'}`);\n console.log(` Org ID: ${gatewayConfig.orgId || 'not set'}`);\n console.log(` CORS Origins: ${gatewayConfig.corsOrigins?.join(', ') || 'not set'}`);\n\n const server = new MCPGatewayServer(gatewayConfig);\n\n // Graceful shutdown handler\n const gracefulShutdown = async (signal: string) => {\n if (isShuttingDown) {\n console.log('Shutdown already in progress, ignoring signal:', signal);\n return;\n }\n\n isShuttingDown = true;\n console.log(`\\nReceived ${signal}, shutting down gracefully...`);\n\n try {\n await server.close();\n console.log('Server closed successfully');\n process.exit(0);\n } catch (error) {\n console.error('Error during shutdown:', error);\n process.exit(1);\n }\n };\n\n // Register signal handlers\n process.on('SIGINT', () => gracefulShutdown('SIGINT'));\n process.on('SIGTERM', () => gracefulShutdown('SIGTERM'));\n\n try {\n await server.start();\n } catch (error) {\n console.error('Failed to start MCP Gateway:', error);\n process.exit(1);\n }\n}\n\nmain();\n"],"mappings":";;;AAGA,OAAO,aAA6C;AACpD,OAAO,UAAU;AACjB,SAAS,0BAA0B;;;ACAnC,SAAS,oBAAoB;AAQtB,IAAM,oBAAN,MAA6C;AAAA,EAClD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEQ,UAAU;AAAA,EACV,UAAU,IAAI,aAAa;AAAA,EAC3B,mBAAmB,oBAAI,IAAyD;AAAA,EAExF,MAAM,QAAuB;AAC3B,SAAK,UAAU;AACf,SAAK,YAAY,YAAY,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,CAAC,CAAC;AAAA,EACpF;AAAA,EAEA,MAAM,KAAK,SAAwC;AACjD,QAAI,CAAC,KAAK,SAAS;AACjB,YAAM,IAAI,MAAM,uBAAuB;AAAA,IACzC;AAGA,QAAI,YAAY,WAAW,WAAW,SAAS;AAC7C,YAAM,WAAW;AACjB,YAAM,UAAU,KAAK,iBAAiB,IAAI,SAAS,EAAG;AACtD,UAAI,SAAS;AACX,gBAAQ,OAAO;AACf,aAAK,iBAAiB,OAAO,SAAS,EAAG;AAAA,MAC3C;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,QAAuB;AAC3B,SAAK,UAAU;AACf,SAAK,iBAAiB,MAAM;AAC5B,SAAK,UA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ACjB,YAAQ,IAAI;AAAA,WAAc,MAAM,+BAA+B;AAE/D,QAAI;AACF,YAAM,OAAO,MAAM;AACnB,cAAQ,IAAI,4BAA4B;AACxC,cAAQ,KAAK,CAAC;AAAA,IAChB,SAAS,OAAO;AACd,cAAQ,MAAM,0BAA0B,KAAK;AAC7C,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AAGA,UAAQ,GAAG,UAAU,MAAM,iBAAiB,QAAQ,CAAC;AACrD,UAAQ,GAAG,WAAW,MAAM,iBAAiB,SAAS,CAAC;AAEvD,MAAI;AACF,UAAM,OAAO,MAAM;AAAA,EACrB,SAAS,OAAO;AACd,YAAQ,MAAM,gCAAgC,KAAK;AACnD,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AAEA,KAAK;","names":["resolve","config","resolve"]}
@@ -0,0 +1,86 @@
1
+ interface MCPGatewayConfig {
2
+ port: number;
3
+ host: string;
4
+ rxdbServerUrl: string;
5
+ authToken: string;
6
+ domainId: string;
7
+ projectPath?: string;
8
+ userId?: string;
9
+ orgId?: string;
10
+ corsOrigins?: string[];
11
+ }
12
+ interface ToolDefinition {
13
+ name: string;
14
+ description: string;
15
+ inputSchema: any;
16
+ }
17
+ interface ToolCallRequest {
18
+ toolName: string;
19
+ arguments: Record<string, any>;
20
+ }
21
+ interface ToolCallResponse {
22
+ success: boolean;
23
+ result?: any;
24
+ error?: string;
25
+ }
26
+
27
+ declare class MCPGatewayServer {
28
+ private app;
29
+ private mcpServer;
30
+ private config;
31
+ private isInitialized;
32
+ private httpServer?;
33
+ private transport?;
34
+ constructor(config: MCPGatewayConfig);
35
+ /**
36
+ * Get list of tools from MCP server
37
+ *
38
+ * WARNING: This method accesses internal MCP server API via type casting.
39
+ * This is necessary because FlowStateMCPServer doesn't expose a public method
40
+ * for listing tools. The underlying server.request() method is used directly.
41
+ *
42
+ * RISKS:
43
+ * - Internal API may change without notice in future versions
44
+ * - Type casting bypasses TypeScript safety checks
45
+ * - May break if FlowStateMCPServer implementation changes
46
+ *
47
+ * TODO: Consider requesting a public API method in FlowStateMCPServer
48
+ * for listing and calling tools to avoid internal API access.
49
+ */
50
+ private listTools;
51
+ /**
52
+ * Call a tool on the MCP server
53
+ *
54
+ * WARNING: This method accesses internal MCP server API via type casting.
55
+ * This is necessary because FlowStateMCPServer doesn't expose a public method
56
+ * for calling tools. The underlying server.request() method is used directly.
57
+ *
58
+ * RISKS:
59
+ * - Internal API may change without notice in future versions
60
+ * - Type casting bypasses TypeScript safety checks
61
+ * - May break if FlowStateMCPServer implementation changes
62
+ *
63
+ * TODO: Consider requesting a public API method in FlowStateMCPServer
64
+ * for listing and calling tools to avoid internal API access.
65
+ *
66
+ * NOTE: The MCP SDK's server.request() method appears to require the request
67
+ * object to be passed twice (once as the request, once as params). This seems
68
+ * to be how the underlying MCP SDK expects the call to be structured based on
69
+ * the protocol specification.
70
+ */
71
+ private callTool;
72
+ private setupMiddleware;
73
+ /**
74
+ * Extract and forward auth token from request to MCP server
75
+ *
76
+ * This enables per-request auth so each API call can use its own token,
77
+ * rather than relying on the initial config token.
78
+ */
79
+ private updateAuthFromRequest;
80
+ private setupRoutes;
81
+ initialize(): Promise<void>;
82
+ start(): Promise<void>;
83
+ close(): Promise<void>;
84
+ }
85
+
86
+ export { type MCPGatewayConfig, MCPGatewayServer, type ToolCallRequest, type ToolCallResponse, type ToolDefinition };
@@ -0,0 +1,86 @@
1
+ interface MCPGatewayConfig {
2
+ port: number;
3
+ host: string;
4
+ rxdbServerUrl: string;
5
+ authToken: string;
6
+ domainId: string;
7
+ projectPath?: string;
8
+ userId?: string;
9
+ orgId?: string;
10
+ corsOrigins?: string[];
11
+ }
12
+ interface ToolDefinition {
13
+ name: string;
14
+ description: string;
15
+ inputSchema: any;
16
+ }
17
+ interface ToolCallRequest {
18
+ toolName: string;
19
+ arguments: Record<string, any>;
20
+ }
21
+ interface ToolCallResponse {
22
+ success: boolean;
23
+ result?: any;
24
+ error?: string;
25
+ }
26
+
27
+ declare class MCPGatewayServer {
28
+ private app;
29
+ private mcpServer;
30
+ private config;
31
+ private isInitialized;
32
+ private httpServer?;
33
+ private transport?;
34
+ constructor(config: MCPGatewayConfig);
35
+ /**
36
+ * Get list of tools from MCP server
37
+ *
38
+ * WARNING: This method accesses internal MCP server API via type casting.
39
+ * This is necessary because FlowStateMCPServer doesn't expose a public method
40
+ * for listing tools. The underlying server.request() method is used directly.
41
+ *
42
+ * RISKS:
43
+ * - Internal API may change without notice in future versions
44
+ * - Type casting bypasses TypeScript safety checks
45
+ * - May break if FlowStateMCPServer implementation changes
46
+ *
47
+ * TODO: Consider requesting a public API method in FlowStateMCPServer
48
+ * for listing and calling tools to avoid internal API access.
49
+ */
50
+ private listTools;
51
+ /**
52
+ * Call a tool on the MCP server
53
+ *
54
+ * WARNING: This method accesses internal MCP server API via type casting.
55
+ * This is necessary because FlowStateMCPServer doesn't expose a public method
56
+ * for calling tools. The underlying server.request() method is used directly.
57
+ *
58
+ * RISKS:
59
+ * - Internal API may change without notice in future versions
60
+ * - Type casting bypasses TypeScript safety checks
61
+ * - May break if FlowStateMCPServer implementation changes
62
+ *
63
+ * TODO: Consider requesting a public API method in FlowStateMCPServer
64
+ * for listing and calling tools to avoid internal API access.
65
+ *
66
+ * NOTE: The MCP SDK's server.request() method appears to require the request
67
+ * object to be passed twice (once as the request, once as params). This seems
68
+ * to be how the underlying MCP SDK expects the call to be structured based on
69
+ * the protocol specification.
70
+ */
71
+ private callTool;
72
+ private setupMiddleware;
73
+ /**
74
+ * Extract and forward auth token from request to MCP server
75
+ *
76
+ * This enables per-request auth so each API call can use its own token,
77
+ * rather than relying on the initial config token.
78
+ */
79
+ private updateAuthFromRequest;
80
+ private setupRoutes;
81
+ initialize(): Promise<void>;
82
+ start(): Promise<void>;
83
+ close(): Promise<void>;
84
+ }
85
+
86
+ export { type MCPGatewayConfig, MCPGatewayServer, type ToolCallRequest, type ToolCallResponse, type ToolDefinition };