@agimon-ai/mcp-proxy 0.4.8 → 0.4.10

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.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const require_src = require('./src-CTeN-GJT.cjs');
2
+ const require_src = require('./src-5rGDc0sh.cjs');
3
3
  let node_crypto = require("node:crypto");
4
4
  let node_fs_promises = require("node:fs/promises");
5
5
  let node_path = require("node:path");
@@ -138,6 +138,27 @@ function resolveWorkspaceRoot(startPath = process.env.PROJECT_PATH || process.cw
138
138
  current = parent;
139
139
  }
140
140
  }
141
+ const PROCESS_REGISTRY_SERVICE_HTTP$1 = "mcp-proxy-http";
142
+ async function findExistingHealthyRuntime(workspaceRoot) {
143
+ const match = (await new __agimon_ai_foundation_process_registry.ProcessRegistryService(process.env.PROCESS_REGISTRY_PATH).listProcesses({
144
+ repositoryPath: workspaceRoot,
145
+ serviceName: PROCESS_REGISTRY_SERVICE_HTTP$1
146
+ }))[0];
147
+ if (!match?.host || !match?.port) return null;
148
+ try {
149
+ const healthUrl = `http://${match.host}:${match.port}/health`;
150
+ if ((await fetch(healthUrl)).ok) {
151
+ const metadata = match.metadata;
152
+ return {
153
+ host: match.host,
154
+ port: match.port,
155
+ serverId: metadata?.serverId ?? "unknown",
156
+ workspaceRoot
157
+ };
158
+ }
159
+ } catch {}
160
+ return null;
161
+ }
141
162
  function resolveSiblingRegistryPath(registryPath, fileName) {
142
163
  if (!registryPath) return;
143
164
  const resolved = node_path.default.resolve(registryPath);
@@ -217,11 +238,33 @@ function spawnBackgroundRuntime(args, env, cwd) {
217
238
  child.unref();
218
239
  return child;
219
240
  }
241
+ async function stopExistingRuntime(runtimeStateService, serverId, host, port) {
242
+ const runtimes = await runtimeStateService.list();
243
+ const targetHost = host || DEFAULT_HOST$1;
244
+ const match = runtimes.find((r) => {
245
+ if (serverId && r.serverId === serverId) return true;
246
+ if (port !== void 0 && r.host === targetHost && r.port === port) return true;
247
+ return false;
248
+ });
249
+ if (!match) return;
250
+ const stopService = new require_src.StopServerService(runtimeStateService);
251
+ try {
252
+ await stopService.stop({
253
+ serverId: match.serverId,
254
+ force: true
255
+ });
256
+ } catch {
257
+ await runtimeStateService.remove(match.serverId);
258
+ }
259
+ }
220
260
  async function prestartHttpRuntime(options) {
221
261
  const serverId = options.id || require_src.generateServerId();
222
262
  const timeoutMs = parseTimeoutMs(options.timeoutMs);
223
263
  const registryPath = options.registryPath || options.registryDir;
224
264
  const workspaceRoot = resolveWorkspaceRoot();
265
+ const existing = await findExistingHealthyRuntime(workspaceRoot);
266
+ if (existing) return existing;
267
+ await stopExistingRuntime(new require_src.RuntimeStateService(), options.id, options.host, options.port);
225
268
  const childEnv = {
226
269
  ...process.env,
227
270
  ...registryPath ? {
@@ -261,7 +304,7 @@ async function prestartHttpRuntime(options) {
261
304
  workspaceRoot
262
305
  };
263
306
  } catch (error) {
264
- throw new Error(`Failed to prestart HTTP runtime '${serverId}': ${error instanceof Error ? error.message : String(error)}`);
307
+ throw new Error(`Failed to prestart HTTP runtime '${serverId}': ${error instanceof Error ? error.message : String(error)}`, { cause: error });
265
308
  }
266
309
  }
267
310
  const prestartHttpCommand = new commander.Command("prestart-http").description("Start an mcp-proxy HTTP runtime in the background and wait until it is healthy").option("--id <id>", "Server identifier to assign to the runtime").option("--host <host>", "Host to bind to", DEFAULT_HOST$1).option("-p, --port <port>", "Preferred HTTP port for the runtime", (value) => Number.parseInt(value, 10)).option("-c, --config <path>", "Path to MCP server configuration file").option("--no-cache", "Disable configuration caching, always reload from config file").option("--definitions-cache <path>", "Path to prefetched tool/prompt/skill definitions cache file").option("--clear-definitions-cache", "Delete definitions cache before startup", false).option("--proxy-mode <mode>", "How mcp-proxy exposes downstream tools: meta, flat, or search", "meta").option("--registry-path <path>", "Custom registry path or directory for service discovery").option("--registry-dir <path>", "Custom registry directory for service discovery").option("--timeout-ms <ms>", "How long to wait for the runtime to become healthy", String(DEFAULT_TIMEOUT_MS)).action(async (options) => {
@@ -272,7 +315,7 @@ const prestartHttpCommand = new commander.Command("prestart-http").description("
272
315
  process.stdout.write(`runtimeUrl=http://${host}:${port}\n`);
273
316
  process.stdout.write(`workspaceRoot=${workspaceRoot}\n`);
274
317
  } catch (error) {
275
- throw new Error(`Failed to prestart HTTP runtime '${options.id || "generated-server-id"}': ${error instanceof Error ? error.message : String(error)}`);
318
+ throw new Error(`Failed to prestart HTTP runtime '${options.id || "generated-server-id"}': ${error instanceof Error ? error.message : String(error)}`, { cause: error });
276
319
  }
277
320
  });
278
321
 
@@ -672,7 +715,24 @@ async function startStdioTransport(serverOptions) {
672
715
  }
673
716
  async function startSseTransport(serverOptions, config) {
674
717
  try {
675
- await startServer(new require_src.SseTransportHandler(await require_src.createServer(serverOptions), config));
718
+ const requestedPort = config.port;
719
+ const portRange = requestedPort !== void 0 ? {
720
+ min: requestedPort,
721
+ max: requestedPort
722
+ } : __agimon_ai_foundation_port_registry.DEFAULT_PORT_RANGE;
723
+ const portLease = await createPortRegistryLease("mcp-proxy-sse", config.host ?? DEFAULT_HOST, requestedPort, serverOptions.serverId ?? require_src.generateServerId(), TRANSPORT_TYPE_SSE, void 0, portRange);
724
+ const resolvedConfig = {
725
+ ...config,
726
+ port: portLease.port
727
+ };
728
+ const handler = new require_src.SseTransportHandler(await require_src.createServer(serverOptions), resolvedConfig);
729
+ const shutdown = async () => {
730
+ await handler.stop();
731
+ await portLease.release();
732
+ };
733
+ process.on("SIGINT", shutdown);
734
+ process.on("SIGTERM", shutdown);
735
+ await startServer(handler);
676
736
  } catch (error) {
677
737
  throw new Error(`Failed to start SSE transport: ${toErrorMessage$9(error)}`);
678
738
  }
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { D as findConfigFile, E as generateServerId, T as DefinitionsCacheService, d as version, f as StdioHttpTransportHandler, h as HttpTransportHandler, m as SseTransportHandler, n as createServer, o as createProxyIoCContainer, p as StdioTransportHandler, r as createSessionServer, t as TRANSPORT_MODE, u as initializeSharedServices, v as RuntimeStateService } from "./src-koR2D9Bb.mjs";
2
+ import { D as findConfigFile, E as generateServerId, T as DefinitionsCacheService, _ as StopServerService, d as version, f as StdioHttpTransportHandler, h as HttpTransportHandler, m as SseTransportHandler, n as createServer, o as createProxyIoCContainer, p as StdioTransportHandler, r as createSessionServer, t as TRANSPORT_MODE, u as initializeSharedServices, v as RuntimeStateService } from "./src-BErGW2ax.mjs";
3
3
  import { randomUUID } from "node:crypto";
4
4
  import { access, writeFile } from "node:fs/promises";
5
5
  import path, { join, resolve } from "node:path";
@@ -137,6 +137,27 @@ function resolveWorkspaceRoot(startPath = process.env.PROJECT_PATH || process.cw
137
137
  current = parent;
138
138
  }
139
139
  }
140
+ const PROCESS_REGISTRY_SERVICE_HTTP$1 = "mcp-proxy-http";
141
+ async function findExistingHealthyRuntime(workspaceRoot) {
142
+ const match = (await new ProcessRegistryService(process.env.PROCESS_REGISTRY_PATH).listProcesses({
143
+ repositoryPath: workspaceRoot,
144
+ serviceName: PROCESS_REGISTRY_SERVICE_HTTP$1
145
+ }))[0];
146
+ if (!match?.host || !match?.port) return null;
147
+ try {
148
+ const healthUrl = `http://${match.host}:${match.port}/health`;
149
+ if ((await fetch(healthUrl)).ok) {
150
+ const metadata = match.metadata;
151
+ return {
152
+ host: match.host,
153
+ port: match.port,
154
+ serverId: metadata?.serverId ?? "unknown",
155
+ workspaceRoot
156
+ };
157
+ }
158
+ } catch {}
159
+ return null;
160
+ }
140
161
  function resolveSiblingRegistryPath(registryPath, fileName) {
141
162
  if (!registryPath) return;
142
163
  const resolved = path.resolve(registryPath);
@@ -216,11 +237,33 @@ function spawnBackgroundRuntime(args, env, cwd) {
216
237
  child.unref();
217
238
  return child;
218
239
  }
240
+ async function stopExistingRuntime(runtimeStateService, serverId, host, port) {
241
+ const runtimes = await runtimeStateService.list();
242
+ const targetHost = host || DEFAULT_HOST$1;
243
+ const match = runtimes.find((r) => {
244
+ if (serverId && r.serverId === serverId) return true;
245
+ if (port !== void 0 && r.host === targetHost && r.port === port) return true;
246
+ return false;
247
+ });
248
+ if (!match) return;
249
+ const stopService = new StopServerService(runtimeStateService);
250
+ try {
251
+ await stopService.stop({
252
+ serverId: match.serverId,
253
+ force: true
254
+ });
255
+ } catch {
256
+ await runtimeStateService.remove(match.serverId);
257
+ }
258
+ }
219
259
  async function prestartHttpRuntime(options) {
220
260
  const serverId = options.id || generateServerId();
221
261
  const timeoutMs = parseTimeoutMs(options.timeoutMs);
222
262
  const registryPath = options.registryPath || options.registryDir;
223
263
  const workspaceRoot = resolveWorkspaceRoot();
264
+ const existing = await findExistingHealthyRuntime(workspaceRoot);
265
+ if (existing) return existing;
266
+ await stopExistingRuntime(new RuntimeStateService(), options.id, options.host, options.port);
224
267
  const childEnv = {
225
268
  ...process.env,
226
269
  ...registryPath ? {
@@ -260,7 +303,7 @@ async function prestartHttpRuntime(options) {
260
303
  workspaceRoot
261
304
  };
262
305
  } catch (error) {
263
- throw new Error(`Failed to prestart HTTP runtime '${serverId}': ${error instanceof Error ? error.message : String(error)}`);
306
+ throw new Error(`Failed to prestart HTTP runtime '${serverId}': ${error instanceof Error ? error.message : String(error)}`, { cause: error });
264
307
  }
265
308
  }
266
309
  const prestartHttpCommand = new Command("prestart-http").description("Start an mcp-proxy HTTP runtime in the background and wait until it is healthy").option("--id <id>", "Server identifier to assign to the runtime").option("--host <host>", "Host to bind to", DEFAULT_HOST$1).option("-p, --port <port>", "Preferred HTTP port for the runtime", (value) => Number.parseInt(value, 10)).option("-c, --config <path>", "Path to MCP server configuration file").option("--no-cache", "Disable configuration caching, always reload from config file").option("--definitions-cache <path>", "Path to prefetched tool/prompt/skill definitions cache file").option("--clear-definitions-cache", "Delete definitions cache before startup", false).option("--proxy-mode <mode>", "How mcp-proxy exposes downstream tools: meta, flat, or search", "meta").option("--registry-path <path>", "Custom registry path or directory for service discovery").option("--registry-dir <path>", "Custom registry directory for service discovery").option("--timeout-ms <ms>", "How long to wait for the runtime to become healthy", String(DEFAULT_TIMEOUT_MS)).action(async (options) => {
@@ -271,7 +314,7 @@ const prestartHttpCommand = new Command("prestart-http").description("Start an m
271
314
  process.stdout.write(`runtimeUrl=http://${host}:${port}\n`);
272
315
  process.stdout.write(`workspaceRoot=${workspaceRoot}\n`);
273
316
  } catch (error) {
274
- throw new Error(`Failed to prestart HTTP runtime '${options.id || "generated-server-id"}': ${error instanceof Error ? error.message : String(error)}`);
317
+ throw new Error(`Failed to prestart HTTP runtime '${options.id || "generated-server-id"}': ${error instanceof Error ? error.message : String(error)}`, { cause: error });
275
318
  }
276
319
  });
277
320
 
@@ -671,7 +714,24 @@ async function startStdioTransport(serverOptions) {
671
714
  }
672
715
  async function startSseTransport(serverOptions, config) {
673
716
  try {
674
- await startServer(new SseTransportHandler(await createServer(serverOptions), config));
717
+ const requestedPort = config.port;
718
+ const portRange = requestedPort !== void 0 ? {
719
+ min: requestedPort,
720
+ max: requestedPort
721
+ } : DEFAULT_PORT_RANGE;
722
+ const portLease = await createPortRegistryLease("mcp-proxy-sse", config.host ?? DEFAULT_HOST, requestedPort, serverOptions.serverId ?? generateServerId(), TRANSPORT_TYPE_SSE, void 0, portRange);
723
+ const resolvedConfig = {
724
+ ...config,
725
+ port: portLease.port
726
+ };
727
+ const handler = new SseTransportHandler(await createServer(serverOptions), resolvedConfig);
728
+ const shutdown = async () => {
729
+ await handler.stop();
730
+ await portLease.release();
731
+ };
732
+ process.on("SIGINT", shutdown);
733
+ process.on("SIGTERM", shutdown);
734
+ await startServer(handler);
675
735
  } catch (error) {
676
736
  throw new Error(`Failed to start SSE transport: ${toErrorMessage$9(error)}`);
677
737
  }
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_src = require('./src-CTeN-GJT.cjs');
1
+ const require_src = require('./src-5rGDc0sh.cjs');
2
2
 
3
3
  exports.ConfigFetcherService = require_src.ConfigFetcherService;
4
4
  exports.DefinitionsCacheService = require_src.DefinitionsCacheService;
package/dist/index.d.cts CHANGED
@@ -50,7 +50,7 @@ type TransportMode = (typeof TRANSPORT_MODE)[keyof typeof TRANSPORT_MODE];
50
50
  */
51
51
  interface TransportConfig {
52
52
  mode: TransportMode;
53
- port?: number;
53
+ port: number;
54
54
  host?: string;
55
55
  }
56
56
  /**
@@ -1125,7 +1125,7 @@ declare class HttpTransportHandler implements HttpTransportHandler$1 {
1125
1125
  private adminOptions?;
1126
1126
  private adminRateLimiter;
1127
1127
  private logger;
1128
- constructor(serverFactory: (() => Server | Promise<Server>), config: TransportConfig, adminOptions?: HttpTransportAdminOptions, logger?: LoggerLike);
1128
+ constructor(serverFactory: () => Server | Promise<Server>, config: TransportConfig, adminOptions?: HttpTransportAdminOptions, logger?: LoggerLike);
1129
1129
  private setupMiddleware;
1130
1130
  private setupRoutes;
1131
1131
  private isAuthorizedShutdownRequest;
package/dist/index.d.mts CHANGED
@@ -51,7 +51,7 @@ type TransportMode = (typeof TRANSPORT_MODE)[keyof typeof TRANSPORT_MODE];
51
51
  */
52
52
  interface TransportConfig {
53
53
  mode: TransportMode;
54
- port?: number;
54
+ port: number;
55
55
  host?: string;
56
56
  }
57
57
  /**
@@ -1126,7 +1126,7 @@ declare class HttpTransportHandler implements HttpTransportHandler$1 {
1126
1126
  private adminOptions?;
1127
1127
  private adminRateLimiter;
1128
1128
  private logger;
1129
- constructor(serverFactory: (() => Server | Promise<Server>), config: TransportConfig, adminOptions?: HttpTransportAdminOptions, logger?: LoggerLike);
1129
+ constructor(serverFactory: () => Server | Promise<Server>, config: TransportConfig, adminOptions?: HttpTransportAdminOptions, logger?: LoggerLike);
1130
1130
  private setupMiddleware;
1131
1131
  private setupRoutes;
1132
1132
  private isAuthorizedShutdownRequest;
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { C as SearchListToolsTool, D as findConfigFile, E as generateServerId, S as UseToolTool, T as DefinitionsCacheService, _ as StopServerService, a as createProxyContainer, b as createProxyLogger, c as createStdioHttpTransportHandler, f as StdioHttpTransportHandler, g as SkillService, h as HttpTransportHandler, i as createHttpTransportHandler, l as createStdioTransportHandler, m as SseTransportHandler, n as createServer, p as StdioTransportHandler, r as createSessionServer, s as createSseTransportHandler, t as TRANSPORT_MODE, u as initializeSharedServices, v as RuntimeStateService, w as DescribeToolsTool, x as ConfigFetcherService, y as McpClientManagerService } from "./src-koR2D9Bb.mjs";
1
+ import { C as SearchListToolsTool, D as findConfigFile, E as generateServerId, S as UseToolTool, T as DefinitionsCacheService, _ as StopServerService, a as createProxyContainer, b as createProxyLogger, c as createStdioHttpTransportHandler, f as StdioHttpTransportHandler, g as SkillService, h as HttpTransportHandler, i as createHttpTransportHandler, l as createStdioTransportHandler, m as SseTransportHandler, n as createServer, p as StdioTransportHandler, r as createSessionServer, s as createSseTransportHandler, t as TRANSPORT_MODE, u as initializeSharedServices, v as RuntimeStateService, w as DescribeToolsTool, x as ConfigFetcherService, y as McpClientManagerService } from "./src-BErGW2ax.mjs";
2
2
 
3
3
  export { ConfigFetcherService, DefinitionsCacheService, DescribeToolsTool, HttpTransportHandler, McpClientManagerService, RuntimeStateService, SearchListToolsTool, SkillService, SseTransportHandler, StdioHttpTransportHandler, StdioTransportHandler, StopServerService, TRANSPORT_MODE, UseToolTool, createHttpTransportHandler, createProxyContainer, createProxyLogger, createServer, createSessionServer, createSseTransportHandler, createStdioHttpTransportHandler, createStdioTransportHandler, findConfigFile, generateServerId, initializeSharedServices };
@@ -3778,7 +3778,7 @@ var HttpTransportHandler = class {
3778
3778
  this.sessionManager = new HttpFullSessionManager();
3779
3779
  this.config = {
3780
3780
  mode: config.mode,
3781
- port: config.port ?? 3e3,
3781
+ port: config.port,
3782
3782
  host: config.host ?? "localhost"
3783
3783
  };
3784
3784
  this.adminOptions = adminOptions;
@@ -4063,7 +4063,7 @@ var SseTransportHandler = class {
4063
4063
  this.sessionManager = new SseSessionManager();
4064
4064
  this.config = {
4065
4065
  mode: config.mode,
4066
- port: config.port ?? 3e3,
4066
+ port: config.port,
4067
4067
  host: config.host ?? "localhost"
4068
4068
  };
4069
4069
  this.logger = logger;
@@ -4342,7 +4342,7 @@ var StdioHttpTransportHandler = class {
4342
4342
 
4343
4343
  //#endregion
4344
4344
  //#region package.json
4345
- var version = "0.4.6";
4345
+ var version = "0.4.9";
4346
4346
 
4347
4347
  //#endregion
4348
4348
  //#region src/container/index.ts
@@ -3749,7 +3749,7 @@ var HttpTransportHandler = class {
3749
3749
  this.sessionManager = new HttpFullSessionManager();
3750
3750
  this.config = {
3751
3751
  mode: config.mode,
3752
- port: config.port ?? 3e3,
3752
+ port: config.port,
3753
3753
  host: config.host ?? "localhost"
3754
3754
  };
3755
3755
  this.adminOptions = adminOptions;
@@ -4034,7 +4034,7 @@ var SseTransportHandler = class {
4034
4034
  this.sessionManager = new SseSessionManager();
4035
4035
  this.config = {
4036
4036
  mode: config.mode,
4037
- port: config.port ?? 3e3,
4037
+ port: config.port,
4038
4038
  host: config.host ?? "localhost"
4039
4039
  };
4040
4040
  this.logger = logger;
@@ -4313,7 +4313,7 @@ var StdioHttpTransportHandler = class {
4313
4313
 
4314
4314
  //#endregion
4315
4315
  //#region package.json
4316
- var version = "0.4.6";
4316
+ var version = "0.4.9";
4317
4317
 
4318
4318
  //#endregion
4319
4319
  //#region src/container/index.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agimon-ai/mcp-proxy",
3
3
  "description": "MCP proxy server package",
4
- "version": "0.4.8",
4
+ "version": "0.4.10",
5
5
  "license": "AGPL-3.0",
6
6
  "keywords": [
7
7
  "mcp",
@@ -27,9 +27,9 @@
27
27
  "js-yaml": "^4.1.0",
28
28
  "liquidjs": "^10.21.0",
29
29
  "zod": "^3.24.1",
30
- "@agimon-ai/foundation-process-registry": "0.2.6",
31
- "@agimon-ai/log-sink-mcp": "0.2.10",
32
- "@agimon-ai/foundation-port-registry": "0.2.10"
30
+ "@agimon-ai/foundation-process-registry": "0.2.8",
31
+ "@agimon-ai/log-sink-mcp": "0.2.12",
32
+ "@agimon-ai/foundation-port-registry": "0.2.12"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/express": "^5.0.0",