@agimon-ai/mcp-proxy 0.7.3 → 0.8.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.cjs +49 -67
- package/dist/cli.mjs +34 -52
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +5 -5
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +2 -3
- package/dist/{src-Y-cyyxaw.mjs → src-Dorvm5bM.mjs} +201 -313
- package/dist/{src-Dp2m9_I_.cjs → src-dZuRf3Wt.cjs} +389 -506
- package/package.json +18 -18
|
@@ -23,10 +23,8 @@ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/
|
|
|
23
23
|
import { Hono } from "hono";
|
|
24
24
|
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
|
25
25
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
26
|
-
|
|
27
26
|
//#region package.json
|
|
28
|
-
var version = "0.7.
|
|
29
|
-
|
|
27
|
+
var version = "0.7.3";
|
|
30
28
|
//#endregion
|
|
31
29
|
//#region src/utils/mcpConfigSchema.ts
|
|
32
30
|
/**
|
|
@@ -421,7 +419,6 @@ function parseMcpConfig(rawConfig) {
|
|
|
421
419
|
const internalConfig = transformClaudeCodeConfig(ClaudeCodeMcpConfigSchema.parse(rawConfig));
|
|
422
420
|
return InternalMcpConfigSchema.parse(internalConfig);
|
|
423
421
|
}
|
|
424
|
-
|
|
425
422
|
//#endregion
|
|
426
423
|
//#region src/services/RemoteConfigCacheService.ts
|
|
427
424
|
/**
|
|
@@ -648,7 +645,6 @@ var RemoteConfigCacheService = class {
|
|
|
648
645
|
this.writeEnabled = enabled;
|
|
649
646
|
}
|
|
650
647
|
};
|
|
651
|
-
|
|
652
648
|
//#endregion
|
|
653
649
|
//#region src/services/ConfigFetcherService.ts
|
|
654
650
|
/**
|
|
@@ -875,7 +871,6 @@ var ConfigFetcherService = class {
|
|
|
875
871
|
return this.cachedConfig !== null && now - this.lastFetchTime < this.cacheTtlMs;
|
|
876
872
|
}
|
|
877
873
|
};
|
|
878
|
-
|
|
879
874
|
//#endregion
|
|
880
875
|
//#region src/constants/index.ts
|
|
881
876
|
/**
|
|
@@ -895,17 +890,6 @@ const LOG_PREFIX_SKILL_DETECTION = "[skill-detection]";
|
|
|
895
890
|
* Log prefix for general MCP capability discovery messages.
|
|
896
891
|
*/
|
|
897
892
|
const LOG_PREFIX_CAPABILITY_DISCOVERY = "[capability-discovery]";
|
|
898
|
-
/**
|
|
899
|
-
* Prefix for prompt-based skill locations.
|
|
900
|
-
* Format: "prompt:{serverName}:{promptName}"
|
|
901
|
-
*/
|
|
902
|
-
const PROMPT_LOCATION_PREFIX = "prompt:";
|
|
903
|
-
/**
|
|
904
|
-
* Default server ID used when no ID is provided via CLI or config.
|
|
905
|
-
* This fallback is used when auto-generation also fails.
|
|
906
|
-
*/
|
|
907
|
-
const DEFAULT_SERVER_ID = "unknown";
|
|
908
|
-
|
|
909
893
|
//#endregion
|
|
910
894
|
//#region src/utils/findConfigFile.ts
|
|
911
895
|
/**
|
|
@@ -958,7 +942,6 @@ function findConfigFile() {
|
|
|
958
942
|
}
|
|
959
943
|
return null;
|
|
960
944
|
}
|
|
961
|
-
|
|
962
945
|
//#endregion
|
|
963
946
|
//#region src/utils/parseToolName.ts
|
|
964
947
|
/**
|
|
@@ -980,7 +963,6 @@ function parseToolName(toolName) {
|
|
|
980
963
|
};
|
|
981
964
|
return { actualToolName: toolName };
|
|
982
965
|
}
|
|
983
|
-
|
|
984
966
|
//#endregion
|
|
985
967
|
//#region src/utils/parseFrontMatter.ts
|
|
986
968
|
/**
|
|
@@ -1114,7 +1096,6 @@ function extractSkillFrontMatter(content) {
|
|
|
1114
1096
|
};
|
|
1115
1097
|
return null;
|
|
1116
1098
|
}
|
|
1117
|
-
|
|
1118
1099
|
//#endregion
|
|
1119
1100
|
//#region src/utils/generateServerId.ts
|
|
1120
1101
|
/**
|
|
@@ -1179,7 +1160,6 @@ function generateServerId(length = DEFAULT_ID_LENGTH) {
|
|
|
1179
1160
|
}
|
|
1180
1161
|
return result;
|
|
1181
1162
|
}
|
|
1182
|
-
|
|
1183
1163
|
//#endregion
|
|
1184
1164
|
//#region src/services/DefinitionsCacheService.ts
|
|
1185
1165
|
/**
|
|
@@ -1478,7 +1458,6 @@ var DefinitionsCacheService = class {
|
|
|
1478
1458
|
return promptSkills;
|
|
1479
1459
|
}
|
|
1480
1460
|
};
|
|
1481
|
-
|
|
1482
1461
|
//#endregion
|
|
1483
1462
|
//#region src/services/logger.ts
|
|
1484
1463
|
function isRecord(value) {
|
|
@@ -1532,7 +1511,6 @@ async function createProxyLogger(options = {}) {
|
|
|
1532
1511
|
maxFileCount: options.maxFileCount
|
|
1533
1512
|
}));
|
|
1534
1513
|
}
|
|
1535
|
-
|
|
1536
1514
|
//#endregion
|
|
1537
1515
|
//#region src/services/McpClientManagerService.ts
|
|
1538
1516
|
/** Default connection timeout in milliseconds (30 seconds) */
|
|
@@ -1604,8 +1582,8 @@ var McpClient = class {
|
|
|
1604
1582
|
this.logger = logger;
|
|
1605
1583
|
this.client = client;
|
|
1606
1584
|
}
|
|
1607
|
-
setChildProcess(process
|
|
1608
|
-
this.childProcess = process
|
|
1585
|
+
setChildProcess(process) {
|
|
1586
|
+
this.childProcess = process;
|
|
1609
1587
|
}
|
|
1610
1588
|
setConnected(connected) {
|
|
1611
1589
|
this.connected = connected;
|
|
@@ -1734,7 +1712,7 @@ var McpClientManagerService = class {
|
|
|
1734
1712
|
if (childProcess && !childProcess.killed) {
|
|
1735
1713
|
this.logger.info(`Killing stdio MCP server: ${serverName} (PID: ${childProcess.pid})`);
|
|
1736
1714
|
childProcess.kill("SIGTERM");
|
|
1737
|
-
killPromises.push(new Promise((resolve
|
|
1715
|
+
killPromises.push(new Promise((resolve) => {
|
|
1738
1716
|
setTimeout(() => {
|
|
1739
1717
|
try {
|
|
1740
1718
|
if (!childProcess.killed) {
|
|
@@ -1742,7 +1720,7 @@ var McpClientManagerService = class {
|
|
|
1742
1720
|
childProcess.kill("SIGKILL");
|
|
1743
1721
|
}
|
|
1744
1722
|
} catch {}
|
|
1745
|
-
resolve
|
|
1723
|
+
resolve();
|
|
1746
1724
|
}, 1e3);
|
|
1747
1725
|
}));
|
|
1748
1726
|
}
|
|
@@ -1893,7 +1871,6 @@ var McpClientManagerService = class {
|
|
|
1893
1871
|
return this.clients.has(serverName);
|
|
1894
1872
|
}
|
|
1895
1873
|
};
|
|
1896
|
-
|
|
1897
1874
|
//#endregion
|
|
1898
1875
|
//#region src/services/RuntimeStateService.ts
|
|
1899
1876
|
/**
|
|
@@ -1995,24 +1972,10 @@ var RuntimeStateService = class RuntimeStateService {
|
|
|
1995
1972
|
await rm(this.getRecordPath(serverId), { force: true });
|
|
1996
1973
|
}
|
|
1997
1974
|
};
|
|
1998
|
-
|
|
1999
|
-
//#endregion
|
|
2000
|
-
//#region src/services/StopServerService/constants.ts
|
|
2001
|
-
/**
|
|
2002
|
-
* StopServerService constants.
|
|
2003
|
-
*/
|
|
2004
|
-
/** Maximum time in milliseconds to wait for a shutdown to complete. */
|
|
2005
|
-
const DEFAULT_STOP_TIMEOUT_MS = 5e3;
|
|
2006
|
-
/** Minimum timeout in milliseconds for individual health check requests. */
|
|
2007
|
-
const HEALTH_REQUEST_TIMEOUT_FLOOR_MS = 250;
|
|
2008
|
-
/** Delay in milliseconds between shutdown polling attempts. */
|
|
2009
|
-
const SHUTDOWN_POLL_INTERVAL_MS = 200;
|
|
2010
1975
|
/** Path for the runtime health check endpoint. */
|
|
2011
1976
|
const HEALTH_CHECK_PATH = "/health";
|
|
2012
1977
|
/** Path for the authenticated admin shutdown endpoint. */
|
|
2013
1978
|
const ADMIN_SHUTDOWN_PATH = "/admin/shutdown";
|
|
2014
|
-
/** HTTP GET method identifier. */
|
|
2015
|
-
const HTTP_METHOD_GET = "GET";
|
|
2016
1979
|
/** HTTP POST method identifier. */
|
|
2017
1980
|
const HTTP_METHOD_POST = "POST";
|
|
2018
1981
|
/** HTTP header name for bearer token authorization. */
|
|
@@ -2021,35 +1984,12 @@ const AUTHORIZATION_HEADER_NAME = "Authorization";
|
|
|
2021
1984
|
const BEARER_TOKEN_PREFIX = "Bearer ";
|
|
2022
1985
|
/** HTTP protocol scheme prefix for URL construction. */
|
|
2023
1986
|
const HTTP_PROTOCOL = "http://";
|
|
2024
|
-
/** Separator between host and port in URL construction. */
|
|
2025
|
-
const URL_PORT_SEPARATOR = ":";
|
|
2026
|
-
/** Loopback hostname. */
|
|
2027
|
-
const LOOPBACK_HOST_LOCALHOST = "localhost";
|
|
2028
|
-
/** IPv4 loopback address. */
|
|
2029
|
-
const LOOPBACK_HOST_IPV4 = "127.0.0.1";
|
|
2030
|
-
/** IPv6 loopback address. */
|
|
2031
|
-
const LOOPBACK_HOST_IPV6 = "::1";
|
|
2032
1987
|
/** Hosts that are safe to send admin requests to (loopback only). */
|
|
2033
1988
|
const ALLOWED_HOSTS = new Set([
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
1989
|
+
"localhost",
|
|
1990
|
+
"127.0.0.1",
|
|
1991
|
+
"::1"
|
|
2037
1992
|
]);
|
|
2038
|
-
/** Expected status value in a healthy runtime response. */
|
|
2039
|
-
const HEALTH_STATUS_OK = "ok";
|
|
2040
|
-
/** Expected transport value in a healthy runtime response. */
|
|
2041
|
-
const HEALTH_TRANSPORT_HTTP = "http";
|
|
2042
|
-
/** Property key for status field in health responses. */
|
|
2043
|
-
const KEY_STATUS = "status";
|
|
2044
|
-
/** Property key for transport field in health responses. */
|
|
2045
|
-
const KEY_TRANSPORT = "transport";
|
|
2046
|
-
/** Property key for serverId field in runtime responses. */
|
|
2047
|
-
const KEY_SERVER_ID = "serverId";
|
|
2048
|
-
/** Property key for ok field in shutdown responses. */
|
|
2049
|
-
const KEY_OK = "ok";
|
|
2050
|
-
/** Property key for message field in shutdown responses. */
|
|
2051
|
-
const KEY_MESSAGE = "message";
|
|
2052
|
-
|
|
2053
1993
|
//#endregion
|
|
2054
1994
|
//#region src/services/StopServerService/types.ts
|
|
2055
1995
|
/**
|
|
@@ -2068,7 +2008,7 @@ function toRecord(value) {
|
|
|
2068
2008
|
function isHealthResponse(value) {
|
|
2069
2009
|
if (typeof value !== "object" || value === null) return false;
|
|
2070
2010
|
const record = toRecord(value);
|
|
2071
|
-
return
|
|
2011
|
+
return "status" in record && record["status"] === "ok" && "transport" in record && record["transport"] === "http" && (!("serverId" in record) || record["serverId"] === void 0 || typeof record["serverId"] === "string");
|
|
2072
2012
|
}
|
|
2073
2013
|
/**
|
|
2074
2014
|
* Type guard for shutdown responses.
|
|
@@ -2078,9 +2018,8 @@ function isHealthResponse(value) {
|
|
|
2078
2018
|
function isShutdownResponse(value) {
|
|
2079
2019
|
if (typeof value !== "object" || value === null) return false;
|
|
2080
2020
|
const record = toRecord(value);
|
|
2081
|
-
return
|
|
2021
|
+
return "ok" in record && typeof record["ok"] === "boolean" && "message" in record && typeof record["message"] === "string" && (!("serverId" in record) || record["serverId"] === void 0 || typeof record["serverId"] === "string");
|
|
2082
2022
|
}
|
|
2083
|
-
|
|
2084
2023
|
//#endregion
|
|
2085
2024
|
//#region src/services/StopServerService/StopServerService.ts
|
|
2086
2025
|
/**
|
|
@@ -2090,16 +2029,16 @@ function isShutdownResponse(value) {
|
|
|
2090
2029
|
* @param path - Request path to append
|
|
2091
2030
|
* @returns Full runtime URL
|
|
2092
2031
|
*/
|
|
2093
|
-
function buildRuntimeUrl(runtime, path
|
|
2032
|
+
function buildRuntimeUrl(runtime, path) {
|
|
2094
2033
|
if (!ALLOWED_HOSTS.has(runtime.host)) throw new Error(`Refusing to connect to non-loopback host '${runtime.host}'. Only ${Array.from(ALLOWED_HOSTS).join(", ")} are allowed.`);
|
|
2095
|
-
return `${HTTP_PROTOCOL}${runtime.host}
|
|
2034
|
+
return `${HTTP_PROTOCOL}${runtime.host}:${runtime.port}${path}`;
|
|
2096
2035
|
}
|
|
2097
2036
|
function toErrorMessage$1(error) {
|
|
2098
2037
|
return error instanceof Error ? error.message : String(error);
|
|
2099
2038
|
}
|
|
2100
2039
|
function sleep(delayMs) {
|
|
2101
|
-
return new Promise((resolve
|
|
2102
|
-
setTimeout(resolve
|
|
2040
|
+
return new Promise((resolve) => {
|
|
2041
|
+
setTimeout(resolve, delayMs);
|
|
2103
2042
|
});
|
|
2104
2043
|
}
|
|
2105
2044
|
/**
|
|
@@ -2118,7 +2057,7 @@ var StopServerService = class {
|
|
|
2118
2057
|
* @returns Stop result payload
|
|
2119
2058
|
*/
|
|
2120
2059
|
async stop(request) {
|
|
2121
|
-
const timeoutMs = request.timeoutMs ??
|
|
2060
|
+
const timeoutMs = request.timeoutMs ?? 5e3;
|
|
2122
2061
|
const runtime = await this.resolveRuntime(request);
|
|
2123
2062
|
const health = await this.fetchHealth(runtime, timeoutMs);
|
|
2124
2063
|
if (!health.reachable) {
|
|
@@ -2164,7 +2103,7 @@ var StopServerService = class {
|
|
|
2164
2103
|
*/
|
|
2165
2104
|
async fetchHealth(runtime, timeoutMs) {
|
|
2166
2105
|
try {
|
|
2167
|
-
const response = await this.fetchWithTimeout(buildRuntimeUrl(runtime, HEALTH_CHECK_PATH), { method:
|
|
2106
|
+
const response = await this.fetchWithTimeout(buildRuntimeUrl(runtime, HEALTH_CHECK_PATH), { method: "GET" }, timeoutMs);
|
|
2168
2107
|
if (!response.ok) return { reachable: false };
|
|
2169
2108
|
const payload = await response.json();
|
|
2170
2109
|
if (!isHealthResponse(payload)) throw new Error("Received invalid health response payload.");
|
|
@@ -2203,8 +2142,8 @@ var StopServerService = class {
|
|
|
2203
2142
|
async waitForShutdown(runtime, timeoutMs) {
|
|
2204
2143
|
const deadline = Date.now() + timeoutMs;
|
|
2205
2144
|
while (Date.now() < deadline) {
|
|
2206
|
-
if (!(await this.fetchHealth(runtime, Math.max(
|
|
2207
|
-
await sleep(
|
|
2145
|
+
if (!(await this.fetchHealth(runtime, Math.max(250, deadline - Date.now()))).reachable) return;
|
|
2146
|
+
await sleep(200);
|
|
2208
2147
|
}
|
|
2209
2148
|
throw new Error(`Timed out waiting for runtime '${runtime.serverId}' to stop at http://${runtime.host}:${runtime.port}.`);
|
|
2210
2149
|
}
|
|
@@ -2232,7 +2171,6 @@ var StopServerService = class {
|
|
|
2232
2171
|
}
|
|
2233
2172
|
}
|
|
2234
2173
|
};
|
|
2235
|
-
|
|
2236
2174
|
//#endregion
|
|
2237
2175
|
//#region src/services/SkillService.ts
|
|
2238
2176
|
/**
|
|
@@ -2270,13 +2208,13 @@ var SkillLoadError = class extends Error {
|
|
|
2270
2208
|
* @returns true if path exists, false otherwise
|
|
2271
2209
|
* @throws Error for unexpected filesystem errors (permission denied, etc.)
|
|
2272
2210
|
*/
|
|
2273
|
-
async function pathExists(path
|
|
2211
|
+
async function pathExists(path) {
|
|
2274
2212
|
try {
|
|
2275
|
-
await access(path
|
|
2213
|
+
await access(path);
|
|
2276
2214
|
return true;
|
|
2277
2215
|
} catch (error) {
|
|
2278
2216
|
if (error instanceof Error && "code" in error && error.code === "ENOENT") return false;
|
|
2279
|
-
throw new Error(`Failed to check path existence for "${path
|
|
2217
|
+
throw new Error(`Failed to check path existence for "${path}": ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2280
2218
|
}
|
|
2281
2219
|
}
|
|
2282
2220
|
/**
|
|
@@ -2589,54 +2527,14 @@ var SkillService = class {
|
|
|
2589
2527
|
};
|
|
2590
2528
|
}
|
|
2591
2529
|
};
|
|
2592
|
-
|
|
2593
|
-
//#endregion
|
|
2594
|
-
//#region src/services/PrefetchService/constants.ts
|
|
2595
|
-
/**
|
|
2596
|
-
* PrefetchService Constants
|
|
2597
|
-
*
|
|
2598
|
-
* Constants for package manager commands and process configuration.
|
|
2599
|
-
*/
|
|
2600
|
-
/** Transport type for stdio-based MCP servers */
|
|
2601
|
-
const TRANSPORT_STDIO = "stdio";
|
|
2602
|
-
/** npx command name */
|
|
2603
|
-
const COMMAND_NPX = "npx";
|
|
2604
|
-
/** npm command name */
|
|
2605
|
-
const COMMAND_NPM = "npm";
|
|
2606
2530
|
/** pnpx command name (pnpm's npx equivalent) */
|
|
2607
2531
|
const COMMAND_PNPX = "pnpx";
|
|
2608
2532
|
/** pnpm command name */
|
|
2609
2533
|
const COMMAND_PNPM = "pnpm";
|
|
2610
|
-
/** uvx command name */
|
|
2611
|
-
const COMMAND_UVX = "uvx";
|
|
2612
|
-
/** uv command name */
|
|
2613
|
-
const COMMAND_UV = "uv";
|
|
2614
|
-
/** Path suffix for npx command */
|
|
2615
|
-
const COMMAND_NPX_SUFFIX = "/npx";
|
|
2616
|
-
/** Path suffix for pnpx command */
|
|
2617
|
-
const COMMAND_PNPX_SUFFIX = "/pnpx";
|
|
2618
|
-
/** Path suffix for uvx command */
|
|
2619
|
-
const COMMAND_UVX_SUFFIX = "/uvx";
|
|
2620
|
-
/** Path suffix for uv command */
|
|
2621
|
-
const COMMAND_UV_SUFFIX = "/uv";
|
|
2622
|
-
/** Run subcommand for uv */
|
|
2623
|
-
const ARG_RUN = "run";
|
|
2624
2534
|
/** Tool subcommand for uv */
|
|
2625
2535
|
const ARG_TOOL = "tool";
|
|
2626
2536
|
/** Install subcommand for uv tool and npm/pnpm */
|
|
2627
2537
|
const ARG_INSTALL = "install";
|
|
2628
|
-
/** Add subcommand for pnpm */
|
|
2629
|
-
const ARG_ADD = "add";
|
|
2630
|
-
/** Global flag for npm/pnpm install */
|
|
2631
|
-
const ARG_GLOBAL = "-g";
|
|
2632
|
-
/** Flag prefix for command arguments */
|
|
2633
|
-
const FLAG_PREFIX = "-";
|
|
2634
|
-
/** npx --package flag (long form) */
|
|
2635
|
-
const FLAG_PACKAGE_LONG = "--package";
|
|
2636
|
-
/** npx -p flag (short form) */
|
|
2637
|
-
const FLAG_PACKAGE_SHORT = "-p";
|
|
2638
|
-
/** Equals delimiter used in flag=value patterns */
|
|
2639
|
-
const EQUALS_DELIMITER = "=";
|
|
2640
2538
|
/**
|
|
2641
2539
|
* Regex pattern for valid package names (npm, pnpm, uvx, uv)
|
|
2642
2540
|
* Allows: @scope/package-name@version, package-name, package_name
|
|
@@ -2648,13 +2546,10 @@ const EQUALS_DELIMITER = "=";
|
|
|
2648
2546
|
const VALID_PACKAGE_NAME_PATTERN = /^(@[a-zA-Z0-9_-]+\/)?[a-zA-Z0-9._-]+(@[a-zA-Z0-9._-]+)?$/;
|
|
2649
2547
|
/** Windows platform identifier */
|
|
2650
2548
|
const PLATFORM_WIN32 = "win32";
|
|
2651
|
-
/** Success exit code */
|
|
2652
|
-
const EXIT_CODE_SUCCESS = 0;
|
|
2653
2549
|
/** Stdio option to ignore stream */
|
|
2654
2550
|
const STDIO_IGNORE = "ignore";
|
|
2655
2551
|
/** Stdio option to pipe stream */
|
|
2656
2552
|
const STDIO_PIPE = "pipe";
|
|
2657
|
-
|
|
2658
2553
|
//#endregion
|
|
2659
2554
|
//#region src/services/PrefetchService/PrefetchService.ts
|
|
2660
2555
|
/**
|
|
@@ -2714,7 +2609,7 @@ var PrefetchService = class {
|
|
|
2714
2609
|
const { mcpConfig, filter } = this.config;
|
|
2715
2610
|
for (const [serverName, serverConfig] of Object.entries(mcpConfig.mcpServers)) {
|
|
2716
2611
|
if (serverConfig.disabled) continue;
|
|
2717
|
-
if (serverConfig.transport !==
|
|
2612
|
+
if (serverConfig.transport !== "stdio") continue;
|
|
2718
2613
|
if (!isMcpStdioConfig(serverConfig.config)) continue;
|
|
2719
2614
|
const packageInfo = this.extractPackageInfo(serverName, serverConfig.config);
|
|
2720
2615
|
if (packageInfo) {
|
|
@@ -2803,21 +2698,21 @@ var PrefetchService = class {
|
|
|
2803
2698
|
extractPackageInfo(serverName, config) {
|
|
2804
2699
|
const command = config.command.toLowerCase();
|
|
2805
2700
|
const args = config.args || [];
|
|
2806
|
-
if (command ===
|
|
2701
|
+
if (command === "npx" || command.endsWith("/npx")) {
|
|
2807
2702
|
const packageName = this.extractNpxPackage(args);
|
|
2808
2703
|
if (packageName && this.isValidPackageName(packageName)) return {
|
|
2809
2704
|
serverName,
|
|
2810
|
-
packageManager:
|
|
2705
|
+
packageManager: "npx",
|
|
2811
2706
|
packageName,
|
|
2812
2707
|
fullCommand: [
|
|
2813
|
-
|
|
2708
|
+
"npm",
|
|
2814
2709
|
ARG_INSTALL,
|
|
2815
|
-
|
|
2710
|
+
"-g",
|
|
2816
2711
|
packageName
|
|
2817
2712
|
]
|
|
2818
2713
|
};
|
|
2819
2714
|
}
|
|
2820
|
-
if (command ===
|
|
2715
|
+
if (command === "pnpx" || command.endsWith("/pnpx")) {
|
|
2821
2716
|
const packageName = this.extractNpxPackage(args);
|
|
2822
2717
|
if (packageName && this.isValidPackageName(packageName)) return {
|
|
2823
2718
|
serverName,
|
|
@@ -2825,29 +2720,29 @@ var PrefetchService = class {
|
|
|
2825
2720
|
packageName,
|
|
2826
2721
|
fullCommand: [
|
|
2827
2722
|
COMMAND_PNPM,
|
|
2828
|
-
|
|
2829
|
-
|
|
2723
|
+
"add",
|
|
2724
|
+
"-g",
|
|
2830
2725
|
packageName
|
|
2831
2726
|
]
|
|
2832
2727
|
};
|
|
2833
2728
|
}
|
|
2834
|
-
if (command ===
|
|
2729
|
+
if (command === "uvx" || command.endsWith("/uvx")) {
|
|
2835
2730
|
const packageName = this.extractUvxPackage(args);
|
|
2836
2731
|
if (packageName && this.isValidPackageName(packageName)) return {
|
|
2837
2732
|
serverName,
|
|
2838
|
-
packageManager:
|
|
2733
|
+
packageManager: "uvx",
|
|
2839
2734
|
packageName,
|
|
2840
|
-
fullCommand: [
|
|
2735
|
+
fullCommand: ["uvx", packageName]
|
|
2841
2736
|
};
|
|
2842
2737
|
}
|
|
2843
|
-
if ((command ===
|
|
2738
|
+
if ((command === "uv" || command.endsWith("/uv")) && args.includes("run")) {
|
|
2844
2739
|
const packageName = this.extractUvRunPackage(args);
|
|
2845
2740
|
if (packageName && this.isValidPackageName(packageName)) return {
|
|
2846
2741
|
serverName,
|
|
2847
|
-
packageManager:
|
|
2742
|
+
packageManager: "uv",
|
|
2848
2743
|
packageName,
|
|
2849
2744
|
fullCommand: [
|
|
2850
|
-
|
|
2745
|
+
"uv",
|
|
2851
2746
|
ARG_TOOL,
|
|
2852
2747
|
ARG_INSTALL,
|
|
2853
2748
|
packageName
|
|
@@ -2874,18 +2769,18 @@ var PrefetchService = class {
|
|
|
2874
2769
|
extractNpxPackage(args) {
|
|
2875
2770
|
for (let i = 0; i < args.length; i++) {
|
|
2876
2771
|
const arg = args[i];
|
|
2877
|
-
if (arg.startsWith(
|
|
2878
|
-
if (arg ===
|
|
2772
|
+
if (arg.startsWith("--package=")) return arg.slice(10) || null;
|
|
2773
|
+
if (arg === "--package" && i + 1 < args.length) {
|
|
2879
2774
|
const nextArg = args[i + 1];
|
|
2880
|
-
if (!nextArg.startsWith(
|
|
2775
|
+
if (!nextArg.startsWith("-")) return nextArg;
|
|
2881
2776
|
}
|
|
2882
|
-
if (arg ===
|
|
2777
|
+
if (arg === "-p" && i + 1 < args.length) {
|
|
2883
2778
|
const nextArg = args[i + 1];
|
|
2884
|
-
if (!nextArg.startsWith(
|
|
2779
|
+
if (!nextArg.startsWith("-")) return nextArg;
|
|
2885
2780
|
}
|
|
2886
2781
|
}
|
|
2887
2782
|
for (const arg of args) {
|
|
2888
|
-
if (arg.startsWith(
|
|
2783
|
+
if (arg.startsWith("-")) continue;
|
|
2889
2784
|
return arg;
|
|
2890
2785
|
}
|
|
2891
2786
|
return null;
|
|
@@ -2902,7 +2797,7 @@ var PrefetchService = class {
|
|
|
2902
2797
|
*/
|
|
2903
2798
|
extractUvxPackage(args) {
|
|
2904
2799
|
for (const arg of args) {
|
|
2905
|
-
if (arg.startsWith(
|
|
2800
|
+
if (arg.startsWith("-")) continue;
|
|
2906
2801
|
return arg;
|
|
2907
2802
|
}
|
|
2908
2803
|
return null;
|
|
@@ -2919,11 +2814,11 @@ var PrefetchService = class {
|
|
|
2919
2814
|
* extractUvRunPackage(['install', 'pkg']) // returns null (no 'run')
|
|
2920
2815
|
*/
|
|
2921
2816
|
extractUvRunPackage(args) {
|
|
2922
|
-
const runIndex = args.indexOf(
|
|
2817
|
+
const runIndex = args.indexOf("run");
|
|
2923
2818
|
if (runIndex === -1) return null;
|
|
2924
2819
|
for (let i = runIndex + 1; i < args.length; i++) {
|
|
2925
2820
|
const arg = args[i];
|
|
2926
|
-
if (arg.startsWith(
|
|
2821
|
+
if (arg.startsWith("-")) continue;
|
|
2927
2822
|
return arg;
|
|
2928
2823
|
}
|
|
2929
2824
|
return null;
|
|
@@ -2935,7 +2830,7 @@ var PrefetchService = class {
|
|
|
2935
2830
|
* @returns Promise with success status and output
|
|
2936
2831
|
*/
|
|
2937
2832
|
runCommand(command, args) {
|
|
2938
|
-
return new Promise((resolve
|
|
2833
|
+
return new Promise((resolve) => {
|
|
2939
2834
|
const proc = spawn(command, args, {
|
|
2940
2835
|
stdio: [
|
|
2941
2836
|
STDIO_IGNORE,
|
|
@@ -2953,13 +2848,13 @@ var PrefetchService = class {
|
|
|
2953
2848
|
stderr += data.toString();
|
|
2954
2849
|
});
|
|
2955
2850
|
proc.on("close", (code) => {
|
|
2956
|
-
resolve
|
|
2957
|
-
success: code ===
|
|
2851
|
+
resolve({
|
|
2852
|
+
success: code === 0,
|
|
2958
2853
|
output: stdout || stderr
|
|
2959
2854
|
});
|
|
2960
2855
|
});
|
|
2961
2856
|
proc.on("error", (error) => {
|
|
2962
|
-
resolve
|
|
2857
|
+
resolve({
|
|
2963
2858
|
success: false,
|
|
2964
2859
|
output: error.message
|
|
2965
2860
|
});
|
|
@@ -2967,11 +2862,9 @@ var PrefetchService = class {
|
|
|
2967
2862
|
});
|
|
2968
2863
|
}
|
|
2969
2864
|
};
|
|
2970
|
-
|
|
2971
2865
|
//#endregion
|
|
2972
2866
|
//#region src/templates/toolkit-description.liquid?raw
|
|
2973
2867
|
var toolkit_description_default = "<toolkit id=\"{{ serverId }}\">\n<instruction>\nBefore you use any capabilities below, you MUST call this tool with a list of names to learn how to use them properly; this includes:\n- For tools: Arguments schema needed to pass to use_tool\n- For skills: Detailed instructions that will expand when invoked (Prefer to be explored first when relevant)\n\nThis tool is optimized for batch queries - you can request multiple capabilities at once for better performance.\n\nHow to invoke:\n- For MCP tools: Use use_tool with toolName and toolArgs based on the schema\n- For skills: Use this tool with the skill name to get expanded instructions\n</instruction>\n\n<available_capabilities>\n{% for server in servers -%}\n<group original-mcp-server=\"{{ server.name }}\">\n{% if server.instruction -%}\n<group_instruction>{{ server.instruction }}</group_instruction>\n{% endif -%}\n{% if server.omitToolDescription -%}\n{% for toolName in server.toolNames -%}\n<item name=\"{{ toolName }}\"></item>\n{% endfor -%}\n{% else -%}\n{% for tool in server.tools -%}\n<item name=\"{{ tool.displayName }}\"><description>{{ tool.description | default: \"No description\" }}</description></item>\n{% endfor -%}\n{% endif -%}\n</group>\n{% endfor -%}\n{% if skills.size > 0 -%}\n<group name=\"skills\">\n{% for skill in skills -%}\n<item name=\"{{ skill.displayName }}\"><description>{{ skill.description }}</description></item>\n{% endfor -%}\n</group>\n{% endif -%}\n</available_capabilities>\n</toolkit>\n";
|
|
2974
|
-
|
|
2975
2868
|
//#endregion
|
|
2976
2869
|
//#region src/tools/DescribeToolsTool.ts
|
|
2977
2870
|
/**
|
|
@@ -3026,7 +2919,7 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
3026
2919
|
constructor(clientManager, skillService, serverId, definitionsCacheService) {
|
|
3027
2920
|
this.clientManager = clientManager;
|
|
3028
2921
|
this.skillService = skillService;
|
|
3029
|
-
this.serverId = serverId ||
|
|
2922
|
+
this.serverId = serverId || "unknown";
|
|
3030
2923
|
this.definitionsCacheService = definitionsCacheService || new DefinitionsCacheService(clientManager, skillService);
|
|
3031
2924
|
}
|
|
3032
2925
|
/**
|
|
@@ -3142,7 +3035,7 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
3142
3035
|
}).join("\n") || "";
|
|
3143
3036
|
return {
|
|
3144
3037
|
name: promptSkill.skill.name,
|
|
3145
|
-
location: promptSkill.skill.folder ||
|
|
3038
|
+
location: promptSkill.skill.folder || `prompt:${promptSkill.serverName}/${promptSkill.promptName}`,
|
|
3146
3039
|
instructions: formatSkillInstructions(promptSkill.skill.name, rawInstructions)
|
|
3147
3040
|
};
|
|
3148
3041
|
} catch (error) {
|
|
@@ -3258,6 +3151,115 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
3258
3151
|
inputSchema: z.toJSONSchema(DescribeToolsToolInputSchema, { reused: "inline" })
|
|
3259
3152
|
};
|
|
3260
3153
|
}
|
|
3154
|
+
async runLookups(toolNames, serverDefinitions) {
|
|
3155
|
+
const serverToolsMap = /* @__PURE__ */ new Map();
|
|
3156
|
+
const toolToServers = /* @__PURE__ */ new Map();
|
|
3157
|
+
for (const serverDefinition of serverDefinitions) {
|
|
3158
|
+
const typedTools = serverDefinition.tools.map((tool) => ({
|
|
3159
|
+
name: tool.name,
|
|
3160
|
+
description: tool.description,
|
|
3161
|
+
inputSchema: tool.inputSchema
|
|
3162
|
+
}));
|
|
3163
|
+
serverToolsMap.set(serverDefinition.serverName, typedTools);
|
|
3164
|
+
for (const tool of typedTools) {
|
|
3165
|
+
if (!toolToServers.has(tool.name)) toolToServers.set(tool.name, []);
|
|
3166
|
+
toolToServers.get(tool.name)?.push(serverDefinition.serverName);
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
const lookupResults = await Promise.all(toolNames.map(async (requestedName) => {
|
|
3170
|
+
const result = {
|
|
3171
|
+
tools: [],
|
|
3172
|
+
skills: [],
|
|
3173
|
+
notFound: null
|
|
3174
|
+
};
|
|
3175
|
+
if (requestedName.startsWith("skill__")) {
|
|
3176
|
+
const skillName = requestedName.slice(7);
|
|
3177
|
+
if (this.skillService) {
|
|
3178
|
+
const skill = await this.skillService.getSkill(skillName);
|
|
3179
|
+
if (skill) {
|
|
3180
|
+
result.skills.push({
|
|
3181
|
+
name: skill.name,
|
|
3182
|
+
location: skill.basePath,
|
|
3183
|
+
instructions: formatSkillInstructions(skill.name, skill.content)
|
|
3184
|
+
});
|
|
3185
|
+
return result;
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
const promptSkillContent = await this.getPromptSkillContent(skillName);
|
|
3189
|
+
if (promptSkillContent) {
|
|
3190
|
+
result.skills.push(promptSkillContent);
|
|
3191
|
+
return result;
|
|
3192
|
+
}
|
|
3193
|
+
result.notFound = requestedName;
|
|
3194
|
+
return result;
|
|
3195
|
+
}
|
|
3196
|
+
const { serverName, actualToolName } = parseToolName(requestedName);
|
|
3197
|
+
if (serverName) {
|
|
3198
|
+
const serverTools = serverToolsMap.get(serverName);
|
|
3199
|
+
if (!serverTools) {
|
|
3200
|
+
result.notFound = requestedName;
|
|
3201
|
+
return result;
|
|
3202
|
+
}
|
|
3203
|
+
const tool = serverTools.find((t) => t.name === actualToolName);
|
|
3204
|
+
if (tool) result.tools.push({
|
|
3205
|
+
server: serverName,
|
|
3206
|
+
tool: {
|
|
3207
|
+
name: tool.name,
|
|
3208
|
+
description: tool.description,
|
|
3209
|
+
inputSchema: tool.inputSchema
|
|
3210
|
+
}
|
|
3211
|
+
});
|
|
3212
|
+
else result.notFound = requestedName;
|
|
3213
|
+
return result;
|
|
3214
|
+
}
|
|
3215
|
+
const servers = toolToServers.get(actualToolName);
|
|
3216
|
+
if (!servers || servers.length === 0) {
|
|
3217
|
+
if (this.skillService) {
|
|
3218
|
+
const skill = await this.skillService.getSkill(actualToolName);
|
|
3219
|
+
if (skill) {
|
|
3220
|
+
result.skills.push({
|
|
3221
|
+
name: skill.name,
|
|
3222
|
+
location: skill.basePath,
|
|
3223
|
+
instructions: formatSkillInstructions(skill.name, skill.content)
|
|
3224
|
+
});
|
|
3225
|
+
return result;
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
|
+
const promptSkillContent = await this.getPromptSkillContent(actualToolName);
|
|
3229
|
+
if (promptSkillContent) {
|
|
3230
|
+
result.skills.push(promptSkillContent);
|
|
3231
|
+
return result;
|
|
3232
|
+
}
|
|
3233
|
+
result.notFound = requestedName;
|
|
3234
|
+
return result;
|
|
3235
|
+
}
|
|
3236
|
+
for (const server of servers) {
|
|
3237
|
+
const tool = serverToolsMap.get(server).find((t) => t.name === actualToolName);
|
|
3238
|
+
result.tools.push({
|
|
3239
|
+
server,
|
|
3240
|
+
tool: {
|
|
3241
|
+
name: tool.name,
|
|
3242
|
+
description: tool.description,
|
|
3243
|
+
inputSchema: tool.inputSchema
|
|
3244
|
+
}
|
|
3245
|
+
});
|
|
3246
|
+
}
|
|
3247
|
+
return result;
|
|
3248
|
+
}));
|
|
3249
|
+
const foundTools = [];
|
|
3250
|
+
const foundSkills = [];
|
|
3251
|
+
const notFoundItems = [];
|
|
3252
|
+
for (const result of lookupResults) {
|
|
3253
|
+
foundTools.push(...result.tools);
|
|
3254
|
+
foundSkills.push(...result.skills);
|
|
3255
|
+
if (result.notFound) notFoundItems.push(result.notFound);
|
|
3256
|
+
}
|
|
3257
|
+
return {
|
|
3258
|
+
foundTools,
|
|
3259
|
+
foundSkills,
|
|
3260
|
+
notFoundItems
|
|
3261
|
+
};
|
|
3262
|
+
}
|
|
3261
3263
|
/**
|
|
3262
3264
|
* Executes tool description lookup for the requested tool and skill names.
|
|
3263
3265
|
*
|
|
@@ -3272,7 +3274,6 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
3272
3274
|
async execute(rawInput) {
|
|
3273
3275
|
try {
|
|
3274
3276
|
const { toolNames } = DescribeToolsToolInputSchema.parse(rawInput);
|
|
3275
|
-
const serverDefinitions = await this.definitionsCacheService.getServerDefinitions();
|
|
3276
3277
|
if (!toolNames || toolNames.length === 0) return {
|
|
3277
3278
|
content: [{
|
|
3278
3279
|
type: "text",
|
|
@@ -3280,119 +3281,13 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
3280
3281
|
}],
|
|
3281
3282
|
isError: true
|
|
3282
3283
|
};
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
description: tool.description,
|
|
3289
|
-
inputSchema: tool.inputSchema
|
|
3290
|
-
}));
|
|
3291
|
-
serverToolsMap.set(serverDefinition.serverName, typedTools);
|
|
3292
|
-
for (const tool of typedTools) {
|
|
3293
|
-
if (!toolToServers.has(tool.name)) toolToServers.set(tool.name, []);
|
|
3294
|
-
toolToServers.get(tool.name)?.push(serverDefinition.serverName);
|
|
3295
|
-
}
|
|
3296
|
-
}
|
|
3297
|
-
const lookupResults = await Promise.all(toolNames.map(async (requestedName) => {
|
|
3298
|
-
const result$1 = {
|
|
3299
|
-
tools: [],
|
|
3300
|
-
skills: [],
|
|
3301
|
-
notFound: null
|
|
3302
|
-
};
|
|
3303
|
-
if (requestedName.startsWith(SKILL_PREFIX)) {
|
|
3304
|
-
const skillName = requestedName.slice(SKILL_PREFIX.length);
|
|
3305
|
-
if (this.skillService) {
|
|
3306
|
-
const skill = await this.skillService.getSkill(skillName);
|
|
3307
|
-
if (skill) {
|
|
3308
|
-
result$1.skills.push({
|
|
3309
|
-
name: skill.name,
|
|
3310
|
-
location: skill.basePath,
|
|
3311
|
-
instructions: formatSkillInstructions(skill.name, skill.content)
|
|
3312
|
-
});
|
|
3313
|
-
return result$1;
|
|
3314
|
-
}
|
|
3315
|
-
}
|
|
3316
|
-
const promptSkillContent = await this.getPromptSkillContent(skillName);
|
|
3317
|
-
if (promptSkillContent) {
|
|
3318
|
-
result$1.skills.push(promptSkillContent);
|
|
3319
|
-
return result$1;
|
|
3320
|
-
}
|
|
3321
|
-
result$1.notFound = requestedName;
|
|
3322
|
-
return result$1;
|
|
3323
|
-
}
|
|
3324
|
-
const { serverName, actualToolName } = parseToolName(requestedName);
|
|
3325
|
-
if (serverName) {
|
|
3326
|
-
const serverTools = serverToolsMap.get(serverName);
|
|
3327
|
-
if (!serverTools) {
|
|
3328
|
-
result$1.notFound = requestedName;
|
|
3329
|
-
return result$1;
|
|
3330
|
-
}
|
|
3331
|
-
const tool = serverTools.find((t) => t.name === actualToolName);
|
|
3332
|
-
if (tool) result$1.tools.push({
|
|
3333
|
-
server: serverName,
|
|
3334
|
-
tool: {
|
|
3335
|
-
name: tool.name,
|
|
3336
|
-
description: tool.description,
|
|
3337
|
-
inputSchema: tool.inputSchema
|
|
3338
|
-
}
|
|
3339
|
-
});
|
|
3340
|
-
else result$1.notFound = requestedName;
|
|
3341
|
-
return result$1;
|
|
3342
|
-
}
|
|
3343
|
-
const servers = toolToServers.get(actualToolName);
|
|
3344
|
-
if (!servers || servers.length === 0) {
|
|
3345
|
-
if (this.skillService) {
|
|
3346
|
-
const skill = await this.skillService.getSkill(actualToolName);
|
|
3347
|
-
if (skill) {
|
|
3348
|
-
result$1.skills.push({
|
|
3349
|
-
name: skill.name,
|
|
3350
|
-
location: skill.basePath,
|
|
3351
|
-
instructions: formatSkillInstructions(skill.name, skill.content)
|
|
3352
|
-
});
|
|
3353
|
-
return result$1;
|
|
3354
|
-
}
|
|
3355
|
-
}
|
|
3356
|
-
const promptSkillContent = await this.getPromptSkillContent(actualToolName);
|
|
3357
|
-
if (promptSkillContent) {
|
|
3358
|
-
result$1.skills.push(promptSkillContent);
|
|
3359
|
-
return result$1;
|
|
3360
|
-
}
|
|
3361
|
-
result$1.notFound = requestedName;
|
|
3362
|
-
return result$1;
|
|
3363
|
-
}
|
|
3364
|
-
if (servers.length === 1) {
|
|
3365
|
-
const server = servers[0];
|
|
3366
|
-
const tool = serverToolsMap.get(server).find((t) => t.name === actualToolName);
|
|
3367
|
-
result$1.tools.push({
|
|
3368
|
-
server,
|
|
3369
|
-
tool: {
|
|
3370
|
-
name: tool.name,
|
|
3371
|
-
description: tool.description,
|
|
3372
|
-
inputSchema: tool.inputSchema
|
|
3373
|
-
}
|
|
3374
|
-
});
|
|
3375
|
-
} else for (const server of servers) {
|
|
3376
|
-
const tool = serverToolsMap.get(server).find((t) => t.name === actualToolName);
|
|
3377
|
-
result$1.tools.push({
|
|
3378
|
-
server,
|
|
3379
|
-
tool: {
|
|
3380
|
-
name: tool.name,
|
|
3381
|
-
description: tool.description,
|
|
3382
|
-
inputSchema: tool.inputSchema
|
|
3383
|
-
}
|
|
3384
|
-
});
|
|
3385
|
-
}
|
|
3386
|
-
return result$1;
|
|
3387
|
-
}));
|
|
3388
|
-
const foundTools = [];
|
|
3389
|
-
const foundSkills = [];
|
|
3390
|
-
const notFoundItems = [];
|
|
3391
|
-
for (const result$1 of lookupResults) {
|
|
3392
|
-
foundTools.push(...result$1.tools);
|
|
3393
|
-
foundSkills.push(...result$1.skills);
|
|
3394
|
-
if (result$1.notFound) notFoundItems.push(result$1.notFound);
|
|
3284
|
+
let lookup = await this.runLookups(toolNames, await this.definitionsCacheService.getServerDefinitions());
|
|
3285
|
+
if (lookup.notFoundItems.length > 0) {
|
|
3286
|
+
this.definitionsCacheService.clearLiveCache();
|
|
3287
|
+
await this.definitionsCacheService.collectForCache();
|
|
3288
|
+
lookup = await this.runLookups(toolNames, await this.definitionsCacheService.getServerDefinitions());
|
|
3395
3289
|
}
|
|
3290
|
+
const { foundTools, foundSkills, notFoundItems } = lookup;
|
|
3396
3291
|
if (foundTools.length === 0 && foundSkills.length === 0) return {
|
|
3397
3292
|
content: [{
|
|
3398
3293
|
type: "text",
|
|
@@ -3430,7 +3325,6 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
3430
3325
|
}
|
|
3431
3326
|
}
|
|
3432
3327
|
};
|
|
3433
|
-
|
|
3434
3328
|
//#endregion
|
|
3435
3329
|
//#region src/utils/toolCapabilities.ts
|
|
3436
3330
|
const TOOL_CAPABILITIES_META_KEY = "agiflowai/capabilities";
|
|
@@ -3442,7 +3336,6 @@ function getToolCapabilities(tool) {
|
|
|
3442
3336
|
function getUniqueSortedCapabilities(tools) {
|
|
3443
3337
|
return Array.from(new Set(tools.flatMap((tool) => getToolCapabilities(tool)))).sort();
|
|
3444
3338
|
}
|
|
3445
|
-
|
|
3446
3339
|
//#endregion
|
|
3447
3340
|
//#region src/tools/SearchListToolsTool.ts
|
|
3448
3341
|
const SearchListToolsToolInputSchema = z.object({
|
|
@@ -3504,17 +3397,15 @@ var SearchListToolsTool = class SearchListToolsTool {
|
|
|
3504
3397
|
capabilities: getToolCapabilities(tool)
|
|
3505
3398
|
}))
|
|
3506
3399
|
})).filter((server) => server.tools.length > 0);
|
|
3507
|
-
const result = { servers: filteredServers };
|
|
3508
3400
|
return {
|
|
3509
3401
|
content: [{
|
|
3510
3402
|
type: "text",
|
|
3511
|
-
text: JSON.stringify(
|
|
3403
|
+
text: JSON.stringify({ servers: filteredServers }, null, 2)
|
|
3512
3404
|
}],
|
|
3513
3405
|
isError: filteredServers.length === 0 ? true : void 0
|
|
3514
3406
|
};
|
|
3515
3407
|
}
|
|
3516
3408
|
};
|
|
3517
|
-
|
|
3518
3409
|
//#endregion
|
|
3519
3410
|
//#region src/tools/UseToolTool.ts
|
|
3520
3411
|
/**
|
|
@@ -3580,7 +3471,7 @@ var UseToolTool = class UseToolTool {
|
|
|
3580
3471
|
this.clientManager = clientManager;
|
|
3581
3472
|
this.skillService = skillService;
|
|
3582
3473
|
this.definitionsCacheService = definitionsCacheService || new DefinitionsCacheService(clientManager, skillService);
|
|
3583
|
-
this.serverId = serverId ||
|
|
3474
|
+
this.serverId = serverId || "unknown";
|
|
3584
3475
|
}
|
|
3585
3476
|
/**
|
|
3586
3477
|
* Returns the MCP tool definition with name, description, and input schema.
|
|
@@ -3673,8 +3564,8 @@ IMPORTANT: Only use tools discovered from describe_tools with id="${this.serverI
|
|
|
3673
3564
|
async execute(rawInput) {
|
|
3674
3565
|
try {
|
|
3675
3566
|
const { toolName: inputToolName, toolArgs = {} } = UseToolToolInputSchema.parse(rawInput);
|
|
3676
|
-
if (inputToolName.startsWith(
|
|
3677
|
-
const skillName = inputToolName.slice(
|
|
3567
|
+
if (inputToolName.startsWith("skill__")) {
|
|
3568
|
+
const skillName = inputToolName.slice(7);
|
|
3678
3569
|
if (this.skillService) {
|
|
3679
3570
|
const skill = await this.skillService.getSkill(skillName);
|
|
3680
3571
|
if (skill) return this.executeSkill(skill);
|
|
@@ -3712,7 +3603,12 @@ IMPORTANT: Only use tools discovered from describe_tools with id="${this.serverI
|
|
|
3712
3603
|
isError: true
|
|
3713
3604
|
};
|
|
3714
3605
|
}
|
|
3715
|
-
|
|
3606
|
+
let matchingServers = await this.definitionsCacheService.getServersForTool(actualToolName);
|
|
3607
|
+
if (matchingServers.length === 0) {
|
|
3608
|
+
this.definitionsCacheService.clearLiveCache();
|
|
3609
|
+
await this.definitionsCacheService.collectForCache();
|
|
3610
|
+
matchingServers = await this.definitionsCacheService.getServersForTool(actualToolName);
|
|
3611
|
+
}
|
|
3716
3612
|
if (matchingServers.length === 0) {
|
|
3717
3613
|
if (this.skillService) {
|
|
3718
3614
|
const skill = await this.skillService.getSkill(actualToolName);
|
|
@@ -3761,7 +3657,6 @@ IMPORTANT: Only use tools discovered from describe_tools with id="${this.serverI
|
|
|
3761
3657
|
}
|
|
3762
3658
|
}
|
|
3763
3659
|
};
|
|
3764
|
-
|
|
3765
3660
|
//#endregion
|
|
3766
3661
|
//#region src/transports/http.ts
|
|
3767
3662
|
/**
|
|
@@ -3903,13 +3798,13 @@ var AdminRateLimiter = class {
|
|
|
3903
3798
|
* Parse JSON body from IncomingMessage
|
|
3904
3799
|
*/
|
|
3905
3800
|
async function parseJsonBody$1(req) {
|
|
3906
|
-
return new Promise((resolve
|
|
3801
|
+
return new Promise((resolve, reject) => {
|
|
3907
3802
|
const chunks = [];
|
|
3908
3803
|
req.on("data", (chunk) => chunks.push(chunk));
|
|
3909
3804
|
req.on("end", () => {
|
|
3910
3805
|
try {
|
|
3911
3806
|
const body = Buffer.concat(chunks).toString("utf-8");
|
|
3912
|
-
resolve
|
|
3807
|
+
resolve(body ? JSON.parse(body) : void 0);
|
|
3913
3808
|
} catch (error) {
|
|
3914
3809
|
reject(/* @__PURE__ */ new Error(`Failed to parse JSON body: ${toErrorMessage(error)}`));
|
|
3915
3810
|
}
|
|
@@ -3997,24 +3892,24 @@ var HttpTransportHandler = class {
|
|
|
3997
3892
|
}
|
|
3998
3893
|
async handleAdminShutdownRequest(c) {
|
|
3999
3894
|
if (!this.adminOptions?.onShutdownRequested) {
|
|
4000
|
-
const payload
|
|
3895
|
+
const payload = {
|
|
4001
3896
|
ok: false,
|
|
4002
3897
|
message: "Shutdown endpoint is not enabled for this server instance.",
|
|
4003
3898
|
serverId: this.adminOptions?.serverId
|
|
4004
3899
|
};
|
|
4005
|
-
return c.json(payload
|
|
3900
|
+
return c.json(payload, 404);
|
|
4006
3901
|
}
|
|
4007
3902
|
const headers = {
|
|
4008
3903
|
authorization: c.req.header("authorization"),
|
|
4009
3904
|
"x-mcp-proxy-shutdown-token": c.req.header("x-mcp-proxy-shutdown-token")
|
|
4010
3905
|
};
|
|
4011
3906
|
if (!this.isAuthorizedShutdownRequest(headers)) {
|
|
4012
|
-
const payload
|
|
3907
|
+
const payload = {
|
|
4013
3908
|
ok: false,
|
|
4014
3909
|
message: "Unauthorized shutdown request: invalid or missing shutdown token.",
|
|
4015
3910
|
serverId: this.adminOptions?.serverId
|
|
4016
3911
|
};
|
|
4017
|
-
return c.json(payload
|
|
3912
|
+
return c.json(payload, 401);
|
|
4018
3913
|
}
|
|
4019
3914
|
const payload = {
|
|
4020
3915
|
ok: true,
|
|
@@ -4170,7 +4065,6 @@ var HttpTransportHandler = class {
|
|
|
4170
4065
|
return this.config.host;
|
|
4171
4066
|
}
|
|
4172
4067
|
};
|
|
4173
|
-
|
|
4174
4068
|
//#endregion
|
|
4175
4069
|
//#region src/transports/sse.ts
|
|
4176
4070
|
/**
|
|
@@ -4240,13 +4134,13 @@ var SseSessionManager = class {
|
|
|
4240
4134
|
* Parse JSON body from IncomingMessage
|
|
4241
4135
|
*/
|
|
4242
4136
|
async function parseJsonBody(req) {
|
|
4243
|
-
return new Promise((resolve
|
|
4137
|
+
return new Promise((resolve, reject) => {
|
|
4244
4138
|
const chunks = [];
|
|
4245
4139
|
req.on("data", (chunk) => chunks.push(chunk));
|
|
4246
4140
|
req.on("end", () => {
|
|
4247
4141
|
try {
|
|
4248
4142
|
const body = Buffer.concat(chunks).toString("utf-8");
|
|
4249
|
-
resolve
|
|
4143
|
+
resolve(body ? JSON.parse(body) : void 0);
|
|
4250
4144
|
} catch (error) {
|
|
4251
4145
|
reject(/* @__PURE__ */ new Error(`Failed to parse JSON body: ${error instanceof Error ? error.message : String(error)}`));
|
|
4252
4146
|
}
|
|
@@ -4330,7 +4224,7 @@ var SseTransportHandler = class {
|
|
|
4330
4224
|
}
|
|
4331
4225
|
}
|
|
4332
4226
|
async start() {
|
|
4333
|
-
return new Promise((resolve
|
|
4227
|
+
return new Promise((resolve, reject) => {
|
|
4334
4228
|
try {
|
|
4335
4229
|
const honoHandler = getRequestListener(this.honoApp.fetch);
|
|
4336
4230
|
const server = createServer(async (req, res) => {
|
|
@@ -4345,7 +4239,7 @@ var SseTransportHandler = class {
|
|
|
4345
4239
|
this.logger.info(`SSE endpoint: http://${this.config.host}:${this.config.port}/sse`);
|
|
4346
4240
|
this.logger.info(`Messages endpoint: http://${this.config.host}:${this.config.port}/messages`);
|
|
4347
4241
|
this.logger.info(`Health check: http://${this.config.host}:${this.config.port}/health`);
|
|
4348
|
-
resolve
|
|
4242
|
+
resolve();
|
|
4349
4243
|
});
|
|
4350
4244
|
server.on("error", (error) => {
|
|
4351
4245
|
reject(error);
|
|
@@ -4357,7 +4251,7 @@ var SseTransportHandler = class {
|
|
|
4357
4251
|
});
|
|
4358
4252
|
}
|
|
4359
4253
|
async stop() {
|
|
4360
|
-
return new Promise((resolve
|
|
4254
|
+
return new Promise((resolve, reject) => {
|
|
4361
4255
|
if (this.server) {
|
|
4362
4256
|
const server = this.server;
|
|
4363
4257
|
(async () => {
|
|
@@ -4367,14 +4261,14 @@ var SseTransportHandler = class {
|
|
|
4367
4261
|
if (err) reject(err);
|
|
4368
4262
|
else {
|
|
4369
4263
|
this.server = null;
|
|
4370
|
-
resolve
|
|
4264
|
+
resolve();
|
|
4371
4265
|
}
|
|
4372
4266
|
});
|
|
4373
4267
|
} catch (error) {
|
|
4374
4268
|
reject(error);
|
|
4375
4269
|
}
|
|
4376
4270
|
})();
|
|
4377
|
-
} else resolve
|
|
4271
|
+
} else resolve();
|
|
4378
4272
|
});
|
|
4379
4273
|
}
|
|
4380
4274
|
getPort() {
|
|
@@ -4384,7 +4278,6 @@ var SseTransportHandler = class {
|
|
|
4384
4278
|
return this.config.host;
|
|
4385
4279
|
}
|
|
4386
4280
|
};
|
|
4387
|
-
|
|
4388
4281
|
//#endregion
|
|
4389
4282
|
//#region src/transports/stdio.ts
|
|
4390
4283
|
/**
|
|
@@ -4411,7 +4304,6 @@ var StdioTransportHandler = class {
|
|
|
4411
4304
|
}
|
|
4412
4305
|
}
|
|
4413
4306
|
};
|
|
4414
|
-
|
|
4415
4307
|
//#endregion
|
|
4416
4308
|
//#region src/transports/stdio-http.ts
|
|
4417
4309
|
/**
|
|
@@ -4533,7 +4425,7 @@ var StdioHttpTransportHandler = class {
|
|
|
4533
4425
|
async reconnectWithBackoff() {
|
|
4534
4426
|
for (let attempt = 0; attempt < this.MAX_RECONNECT_ATTEMPTS; attempt++) {
|
|
4535
4427
|
const delay = Math.min(this.RECONNECT_BASE_MS * 2 ** attempt, this.RECONNECT_MAX_MS);
|
|
4536
|
-
await new Promise((resolve
|
|
4428
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
4537
4429
|
try {
|
|
4538
4430
|
await this.httpClient?.close().catch(() => void 0);
|
|
4539
4431
|
const client = await this.createAndConnectClient();
|
|
@@ -4619,7 +4511,6 @@ var StdioHttpTransportHandler = class {
|
|
|
4619
4511
|
return proxyServer;
|
|
4620
4512
|
}
|
|
4621
4513
|
};
|
|
4622
|
-
|
|
4623
4514
|
//#endregion
|
|
4624
4515
|
//#region src/container/index.ts
|
|
4625
4516
|
/**
|
|
@@ -4651,13 +4542,13 @@ function createProxyIoCContainer(logger = console) {
|
|
|
4651
4542
|
createDescribeToolsTool: (clientManager, skillService, serverId, definitionsCacheService) => new DescribeToolsTool(clientManager, skillService, serverId, definitionsCacheService),
|
|
4652
4543
|
createUseToolTool: (clientManager, skillService, serverId, definitionsCacheService) => new UseToolTool(clientManager, skillService, serverId, definitionsCacheService),
|
|
4653
4544
|
createSearchListToolsTool: (clientManager, definitionsCacheService) => new SearchListToolsTool(clientManager, definitionsCacheService),
|
|
4654
|
-
createStdioTransportHandler: async (createServer
|
|
4655
|
-
return new StdioTransportHandler(await createServer
|
|
4545
|
+
createStdioTransportHandler: async (createServer) => {
|
|
4546
|
+
return new StdioTransportHandler(await createServer(), logger);
|
|
4656
4547
|
},
|
|
4657
|
-
createSseTransportHandler: async (createServer
|
|
4658
|
-
return new SseTransportHandler(await createServer
|
|
4548
|
+
createSseTransportHandler: async (createServer, config) => {
|
|
4549
|
+
return new SseTransportHandler(await createServer(), config, logger);
|
|
4659
4550
|
},
|
|
4660
|
-
createHttpTransportHandler: (createServer
|
|
4551
|
+
createHttpTransportHandler: (createServer, config, adminOptions) => new HttpTransportHandler(createServer, config, adminOptions, logger),
|
|
4661
4552
|
createStdioHttpTransportHandler: (endpoint) => new StdioHttpTransportHandler({ endpoint }, logger)
|
|
4662
4553
|
};
|
|
4663
4554
|
}
|
|
@@ -4794,22 +4685,22 @@ async function createProxyContainer(options) {
|
|
|
4794
4685
|
/**
|
|
4795
4686
|
* Create a sessionless stdio transport handler from the shared server factory.
|
|
4796
4687
|
*/
|
|
4797
|
-
async function createStdioTransportHandler(createServer
|
|
4798
|
-
const server = await createServer
|
|
4688
|
+
async function createStdioTransportHandler(createServer) {
|
|
4689
|
+
const server = await createServer();
|
|
4799
4690
|
return createProxyIoCContainer().createStdioTransportHandler(() => Promise.resolve(server));
|
|
4800
4691
|
}
|
|
4801
4692
|
/**
|
|
4802
4693
|
* Create an SSE transport handler from the shared server factory.
|
|
4803
4694
|
*/
|
|
4804
|
-
async function createSseTransportHandler(createServer
|
|
4805
|
-
const server = await createServer
|
|
4695
|
+
async function createSseTransportHandler(createServer, config) {
|
|
4696
|
+
const server = await createServer();
|
|
4806
4697
|
return createProxyIoCContainer().createSseTransportHandler(() => Promise.resolve(server), config);
|
|
4807
4698
|
}
|
|
4808
4699
|
/**
|
|
4809
4700
|
* Create an HTTP transport handler from shared services.
|
|
4810
4701
|
*/
|
|
4811
|
-
function createHttpTransportHandler(createServer
|
|
4812
|
-
return createProxyIoCContainer().createHttpTransportHandler(createServer
|
|
4702
|
+
function createHttpTransportHandler(createServer, config, adminOptions) {
|
|
4703
|
+
return createProxyIoCContainer().createHttpTransportHandler(createServer, config, adminOptions);
|
|
4813
4704
|
}
|
|
4814
4705
|
/**
|
|
4815
4706
|
* Create a stdio-http transport handler from an endpoint URL.
|
|
@@ -4823,7 +4714,6 @@ function createStdioHttpTransportHandler(endpoint) {
|
|
|
4823
4714
|
async function initializeSharedServices(options) {
|
|
4824
4715
|
return createProxyContainer(options);
|
|
4825
4716
|
}
|
|
4826
|
-
|
|
4827
4717
|
//#endregion
|
|
4828
4718
|
//#region src/server/index.ts
|
|
4829
4719
|
/**
|
|
@@ -5074,7 +4964,6 @@ async function createSessionServer(shared) {
|
|
|
5074
4964
|
async function createServer$1(options) {
|
|
5075
4965
|
return createSessionServer(await createProxyContainer(options));
|
|
5076
4966
|
}
|
|
5077
|
-
|
|
5078
4967
|
//#endregion
|
|
5079
4968
|
//#region src/types/index.ts
|
|
5080
4969
|
/**
|
|
@@ -5085,6 +4974,5 @@ const TRANSPORT_MODE = {
|
|
|
5085
4974
|
HTTP: "http",
|
|
5086
4975
|
SSE: "sse"
|
|
5087
4976
|
};
|
|
5088
|
-
|
|
5089
4977
|
//#endregion
|
|
5090
|
-
export { DefinitionsCacheService as C, version as D, ConfigFetcherService as E, createProxyLogger as S, findConfigFile as T, DescribeToolsTool as _, createProxyContainer as a, RuntimeStateService as b, createStdioHttpTransportHandler as c, StdioHttpTransportHandler as d, StdioTransportHandler as f, SearchListToolsTool as g, UseToolTool as h, createHttpTransportHandler as i, createStdioTransportHandler as l, HttpTransportHandler as m, createServer$1 as n, createProxyIoCContainer as o, SseTransportHandler as p, createSessionServer as r, createSseTransportHandler as s, TRANSPORT_MODE as t, initializeSharedServices as u, SkillService as v, generateServerId as w, McpClientManagerService as x, StopServerService as y };
|
|
4978
|
+
export { DefinitionsCacheService as C, version as D, ConfigFetcherService as E, createProxyLogger as S, findConfigFile as T, DescribeToolsTool as _, createProxyContainer as a, RuntimeStateService as b, createStdioHttpTransportHandler as c, StdioHttpTransportHandler as d, StdioTransportHandler as f, SearchListToolsTool as g, UseToolTool as h, createHttpTransportHandler as i, createStdioTransportHandler as l, HttpTransportHandler as m, createServer$1 as n, createProxyIoCContainer as o, SseTransportHandler as p, createSessionServer as r, createSseTransportHandler as s, TRANSPORT_MODE as t, initializeSharedServices as u, SkillService as v, generateServerId as w, McpClientManagerService as x, StopServerService as y };
|