@agimon-ai/mcp-proxy 0.4.9 → 0.4.11

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-5rGDc0sh.cjs');
2
+ const require_src = require('./src-DwErnAUn.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);
@@ -241,6 +262,8 @@ async function prestartHttpRuntime(options) {
241
262
  const timeoutMs = parseTimeoutMs(options.timeoutMs);
242
263
  const registryPath = options.registryPath || options.registryDir;
243
264
  const workspaceRoot = resolveWorkspaceRoot();
265
+ const existing = await findExistingHealthyRuntime(workspaceRoot);
266
+ if (existing) return existing;
244
267
  await stopExistingRuntime(new require_src.RuntimeStateService(), options.id, options.host, options.port);
245
268
  const childEnv = {
246
269
  ...process.env,
@@ -281,7 +304,7 @@ async function prestartHttpRuntime(options) {
281
304
  workspaceRoot
282
305
  };
283
306
  } catch (error) {
284
- 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 });
285
308
  }
286
309
  }
287
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) => {
@@ -292,7 +315,7 @@ const prestartHttpCommand = new commander.Command("prestart-http").description("
292
315
  process.stdout.write(`runtimeUrl=http://${host}:${port}\n`);
293
316
  process.stdout.write(`workspaceRoot=${workspaceRoot}\n`);
294
317
  } catch (error) {
295
- 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 });
296
319
  }
297
320
  });
298
321
 
@@ -717,13 +740,28 @@ async function startSseTransport(serverOptions, config) {
717
740
  async function resolveStdioHttpEndpoint(config, options, resolvedConfigPath) {
718
741
  const repositoryPath = getRegistryRepositoryPath();
719
742
  if (config.port !== void 0) return new URL(`http://${config.host ?? DEFAULT_HOST}:${config.port}${MCP_ENDPOINT_PATH}`);
720
- const result = await createPortRegistryService().getPort({
743
+ const portRegistry = createPortRegistryService();
744
+ const result = await portRegistry.getPort({
721
745
  repositoryPath,
722
746
  serviceName: PORT_REGISTRY_SERVICE_HTTP,
723
747
  serviceType: PORT_REGISTRY_SERVICE_TYPE,
724
748
  environment: getRegistryEnvironment()
725
749
  });
726
- if (result.success && result.record) return new URL(`http://${config.host ?? result.record.host}:${result.record.port}${MCP_ENDPOINT_PATH}`);
750
+ if (result.success && result.record) {
751
+ const host = config.host ?? result.record.host;
752
+ const endpoint = new URL(`http://${host}:${result.record.port}${MCP_ENDPOINT_PATH}`);
753
+ try {
754
+ const healthUrl = `http://${host}:${result.record.port}/health`;
755
+ if ((await fetch(healthUrl)).ok) return endpoint;
756
+ } catch {}
757
+ await portRegistry.releasePort({
758
+ repositoryPath,
759
+ serviceName: PORT_REGISTRY_SERVICE_HTTP,
760
+ serviceType: PORT_REGISTRY_SERVICE_TYPE,
761
+ environment: getRegistryEnvironment(),
762
+ force: true
763
+ });
764
+ }
727
765
  const runtime = await prestartHttpRuntime({
728
766
  host: config.host ?? DEFAULT_HOST,
729
767
  config: options.config || resolvedConfigPath,
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, _ 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";
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-Cp1GdSlN.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);
@@ -240,6 +261,8 @@ async function prestartHttpRuntime(options) {
240
261
  const timeoutMs = parseTimeoutMs(options.timeoutMs);
241
262
  const registryPath = options.registryPath || options.registryDir;
242
263
  const workspaceRoot = resolveWorkspaceRoot();
264
+ const existing = await findExistingHealthyRuntime(workspaceRoot);
265
+ if (existing) return existing;
243
266
  await stopExistingRuntime(new RuntimeStateService(), options.id, options.host, options.port);
244
267
  const childEnv = {
245
268
  ...process.env,
@@ -280,7 +303,7 @@ async function prestartHttpRuntime(options) {
280
303
  workspaceRoot
281
304
  };
282
305
  } catch (error) {
283
- 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 });
284
307
  }
285
308
  }
286
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) => {
@@ -291,7 +314,7 @@ const prestartHttpCommand = new Command("prestart-http").description("Start an m
291
314
  process.stdout.write(`runtimeUrl=http://${host}:${port}\n`);
292
315
  process.stdout.write(`workspaceRoot=${workspaceRoot}\n`);
293
316
  } catch (error) {
294
- 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 });
295
318
  }
296
319
  });
297
320
 
@@ -716,13 +739,28 @@ async function startSseTransport(serverOptions, config) {
716
739
  async function resolveStdioHttpEndpoint(config, options, resolvedConfigPath) {
717
740
  const repositoryPath = getRegistryRepositoryPath();
718
741
  if (config.port !== void 0) return new URL(`http://${config.host ?? DEFAULT_HOST}:${config.port}${MCP_ENDPOINT_PATH}`);
719
- const result = await createPortRegistryService().getPort({
742
+ const portRegistry = createPortRegistryService();
743
+ const result = await portRegistry.getPort({
720
744
  repositoryPath,
721
745
  serviceName: PORT_REGISTRY_SERVICE_HTTP,
722
746
  serviceType: PORT_REGISTRY_SERVICE_TYPE,
723
747
  environment: getRegistryEnvironment()
724
748
  });
725
- if (result.success && result.record) return new URL(`http://${config.host ?? result.record.host}:${result.record.port}${MCP_ENDPOINT_PATH}`);
749
+ if (result.success && result.record) {
750
+ const host = config.host ?? result.record.host;
751
+ const endpoint = new URL(`http://${host}:${result.record.port}${MCP_ENDPOINT_PATH}`);
752
+ try {
753
+ const healthUrl = `http://${host}:${result.record.port}/health`;
754
+ if ((await fetch(healthUrl)).ok) return endpoint;
755
+ } catch {}
756
+ await portRegistry.releasePort({
757
+ repositoryPath,
758
+ serviceName: PORT_REGISTRY_SERVICE_HTTP,
759
+ serviceType: PORT_REGISTRY_SERVICE_TYPE,
760
+ environment: getRegistryEnvironment(),
761
+ force: true
762
+ });
763
+ }
726
764
  const runtime = await prestartHttpRuntime({
727
765
  host: config.host ?? DEFAULT_HOST,
728
766
  config: options.config || resolvedConfigPath,
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_src = require('./src-5rGDc0sh.cjs');
1
+ const require_src = require('./src-DwErnAUn.cjs');
2
2
 
3
3
  exports.ConfigFetcherService = require_src.ConfigFetcherService;
4
4
  exports.DefinitionsCacheService = require_src.DefinitionsCacheService;
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-BErGW2ax.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-Cp1GdSlN.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 };
@@ -4313,7 +4313,7 @@ var StdioHttpTransportHandler = class {
4313
4313
 
4314
4314
  //#endregion
4315
4315
  //#region package.json
4316
- var version = "0.4.9";
4316
+ var version = "0.4.10";
4317
4317
 
4318
4318
  //#endregion
4319
4319
  //#region src/container/index.ts
@@ -4342,7 +4342,7 @@ var StdioHttpTransportHandler = class {
4342
4342
 
4343
4343
  //#endregion
4344
4344
  //#region package.json
4345
- var version = "0.4.9";
4345
+ var version = "0.4.10";
4346
4346
 
4347
4347
  //#endregion
4348
4348
  //#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.9",
4
+ "version": "0.4.11",
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.7",
31
- "@agimon-ai/foundation-port-registry": "0.2.11",
32
- "@agimon-ai/log-sink-mcp": "0.2.11"
30
+ "@agimon-ai/foundation-process-registry": "0.2.9",
31
+ "@agimon-ai/log-sink-mcp": "0.2.13",
32
+ "@agimon-ai/foundation-port-registry": "0.2.13"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/express": "^5.0.0",