@agimon-ai/mcp-proxy 0.7.2 → 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 +35 -25
- package/dist/index.d.mts +34 -25
- package/dist/index.mjs +2 -3
- package/dist/{src-NZo_eM6U.mjs → src-Dorvm5bM.mjs} +302 -381
- package/dist/{src-BXEt-Hpg.cjs → src-dZuRf3Wt.cjs} +486 -570
- package/package.json +19 -18
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -6,16 +6,12 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
19
15
|
}
|
|
20
16
|
return to;
|
|
21
17
|
};
|
|
@@ -23,37 +19,35 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
19
|
value: mod,
|
|
24
20
|
enumerable: true
|
|
25
21
|
}) : target, mod));
|
|
26
|
-
|
|
27
22
|
//#endregion
|
|
28
|
-
let
|
|
29
|
-
let
|
|
23
|
+
let _agimon_ai_foundation_validator = require("@agimon-ai/foundation-validator");
|
|
24
|
+
let _modelcontextprotocol_sdk_server_index_js = require("@modelcontextprotocol/sdk/server/index.js");
|
|
25
|
+
let _modelcontextprotocol_sdk_types_js = require("@modelcontextprotocol/sdk/types.js");
|
|
26
|
+
let zod = require("zod");
|
|
30
27
|
let node_fs = require("node:fs");
|
|
31
28
|
let node_fs_promises = require("node:fs/promises");
|
|
32
29
|
let js_yaml = require("js-yaml");
|
|
33
30
|
js_yaml = __toESM(js_yaml);
|
|
34
|
-
let zod = require("zod");
|
|
35
31
|
let node_crypto = require("node:crypto");
|
|
36
32
|
let node_os = require("node:os");
|
|
37
33
|
let node_path = require("node:path");
|
|
38
|
-
let
|
|
39
|
-
let
|
|
40
|
-
let
|
|
41
|
-
let
|
|
42
|
-
let
|
|
34
|
+
let _agimon_ai_log_sink_mcp = require("@agimon-ai/log-sink-mcp");
|
|
35
|
+
let _modelcontextprotocol_sdk_client_index_js = require("@modelcontextprotocol/sdk/client/index.js");
|
|
36
|
+
let _modelcontextprotocol_sdk_client_sse_js = require("@modelcontextprotocol/sdk/client/sse.js");
|
|
37
|
+
let _modelcontextprotocol_sdk_client_stdio_js = require("@modelcontextprotocol/sdk/client/stdio.js");
|
|
38
|
+
let _modelcontextprotocol_sdk_client_streamableHttp_js = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
43
39
|
let node_child_process = require("node:child_process");
|
|
44
40
|
let liquidjs = require("liquidjs");
|
|
45
41
|
let node_events = require("node:events");
|
|
46
42
|
let node_http = require("node:http");
|
|
47
43
|
let node_util = require("node:util");
|
|
48
|
-
let
|
|
49
|
-
let
|
|
44
|
+
let _hono_node_server = require("@hono/node-server");
|
|
45
|
+
let _modelcontextprotocol_sdk_server_streamableHttp_js = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
50
46
|
let hono = require("hono");
|
|
51
|
-
let
|
|
52
|
-
let
|
|
53
|
-
|
|
47
|
+
let _modelcontextprotocol_sdk_server_sse_js = require("@modelcontextprotocol/sdk/server/sse.js");
|
|
48
|
+
let _modelcontextprotocol_sdk_server_stdio_js = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
54
49
|
//#region package.json
|
|
55
|
-
var version = "0.7.
|
|
56
|
-
|
|
50
|
+
var version = "0.7.3";
|
|
57
51
|
//#endregion
|
|
58
52
|
//#region src/utils/mcpConfigSchema.ts
|
|
59
53
|
/**
|
|
@@ -448,7 +442,6 @@ function parseMcpConfig(rawConfig) {
|
|
|
448
442
|
const internalConfig = transformClaudeCodeConfig(ClaudeCodeMcpConfigSchema.parse(rawConfig));
|
|
449
443
|
return InternalMcpConfigSchema.parse(internalConfig);
|
|
450
444
|
}
|
|
451
|
-
|
|
452
445
|
//#endregion
|
|
453
446
|
//#region src/services/RemoteConfigCacheService.ts
|
|
454
447
|
/**
|
|
@@ -675,7 +668,6 @@ var RemoteConfigCacheService = class {
|
|
|
675
668
|
this.writeEnabled = enabled;
|
|
676
669
|
}
|
|
677
670
|
};
|
|
678
|
-
|
|
679
671
|
//#endregion
|
|
680
672
|
//#region src/services/ConfigFetcherService.ts
|
|
681
673
|
/**
|
|
@@ -902,7 +894,6 @@ var ConfigFetcherService = class {
|
|
|
902
894
|
return this.cachedConfig !== null && now - this.lastFetchTime < this.cacheTtlMs;
|
|
903
895
|
}
|
|
904
896
|
};
|
|
905
|
-
|
|
906
897
|
//#endregion
|
|
907
898
|
//#region src/constants/index.ts
|
|
908
899
|
/**
|
|
@@ -922,17 +913,6 @@ const LOG_PREFIX_SKILL_DETECTION = "[skill-detection]";
|
|
|
922
913
|
* Log prefix for general MCP capability discovery messages.
|
|
923
914
|
*/
|
|
924
915
|
const LOG_PREFIX_CAPABILITY_DISCOVERY = "[capability-discovery]";
|
|
925
|
-
/**
|
|
926
|
-
* Prefix for prompt-based skill locations.
|
|
927
|
-
* Format: "prompt:{serverName}:{promptName}"
|
|
928
|
-
*/
|
|
929
|
-
const PROMPT_LOCATION_PREFIX = "prompt:";
|
|
930
|
-
/**
|
|
931
|
-
* Default server ID used when no ID is provided via CLI or config.
|
|
932
|
-
* This fallback is used when auto-generation also fails.
|
|
933
|
-
*/
|
|
934
|
-
const DEFAULT_SERVER_ID = "unknown";
|
|
935
|
-
|
|
936
916
|
//#endregion
|
|
937
917
|
//#region src/utils/findConfigFile.ts
|
|
938
918
|
/**
|
|
@@ -985,7 +965,6 @@ function findConfigFile() {
|
|
|
985
965
|
}
|
|
986
966
|
return null;
|
|
987
967
|
}
|
|
988
|
-
|
|
989
968
|
//#endregion
|
|
990
969
|
//#region src/utils/parseToolName.ts
|
|
991
970
|
/**
|
|
@@ -1007,7 +986,6 @@ function parseToolName(toolName) {
|
|
|
1007
986
|
};
|
|
1008
987
|
return { actualToolName: toolName };
|
|
1009
988
|
}
|
|
1010
|
-
|
|
1011
989
|
//#endregion
|
|
1012
990
|
//#region src/utils/parseFrontMatter.ts
|
|
1013
991
|
/**
|
|
@@ -1141,7 +1119,6 @@ function extractSkillFrontMatter(content) {
|
|
|
1141
1119
|
};
|
|
1142
1120
|
return null;
|
|
1143
1121
|
}
|
|
1144
|
-
|
|
1145
1122
|
//#endregion
|
|
1146
1123
|
//#region src/utils/generateServerId.ts
|
|
1147
1124
|
/**
|
|
@@ -1206,7 +1183,6 @@ function generateServerId(length = DEFAULT_ID_LENGTH) {
|
|
|
1206
1183
|
}
|
|
1207
1184
|
return result;
|
|
1208
1185
|
}
|
|
1209
|
-
|
|
1210
1186
|
//#endregion
|
|
1211
1187
|
//#region src/services/DefinitionsCacheService.ts
|
|
1212
1188
|
/**
|
|
@@ -1365,6 +1341,9 @@ var DefinitionsCacheService = class {
|
|
|
1365
1341
|
async getServersForTool(toolName) {
|
|
1366
1342
|
return (await this.getServerDefinitions()).filter((serverDefinition) => serverDefinition.tools.some((tool) => tool.name === toolName)).map((serverDefinition) => serverDefinition.serverName);
|
|
1367
1343
|
}
|
|
1344
|
+
async getToolSchema(serverName, toolName) {
|
|
1345
|
+
return (await this.getDefinitions()).servers[serverName]?.tools.find((t) => t.name === toolName)?.inputSchema;
|
|
1346
|
+
}
|
|
1368
1347
|
async getServersForResource(uri) {
|
|
1369
1348
|
return (await this.getServerDefinitions()).filter((serverDefinition) => serverDefinition.resources.some((resource) => resource.uri === uri)).map((serverDefinition) => serverDefinition.serverName);
|
|
1370
1349
|
}
|
|
@@ -1502,7 +1481,6 @@ var DefinitionsCacheService = class {
|
|
|
1502
1481
|
return promptSkills;
|
|
1503
1482
|
}
|
|
1504
1483
|
};
|
|
1505
|
-
|
|
1506
1484
|
//#endregion
|
|
1507
1485
|
//#region src/services/logger.ts
|
|
1508
1486
|
function isRecord(value) {
|
|
@@ -1545,7 +1523,7 @@ function createLoggerFacade(handle) {
|
|
|
1545
1523
|
};
|
|
1546
1524
|
}
|
|
1547
1525
|
async function createProxyLogger(options = {}) {
|
|
1548
|
-
return createLoggerFacade(await (0,
|
|
1526
|
+
return createLoggerFacade(await (0, _agimon_ai_log_sink_mcp.createNodeTelemetry)({
|
|
1549
1527
|
env: options.env,
|
|
1550
1528
|
workspaceRoot: options.workspaceRoot,
|
|
1551
1529
|
serviceName: options.serviceName ?? "@agimon-ai/mcp-proxy",
|
|
@@ -1556,7 +1534,6 @@ async function createProxyLogger(options = {}) {
|
|
|
1556
1534
|
maxFileCount: options.maxFileCount
|
|
1557
1535
|
}));
|
|
1558
1536
|
}
|
|
1559
|
-
|
|
1560
1537
|
//#endregion
|
|
1561
1538
|
//#region src/services/McpClientManagerService.ts
|
|
1562
1539
|
/** Default connection timeout in milliseconds (30 seconds) */
|
|
@@ -1628,8 +1605,8 @@ var McpClient = class {
|
|
|
1628
1605
|
this.logger = logger;
|
|
1629
1606
|
this.client = client;
|
|
1630
1607
|
}
|
|
1631
|
-
setChildProcess(process
|
|
1632
|
-
this.childProcess = process
|
|
1608
|
+
setChildProcess(process) {
|
|
1609
|
+
this.childProcess = process;
|
|
1633
1610
|
}
|
|
1634
1611
|
setConnected(connected) {
|
|
1635
1612
|
this.connected = connected;
|
|
@@ -1758,7 +1735,7 @@ var McpClientManagerService = class {
|
|
|
1758
1735
|
if (childProcess && !childProcess.killed) {
|
|
1759
1736
|
this.logger.info(`Killing stdio MCP server: ${serverName} (PID: ${childProcess.pid})`);
|
|
1760
1737
|
childProcess.kill("SIGTERM");
|
|
1761
|
-
killPromises.push(new Promise((resolve
|
|
1738
|
+
killPromises.push(new Promise((resolve) => {
|
|
1762
1739
|
setTimeout(() => {
|
|
1763
1740
|
try {
|
|
1764
1741
|
if (!childProcess.killed) {
|
|
@@ -1766,7 +1743,7 @@ var McpClientManagerService = class {
|
|
|
1766
1743
|
childProcess.kill("SIGKILL");
|
|
1767
1744
|
}
|
|
1768
1745
|
} catch {}
|
|
1769
|
-
resolve
|
|
1746
|
+
resolve();
|
|
1770
1747
|
}, 1e3);
|
|
1771
1748
|
}));
|
|
1772
1749
|
}
|
|
@@ -1809,8 +1786,8 @@ var McpClientManagerService = class {
|
|
|
1809
1786
|
}
|
|
1810
1787
|
async createConnection(serverName, config) {
|
|
1811
1788
|
const timeoutMs = config.timeout ?? DEFAULT_CONNECTION_TIMEOUT_MS;
|
|
1812
|
-
const client = new
|
|
1813
|
-
name:
|
|
1789
|
+
const client = new _modelcontextprotocol_sdk_client_index_js.Client({
|
|
1790
|
+
name: "@agimon-ai/mcp-proxy-client",
|
|
1814
1791
|
version: "0.1.0"
|
|
1815
1792
|
}, { capabilities: {} });
|
|
1816
1793
|
const mcpClient = new McpClient(serverName, config.transport, client, this.logger, {
|
|
@@ -1824,7 +1801,7 @@ var McpClientManagerService = class {
|
|
|
1824
1801
|
mcpClient.setConnected(true);
|
|
1825
1802
|
if (config.transport === "http" || config.transport === "sse") mcpClient.setReconnectFn(async () => {
|
|
1826
1803
|
try {
|
|
1827
|
-
const newClient = new
|
|
1804
|
+
const newClient = new _modelcontextprotocol_sdk_client_index_js.Client({
|
|
1828
1805
|
name: "@agimon-ai/mcp-proxy-client",
|
|
1829
1806
|
version: "0.1.0"
|
|
1830
1807
|
}, { capabilities: {} });
|
|
@@ -1859,7 +1836,7 @@ var McpClientManagerService = class {
|
|
|
1859
1836
|
else throw new Error(`Unsupported transport type: ${config.transport}`);
|
|
1860
1837
|
}
|
|
1861
1838
|
async connectStdioClient(mcpClient, config) {
|
|
1862
|
-
const transport = new
|
|
1839
|
+
const transport = new _modelcontextprotocol_sdk_client_stdio_js.StdioClientTransport({
|
|
1863
1840
|
command: config.command,
|
|
1864
1841
|
args: config.args,
|
|
1865
1842
|
env: {
|
|
@@ -1872,11 +1849,11 @@ var McpClientManagerService = class {
|
|
|
1872
1849
|
if (childProcess) mcpClient.setChildProcess(childProcess);
|
|
1873
1850
|
}
|
|
1874
1851
|
async connectHttpClient(mcpClient, config) {
|
|
1875
|
-
const transport = new
|
|
1852
|
+
const transport = new _modelcontextprotocol_sdk_client_streamableHttp_js.StreamableHTTPClientTransport(new URL(config.url), { requestInit: config.headers ? { headers: config.headers } : void 0 });
|
|
1876
1853
|
await mcpClient["client"].connect(transport);
|
|
1877
1854
|
}
|
|
1878
1855
|
async connectSseClient(mcpClient, config) {
|
|
1879
|
-
const transport = new
|
|
1856
|
+
const transport = new _modelcontextprotocol_sdk_client_sse_js.SSEClientTransport(new URL(config.url));
|
|
1880
1857
|
await mcpClient["client"].connect(transport);
|
|
1881
1858
|
}
|
|
1882
1859
|
/**
|
|
@@ -1917,7 +1894,6 @@ var McpClientManagerService = class {
|
|
|
1917
1894
|
return this.clients.has(serverName);
|
|
1918
1895
|
}
|
|
1919
1896
|
};
|
|
1920
|
-
|
|
1921
1897
|
//#endregion
|
|
1922
1898
|
//#region src/services/RuntimeStateService.ts
|
|
1923
1899
|
/**
|
|
@@ -2019,24 +1995,10 @@ var RuntimeStateService = class RuntimeStateService {
|
|
|
2019
1995
|
await (0, node_fs_promises.rm)(this.getRecordPath(serverId), { force: true });
|
|
2020
1996
|
}
|
|
2021
1997
|
};
|
|
2022
|
-
|
|
2023
|
-
//#endregion
|
|
2024
|
-
//#region src/services/StopServerService/constants.ts
|
|
2025
|
-
/**
|
|
2026
|
-
* StopServerService constants.
|
|
2027
|
-
*/
|
|
2028
|
-
/** Maximum time in milliseconds to wait for a shutdown to complete. */
|
|
2029
|
-
const DEFAULT_STOP_TIMEOUT_MS = 5e3;
|
|
2030
|
-
/** Minimum timeout in milliseconds for individual health check requests. */
|
|
2031
|
-
const HEALTH_REQUEST_TIMEOUT_FLOOR_MS = 250;
|
|
2032
|
-
/** Delay in milliseconds between shutdown polling attempts. */
|
|
2033
|
-
const SHUTDOWN_POLL_INTERVAL_MS = 200;
|
|
2034
1998
|
/** Path for the runtime health check endpoint. */
|
|
2035
1999
|
const HEALTH_CHECK_PATH = "/health";
|
|
2036
2000
|
/** Path for the authenticated admin shutdown endpoint. */
|
|
2037
2001
|
const ADMIN_SHUTDOWN_PATH = "/admin/shutdown";
|
|
2038
|
-
/** HTTP GET method identifier. */
|
|
2039
|
-
const HTTP_METHOD_GET = "GET";
|
|
2040
2002
|
/** HTTP POST method identifier. */
|
|
2041
2003
|
const HTTP_METHOD_POST = "POST";
|
|
2042
2004
|
/** HTTP header name for bearer token authorization. */
|
|
@@ -2045,35 +2007,12 @@ const AUTHORIZATION_HEADER_NAME = "Authorization";
|
|
|
2045
2007
|
const BEARER_TOKEN_PREFIX = "Bearer ";
|
|
2046
2008
|
/** HTTP protocol scheme prefix for URL construction. */
|
|
2047
2009
|
const HTTP_PROTOCOL = "http://";
|
|
2048
|
-
/** Separator between host and port in URL construction. */
|
|
2049
|
-
const URL_PORT_SEPARATOR = ":";
|
|
2050
|
-
/** Loopback hostname. */
|
|
2051
|
-
const LOOPBACK_HOST_LOCALHOST = "localhost";
|
|
2052
|
-
/** IPv4 loopback address. */
|
|
2053
|
-
const LOOPBACK_HOST_IPV4 = "127.0.0.1";
|
|
2054
|
-
/** IPv6 loopback address. */
|
|
2055
|
-
const LOOPBACK_HOST_IPV6 = "::1";
|
|
2056
2010
|
/** Hosts that are safe to send admin requests to (loopback only). */
|
|
2057
2011
|
const ALLOWED_HOSTS = new Set([
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2012
|
+
"localhost",
|
|
2013
|
+
"127.0.0.1",
|
|
2014
|
+
"::1"
|
|
2061
2015
|
]);
|
|
2062
|
-
/** Expected status value in a healthy runtime response. */
|
|
2063
|
-
const HEALTH_STATUS_OK = "ok";
|
|
2064
|
-
/** Expected transport value in a healthy runtime response. */
|
|
2065
|
-
const HEALTH_TRANSPORT_HTTP = "http";
|
|
2066
|
-
/** Property key for status field in health responses. */
|
|
2067
|
-
const KEY_STATUS = "status";
|
|
2068
|
-
/** Property key for transport field in health responses. */
|
|
2069
|
-
const KEY_TRANSPORT = "transport";
|
|
2070
|
-
/** Property key for serverId field in runtime responses. */
|
|
2071
|
-
const KEY_SERVER_ID = "serverId";
|
|
2072
|
-
/** Property key for ok field in shutdown responses. */
|
|
2073
|
-
const KEY_OK = "ok";
|
|
2074
|
-
/** Property key for message field in shutdown responses. */
|
|
2075
|
-
const KEY_MESSAGE = "message";
|
|
2076
|
-
|
|
2077
2016
|
//#endregion
|
|
2078
2017
|
//#region src/services/StopServerService/types.ts
|
|
2079
2018
|
/**
|
|
@@ -2092,7 +2031,7 @@ function toRecord(value) {
|
|
|
2092
2031
|
function isHealthResponse(value) {
|
|
2093
2032
|
if (typeof value !== "object" || value === null) return false;
|
|
2094
2033
|
const record = toRecord(value);
|
|
2095
|
-
return
|
|
2034
|
+
return "status" in record && record["status"] === "ok" && "transport" in record && record["transport"] === "http" && (!("serverId" in record) || record["serverId"] === void 0 || typeof record["serverId"] === "string");
|
|
2096
2035
|
}
|
|
2097
2036
|
/**
|
|
2098
2037
|
* Type guard for shutdown responses.
|
|
@@ -2102,9 +2041,8 @@ function isHealthResponse(value) {
|
|
|
2102
2041
|
function isShutdownResponse(value) {
|
|
2103
2042
|
if (typeof value !== "object" || value === null) return false;
|
|
2104
2043
|
const record = toRecord(value);
|
|
2105
|
-
return
|
|
2044
|
+
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");
|
|
2106
2045
|
}
|
|
2107
|
-
|
|
2108
2046
|
//#endregion
|
|
2109
2047
|
//#region src/services/StopServerService/StopServerService.ts
|
|
2110
2048
|
/**
|
|
@@ -2116,14 +2054,14 @@ function isShutdownResponse(value) {
|
|
|
2116
2054
|
*/
|
|
2117
2055
|
function buildRuntimeUrl(runtime, path) {
|
|
2118
2056
|
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.`);
|
|
2119
|
-
return `${HTTP_PROTOCOL}${runtime.host}
|
|
2057
|
+
return `${HTTP_PROTOCOL}${runtime.host}:${runtime.port}${path}`;
|
|
2120
2058
|
}
|
|
2121
2059
|
function toErrorMessage$1(error) {
|
|
2122
2060
|
return error instanceof Error ? error.message : String(error);
|
|
2123
2061
|
}
|
|
2124
2062
|
function sleep(delayMs) {
|
|
2125
|
-
return new Promise((resolve
|
|
2126
|
-
setTimeout(resolve
|
|
2063
|
+
return new Promise((resolve) => {
|
|
2064
|
+
setTimeout(resolve, delayMs);
|
|
2127
2065
|
});
|
|
2128
2066
|
}
|
|
2129
2067
|
/**
|
|
@@ -2142,7 +2080,7 @@ var StopServerService = class {
|
|
|
2142
2080
|
* @returns Stop result payload
|
|
2143
2081
|
*/
|
|
2144
2082
|
async stop(request) {
|
|
2145
|
-
const timeoutMs = request.timeoutMs ??
|
|
2083
|
+
const timeoutMs = request.timeoutMs ?? 5e3;
|
|
2146
2084
|
const runtime = await this.resolveRuntime(request);
|
|
2147
2085
|
const health = await this.fetchHealth(runtime, timeoutMs);
|
|
2148
2086
|
if (!health.reachable) {
|
|
@@ -2188,7 +2126,7 @@ var StopServerService = class {
|
|
|
2188
2126
|
*/
|
|
2189
2127
|
async fetchHealth(runtime, timeoutMs) {
|
|
2190
2128
|
try {
|
|
2191
|
-
const response = await this.fetchWithTimeout(buildRuntimeUrl(runtime, HEALTH_CHECK_PATH), { method:
|
|
2129
|
+
const response = await this.fetchWithTimeout(buildRuntimeUrl(runtime, HEALTH_CHECK_PATH), { method: "GET" }, timeoutMs);
|
|
2192
2130
|
if (!response.ok) return { reachable: false };
|
|
2193
2131
|
const payload = await response.json();
|
|
2194
2132
|
if (!isHealthResponse(payload)) throw new Error("Received invalid health response payload.");
|
|
@@ -2227,8 +2165,8 @@ var StopServerService = class {
|
|
|
2227
2165
|
async waitForShutdown(runtime, timeoutMs) {
|
|
2228
2166
|
const deadline = Date.now() + timeoutMs;
|
|
2229
2167
|
while (Date.now() < deadline) {
|
|
2230
|
-
if (!(await this.fetchHealth(runtime, Math.max(
|
|
2231
|
-
await sleep(
|
|
2168
|
+
if (!(await this.fetchHealth(runtime, Math.max(250, deadline - Date.now()))).reachable) return;
|
|
2169
|
+
await sleep(200);
|
|
2232
2170
|
}
|
|
2233
2171
|
throw new Error(`Timed out waiting for runtime '${runtime.serverId}' to stop at http://${runtime.host}:${runtime.port}.`);
|
|
2234
2172
|
}
|
|
@@ -2256,7 +2194,6 @@ var StopServerService = class {
|
|
|
2256
2194
|
}
|
|
2257
2195
|
}
|
|
2258
2196
|
};
|
|
2259
|
-
|
|
2260
2197
|
//#endregion
|
|
2261
2198
|
//#region src/services/SkillService.ts
|
|
2262
2199
|
/**
|
|
@@ -2613,54 +2550,14 @@ var SkillService = class {
|
|
|
2613
2550
|
};
|
|
2614
2551
|
}
|
|
2615
2552
|
};
|
|
2616
|
-
|
|
2617
|
-
//#endregion
|
|
2618
|
-
//#region src/services/PrefetchService/constants.ts
|
|
2619
|
-
/**
|
|
2620
|
-
* PrefetchService Constants
|
|
2621
|
-
*
|
|
2622
|
-
* Constants for package manager commands and process configuration.
|
|
2623
|
-
*/
|
|
2624
|
-
/** Transport type for stdio-based MCP servers */
|
|
2625
|
-
const TRANSPORT_STDIO = "stdio";
|
|
2626
|
-
/** npx command name */
|
|
2627
|
-
const COMMAND_NPX = "npx";
|
|
2628
|
-
/** npm command name */
|
|
2629
|
-
const COMMAND_NPM = "npm";
|
|
2630
2553
|
/** pnpx command name (pnpm's npx equivalent) */
|
|
2631
2554
|
const COMMAND_PNPX = "pnpx";
|
|
2632
2555
|
/** pnpm command name */
|
|
2633
2556
|
const COMMAND_PNPM = "pnpm";
|
|
2634
|
-
/** uvx command name */
|
|
2635
|
-
const COMMAND_UVX = "uvx";
|
|
2636
|
-
/** uv command name */
|
|
2637
|
-
const COMMAND_UV = "uv";
|
|
2638
|
-
/** Path suffix for npx command */
|
|
2639
|
-
const COMMAND_NPX_SUFFIX = "/npx";
|
|
2640
|
-
/** Path suffix for pnpx command */
|
|
2641
|
-
const COMMAND_PNPX_SUFFIX = "/pnpx";
|
|
2642
|
-
/** Path suffix for uvx command */
|
|
2643
|
-
const COMMAND_UVX_SUFFIX = "/uvx";
|
|
2644
|
-
/** Path suffix for uv command */
|
|
2645
|
-
const COMMAND_UV_SUFFIX = "/uv";
|
|
2646
|
-
/** Run subcommand for uv */
|
|
2647
|
-
const ARG_RUN = "run";
|
|
2648
2557
|
/** Tool subcommand for uv */
|
|
2649
2558
|
const ARG_TOOL = "tool";
|
|
2650
2559
|
/** Install subcommand for uv tool and npm/pnpm */
|
|
2651
2560
|
const ARG_INSTALL = "install";
|
|
2652
|
-
/** Add subcommand for pnpm */
|
|
2653
|
-
const ARG_ADD = "add";
|
|
2654
|
-
/** Global flag for npm/pnpm install */
|
|
2655
|
-
const ARG_GLOBAL = "-g";
|
|
2656
|
-
/** Flag prefix for command arguments */
|
|
2657
|
-
const FLAG_PREFIX = "-";
|
|
2658
|
-
/** npx --package flag (long form) */
|
|
2659
|
-
const FLAG_PACKAGE_LONG = "--package";
|
|
2660
|
-
/** npx -p flag (short form) */
|
|
2661
|
-
const FLAG_PACKAGE_SHORT = "-p";
|
|
2662
|
-
/** Equals delimiter used in flag=value patterns */
|
|
2663
|
-
const EQUALS_DELIMITER = "=";
|
|
2664
2561
|
/**
|
|
2665
2562
|
* Regex pattern for valid package names (npm, pnpm, uvx, uv)
|
|
2666
2563
|
* Allows: @scope/package-name@version, package-name, package_name
|
|
@@ -2672,13 +2569,10 @@ const EQUALS_DELIMITER = "=";
|
|
|
2672
2569
|
const VALID_PACKAGE_NAME_PATTERN = /^(@[a-zA-Z0-9_-]+\/)?[a-zA-Z0-9._-]+(@[a-zA-Z0-9._-]+)?$/;
|
|
2673
2570
|
/** Windows platform identifier */
|
|
2674
2571
|
const PLATFORM_WIN32 = "win32";
|
|
2675
|
-
/** Success exit code */
|
|
2676
|
-
const EXIT_CODE_SUCCESS = 0;
|
|
2677
2572
|
/** Stdio option to ignore stream */
|
|
2678
2573
|
const STDIO_IGNORE = "ignore";
|
|
2679
2574
|
/** Stdio option to pipe stream */
|
|
2680
2575
|
const STDIO_PIPE = "pipe";
|
|
2681
|
-
|
|
2682
2576
|
//#endregion
|
|
2683
2577
|
//#region src/services/PrefetchService/PrefetchService.ts
|
|
2684
2578
|
/**
|
|
@@ -2738,7 +2632,7 @@ var PrefetchService = class {
|
|
|
2738
2632
|
const { mcpConfig, filter } = this.config;
|
|
2739
2633
|
for (const [serverName, serverConfig] of Object.entries(mcpConfig.mcpServers)) {
|
|
2740
2634
|
if (serverConfig.disabled) continue;
|
|
2741
|
-
if (serverConfig.transport !==
|
|
2635
|
+
if (serverConfig.transport !== "stdio") continue;
|
|
2742
2636
|
if (!isMcpStdioConfig(serverConfig.config)) continue;
|
|
2743
2637
|
const packageInfo = this.extractPackageInfo(serverName, serverConfig.config);
|
|
2744
2638
|
if (packageInfo) {
|
|
@@ -2827,21 +2721,21 @@ var PrefetchService = class {
|
|
|
2827
2721
|
extractPackageInfo(serverName, config) {
|
|
2828
2722
|
const command = config.command.toLowerCase();
|
|
2829
2723
|
const args = config.args || [];
|
|
2830
|
-
if (command ===
|
|
2724
|
+
if (command === "npx" || command.endsWith("/npx")) {
|
|
2831
2725
|
const packageName = this.extractNpxPackage(args);
|
|
2832
2726
|
if (packageName && this.isValidPackageName(packageName)) return {
|
|
2833
2727
|
serverName,
|
|
2834
|
-
packageManager:
|
|
2728
|
+
packageManager: "npx",
|
|
2835
2729
|
packageName,
|
|
2836
2730
|
fullCommand: [
|
|
2837
|
-
|
|
2731
|
+
"npm",
|
|
2838
2732
|
ARG_INSTALL,
|
|
2839
|
-
|
|
2733
|
+
"-g",
|
|
2840
2734
|
packageName
|
|
2841
2735
|
]
|
|
2842
2736
|
};
|
|
2843
2737
|
}
|
|
2844
|
-
if (command ===
|
|
2738
|
+
if (command === "pnpx" || command.endsWith("/pnpx")) {
|
|
2845
2739
|
const packageName = this.extractNpxPackage(args);
|
|
2846
2740
|
if (packageName && this.isValidPackageName(packageName)) return {
|
|
2847
2741
|
serverName,
|
|
@@ -2849,29 +2743,29 @@ var PrefetchService = class {
|
|
|
2849
2743
|
packageName,
|
|
2850
2744
|
fullCommand: [
|
|
2851
2745
|
COMMAND_PNPM,
|
|
2852
|
-
|
|
2853
|
-
|
|
2746
|
+
"add",
|
|
2747
|
+
"-g",
|
|
2854
2748
|
packageName
|
|
2855
2749
|
]
|
|
2856
2750
|
};
|
|
2857
2751
|
}
|
|
2858
|
-
if (command ===
|
|
2752
|
+
if (command === "uvx" || command.endsWith("/uvx")) {
|
|
2859
2753
|
const packageName = this.extractUvxPackage(args);
|
|
2860
2754
|
if (packageName && this.isValidPackageName(packageName)) return {
|
|
2861
2755
|
serverName,
|
|
2862
|
-
packageManager:
|
|
2756
|
+
packageManager: "uvx",
|
|
2863
2757
|
packageName,
|
|
2864
|
-
fullCommand: [
|
|
2758
|
+
fullCommand: ["uvx", packageName]
|
|
2865
2759
|
};
|
|
2866
2760
|
}
|
|
2867
|
-
if ((command ===
|
|
2761
|
+
if ((command === "uv" || command.endsWith("/uv")) && args.includes("run")) {
|
|
2868
2762
|
const packageName = this.extractUvRunPackage(args);
|
|
2869
2763
|
if (packageName && this.isValidPackageName(packageName)) return {
|
|
2870
2764
|
serverName,
|
|
2871
|
-
packageManager:
|
|
2765
|
+
packageManager: "uv",
|
|
2872
2766
|
packageName,
|
|
2873
2767
|
fullCommand: [
|
|
2874
|
-
|
|
2768
|
+
"uv",
|
|
2875
2769
|
ARG_TOOL,
|
|
2876
2770
|
ARG_INSTALL,
|
|
2877
2771
|
packageName
|
|
@@ -2898,18 +2792,18 @@ var PrefetchService = class {
|
|
|
2898
2792
|
extractNpxPackage(args) {
|
|
2899
2793
|
for (let i = 0; i < args.length; i++) {
|
|
2900
2794
|
const arg = args[i];
|
|
2901
|
-
if (arg.startsWith(
|
|
2902
|
-
if (arg ===
|
|
2795
|
+
if (arg.startsWith("--package=")) return arg.slice(10) || null;
|
|
2796
|
+
if (arg === "--package" && i + 1 < args.length) {
|
|
2903
2797
|
const nextArg = args[i + 1];
|
|
2904
|
-
if (!nextArg.startsWith(
|
|
2798
|
+
if (!nextArg.startsWith("-")) return nextArg;
|
|
2905
2799
|
}
|
|
2906
|
-
if (arg ===
|
|
2800
|
+
if (arg === "-p" && i + 1 < args.length) {
|
|
2907
2801
|
const nextArg = args[i + 1];
|
|
2908
|
-
if (!nextArg.startsWith(
|
|
2802
|
+
if (!nextArg.startsWith("-")) return nextArg;
|
|
2909
2803
|
}
|
|
2910
2804
|
}
|
|
2911
2805
|
for (const arg of args) {
|
|
2912
|
-
if (arg.startsWith(
|
|
2806
|
+
if (arg.startsWith("-")) continue;
|
|
2913
2807
|
return arg;
|
|
2914
2808
|
}
|
|
2915
2809
|
return null;
|
|
@@ -2926,7 +2820,7 @@ var PrefetchService = class {
|
|
|
2926
2820
|
*/
|
|
2927
2821
|
extractUvxPackage(args) {
|
|
2928
2822
|
for (const arg of args) {
|
|
2929
|
-
if (arg.startsWith(
|
|
2823
|
+
if (arg.startsWith("-")) continue;
|
|
2930
2824
|
return arg;
|
|
2931
2825
|
}
|
|
2932
2826
|
return null;
|
|
@@ -2943,11 +2837,11 @@ var PrefetchService = class {
|
|
|
2943
2837
|
* extractUvRunPackage(['install', 'pkg']) // returns null (no 'run')
|
|
2944
2838
|
*/
|
|
2945
2839
|
extractUvRunPackage(args) {
|
|
2946
|
-
const runIndex = args.indexOf(
|
|
2840
|
+
const runIndex = args.indexOf("run");
|
|
2947
2841
|
if (runIndex === -1) return null;
|
|
2948
2842
|
for (let i = runIndex + 1; i < args.length; i++) {
|
|
2949
2843
|
const arg = args[i];
|
|
2950
|
-
if (arg.startsWith(
|
|
2844
|
+
if (arg.startsWith("-")) continue;
|
|
2951
2845
|
return arg;
|
|
2952
2846
|
}
|
|
2953
2847
|
return null;
|
|
@@ -2959,7 +2853,7 @@ var PrefetchService = class {
|
|
|
2959
2853
|
* @returns Promise with success status and output
|
|
2960
2854
|
*/
|
|
2961
2855
|
runCommand(command, args) {
|
|
2962
|
-
return new Promise((resolve
|
|
2856
|
+
return new Promise((resolve) => {
|
|
2963
2857
|
const proc = (0, node_child_process.spawn)(command, args, {
|
|
2964
2858
|
stdio: [
|
|
2965
2859
|
STDIO_IGNORE,
|
|
@@ -2977,13 +2871,13 @@ var PrefetchService = class {
|
|
|
2977
2871
|
stderr += data.toString();
|
|
2978
2872
|
});
|
|
2979
2873
|
proc.on("close", (code) => {
|
|
2980
|
-
resolve
|
|
2981
|
-
success: code ===
|
|
2874
|
+
resolve({
|
|
2875
|
+
success: code === 0,
|
|
2982
2876
|
output: stdout || stderr
|
|
2983
2877
|
});
|
|
2984
2878
|
});
|
|
2985
2879
|
proc.on("error", (error) => {
|
|
2986
|
-
resolve
|
|
2880
|
+
resolve({
|
|
2987
2881
|
success: false,
|
|
2988
2882
|
output: error.message
|
|
2989
2883
|
});
|
|
@@ -2991,11 +2885,9 @@ var PrefetchService = class {
|
|
|
2991
2885
|
});
|
|
2992
2886
|
}
|
|
2993
2887
|
};
|
|
2994
|
-
|
|
2995
2888
|
//#endregion
|
|
2996
2889
|
//#region src/templates/toolkit-description.liquid?raw
|
|
2997
|
-
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
|
|
2998
|
-
|
|
2890
|
+
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";
|
|
2999
2891
|
//#endregion
|
|
3000
2892
|
//#region src/tools/DescribeToolsTool.ts
|
|
3001
2893
|
/**
|
|
@@ -3010,6 +2902,11 @@ function formatSkillInstructions(name, instructions) {
|
|
|
3010
2902
|
return `<command-message>The "${name}" skill is loading</command-message>\n${instructions}`;
|
|
3011
2903
|
}
|
|
3012
2904
|
/**
|
|
2905
|
+
* Input schema for the DescribeToolsTool
|
|
2906
|
+
* @property toolNames - Array of tool names to get detailed information about
|
|
2907
|
+
*/
|
|
2908
|
+
const DescribeToolsToolInputSchema = zod.z.object({ toolNames: zod.z.array(zod.z.string().min(1)).min(1).describe("List of tool names to get detailed information about") });
|
|
2909
|
+
/**
|
|
3013
2910
|
* DescribeToolsTool provides progressive disclosure of MCP tools and skills.
|
|
3014
2911
|
*
|
|
3015
2912
|
* This tool lists available tools from all connected MCP servers and skills
|
|
@@ -3045,7 +2942,7 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
3045
2942
|
constructor(clientManager, skillService, serverId, definitionsCacheService) {
|
|
3046
2943
|
this.clientManager = clientManager;
|
|
3047
2944
|
this.skillService = skillService;
|
|
3048
|
-
this.serverId = serverId ||
|
|
2945
|
+
this.serverId = serverId || "unknown";
|
|
3049
2946
|
this.definitionsCacheService = definitionsCacheService || new DefinitionsCacheService(clientManager, skillService);
|
|
3050
2947
|
}
|
|
3051
2948
|
/**
|
|
@@ -3161,7 +3058,7 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
3161
3058
|
}).join("\n") || "";
|
|
3162
3059
|
return {
|
|
3163
3060
|
name: promptSkill.skill.name,
|
|
3164
|
-
location: promptSkill.skill.folder ||
|
|
3061
|
+
location: promptSkill.skill.folder || `prompt:${promptSkill.serverName}/${promptSkill.promptName}`,
|
|
3165
3062
|
instructions: formatSkillInstructions(promptSkill.skill.name, rawInstructions)
|
|
3166
3063
|
};
|
|
3167
3064
|
} catch (error) {
|
|
@@ -3266,25 +3163,124 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
3266
3163
|
*
|
|
3267
3164
|
* @returns Tool definition with description and input schema
|
|
3268
3165
|
*/
|
|
3166
|
+
getInputSchema() {
|
|
3167
|
+
return DescribeToolsToolInputSchema;
|
|
3168
|
+
}
|
|
3269
3169
|
async getDefinition() {
|
|
3270
3170
|
const { content } = await this.buildToolkitDescription();
|
|
3271
3171
|
return {
|
|
3272
3172
|
name: DescribeToolsTool.TOOL_NAME,
|
|
3273
3173
|
description: content,
|
|
3274
|
-
inputSchema: {
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3174
|
+
inputSchema: zod.z.toJSONSchema(DescribeToolsToolInputSchema, { reused: "inline" })
|
|
3175
|
+
};
|
|
3176
|
+
}
|
|
3177
|
+
async runLookups(toolNames, serverDefinitions) {
|
|
3178
|
+
const serverToolsMap = /* @__PURE__ */ new Map();
|
|
3179
|
+
const toolToServers = /* @__PURE__ */ new Map();
|
|
3180
|
+
for (const serverDefinition of serverDefinitions) {
|
|
3181
|
+
const typedTools = serverDefinition.tools.map((tool) => ({
|
|
3182
|
+
name: tool.name,
|
|
3183
|
+
description: tool.description,
|
|
3184
|
+
inputSchema: tool.inputSchema
|
|
3185
|
+
}));
|
|
3186
|
+
serverToolsMap.set(serverDefinition.serverName, typedTools);
|
|
3187
|
+
for (const tool of typedTools) {
|
|
3188
|
+
if (!toolToServers.has(tool.name)) toolToServers.set(tool.name, []);
|
|
3189
|
+
toolToServers.get(tool.name)?.push(serverDefinition.serverName);
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
const lookupResults = await Promise.all(toolNames.map(async (requestedName) => {
|
|
3193
|
+
const result = {
|
|
3194
|
+
tools: [],
|
|
3195
|
+
skills: [],
|
|
3196
|
+
notFound: null
|
|
3197
|
+
};
|
|
3198
|
+
if (requestedName.startsWith("skill__")) {
|
|
3199
|
+
const skillName = requestedName.slice(7);
|
|
3200
|
+
if (this.skillService) {
|
|
3201
|
+
const skill = await this.skillService.getSkill(skillName);
|
|
3202
|
+
if (skill) {
|
|
3203
|
+
result.skills.push({
|
|
3204
|
+
name: skill.name,
|
|
3205
|
+
location: skill.basePath,
|
|
3206
|
+
instructions: formatSkillInstructions(skill.name, skill.content)
|
|
3207
|
+
});
|
|
3208
|
+
return result;
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
const promptSkillContent = await this.getPromptSkillContent(skillName);
|
|
3212
|
+
if (promptSkillContent) {
|
|
3213
|
+
result.skills.push(promptSkillContent);
|
|
3214
|
+
return result;
|
|
3215
|
+
}
|
|
3216
|
+
result.notFound = requestedName;
|
|
3217
|
+
return result;
|
|
3218
|
+
}
|
|
3219
|
+
const { serverName, actualToolName } = parseToolName(requestedName);
|
|
3220
|
+
if (serverName) {
|
|
3221
|
+
const serverTools = serverToolsMap.get(serverName);
|
|
3222
|
+
if (!serverTools) {
|
|
3223
|
+
result.notFound = requestedName;
|
|
3224
|
+
return result;
|
|
3225
|
+
}
|
|
3226
|
+
const tool = serverTools.find((t) => t.name === actualToolName);
|
|
3227
|
+
if (tool) result.tools.push({
|
|
3228
|
+
server: serverName,
|
|
3229
|
+
tool: {
|
|
3230
|
+
name: tool.name,
|
|
3231
|
+
description: tool.description,
|
|
3232
|
+
inputSchema: tool.inputSchema
|
|
3233
|
+
}
|
|
3234
|
+
});
|
|
3235
|
+
else result.notFound = requestedName;
|
|
3236
|
+
return result;
|
|
3237
|
+
}
|
|
3238
|
+
const servers = toolToServers.get(actualToolName);
|
|
3239
|
+
if (!servers || servers.length === 0) {
|
|
3240
|
+
if (this.skillService) {
|
|
3241
|
+
const skill = await this.skillService.getSkill(actualToolName);
|
|
3242
|
+
if (skill) {
|
|
3243
|
+
result.skills.push({
|
|
3244
|
+
name: skill.name,
|
|
3245
|
+
location: skill.basePath,
|
|
3246
|
+
instructions: formatSkillInstructions(skill.name, skill.content)
|
|
3247
|
+
});
|
|
3248
|
+
return result;
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
3251
|
+
const promptSkillContent = await this.getPromptSkillContent(actualToolName);
|
|
3252
|
+
if (promptSkillContent) {
|
|
3253
|
+
result.skills.push(promptSkillContent);
|
|
3254
|
+
return result;
|
|
3255
|
+
}
|
|
3256
|
+
result.notFound = requestedName;
|
|
3257
|
+
return result;
|
|
3287
3258
|
}
|
|
3259
|
+
for (const server of servers) {
|
|
3260
|
+
const tool = serverToolsMap.get(server).find((t) => t.name === actualToolName);
|
|
3261
|
+
result.tools.push({
|
|
3262
|
+
server,
|
|
3263
|
+
tool: {
|
|
3264
|
+
name: tool.name,
|
|
3265
|
+
description: tool.description,
|
|
3266
|
+
inputSchema: tool.inputSchema
|
|
3267
|
+
}
|
|
3268
|
+
});
|
|
3269
|
+
}
|
|
3270
|
+
return result;
|
|
3271
|
+
}));
|
|
3272
|
+
const foundTools = [];
|
|
3273
|
+
const foundSkills = [];
|
|
3274
|
+
const notFoundItems = [];
|
|
3275
|
+
for (const result of lookupResults) {
|
|
3276
|
+
foundTools.push(...result.tools);
|
|
3277
|
+
foundSkills.push(...result.skills);
|
|
3278
|
+
if (result.notFound) notFoundItems.push(result.notFound);
|
|
3279
|
+
}
|
|
3280
|
+
return {
|
|
3281
|
+
foundTools,
|
|
3282
|
+
foundSkills,
|
|
3283
|
+
notFoundItems
|
|
3288
3284
|
};
|
|
3289
3285
|
}
|
|
3290
3286
|
/**
|
|
@@ -3298,10 +3294,9 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
3298
3294
|
* @param input - Object containing toolNames array
|
|
3299
3295
|
* @returns CallToolResult with tool/skill descriptions or error
|
|
3300
3296
|
*/
|
|
3301
|
-
async execute(
|
|
3297
|
+
async execute(rawInput) {
|
|
3302
3298
|
try {
|
|
3303
|
-
const { toolNames } =
|
|
3304
|
-
const serverDefinitions = await this.definitionsCacheService.getServerDefinitions();
|
|
3299
|
+
const { toolNames } = DescribeToolsToolInputSchema.parse(rawInput);
|
|
3305
3300
|
if (!toolNames || toolNames.length === 0) return {
|
|
3306
3301
|
content: [{
|
|
3307
3302
|
type: "text",
|
|
@@ -3309,119 +3304,13 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
3309
3304
|
}],
|
|
3310
3305
|
isError: true
|
|
3311
3306
|
};
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
description: tool.description,
|
|
3318
|
-
inputSchema: tool.inputSchema
|
|
3319
|
-
}));
|
|
3320
|
-
serverToolsMap.set(serverDefinition.serverName, typedTools);
|
|
3321
|
-
for (const tool of typedTools) {
|
|
3322
|
-
if (!toolToServers.has(tool.name)) toolToServers.set(tool.name, []);
|
|
3323
|
-
toolToServers.get(tool.name)?.push(serverDefinition.serverName);
|
|
3324
|
-
}
|
|
3325
|
-
}
|
|
3326
|
-
const lookupResults = await Promise.all(toolNames.map(async (requestedName) => {
|
|
3327
|
-
const result$1 = {
|
|
3328
|
-
tools: [],
|
|
3329
|
-
skills: [],
|
|
3330
|
-
notFound: null
|
|
3331
|
-
};
|
|
3332
|
-
if (requestedName.startsWith(SKILL_PREFIX)) {
|
|
3333
|
-
const skillName = requestedName.slice(SKILL_PREFIX.length);
|
|
3334
|
-
if (this.skillService) {
|
|
3335
|
-
const skill = await this.skillService.getSkill(skillName);
|
|
3336
|
-
if (skill) {
|
|
3337
|
-
result$1.skills.push({
|
|
3338
|
-
name: skill.name,
|
|
3339
|
-
location: skill.basePath,
|
|
3340
|
-
instructions: formatSkillInstructions(skill.name, skill.content)
|
|
3341
|
-
});
|
|
3342
|
-
return result$1;
|
|
3343
|
-
}
|
|
3344
|
-
}
|
|
3345
|
-
const promptSkillContent = await this.getPromptSkillContent(skillName);
|
|
3346
|
-
if (promptSkillContent) {
|
|
3347
|
-
result$1.skills.push(promptSkillContent);
|
|
3348
|
-
return result$1;
|
|
3349
|
-
}
|
|
3350
|
-
result$1.notFound = requestedName;
|
|
3351
|
-
return result$1;
|
|
3352
|
-
}
|
|
3353
|
-
const { serverName, actualToolName } = parseToolName(requestedName);
|
|
3354
|
-
if (serverName) {
|
|
3355
|
-
const serverTools = serverToolsMap.get(serverName);
|
|
3356
|
-
if (!serverTools) {
|
|
3357
|
-
result$1.notFound = requestedName;
|
|
3358
|
-
return result$1;
|
|
3359
|
-
}
|
|
3360
|
-
const tool = serverTools.find((t) => t.name === actualToolName);
|
|
3361
|
-
if (tool) result$1.tools.push({
|
|
3362
|
-
server: serverName,
|
|
3363
|
-
tool: {
|
|
3364
|
-
name: tool.name,
|
|
3365
|
-
description: tool.description,
|
|
3366
|
-
inputSchema: tool.inputSchema
|
|
3367
|
-
}
|
|
3368
|
-
});
|
|
3369
|
-
else result$1.notFound = requestedName;
|
|
3370
|
-
return result$1;
|
|
3371
|
-
}
|
|
3372
|
-
const servers = toolToServers.get(actualToolName);
|
|
3373
|
-
if (!servers || servers.length === 0) {
|
|
3374
|
-
if (this.skillService) {
|
|
3375
|
-
const skill = await this.skillService.getSkill(actualToolName);
|
|
3376
|
-
if (skill) {
|
|
3377
|
-
result$1.skills.push({
|
|
3378
|
-
name: skill.name,
|
|
3379
|
-
location: skill.basePath,
|
|
3380
|
-
instructions: formatSkillInstructions(skill.name, skill.content)
|
|
3381
|
-
});
|
|
3382
|
-
return result$1;
|
|
3383
|
-
}
|
|
3384
|
-
}
|
|
3385
|
-
const promptSkillContent = await this.getPromptSkillContent(actualToolName);
|
|
3386
|
-
if (promptSkillContent) {
|
|
3387
|
-
result$1.skills.push(promptSkillContent);
|
|
3388
|
-
return result$1;
|
|
3389
|
-
}
|
|
3390
|
-
result$1.notFound = requestedName;
|
|
3391
|
-
return result$1;
|
|
3392
|
-
}
|
|
3393
|
-
if (servers.length === 1) {
|
|
3394
|
-
const server = servers[0];
|
|
3395
|
-
const tool = serverToolsMap.get(server).find((t) => t.name === actualToolName);
|
|
3396
|
-
result$1.tools.push({
|
|
3397
|
-
server,
|
|
3398
|
-
tool: {
|
|
3399
|
-
name: tool.name,
|
|
3400
|
-
description: tool.description,
|
|
3401
|
-
inputSchema: tool.inputSchema
|
|
3402
|
-
}
|
|
3403
|
-
});
|
|
3404
|
-
} else for (const server of servers) {
|
|
3405
|
-
const tool = serverToolsMap.get(server).find((t) => t.name === actualToolName);
|
|
3406
|
-
result$1.tools.push({
|
|
3407
|
-
server,
|
|
3408
|
-
tool: {
|
|
3409
|
-
name: tool.name,
|
|
3410
|
-
description: tool.description,
|
|
3411
|
-
inputSchema: tool.inputSchema
|
|
3412
|
-
}
|
|
3413
|
-
});
|
|
3414
|
-
}
|
|
3415
|
-
return result$1;
|
|
3416
|
-
}));
|
|
3417
|
-
const foundTools = [];
|
|
3418
|
-
const foundSkills = [];
|
|
3419
|
-
const notFoundItems = [];
|
|
3420
|
-
for (const result$1 of lookupResults) {
|
|
3421
|
-
foundTools.push(...result$1.tools);
|
|
3422
|
-
foundSkills.push(...result$1.skills);
|
|
3423
|
-
if (result$1.notFound) notFoundItems.push(result$1.notFound);
|
|
3307
|
+
let lookup = await this.runLookups(toolNames, await this.definitionsCacheService.getServerDefinitions());
|
|
3308
|
+
if (lookup.notFoundItems.length > 0) {
|
|
3309
|
+
this.definitionsCacheService.clearLiveCache();
|
|
3310
|
+
await this.definitionsCacheService.collectForCache();
|
|
3311
|
+
lookup = await this.runLookups(toolNames, await this.definitionsCacheService.getServerDefinitions());
|
|
3424
3312
|
}
|
|
3313
|
+
const { foundTools, foundSkills, notFoundItems } = lookup;
|
|
3425
3314
|
if (foundTools.length === 0 && foundSkills.length === 0) return {
|
|
3426
3315
|
content: [{
|
|
3427
3316
|
type: "text",
|
|
@@ -3459,7 +3348,6 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
3459
3348
|
}
|
|
3460
3349
|
}
|
|
3461
3350
|
};
|
|
3462
|
-
|
|
3463
3351
|
//#endregion
|
|
3464
3352
|
//#region src/utils/toolCapabilities.ts
|
|
3465
3353
|
const TOOL_CAPABILITIES_META_KEY = "agiflowai/capabilities";
|
|
@@ -3471,9 +3359,12 @@ function getToolCapabilities(tool) {
|
|
|
3471
3359
|
function getUniqueSortedCapabilities(tools) {
|
|
3472
3360
|
return Array.from(new Set(tools.flatMap((tool) => getToolCapabilities(tool)))).sort();
|
|
3473
3361
|
}
|
|
3474
|
-
|
|
3475
3362
|
//#endregion
|
|
3476
3363
|
//#region src/tools/SearchListToolsTool.ts
|
|
3364
|
+
const SearchListToolsToolInputSchema = zod.z.object({
|
|
3365
|
+
capability: zod.z.string().optional().describe("Optional capability filter. Matches explicit capability tags first, then server summaries, server names, tool names, and tool descriptions."),
|
|
3366
|
+
serverName: zod.z.string().optional().describe("Optional server name filter.")
|
|
3367
|
+
});
|
|
3477
3368
|
var SearchListToolsTool = class SearchListToolsTool {
|
|
3478
3369
|
static TOOL_NAME = "list_tools";
|
|
3479
3370
|
constructor(_clientManager, definitionsCacheService) {
|
|
@@ -3483,6 +3374,9 @@ var SearchListToolsTool = class SearchListToolsTool {
|
|
|
3483
3374
|
formatToolName(toolName, serverName, toolToServers) {
|
|
3484
3375
|
return (toolToServers.get(toolName) || []).length > 1 ? `${serverName}__${toolName}` : toolName;
|
|
3485
3376
|
}
|
|
3377
|
+
getInputSchema() {
|
|
3378
|
+
return SearchListToolsToolInputSchema;
|
|
3379
|
+
}
|
|
3486
3380
|
async getDefinition() {
|
|
3487
3381
|
const serverDefinitions = await this.definitionsCacheService.getServerDefinitions();
|
|
3488
3382
|
const capabilitySummary = serverDefinitions.length > 0 ? serverDefinitions.map((server) => {
|
|
@@ -3493,23 +3387,11 @@ var SearchListToolsTool = class SearchListToolsTool {
|
|
|
3493
3387
|
return {
|
|
3494
3388
|
name: SearchListToolsTool.TOOL_NAME,
|
|
3495
3389
|
description: `Search proxied MCP tools by server capability summary.\n\nAvailable capabilities:\n${capabilitySummary}`,
|
|
3496
|
-
inputSchema: {
|
|
3497
|
-
type: "object",
|
|
3498
|
-
properties: {
|
|
3499
|
-
capability: {
|
|
3500
|
-
type: "string",
|
|
3501
|
-
description: "Optional capability filter. Matches explicit capability tags first, then server summaries, server names, tool names, and tool descriptions."
|
|
3502
|
-
},
|
|
3503
|
-
serverName: {
|
|
3504
|
-
type: "string",
|
|
3505
|
-
description: "Optional server name filter."
|
|
3506
|
-
}
|
|
3507
|
-
},
|
|
3508
|
-
additionalProperties: false
|
|
3509
|
-
}
|
|
3390
|
+
inputSchema: zod.z.toJSONSchema(SearchListToolsToolInputSchema, { reused: "inline" })
|
|
3510
3391
|
};
|
|
3511
3392
|
}
|
|
3512
|
-
async execute(
|
|
3393
|
+
async execute(rawInput) {
|
|
3394
|
+
const input = SearchListToolsToolInputSchema.parse(rawInput);
|
|
3513
3395
|
const serverDefinitions = await this.definitionsCacheService.getServerDefinitions();
|
|
3514
3396
|
const capabilityFilter = input.capability?.trim().toLowerCase();
|
|
3515
3397
|
const serverNameFilter = input.serverName?.trim().toLowerCase();
|
|
@@ -3538,20 +3420,51 @@ var SearchListToolsTool = class SearchListToolsTool {
|
|
|
3538
3420
|
capabilities: getToolCapabilities(tool)
|
|
3539
3421
|
}))
|
|
3540
3422
|
})).filter((server) => server.tools.length > 0);
|
|
3541
|
-
const result = { servers: filteredServers };
|
|
3542
3423
|
return {
|
|
3543
3424
|
content: [{
|
|
3544
3425
|
type: "text",
|
|
3545
|
-
text: JSON.stringify(
|
|
3426
|
+
text: JSON.stringify({ servers: filteredServers }, null, 2)
|
|
3546
3427
|
}],
|
|
3547
3428
|
isError: filteredServers.length === 0 ? true : void 0
|
|
3548
3429
|
};
|
|
3549
3430
|
}
|
|
3550
3431
|
};
|
|
3551
|
-
|
|
3552
3432
|
//#endregion
|
|
3553
3433
|
//#region src/tools/UseToolTool.ts
|
|
3554
3434
|
/**
|
|
3435
|
+
* UseToolTool - Progressive disclosure tool for calling MCP tools and skills
|
|
3436
|
+
*
|
|
3437
|
+
* DESIGN PATTERNS:
|
|
3438
|
+
* - Tool pattern with getDefinition() and execute() methods
|
|
3439
|
+
* - Dependency injection for client manager and skill service
|
|
3440
|
+
* - Progressive disclosure pattern
|
|
3441
|
+
* - Proxy pattern for forwarding tool calls
|
|
3442
|
+
*
|
|
3443
|
+
* CODING STANDARDS:
|
|
3444
|
+
* - Implement Tool interface from ../types
|
|
3445
|
+
* - Use TOOL_NAME constant with snake_case
|
|
3446
|
+
* - Return CallToolResult with content array
|
|
3447
|
+
* - Handle errors with isError flag
|
|
3448
|
+
*
|
|
3449
|
+
* AVOID:
|
|
3450
|
+
* - Complex business logic in execute method
|
|
3451
|
+
* - Unhandled promise rejections
|
|
3452
|
+
* - Missing error handling
|
|
3453
|
+
*
|
|
3454
|
+
* NAMING CONVENTIONS:
|
|
3455
|
+
* - Tools from MCP servers use serverName__toolName format when clashing
|
|
3456
|
+
* - Skills use skill__skillName format (skill__ prefix)
|
|
3457
|
+
*/
|
|
3458
|
+
/**
|
|
3459
|
+
* Input schema for UseToolTool
|
|
3460
|
+
* @property toolName - Name of the tool or skill to execute
|
|
3461
|
+
* @property toolArgs - Arguments to pass to the tool (from describe_tools schema)
|
|
3462
|
+
*/
|
|
3463
|
+
const UseToolToolInputSchema = zod.z.object({
|
|
3464
|
+
toolName: zod.z.string().min(1).describe("Name of the tool to execute"),
|
|
3465
|
+
toolArgs: zod.z.record(zod.z.string(), zod.z.unknown()).optional().describe("Arguments to pass to the tool, as discovered from describe_tools")
|
|
3466
|
+
});
|
|
3467
|
+
/**
|
|
3555
3468
|
* UseToolTool executes MCP tools and skills with proper error handling.
|
|
3556
3469
|
*
|
|
3557
3470
|
* This tool supports three invocation patterns:
|
|
@@ -3581,7 +3494,7 @@ var UseToolTool = class UseToolTool {
|
|
|
3581
3494
|
this.clientManager = clientManager;
|
|
3582
3495
|
this.skillService = skillService;
|
|
3583
3496
|
this.definitionsCacheService = definitionsCacheService || new DefinitionsCacheService(clientManager, skillService);
|
|
3584
|
-
this.serverId = serverId ||
|
|
3497
|
+
this.serverId = serverId || "unknown";
|
|
3585
3498
|
}
|
|
3586
3499
|
/**
|
|
3587
3500
|
* Returns the MCP tool definition with name, description, and input schema.
|
|
@@ -3591,6 +3504,9 @@ var UseToolTool = class UseToolTool {
|
|
|
3591
3504
|
*
|
|
3592
3505
|
* @returns The tool definition conforming to MCP spec
|
|
3593
3506
|
*/
|
|
3507
|
+
getInputSchema() {
|
|
3508
|
+
return UseToolToolInputSchema;
|
|
3509
|
+
}
|
|
3594
3510
|
getDefinition() {
|
|
3595
3511
|
return {
|
|
3596
3512
|
name: UseToolTool.TOOL_NAME,
|
|
@@ -3600,22 +3516,7 @@ var UseToolTool = class UseToolTool {
|
|
|
3600
3516
|
|
|
3601
3517
|
IMPORTANT: Only use tools discovered from describe_tools with id="${this.serverId}".
|
|
3602
3518
|
`,
|
|
3603
|
-
inputSchema: {
|
|
3604
|
-
type: "object",
|
|
3605
|
-
properties: {
|
|
3606
|
-
toolName: {
|
|
3607
|
-
type: "string",
|
|
3608
|
-
description: "Name of the tool to execute",
|
|
3609
|
-
minLength: 1
|
|
3610
|
-
},
|
|
3611
|
-
toolArgs: {
|
|
3612
|
-
type: "object",
|
|
3613
|
-
description: "Arguments to pass to the tool, as discovered from describe_tools"
|
|
3614
|
-
}
|
|
3615
|
-
},
|
|
3616
|
-
required: ["toolName"],
|
|
3617
|
-
additionalProperties: false
|
|
3618
|
-
}
|
|
3519
|
+
inputSchema: zod.z.toJSONSchema(UseToolToolInputSchema, { reused: "inline" })
|
|
3619
3520
|
};
|
|
3620
3521
|
}
|
|
3621
3522
|
/**
|
|
@@ -3628,6 +3529,16 @@ IMPORTANT: Only use tools discovered from describe_tools with id="${this.serverI
|
|
|
3628
3529
|
* @param skill - The skill that was requested
|
|
3629
3530
|
* @returns CallToolResult with guidance message
|
|
3630
3531
|
*/
|
|
3532
|
+
/**
|
|
3533
|
+
* Coerce toolArgs using the downstream tool's cached JSON Schema.
|
|
3534
|
+
* Converts the schema to Zod and runs coerceArgs so that string-encoded
|
|
3535
|
+
* objects/arrays are parsed before being forwarded to the downstream server.
|
|
3536
|
+
*/
|
|
3537
|
+
async coerceToolArgs(serverName, toolName, toolArgs) {
|
|
3538
|
+
const jsonSchema = await this.definitionsCacheService.getToolSchema(serverName, toolName);
|
|
3539
|
+
if (!jsonSchema) return toolArgs;
|
|
3540
|
+
return (0, _agimon_ai_foundation_validator.coerceArgs)(toolArgs, (0, _agimon_ai_foundation_validator.jsonSchemaToZod)(jsonSchema));
|
|
3541
|
+
}
|
|
3631
3542
|
executeSkill(skill) {
|
|
3632
3543
|
return { content: [{
|
|
3633
3544
|
type: "text",
|
|
@@ -3673,11 +3584,11 @@ IMPORTANT: Only use tools discovered from describe_tools with id="${this.serverI
|
|
|
3673
3584
|
* @param input - The tool/skill name and optional arguments
|
|
3674
3585
|
* @returns CallToolResult with execution output or error
|
|
3675
3586
|
*/
|
|
3676
|
-
async execute(
|
|
3587
|
+
async execute(rawInput) {
|
|
3677
3588
|
try {
|
|
3678
|
-
const { toolName: inputToolName, toolArgs = {} } =
|
|
3679
|
-
if (inputToolName.startsWith(
|
|
3680
|
-
const skillName = inputToolName.slice(
|
|
3589
|
+
const { toolName: inputToolName, toolArgs = {} } = UseToolToolInputSchema.parse(rawInput);
|
|
3590
|
+
if (inputToolName.startsWith("skill__")) {
|
|
3591
|
+
const skillName = inputToolName.slice(7);
|
|
3681
3592
|
if (this.skillService) {
|
|
3682
3593
|
const skill = await this.skillService.getSkill(skillName);
|
|
3683
3594
|
if (skill) return this.executeSkill(skill);
|
|
@@ -3704,7 +3615,8 @@ IMPORTANT: Only use tools discovered from describe_tools with id="${this.serverI
|
|
|
3704
3615
|
isError: true
|
|
3705
3616
|
};
|
|
3706
3617
|
const reqTimeout = this.clientManager.getServerRequestTimeout(serverName);
|
|
3707
|
-
|
|
3618
|
+
const coercedArgs = await this.coerceToolArgs(serverName, actualToolName, toolArgs);
|
|
3619
|
+
return await client.callTool(actualToolName, coercedArgs, reqTimeout ? { timeout: reqTimeout } : void 0);
|
|
3708
3620
|
} catch (error) {
|
|
3709
3621
|
return {
|
|
3710
3622
|
content: [{
|
|
@@ -3714,7 +3626,12 @@ IMPORTANT: Only use tools discovered from describe_tools with id="${this.serverI
|
|
|
3714
3626
|
isError: true
|
|
3715
3627
|
};
|
|
3716
3628
|
}
|
|
3717
|
-
|
|
3629
|
+
let matchingServers = await this.definitionsCacheService.getServersForTool(actualToolName);
|
|
3630
|
+
if (matchingServers.length === 0) {
|
|
3631
|
+
this.definitionsCacheService.clearLiveCache();
|
|
3632
|
+
await this.definitionsCacheService.collectForCache();
|
|
3633
|
+
matchingServers = await this.definitionsCacheService.getServersForTool(actualToolName);
|
|
3634
|
+
}
|
|
3718
3635
|
if (matchingServers.length === 0) {
|
|
3719
3636
|
if (this.skillService) {
|
|
3720
3637
|
const skill = await this.skillService.getSkill(actualToolName);
|
|
@@ -3741,7 +3658,8 @@ IMPORTANT: Only use tools discovered from describe_tools with id="${this.serverI
|
|
|
3741
3658
|
const targetServerName = matchingServers[0];
|
|
3742
3659
|
const client = await this.clientManager.ensureConnected(targetServerName);
|
|
3743
3660
|
const targetReqTimeout = this.clientManager.getServerRequestTimeout(targetServerName);
|
|
3744
|
-
|
|
3661
|
+
const coercedArgs = await this.coerceToolArgs(targetServerName, actualToolName, toolArgs);
|
|
3662
|
+
return await client.callTool(actualToolName, coercedArgs, targetReqTimeout ? { timeout: targetReqTimeout } : void 0);
|
|
3745
3663
|
} catch (error) {
|
|
3746
3664
|
return {
|
|
3747
3665
|
content: [{
|
|
@@ -3762,7 +3680,6 @@ IMPORTANT: Only use tools discovered from describe_tools with id="${this.serverI
|
|
|
3762
3680
|
}
|
|
3763
3681
|
}
|
|
3764
3682
|
};
|
|
3765
|
-
|
|
3766
3683
|
//#endregion
|
|
3767
3684
|
//#region src/transports/http.ts
|
|
3768
3685
|
/**
|
|
@@ -3904,13 +3821,13 @@ var AdminRateLimiter = class {
|
|
|
3904
3821
|
* Parse JSON body from IncomingMessage
|
|
3905
3822
|
*/
|
|
3906
3823
|
async function parseJsonBody$1(req) {
|
|
3907
|
-
return new Promise((resolve
|
|
3824
|
+
return new Promise((resolve, reject) => {
|
|
3908
3825
|
const chunks = [];
|
|
3909
3826
|
req.on("data", (chunk) => chunks.push(chunk));
|
|
3910
3827
|
req.on("end", () => {
|
|
3911
3828
|
try {
|
|
3912
3829
|
const body = Buffer.concat(chunks).toString("utf-8");
|
|
3913
|
-
resolve
|
|
3830
|
+
resolve(body ? JSON.parse(body) : void 0);
|
|
3914
3831
|
} catch (error) {
|
|
3915
3832
|
reject(/* @__PURE__ */ new Error(`Failed to parse JSON body: ${toErrorMessage(error)}`));
|
|
3916
3833
|
}
|
|
@@ -3998,24 +3915,24 @@ var HttpTransportHandler = class {
|
|
|
3998
3915
|
}
|
|
3999
3916
|
async handleAdminShutdownRequest(c) {
|
|
4000
3917
|
if (!this.adminOptions?.onShutdownRequested) {
|
|
4001
|
-
const payload
|
|
3918
|
+
const payload = {
|
|
4002
3919
|
ok: false,
|
|
4003
3920
|
message: "Shutdown endpoint is not enabled for this server instance.",
|
|
4004
3921
|
serverId: this.adminOptions?.serverId
|
|
4005
3922
|
};
|
|
4006
|
-
return c.json(payload
|
|
3923
|
+
return c.json(payload, 404);
|
|
4007
3924
|
}
|
|
4008
3925
|
const headers = {
|
|
4009
3926
|
authorization: c.req.header("authorization"),
|
|
4010
3927
|
"x-mcp-proxy-shutdown-token": c.req.header("x-mcp-proxy-shutdown-token")
|
|
4011
3928
|
};
|
|
4012
3929
|
if (!this.isAuthorizedShutdownRequest(headers)) {
|
|
4013
|
-
const payload
|
|
3930
|
+
const payload = {
|
|
4014
3931
|
ok: false,
|
|
4015
3932
|
message: "Unauthorized shutdown request: invalid or missing shutdown token.",
|
|
4016
3933
|
serverId: this.adminOptions?.serverId
|
|
4017
3934
|
};
|
|
4018
|
-
return c.json(payload
|
|
3935
|
+
return c.json(payload, 401);
|
|
4019
3936
|
}
|
|
4020
3937
|
const payload = {
|
|
4021
3938
|
ok: true,
|
|
@@ -4057,9 +3974,9 @@ var HttpTransportHandler = class {
|
|
|
4057
3974
|
const body = await parseJsonBody$1(req);
|
|
4058
3975
|
let transport;
|
|
4059
3976
|
if (sessionId && this.sessionManager.hasSession(sessionId)) transport = this.sessionManager.getSession(sessionId).transport;
|
|
4060
|
-
else if (!sessionId && (0,
|
|
3977
|
+
else if (!sessionId && (0, _modelcontextprotocol_sdk_types_js.isInitializeRequest)(body)) {
|
|
4061
3978
|
const mcpServer = await this.serverFactory();
|
|
4062
|
-
transport = new
|
|
3979
|
+
transport = new _modelcontextprotocol_sdk_server_streamableHttp_js.StreamableHTTPServerTransport({
|
|
4063
3980
|
sessionIdGenerator: () => (0, node_crypto.randomUUID)(),
|
|
4064
3981
|
enableJsonResponse: true,
|
|
4065
3982
|
onsessioninitialized: (initializedSessionId) => {
|
|
@@ -4126,7 +4043,7 @@ var HttpTransportHandler = class {
|
|
|
4126
4043
|
}
|
|
4127
4044
|
async start() {
|
|
4128
4045
|
try {
|
|
4129
|
-
const honoHandler = (0,
|
|
4046
|
+
const honoHandler = (0, _hono_node_server.getRequestListener)(this.honoApp.fetch);
|
|
4130
4047
|
const server = (0, node_http.createServer)(async (req, res) => {
|
|
4131
4048
|
if (new URL(req.url ?? "/", `http://${req.headers.host ?? this.config.host}`).pathname === "/mcp") await this.handleMcpRequest(req, res);
|
|
4132
4049
|
else honoHandler(req, res);
|
|
@@ -4171,7 +4088,6 @@ var HttpTransportHandler = class {
|
|
|
4171
4088
|
return this.config.host;
|
|
4172
4089
|
}
|
|
4173
4090
|
};
|
|
4174
|
-
|
|
4175
4091
|
//#endregion
|
|
4176
4092
|
//#region src/transports/sse.ts
|
|
4177
4093
|
/**
|
|
@@ -4241,13 +4157,13 @@ var SseSessionManager = class {
|
|
|
4241
4157
|
* Parse JSON body from IncomingMessage
|
|
4242
4158
|
*/
|
|
4243
4159
|
async function parseJsonBody(req) {
|
|
4244
|
-
return new Promise((resolve
|
|
4160
|
+
return new Promise((resolve, reject) => {
|
|
4245
4161
|
const chunks = [];
|
|
4246
4162
|
req.on("data", (chunk) => chunks.push(chunk));
|
|
4247
4163
|
req.on("end", () => {
|
|
4248
4164
|
try {
|
|
4249
4165
|
const body = Buffer.concat(chunks).toString("utf-8");
|
|
4250
|
-
resolve
|
|
4166
|
+
resolve(body ? JSON.parse(body) : void 0);
|
|
4251
4167
|
} catch (error) {
|
|
4252
4168
|
reject(/* @__PURE__ */ new Error(`Failed to parse JSON body: ${error instanceof Error ? error.message : String(error)}`));
|
|
4253
4169
|
}
|
|
@@ -4290,7 +4206,7 @@ var SseTransportHandler = class {
|
|
|
4290
4206
|
async handleSseConnection(res) {
|
|
4291
4207
|
try {
|
|
4292
4208
|
const mcpServer = this.serverFactory();
|
|
4293
|
-
const transport = new
|
|
4209
|
+
const transport = new _modelcontextprotocol_sdk_server_sse_js.SSEServerTransport("/messages", res);
|
|
4294
4210
|
this.sessionManager.setSession(transport.sessionId, transport, mcpServer);
|
|
4295
4211
|
res.on("close", () => {
|
|
4296
4212
|
const sessionId = transport.sessionId;
|
|
@@ -4331,9 +4247,9 @@ var SseTransportHandler = class {
|
|
|
4331
4247
|
}
|
|
4332
4248
|
}
|
|
4333
4249
|
async start() {
|
|
4334
|
-
return new Promise((resolve
|
|
4250
|
+
return new Promise((resolve, reject) => {
|
|
4335
4251
|
try {
|
|
4336
|
-
const honoHandler = (0,
|
|
4252
|
+
const honoHandler = (0, _hono_node_server.getRequestListener)(this.honoApp.fetch);
|
|
4337
4253
|
const server = (0, node_http.createServer)(async (req, res) => {
|
|
4338
4254
|
const url = new URL(req.url ?? "/", `http://${req.headers.host ?? this.config.host}`);
|
|
4339
4255
|
const method = req.method?.toUpperCase();
|
|
@@ -4346,7 +4262,7 @@ var SseTransportHandler = class {
|
|
|
4346
4262
|
this.logger.info(`SSE endpoint: http://${this.config.host}:${this.config.port}/sse`);
|
|
4347
4263
|
this.logger.info(`Messages endpoint: http://${this.config.host}:${this.config.port}/messages`);
|
|
4348
4264
|
this.logger.info(`Health check: http://${this.config.host}:${this.config.port}/health`);
|
|
4349
|
-
resolve
|
|
4265
|
+
resolve();
|
|
4350
4266
|
});
|
|
4351
4267
|
server.on("error", (error) => {
|
|
4352
4268
|
reject(error);
|
|
@@ -4358,7 +4274,7 @@ var SseTransportHandler = class {
|
|
|
4358
4274
|
});
|
|
4359
4275
|
}
|
|
4360
4276
|
async stop() {
|
|
4361
|
-
return new Promise((resolve
|
|
4277
|
+
return new Promise((resolve, reject) => {
|
|
4362
4278
|
if (this.server) {
|
|
4363
4279
|
const server = this.server;
|
|
4364
4280
|
(async () => {
|
|
@@ -4368,14 +4284,14 @@ var SseTransportHandler = class {
|
|
|
4368
4284
|
if (err) reject(err);
|
|
4369
4285
|
else {
|
|
4370
4286
|
this.server = null;
|
|
4371
|
-
resolve
|
|
4287
|
+
resolve();
|
|
4372
4288
|
}
|
|
4373
4289
|
});
|
|
4374
4290
|
} catch (error) {
|
|
4375
4291
|
reject(error);
|
|
4376
4292
|
}
|
|
4377
4293
|
})();
|
|
4378
|
-
} else resolve
|
|
4294
|
+
} else resolve();
|
|
4379
4295
|
});
|
|
4380
4296
|
}
|
|
4381
4297
|
getPort() {
|
|
@@ -4385,7 +4301,6 @@ var SseTransportHandler = class {
|
|
|
4385
4301
|
return this.config.host;
|
|
4386
4302
|
}
|
|
4387
4303
|
};
|
|
4388
|
-
|
|
4389
4304
|
//#endregion
|
|
4390
4305
|
//#region src/transports/stdio.ts
|
|
4391
4306
|
/**
|
|
@@ -4401,7 +4316,7 @@ var StdioTransportHandler = class {
|
|
|
4401
4316
|
this.logger = logger;
|
|
4402
4317
|
}
|
|
4403
4318
|
async start() {
|
|
4404
|
-
this.transport = new
|
|
4319
|
+
this.transport = new _modelcontextprotocol_sdk_server_stdio_js.StdioServerTransport();
|
|
4405
4320
|
await this.server.connect(this.transport);
|
|
4406
4321
|
this.logger.info("@agimon-ai/mcp-proxy MCP server started on stdio");
|
|
4407
4322
|
}
|
|
@@ -4412,7 +4327,6 @@ var StdioTransportHandler = class {
|
|
|
4412
4327
|
}
|
|
4413
4328
|
}
|
|
4414
4329
|
};
|
|
4415
|
-
|
|
4416
4330
|
//#endregion
|
|
4417
4331
|
//#region src/transports/stdio-http.ts
|
|
4418
4332
|
/**
|
|
@@ -4474,7 +4388,7 @@ var StdioHttpTransportHandler = class {
|
|
|
4474
4388
|
this.httpClient = client;
|
|
4475
4389
|
this.stdioProxyServer = this.createProxyServer();
|
|
4476
4390
|
this.registerElicitationHandler(client);
|
|
4477
|
-
this.stdioTransport = new
|
|
4391
|
+
this.stdioTransport = new _modelcontextprotocol_sdk_server_stdio_js.StdioServerTransport();
|
|
4478
4392
|
await this.stdioProxyServer.connect(this.stdioTransport);
|
|
4479
4393
|
this.logger.info(`@agimon-ai/mcp-proxy MCP stdio proxy connected to ${this.endpoint.toString()}`);
|
|
4480
4394
|
} catch (error) {
|
|
@@ -4516,8 +4430,8 @@ var StdioHttpTransportHandler = class {
|
|
|
4516
4430
|
if (cleanupErrors.length > 0) throw new Error(`Failed to stop stdio-http proxy transport: ${cleanupErrors.join("; ")}`);
|
|
4517
4431
|
}
|
|
4518
4432
|
async createAndConnectClient() {
|
|
4519
|
-
const httpClientTransport = new
|
|
4520
|
-
const client = new
|
|
4433
|
+
const httpClientTransport = new _modelcontextprotocol_sdk_client_streamableHttp_js.StreamableHTTPClientTransport(this.endpoint);
|
|
4434
|
+
const client = new _modelcontextprotocol_sdk_client_index_js.Client({
|
|
4521
4435
|
name: "@agimon-ai/mcp-proxy-stdio-http-proxy",
|
|
4522
4436
|
version: "0.1.0"
|
|
4523
4437
|
}, { capabilities: { elicitation: {} } });
|
|
@@ -4527,14 +4441,14 @@ var StdioHttpTransportHandler = class {
|
|
|
4527
4441
|
registerElicitationHandler(client) {
|
|
4528
4442
|
const proxyServer = this.stdioProxyServer;
|
|
4529
4443
|
if (!proxyServer) return;
|
|
4530
|
-
client.setRequestHandler(
|
|
4444
|
+
client.setRequestHandler(_modelcontextprotocol_sdk_types_js.ElicitRequestSchema, async (request) => {
|
|
4531
4445
|
return await proxyServer.elicitInput(request.params);
|
|
4532
4446
|
});
|
|
4533
4447
|
}
|
|
4534
4448
|
async reconnectWithBackoff() {
|
|
4535
4449
|
for (let attempt = 0; attempt < this.MAX_RECONNECT_ATTEMPTS; attempt++) {
|
|
4536
4450
|
const delay = Math.min(this.RECONNECT_BASE_MS * 2 ** attempt, this.RECONNECT_MAX_MS);
|
|
4537
|
-
await new Promise((resolve
|
|
4451
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
4538
4452
|
try {
|
|
4539
4453
|
await this.httpClient?.close().catch(() => void 0);
|
|
4540
4454
|
const client = await this.createAndConnectClient();
|
|
@@ -4561,7 +4475,7 @@ var StdioHttpTransportHandler = class {
|
|
|
4561
4475
|
}
|
|
4562
4476
|
}
|
|
4563
4477
|
createProxyServer() {
|
|
4564
|
-
const proxyServer = new
|
|
4478
|
+
const proxyServer = new _modelcontextprotocol_sdk_server_index_js.Server({
|
|
4565
4479
|
name: "@agimon-ai/mcp-proxy-stdio-http-proxy",
|
|
4566
4480
|
version: "0.1.0"
|
|
4567
4481
|
}, { capabilities: {
|
|
@@ -4569,14 +4483,14 @@ var StdioHttpTransportHandler = class {
|
|
|
4569
4483
|
resources: {},
|
|
4570
4484
|
prompts: {}
|
|
4571
4485
|
} });
|
|
4572
|
-
proxyServer.setRequestHandler(
|
|
4486
|
+
proxyServer.setRequestHandler(_modelcontextprotocol_sdk_types_js.ListToolsRequestSchema, async () => {
|
|
4573
4487
|
try {
|
|
4574
4488
|
return await this.withReconnect(() => this.httpClient.listTools());
|
|
4575
4489
|
} catch (error) {
|
|
4576
4490
|
throw new Error(`Failed forwarding tools/list to HTTP backend: ${error instanceof Error ? error.message : String(error)}`);
|
|
4577
4491
|
}
|
|
4578
4492
|
});
|
|
4579
|
-
proxyServer.setRequestHandler(
|
|
4493
|
+
proxyServer.setRequestHandler(_modelcontextprotocol_sdk_types_js.CallToolRequestSchema, async (request) => {
|
|
4580
4494
|
try {
|
|
4581
4495
|
return await this.withReconnect(() => this.httpClient.callTool({
|
|
4582
4496
|
name: request.params.name,
|
|
@@ -4586,28 +4500,28 @@ var StdioHttpTransportHandler = class {
|
|
|
4586
4500
|
throw new Error(`Failed forwarding tools/call (${request.params.name}) to HTTP backend: ${error instanceof Error ? error.message : String(error)}`);
|
|
4587
4501
|
}
|
|
4588
4502
|
});
|
|
4589
|
-
proxyServer.setRequestHandler(
|
|
4503
|
+
proxyServer.setRequestHandler(_modelcontextprotocol_sdk_types_js.ListResourcesRequestSchema, async () => {
|
|
4590
4504
|
try {
|
|
4591
4505
|
return await this.withReconnect(() => this.httpClient.listResources());
|
|
4592
4506
|
} catch (error) {
|
|
4593
4507
|
throw new Error(`Failed forwarding resources/list to HTTP backend: ${error instanceof Error ? error.message : String(error)}`);
|
|
4594
4508
|
}
|
|
4595
4509
|
});
|
|
4596
|
-
proxyServer.setRequestHandler(
|
|
4510
|
+
proxyServer.setRequestHandler(_modelcontextprotocol_sdk_types_js.ReadResourceRequestSchema, async (request) => {
|
|
4597
4511
|
try {
|
|
4598
4512
|
return await this.withReconnect(() => this.httpClient.readResource({ uri: request.params.uri }));
|
|
4599
4513
|
} catch (error) {
|
|
4600
4514
|
throw new Error(`Failed forwarding resources/read (${request.params.uri}) to HTTP backend: ${error instanceof Error ? error.message : String(error)}`);
|
|
4601
4515
|
}
|
|
4602
4516
|
});
|
|
4603
|
-
proxyServer.setRequestHandler(
|
|
4517
|
+
proxyServer.setRequestHandler(_modelcontextprotocol_sdk_types_js.ListPromptsRequestSchema, async () => {
|
|
4604
4518
|
try {
|
|
4605
4519
|
return await this.withReconnect(() => this.httpClient.listPrompts());
|
|
4606
4520
|
} catch (error) {
|
|
4607
4521
|
throw new Error(`Failed forwarding prompts/list to HTTP backend: ${error instanceof Error ? error.message : String(error)}`);
|
|
4608
4522
|
}
|
|
4609
4523
|
});
|
|
4610
|
-
proxyServer.setRequestHandler(
|
|
4524
|
+
proxyServer.setRequestHandler(_modelcontextprotocol_sdk_types_js.GetPromptRequestSchema, async (request) => {
|
|
4611
4525
|
try {
|
|
4612
4526
|
return await this.withReconnect(() => this.httpClient.getPrompt({
|
|
4613
4527
|
name: request.params.name,
|
|
@@ -4620,7 +4534,6 @@ var StdioHttpTransportHandler = class {
|
|
|
4620
4534
|
return proxyServer;
|
|
4621
4535
|
}
|
|
4622
4536
|
};
|
|
4623
|
-
|
|
4624
4537
|
//#endregion
|
|
4625
4538
|
//#region src/container/index.ts
|
|
4626
4539
|
/**
|
|
@@ -4652,13 +4565,13 @@ function createProxyIoCContainer(logger = console) {
|
|
|
4652
4565
|
createDescribeToolsTool: (clientManager, skillService, serverId, definitionsCacheService) => new DescribeToolsTool(clientManager, skillService, serverId, definitionsCacheService),
|
|
4653
4566
|
createUseToolTool: (clientManager, skillService, serverId, definitionsCacheService) => new UseToolTool(clientManager, skillService, serverId, definitionsCacheService),
|
|
4654
4567
|
createSearchListToolsTool: (clientManager, definitionsCacheService) => new SearchListToolsTool(clientManager, definitionsCacheService),
|
|
4655
|
-
createStdioTransportHandler: async (createServer
|
|
4656
|
-
return new StdioTransportHandler(await createServer
|
|
4568
|
+
createStdioTransportHandler: async (createServer) => {
|
|
4569
|
+
return new StdioTransportHandler(await createServer(), logger);
|
|
4657
4570
|
},
|
|
4658
|
-
createSseTransportHandler: async (createServer
|
|
4659
|
-
return new SseTransportHandler(await createServer
|
|
4571
|
+
createSseTransportHandler: async (createServer, config) => {
|
|
4572
|
+
return new SseTransportHandler(await createServer(), config, logger);
|
|
4660
4573
|
},
|
|
4661
|
-
createHttpTransportHandler: (createServer
|
|
4574
|
+
createHttpTransportHandler: (createServer, config, adminOptions) => new HttpTransportHandler(createServer, config, adminOptions, logger),
|
|
4662
4575
|
createStdioHttpTransportHandler: (endpoint) => new StdioHttpTransportHandler({ endpoint }, logger)
|
|
4663
4576
|
};
|
|
4664
4577
|
}
|
|
@@ -4795,22 +4708,22 @@ async function createProxyContainer(options) {
|
|
|
4795
4708
|
/**
|
|
4796
4709
|
* Create a sessionless stdio transport handler from the shared server factory.
|
|
4797
4710
|
*/
|
|
4798
|
-
async function createStdioTransportHandler(createServer
|
|
4799
|
-
const server = await createServer
|
|
4711
|
+
async function createStdioTransportHandler(createServer) {
|
|
4712
|
+
const server = await createServer();
|
|
4800
4713
|
return createProxyIoCContainer().createStdioTransportHandler(() => Promise.resolve(server));
|
|
4801
4714
|
}
|
|
4802
4715
|
/**
|
|
4803
4716
|
* Create an SSE transport handler from the shared server factory.
|
|
4804
4717
|
*/
|
|
4805
|
-
async function createSseTransportHandler(createServer
|
|
4806
|
-
const server = await createServer
|
|
4718
|
+
async function createSseTransportHandler(createServer, config) {
|
|
4719
|
+
const server = await createServer();
|
|
4807
4720
|
return createProxyIoCContainer().createSseTransportHandler(() => Promise.resolve(server), config);
|
|
4808
4721
|
}
|
|
4809
4722
|
/**
|
|
4810
4723
|
* Create an HTTP transport handler from shared services.
|
|
4811
4724
|
*/
|
|
4812
|
-
function createHttpTransportHandler(createServer
|
|
4813
|
-
return createProxyIoCContainer().createHttpTransportHandler(createServer
|
|
4725
|
+
function createHttpTransportHandler(createServer, config, adminOptions) {
|
|
4726
|
+
return createProxyIoCContainer().createHttpTransportHandler(createServer, config, adminOptions);
|
|
4814
4727
|
}
|
|
4815
4728
|
/**
|
|
4816
4729
|
* Create a stdio-http transport handler from an endpoint URL.
|
|
@@ -4824,7 +4737,6 @@ function createStdioHttpTransportHandler(endpoint) {
|
|
|
4824
4737
|
async function initializeSharedServices(options) {
|
|
4825
4738
|
return createProxyContainer(options);
|
|
4826
4739
|
}
|
|
4827
|
-
|
|
4828
4740
|
//#endregion
|
|
4829
4741
|
//#region src/server/index.ts
|
|
4830
4742
|
/**
|
|
@@ -4951,7 +4863,7 @@ function buildProxyInstructions(serverDefinitions, mode, includeSkillsTool) {
|
|
|
4951
4863
|
*/
|
|
4952
4864
|
async function createSessionServer(shared) {
|
|
4953
4865
|
const { clientManager, definitionsCacheService, skillService, describeTools, useTool: useToolWithCache, searchListTools, serverId, proxyMode } = shared;
|
|
4954
|
-
const server = new
|
|
4866
|
+
const server = new _modelcontextprotocol_sdk_server_index_js.Server({
|
|
4955
4867
|
name: "@agimon-ai/mcp-proxy",
|
|
4956
4868
|
version: "0.1.0"
|
|
4957
4869
|
}, {
|
|
@@ -4962,7 +4874,7 @@ async function createSessionServer(shared) {
|
|
|
4962
4874
|
},
|
|
4963
4875
|
instructions: buildProxyInstructions(await definitionsCacheService.getServerDefinitions(), proxyMode, await hasAnySkills(definitionsCacheService, skillService))
|
|
4964
4876
|
});
|
|
4965
|
-
server.setRequestHandler(
|
|
4877
|
+
server.setRequestHandler(_modelcontextprotocol_sdk_types_js.ListToolsRequestSchema, async () => ({ tools: proxyMode === "flat" ? await (async () => {
|
|
4966
4878
|
const currentServerDefinitions = await definitionsCacheService.getServerDefinitions();
|
|
4967
4879
|
const shouldIncludeSkillsTool = await hasAnySkills(definitionsCacheService, skillService);
|
|
4968
4880
|
return [...buildFlatToolDefinitions(currentServerDefinitions), ...shouldIncludeSkillsTool ? [buildSkillsDescribeDefinition(currentServerDefinitions, serverId)] : []];
|
|
@@ -4973,30 +4885,36 @@ async function createSessionServer(shared) {
|
|
|
4973
4885
|
useToolWithCache.getDefinition()
|
|
4974
4886
|
];
|
|
4975
4887
|
})() : [await describeTools.getDefinition(), useToolWithCache.getDefinition()] }));
|
|
4976
|
-
server.setRequestHandler(
|
|
4888
|
+
server.setRequestHandler(_modelcontextprotocol_sdk_types_js.CallToolRequestSchema, async (request) => {
|
|
4977
4889
|
const { name, arguments: args } = request.params;
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4890
|
+
const executeWithCoercion = async (tool, toolName) => {
|
|
4891
|
+
const coerced = (0, _agimon_ai_foundation_validator.coerceArgs)(args ?? {}, tool.getInputSchema());
|
|
4892
|
+
try {
|
|
4893
|
+
return await tool.execute(coerced);
|
|
4894
|
+
} catch (error) {
|
|
4895
|
+
if (error instanceof zod.z.ZodError) return {
|
|
4896
|
+
content: [{
|
|
4897
|
+
type: "text",
|
|
4898
|
+
text: (0, _agimon_ai_foundation_validator.formatZodError)(error, {
|
|
4899
|
+
schemaName: toolName,
|
|
4900
|
+
schema: tool.getInputSchema()
|
|
4901
|
+
})
|
|
4902
|
+
}],
|
|
4903
|
+
isError: true
|
|
4904
|
+
};
|
|
4905
|
+
throw new Error(`Failed to execute ${toolName}: ${error instanceof Error ? error.message : String(error)}`);
|
|
4906
|
+
}
|
|
4907
|
+
};
|
|
4908
|
+
if (name === DescribeToolsTool.TOOL_NAME) return await executeWithCoercion(describeTools, name);
|
|
4909
|
+
if (name === UseToolTool.TOOL_NAME) return await executeWithCoercion(useToolWithCache, name);
|
|
4910
|
+
if (name === SearchListToolsTool.TOOL_NAME && proxyMode === "search") return await executeWithCoercion(searchListTools, name);
|
|
4993
4911
|
if (proxyMode === "flat") return await useToolWithCache.execute({
|
|
4994
4912
|
toolName: name,
|
|
4995
4913
|
toolArgs: args || {}
|
|
4996
4914
|
});
|
|
4997
4915
|
throw new Error(`Unknown tool: ${name}`);
|
|
4998
4916
|
});
|
|
4999
|
-
server.setRequestHandler(
|
|
4917
|
+
server.setRequestHandler(_modelcontextprotocol_sdk_types_js.ListResourcesRequestSchema, async () => {
|
|
5000
4918
|
const currentServerDefinitions = await definitionsCacheService.getServerDefinitions();
|
|
5001
4919
|
const resourceToServers = /* @__PURE__ */ new Map();
|
|
5002
4920
|
for (const serverDefinition of currentServerDefinitions) for (const resource of serverDefinition.resources) {
|
|
@@ -5013,7 +4931,7 @@ async function createSessionServer(shared) {
|
|
|
5013
4931
|
}
|
|
5014
4932
|
return { resources };
|
|
5015
4933
|
});
|
|
5016
|
-
server.setRequestHandler(
|
|
4934
|
+
server.setRequestHandler(_modelcontextprotocol_sdk_types_js.ReadResourceRequestSchema, async (request) => {
|
|
5017
4935
|
const { uri } = request.params;
|
|
5018
4936
|
const { serverName, actualToolName: actualUri } = parseToolName(uri);
|
|
5019
4937
|
if (serverName) return await (await clientManager.ensureConnected(serverName)).readResource(actualUri);
|
|
@@ -5022,7 +4940,7 @@ async function createSessionServer(shared) {
|
|
|
5022
4940
|
if (matchingServers.length > 1) throw new Error(`Resource "${actualUri}" exists on multiple servers: ${matchingServers.join(", ")}. Use the prefixed format (e.g., "${matchingServers[0]}__${actualUri}") to specify which server to use.`);
|
|
5023
4941
|
return await (await clientManager.ensureConnected(matchingServers[0])).readResource(actualUri);
|
|
5024
4942
|
});
|
|
5025
|
-
server.setRequestHandler(
|
|
4943
|
+
server.setRequestHandler(_modelcontextprotocol_sdk_types_js.ListPromptsRequestSchema, async () => {
|
|
5026
4944
|
const currentServerDefinitions = await definitionsCacheService.getServerDefinitions();
|
|
5027
4945
|
const promptToServers = /* @__PURE__ */ new Map();
|
|
5028
4946
|
const serverPromptsMap = /* @__PURE__ */ new Map();
|
|
@@ -5047,7 +4965,7 @@ async function createSessionServer(shared) {
|
|
|
5047
4965
|
}
|
|
5048
4966
|
return { prompts: aggregatedPrompts };
|
|
5049
4967
|
});
|
|
5050
|
-
server.setRequestHandler(
|
|
4968
|
+
server.setRequestHandler(_modelcontextprotocol_sdk_types_js.GetPromptRequestSchema, async (request) => {
|
|
5051
4969
|
const { name, arguments: args } = request.params;
|
|
5052
4970
|
const currentServerDefinitions = await definitionsCacheService.getServerDefinitions();
|
|
5053
4971
|
const { serverName, actualToolName: actualPromptName } = parseToolName(name);
|
|
@@ -5069,7 +4987,6 @@ async function createSessionServer(shared) {
|
|
|
5069
4987
|
async function createServer(options) {
|
|
5070
4988
|
return createSessionServer(await createProxyContainer(options));
|
|
5071
4989
|
}
|
|
5072
|
-
|
|
5073
4990
|
//#endregion
|
|
5074
4991
|
//#region src/types/index.ts
|
|
5075
4992
|
/**
|
|
@@ -5080,173 +4997,172 @@ const TRANSPORT_MODE = {
|
|
|
5080
4997
|
HTTP: "http",
|
|
5081
4998
|
SSE: "sse"
|
|
5082
4999
|
};
|
|
5083
|
-
|
|
5084
5000
|
//#endregion
|
|
5085
|
-
Object.defineProperty(exports,
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5001
|
+
Object.defineProperty(exports, "ConfigFetcherService", {
|
|
5002
|
+
enumerable: true,
|
|
5003
|
+
get: function() {
|
|
5004
|
+
return ConfigFetcherService;
|
|
5005
|
+
}
|
|
5090
5006
|
});
|
|
5091
|
-
Object.defineProperty(exports,
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5007
|
+
Object.defineProperty(exports, "DefinitionsCacheService", {
|
|
5008
|
+
enumerable: true,
|
|
5009
|
+
get: function() {
|
|
5010
|
+
return DefinitionsCacheService;
|
|
5011
|
+
}
|
|
5096
5012
|
});
|
|
5097
|
-
Object.defineProperty(exports,
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5013
|
+
Object.defineProperty(exports, "DescribeToolsTool", {
|
|
5014
|
+
enumerable: true,
|
|
5015
|
+
get: function() {
|
|
5016
|
+
return DescribeToolsTool;
|
|
5017
|
+
}
|
|
5102
5018
|
});
|
|
5103
|
-
Object.defineProperty(exports,
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5019
|
+
Object.defineProperty(exports, "HttpTransportHandler", {
|
|
5020
|
+
enumerable: true,
|
|
5021
|
+
get: function() {
|
|
5022
|
+
return HttpTransportHandler;
|
|
5023
|
+
}
|
|
5108
5024
|
});
|
|
5109
|
-
Object.defineProperty(exports,
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5025
|
+
Object.defineProperty(exports, "McpClientManagerService", {
|
|
5026
|
+
enumerable: true,
|
|
5027
|
+
get: function() {
|
|
5028
|
+
return McpClientManagerService;
|
|
5029
|
+
}
|
|
5030
|
+
});
|
|
5031
|
+
Object.defineProperty(exports, "RuntimeStateService", {
|
|
5032
|
+
enumerable: true,
|
|
5033
|
+
get: function() {
|
|
5034
|
+
return RuntimeStateService;
|
|
5035
|
+
}
|
|
5114
5036
|
});
|
|
5115
|
-
Object.defineProperty(exports,
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5037
|
+
Object.defineProperty(exports, "SearchListToolsTool", {
|
|
5038
|
+
enumerable: true,
|
|
5039
|
+
get: function() {
|
|
5040
|
+
return SearchListToolsTool;
|
|
5041
|
+
}
|
|
5120
5042
|
});
|
|
5121
|
-
Object.defineProperty(exports,
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5043
|
+
Object.defineProperty(exports, "SkillService", {
|
|
5044
|
+
enumerable: true,
|
|
5045
|
+
get: function() {
|
|
5046
|
+
return SkillService;
|
|
5047
|
+
}
|
|
5126
5048
|
});
|
|
5127
|
-
Object.defineProperty(exports,
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5049
|
+
Object.defineProperty(exports, "SseTransportHandler", {
|
|
5050
|
+
enumerable: true,
|
|
5051
|
+
get: function() {
|
|
5052
|
+
return SseTransportHandler;
|
|
5053
|
+
}
|
|
5132
5054
|
});
|
|
5133
|
-
Object.defineProperty(exports,
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5055
|
+
Object.defineProperty(exports, "StdioHttpTransportHandler", {
|
|
5056
|
+
enumerable: true,
|
|
5057
|
+
get: function() {
|
|
5058
|
+
return StdioHttpTransportHandler;
|
|
5059
|
+
}
|
|
5138
5060
|
});
|
|
5139
|
-
Object.defineProperty(exports,
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5061
|
+
Object.defineProperty(exports, "StdioTransportHandler", {
|
|
5062
|
+
enumerable: true,
|
|
5063
|
+
get: function() {
|
|
5064
|
+
return StdioTransportHandler;
|
|
5065
|
+
}
|
|
5144
5066
|
});
|
|
5145
|
-
Object.defineProperty(exports,
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5067
|
+
Object.defineProperty(exports, "StopServerService", {
|
|
5068
|
+
enumerable: true,
|
|
5069
|
+
get: function() {
|
|
5070
|
+
return StopServerService;
|
|
5071
|
+
}
|
|
5150
5072
|
});
|
|
5151
|
-
Object.defineProperty(exports,
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5073
|
+
Object.defineProperty(exports, "TRANSPORT_MODE", {
|
|
5074
|
+
enumerable: true,
|
|
5075
|
+
get: function() {
|
|
5076
|
+
return TRANSPORT_MODE;
|
|
5077
|
+
}
|
|
5156
5078
|
});
|
|
5157
|
-
Object.defineProperty(exports,
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5079
|
+
Object.defineProperty(exports, "UseToolTool", {
|
|
5080
|
+
enumerable: true,
|
|
5081
|
+
get: function() {
|
|
5082
|
+
return UseToolTool;
|
|
5083
|
+
}
|
|
5162
5084
|
});
|
|
5163
|
-
Object.defineProperty(exports,
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5085
|
+
Object.defineProperty(exports, "__toESM", {
|
|
5086
|
+
enumerable: true,
|
|
5087
|
+
get: function() {
|
|
5088
|
+
return __toESM;
|
|
5089
|
+
}
|
|
5168
5090
|
});
|
|
5169
|
-
Object.defineProperty(exports,
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5091
|
+
Object.defineProperty(exports, "createHttpTransportHandler", {
|
|
5092
|
+
enumerable: true,
|
|
5093
|
+
get: function() {
|
|
5094
|
+
return createHttpTransportHandler;
|
|
5095
|
+
}
|
|
5174
5096
|
});
|
|
5175
|
-
Object.defineProperty(exports,
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5097
|
+
Object.defineProperty(exports, "createProxyContainer", {
|
|
5098
|
+
enumerable: true,
|
|
5099
|
+
get: function() {
|
|
5100
|
+
return createProxyContainer;
|
|
5101
|
+
}
|
|
5180
5102
|
});
|
|
5181
|
-
Object.defineProperty(exports,
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5103
|
+
Object.defineProperty(exports, "createProxyIoCContainer", {
|
|
5104
|
+
enumerable: true,
|
|
5105
|
+
get: function() {
|
|
5106
|
+
return createProxyIoCContainer;
|
|
5107
|
+
}
|
|
5186
5108
|
});
|
|
5187
|
-
Object.defineProperty(exports,
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5109
|
+
Object.defineProperty(exports, "createProxyLogger", {
|
|
5110
|
+
enumerable: true,
|
|
5111
|
+
get: function() {
|
|
5112
|
+
return createProxyLogger;
|
|
5113
|
+
}
|
|
5192
5114
|
});
|
|
5193
|
-
Object.defineProperty(exports,
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5115
|
+
Object.defineProperty(exports, "createServer", {
|
|
5116
|
+
enumerable: true,
|
|
5117
|
+
get: function() {
|
|
5118
|
+
return createServer;
|
|
5119
|
+
}
|
|
5198
5120
|
});
|
|
5199
|
-
Object.defineProperty(exports,
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5121
|
+
Object.defineProperty(exports, "createSessionServer", {
|
|
5122
|
+
enumerable: true,
|
|
5123
|
+
get: function() {
|
|
5124
|
+
return createSessionServer;
|
|
5125
|
+
}
|
|
5204
5126
|
});
|
|
5205
|
-
Object.defineProperty(exports,
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5127
|
+
Object.defineProperty(exports, "createSseTransportHandler", {
|
|
5128
|
+
enumerable: true,
|
|
5129
|
+
get: function() {
|
|
5130
|
+
return createSseTransportHandler;
|
|
5131
|
+
}
|
|
5210
5132
|
});
|
|
5211
|
-
Object.defineProperty(exports,
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5133
|
+
Object.defineProperty(exports, "createStdioHttpTransportHandler", {
|
|
5134
|
+
enumerable: true,
|
|
5135
|
+
get: function() {
|
|
5136
|
+
return createStdioHttpTransportHandler;
|
|
5137
|
+
}
|
|
5216
5138
|
});
|
|
5217
|
-
Object.defineProperty(exports,
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5139
|
+
Object.defineProperty(exports, "createStdioTransportHandler", {
|
|
5140
|
+
enumerable: true,
|
|
5141
|
+
get: function() {
|
|
5142
|
+
return createStdioTransportHandler;
|
|
5143
|
+
}
|
|
5222
5144
|
});
|
|
5223
|
-
Object.defineProperty(exports,
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5145
|
+
Object.defineProperty(exports, "findConfigFile", {
|
|
5146
|
+
enumerable: true,
|
|
5147
|
+
get: function() {
|
|
5148
|
+
return findConfigFile;
|
|
5149
|
+
}
|
|
5228
5150
|
});
|
|
5229
|
-
Object.defineProperty(exports,
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5151
|
+
Object.defineProperty(exports, "generateServerId", {
|
|
5152
|
+
enumerable: true,
|
|
5153
|
+
get: function() {
|
|
5154
|
+
return generateServerId;
|
|
5155
|
+
}
|
|
5234
5156
|
});
|
|
5235
|
-
Object.defineProperty(exports,
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5157
|
+
Object.defineProperty(exports, "initializeSharedServices", {
|
|
5158
|
+
enumerable: true,
|
|
5159
|
+
get: function() {
|
|
5160
|
+
return initializeSharedServices;
|
|
5161
|
+
}
|
|
5240
5162
|
});
|
|
5241
|
-
Object.defineProperty(exports,
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5163
|
+
Object.defineProperty(exports, "version", {
|
|
5164
|
+
enumerable: true,
|
|
5165
|
+
get: function() {
|
|
5166
|
+
return version;
|
|
5167
|
+
}
|
|
5246
5168
|
});
|
|
5247
|
-
Object.defineProperty(exports, 'version', {
|
|
5248
|
-
enumerable: true,
|
|
5249
|
-
get: function () {
|
|
5250
|
-
return version;
|
|
5251
|
-
}
|
|
5252
|
-
});
|