@agiflowai/one-mcp 0.3.18 → 0.4.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 +95 -153
- package/dist/cli.mjs +56 -114
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +1 -12
- package/dist/index.d.mts +1 -11
- package/dist/index.mjs +2 -3
- package/dist/{src-DPIjPYdS.mjs → src-BhNZiv0s.mjs} +84 -173
- package/dist/{src-hm1dRqUF.cjs → src-Cc3lEKJ5.cjs} +233 -327
- package/package.json +15 -15
|
@@ -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,31 +19,29 @@ 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 _modelcontextprotocol_sdk_server_index_js = require("@modelcontextprotocol/sdk/server/index.js");
|
|
24
|
+
let _modelcontextprotocol_sdk_types_js = require("@modelcontextprotocol/sdk/types.js");
|
|
30
25
|
let node_fs_promises = require("node:fs/promises");
|
|
31
26
|
let node_fs = require("node:fs");
|
|
32
27
|
let js_yaml = require("js-yaml");
|
|
33
|
-
js_yaml = __toESM(js_yaml);
|
|
28
|
+
js_yaml = __toESM(js_yaml, 1);
|
|
34
29
|
let zod = require("zod");
|
|
35
30
|
let node_crypto = require("node:crypto");
|
|
36
31
|
let node_path = require("node:path");
|
|
37
32
|
let node_os = require("node:os");
|
|
38
|
-
let
|
|
39
|
-
let
|
|
40
|
-
let
|
|
41
|
-
let
|
|
33
|
+
let _modelcontextprotocol_sdk_client_index_js = require("@modelcontextprotocol/sdk/client/index.js");
|
|
34
|
+
let _modelcontextprotocol_sdk_client_sse_js = require("@modelcontextprotocol/sdk/client/sse.js");
|
|
35
|
+
let _modelcontextprotocol_sdk_client_stdio_js = require("@modelcontextprotocol/sdk/client/stdio.js");
|
|
36
|
+
let _modelcontextprotocol_sdk_client_streamableHttp_js = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
42
37
|
let liquidjs = require("liquidjs");
|
|
43
38
|
let node_events = require("node:events");
|
|
44
39
|
let node_util = require("node:util");
|
|
45
|
-
let
|
|
40
|
+
let _modelcontextprotocol_sdk_server_streamableHttp_js = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
46
41
|
let express = require("express");
|
|
47
|
-
express = __toESM(express);
|
|
48
|
-
let
|
|
49
|
-
let
|
|
50
|
-
|
|
42
|
+
express = __toESM(express, 1);
|
|
43
|
+
let _modelcontextprotocol_sdk_server_sse_js = require("@modelcontextprotocol/sdk/server/sse.js");
|
|
44
|
+
let _modelcontextprotocol_sdk_server_stdio_js = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
51
45
|
//#region src/utils/mcpConfigSchema.ts
|
|
52
46
|
/**
|
|
53
47
|
* mcpConfigSchema Utilities
|
|
@@ -422,7 +416,6 @@ function parseMcpConfig(rawConfig) {
|
|
|
422
416
|
const internalConfig = transformClaudeCodeConfig(ClaudeCodeMcpConfigSchema.parse(rawConfig));
|
|
423
417
|
return InternalMcpConfigSchema.parse(internalConfig);
|
|
424
418
|
}
|
|
425
|
-
|
|
426
419
|
//#endregion
|
|
427
420
|
//#region src/services/RemoteConfigCacheService.ts
|
|
428
421
|
/**
|
|
@@ -642,7 +635,6 @@ var RemoteConfigCacheService = class {
|
|
|
642
635
|
this.writeEnabled = enabled;
|
|
643
636
|
}
|
|
644
637
|
};
|
|
645
|
-
|
|
646
638
|
//#endregion
|
|
647
639
|
//#region src/services/ConfigFetcherService.ts
|
|
648
640
|
/**
|
|
@@ -864,7 +856,6 @@ var ConfigFetcherService = class {
|
|
|
864
856
|
return this.cachedConfig !== null && now - this.lastFetchTime < this.cacheTtlMs;
|
|
865
857
|
}
|
|
866
858
|
};
|
|
867
|
-
|
|
868
859
|
//#endregion
|
|
869
860
|
//#region src/utils/findConfigFile.ts
|
|
870
861
|
/**
|
|
@@ -911,7 +902,6 @@ function findConfigFile() {
|
|
|
911
902
|
}
|
|
912
903
|
return null;
|
|
913
904
|
}
|
|
914
|
-
|
|
915
905
|
//#endregion
|
|
916
906
|
//#region src/utils/parseToolName.ts
|
|
917
907
|
/**
|
|
@@ -933,7 +923,6 @@ function parseToolName(toolName) {
|
|
|
933
923
|
};
|
|
934
924
|
return { actualToolName: toolName };
|
|
935
925
|
}
|
|
936
|
-
|
|
937
926
|
//#endregion
|
|
938
927
|
//#region src/utils/parseFrontMatter.ts
|
|
939
928
|
/**
|
|
@@ -1067,7 +1056,6 @@ function extractSkillFrontMatter(content) {
|
|
|
1067
1056
|
};
|
|
1068
1057
|
return null;
|
|
1069
1058
|
}
|
|
1070
|
-
|
|
1071
1059
|
//#endregion
|
|
1072
1060
|
//#region src/utils/generateServerId.ts
|
|
1073
1061
|
/**
|
|
@@ -1132,7 +1120,6 @@ function generateServerId(length = DEFAULT_ID_LENGTH) {
|
|
|
1132
1120
|
}
|
|
1133
1121
|
return result;
|
|
1134
1122
|
}
|
|
1135
|
-
|
|
1136
1123
|
//#endregion
|
|
1137
1124
|
//#region src/constants/index.ts
|
|
1138
1125
|
/**
|
|
@@ -1152,17 +1139,6 @@ const LOG_PREFIX_SKILL_DETECTION = "[skill-detection]";
|
|
|
1152
1139
|
* Log prefix for general MCP capability discovery messages.
|
|
1153
1140
|
*/
|
|
1154
1141
|
const LOG_PREFIX_CAPABILITY_DISCOVERY = "[capability-discovery]";
|
|
1155
|
-
/**
|
|
1156
|
-
* Prefix for prompt-based skill locations.
|
|
1157
|
-
* Format: "prompt:{serverName}:{promptName}"
|
|
1158
|
-
*/
|
|
1159
|
-
const PROMPT_LOCATION_PREFIX = "prompt:";
|
|
1160
|
-
/**
|
|
1161
|
-
* Default server ID used when no ID is provided via CLI or config.
|
|
1162
|
-
* This fallback is used when auto-generation also fails.
|
|
1163
|
-
*/
|
|
1164
|
-
const DEFAULT_SERVER_ID = "unknown";
|
|
1165
|
-
|
|
1166
1142
|
//#endregion
|
|
1167
1143
|
//#region src/services/DefinitionsCacheService.ts
|
|
1168
1144
|
/**
|
|
@@ -1454,7 +1430,6 @@ var DefinitionsCacheService = class {
|
|
|
1454
1430
|
return promptSkills;
|
|
1455
1431
|
}
|
|
1456
1432
|
};
|
|
1457
|
-
|
|
1458
1433
|
//#endregion
|
|
1459
1434
|
//#region src/services/McpClientManagerService.ts
|
|
1460
1435
|
/** Default connection timeout in milliseconds (30 seconds) */
|
|
@@ -1491,8 +1466,8 @@ var McpClient = class {
|
|
|
1491
1466
|
this.transport = transport;
|
|
1492
1467
|
this.client = client;
|
|
1493
1468
|
}
|
|
1494
|
-
setChildProcess(process
|
|
1495
|
-
this.childProcess = process
|
|
1469
|
+
setChildProcess(process) {
|
|
1470
|
+
this.childProcess = process;
|
|
1496
1471
|
}
|
|
1497
1472
|
setConnected(connected) {
|
|
1498
1473
|
this.connected = connected;
|
|
@@ -1638,7 +1613,7 @@ var McpClientManagerService = class {
|
|
|
1638
1613
|
}
|
|
1639
1614
|
async createConnection(serverName, config) {
|
|
1640
1615
|
const timeoutMs = config.timeout ?? DEFAULT_CONNECTION_TIMEOUT_MS;
|
|
1641
|
-
const client = new
|
|
1616
|
+
const client = new _modelcontextprotocol_sdk_client_index_js.Client({
|
|
1642
1617
|
name: `@agiflowai/one-mcp-client`,
|
|
1643
1618
|
version: "0.1.0"
|
|
1644
1619
|
}, { capabilities: {} });
|
|
@@ -1653,7 +1628,7 @@ var McpClientManagerService = class {
|
|
|
1653
1628
|
mcpClient.setConnected(true);
|
|
1654
1629
|
if (config.transport === "http" || config.transport === "sse") mcpClient.setReconnectFn(async () => {
|
|
1655
1630
|
try {
|
|
1656
|
-
const newClient = new
|
|
1631
|
+
const newClient = new _modelcontextprotocol_sdk_client_index_js.Client({
|
|
1657
1632
|
name: "@agiflowai/one-mcp-client",
|
|
1658
1633
|
version: "0.1.0"
|
|
1659
1634
|
}, { capabilities: {} });
|
|
@@ -1688,7 +1663,7 @@ var McpClientManagerService = class {
|
|
|
1688
1663
|
else throw new Error(`Unsupported transport type: ${config.transport}`);
|
|
1689
1664
|
}
|
|
1690
1665
|
async connectStdioClient(mcpClient, config) {
|
|
1691
|
-
const transport = new
|
|
1666
|
+
const transport = new _modelcontextprotocol_sdk_client_stdio_js.StdioClientTransport({
|
|
1692
1667
|
command: config.command,
|
|
1693
1668
|
args: config.args,
|
|
1694
1669
|
env: {
|
|
@@ -1701,11 +1676,11 @@ var McpClientManagerService = class {
|
|
|
1701
1676
|
if (childProcess) mcpClient.setChildProcess(childProcess);
|
|
1702
1677
|
}
|
|
1703
1678
|
async connectHttpClient(mcpClient, config) {
|
|
1704
|
-
const transport = new
|
|
1679
|
+
const transport = new _modelcontextprotocol_sdk_client_streamableHttp_js.StreamableHTTPClientTransport(new URL(config.url), { requestInit: config.headers ? { headers: config.headers } : void 0 });
|
|
1705
1680
|
await mcpClient["client"].connect(transport);
|
|
1706
1681
|
}
|
|
1707
1682
|
async connectSseClient(mcpClient, config) {
|
|
1708
|
-
const transport = new
|
|
1683
|
+
const transport = new _modelcontextprotocol_sdk_client_sse_js.SSEClientTransport(new URL(config.url));
|
|
1709
1684
|
await mcpClient["client"].connect(transport);
|
|
1710
1685
|
}
|
|
1711
1686
|
/**
|
|
@@ -1746,7 +1721,6 @@ var McpClientManagerService = class {
|
|
|
1746
1721
|
return this.clients.has(serverName);
|
|
1747
1722
|
}
|
|
1748
1723
|
};
|
|
1749
|
-
|
|
1750
1724
|
//#endregion
|
|
1751
1725
|
//#region src/services/SkillService.ts
|
|
1752
1726
|
/**
|
|
@@ -2101,11 +2075,9 @@ var SkillService = class {
|
|
|
2101
2075
|
};
|
|
2102
2076
|
}
|
|
2103
2077
|
};
|
|
2104
|
-
|
|
2105
2078
|
//#endregion
|
|
2106
2079
|
//#region src/templates/toolkit-description.liquid?raw
|
|
2107
2080
|
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 name=\"{{ 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";
|
|
2108
|
-
|
|
2109
2081
|
//#endregion
|
|
2110
2082
|
//#region src/tools/DescribeToolsTool.ts
|
|
2111
2083
|
/**
|
|
@@ -2155,7 +2127,7 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
2155
2127
|
constructor(clientManager, skillService, serverId, definitionsCacheService) {
|
|
2156
2128
|
this.clientManager = clientManager;
|
|
2157
2129
|
this.skillService = skillService;
|
|
2158
|
-
this.serverId = serverId ||
|
|
2130
|
+
this.serverId = serverId || "unknown";
|
|
2159
2131
|
this.definitionsCacheService = definitionsCacheService || new DefinitionsCacheService(clientManager, skillService);
|
|
2160
2132
|
}
|
|
2161
2133
|
/**
|
|
@@ -2271,7 +2243,7 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
2271
2243
|
}).join("\n") || "";
|
|
2272
2244
|
return {
|
|
2273
2245
|
name: promptSkill.skill.name,
|
|
2274
|
-
location: promptSkill.skill.folder ||
|
|
2246
|
+
location: promptSkill.skill.folder || `prompt:${promptSkill.serverName}/${promptSkill.promptName}`,
|
|
2275
2247
|
instructions: formatSkillInstructions(promptSkill.skill.name, rawInstructions)
|
|
2276
2248
|
};
|
|
2277
2249
|
} catch (error) {
|
|
@@ -2434,41 +2406,41 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
2434
2406
|
}
|
|
2435
2407
|
}
|
|
2436
2408
|
const lookupResults = await Promise.all(toolNames.map(async (requestedName) => {
|
|
2437
|
-
const result
|
|
2409
|
+
const result = {
|
|
2438
2410
|
tools: [],
|
|
2439
2411
|
skills: [],
|
|
2440
2412
|
notFound: null
|
|
2441
2413
|
};
|
|
2442
|
-
if (requestedName.startsWith(
|
|
2443
|
-
const skillName = requestedName.slice(
|
|
2414
|
+
if (requestedName.startsWith("skill__")) {
|
|
2415
|
+
const skillName = requestedName.slice(7);
|
|
2444
2416
|
if (this.skillService) {
|
|
2445
2417
|
const skill = await this.skillService.getSkill(skillName);
|
|
2446
2418
|
if (skill) {
|
|
2447
|
-
result
|
|
2419
|
+
result.skills.push({
|
|
2448
2420
|
name: skill.name,
|
|
2449
2421
|
location: skill.basePath,
|
|
2450
2422
|
instructions: formatSkillInstructions(skill.name, skill.content)
|
|
2451
2423
|
});
|
|
2452
|
-
return result
|
|
2424
|
+
return result;
|
|
2453
2425
|
}
|
|
2454
2426
|
}
|
|
2455
2427
|
const promptSkillContent = await this.getPromptSkillContent(skillName);
|
|
2456
2428
|
if (promptSkillContent) {
|
|
2457
|
-
result
|
|
2458
|
-
return result
|
|
2429
|
+
result.skills.push(promptSkillContent);
|
|
2430
|
+
return result;
|
|
2459
2431
|
}
|
|
2460
|
-
result
|
|
2461
|
-
return result
|
|
2432
|
+
result.notFound = requestedName;
|
|
2433
|
+
return result;
|
|
2462
2434
|
}
|
|
2463
2435
|
const { serverName, actualToolName } = parseToolName(requestedName);
|
|
2464
2436
|
if (serverName) {
|
|
2465
2437
|
const serverTools = serverToolsMap.get(serverName);
|
|
2466
2438
|
if (!serverTools) {
|
|
2467
|
-
result
|
|
2468
|
-
return result
|
|
2439
|
+
result.notFound = requestedName;
|
|
2440
|
+
return result;
|
|
2469
2441
|
}
|
|
2470
2442
|
const tool = serverTools.find((t) => t.name === actualToolName);
|
|
2471
|
-
if (tool) result
|
|
2443
|
+
if (tool) result.tools.push({
|
|
2472
2444
|
server: serverName,
|
|
2473
2445
|
tool: {
|
|
2474
2446
|
name: tool.name,
|
|
@@ -2476,34 +2448,34 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
2476
2448
|
inputSchema: tool.inputSchema
|
|
2477
2449
|
}
|
|
2478
2450
|
});
|
|
2479
|
-
else result
|
|
2480
|
-
return result
|
|
2451
|
+
else result.notFound = requestedName;
|
|
2452
|
+
return result;
|
|
2481
2453
|
}
|
|
2482
2454
|
const servers = toolToServers.get(actualToolName);
|
|
2483
2455
|
if (!servers || servers.length === 0) {
|
|
2484
2456
|
if (this.skillService) {
|
|
2485
2457
|
const skill = await this.skillService.getSkill(actualToolName);
|
|
2486
2458
|
if (skill) {
|
|
2487
|
-
result
|
|
2459
|
+
result.skills.push({
|
|
2488
2460
|
name: skill.name,
|
|
2489
2461
|
location: skill.basePath,
|
|
2490
2462
|
instructions: formatSkillInstructions(skill.name, skill.content)
|
|
2491
2463
|
});
|
|
2492
|
-
return result
|
|
2464
|
+
return result;
|
|
2493
2465
|
}
|
|
2494
2466
|
}
|
|
2495
2467
|
const promptSkillContent = await this.getPromptSkillContent(actualToolName);
|
|
2496
2468
|
if (promptSkillContent) {
|
|
2497
|
-
result
|
|
2498
|
-
return result
|
|
2469
|
+
result.skills.push(promptSkillContent);
|
|
2470
|
+
return result;
|
|
2499
2471
|
}
|
|
2500
|
-
result
|
|
2501
|
-
return result
|
|
2472
|
+
result.notFound = requestedName;
|
|
2473
|
+
return result;
|
|
2502
2474
|
}
|
|
2503
2475
|
if (servers.length === 1) {
|
|
2504
2476
|
const server = servers[0];
|
|
2505
2477
|
const tool = serverToolsMap.get(server).find((t) => t.name === actualToolName);
|
|
2506
|
-
result
|
|
2478
|
+
result.tools.push({
|
|
2507
2479
|
server,
|
|
2508
2480
|
tool: {
|
|
2509
2481
|
name: tool.name,
|
|
@@ -2513,7 +2485,7 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
2513
2485
|
});
|
|
2514
2486
|
} else for (const server of servers) {
|
|
2515
2487
|
const tool = serverToolsMap.get(server).find((t) => t.name === actualToolName);
|
|
2516
|
-
result
|
|
2488
|
+
result.tools.push({
|
|
2517
2489
|
server,
|
|
2518
2490
|
tool: {
|
|
2519
2491
|
name: tool.name,
|
|
@@ -2522,15 +2494,15 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
2522
2494
|
}
|
|
2523
2495
|
});
|
|
2524
2496
|
}
|
|
2525
|
-
return result
|
|
2497
|
+
return result;
|
|
2526
2498
|
}));
|
|
2527
2499
|
const foundTools = [];
|
|
2528
2500
|
const foundSkills = [];
|
|
2529
2501
|
const notFoundItems = [];
|
|
2530
|
-
for (const result
|
|
2531
|
-
foundTools.push(...result
|
|
2532
|
-
foundSkills.push(...result
|
|
2533
|
-
if (result
|
|
2502
|
+
for (const result of lookupResults) {
|
|
2503
|
+
foundTools.push(...result.tools);
|
|
2504
|
+
foundSkills.push(...result.skills);
|
|
2505
|
+
if (result.notFound) notFoundItems.push(result.notFound);
|
|
2534
2506
|
}
|
|
2535
2507
|
if (foundTools.length === 0 && foundSkills.length === 0) return {
|
|
2536
2508
|
content: [{
|
|
@@ -2569,7 +2541,6 @@ var DescribeToolsTool = class DescribeToolsTool {
|
|
|
2569
2541
|
}
|
|
2570
2542
|
}
|
|
2571
2543
|
};
|
|
2572
|
-
|
|
2573
2544
|
//#endregion
|
|
2574
2545
|
//#region src/utils/toolCapabilities.ts
|
|
2575
2546
|
const TOOL_CAPABILITIES_META_KEY = "agiflowai/capabilities";
|
|
@@ -2581,7 +2552,6 @@ function getToolCapabilities(tool) {
|
|
|
2581
2552
|
function getUniqueSortedCapabilities(tools) {
|
|
2582
2553
|
return Array.from(new Set(tools.flatMap((tool) => getToolCapabilities(tool)))).sort();
|
|
2583
2554
|
}
|
|
2584
|
-
|
|
2585
2555
|
//#endregion
|
|
2586
2556
|
//#region src/tools/SearchListToolsTool.ts
|
|
2587
2557
|
var SearchListToolsTool = class SearchListToolsTool {
|
|
@@ -2648,17 +2618,15 @@ var SearchListToolsTool = class SearchListToolsTool {
|
|
|
2648
2618
|
capabilities: getToolCapabilities(tool)
|
|
2649
2619
|
}))
|
|
2650
2620
|
})).filter((server) => server.tools.length > 0);
|
|
2651
|
-
const result = { servers: filteredServers };
|
|
2652
2621
|
return {
|
|
2653
2622
|
content: [{
|
|
2654
2623
|
type: "text",
|
|
2655
|
-
text: JSON.stringify(
|
|
2624
|
+
text: JSON.stringify({ servers: filteredServers }, null, 2)
|
|
2656
2625
|
}],
|
|
2657
2626
|
isError: filteredServers.length === 0 ? true : void 0
|
|
2658
2627
|
};
|
|
2659
2628
|
}
|
|
2660
2629
|
};
|
|
2661
|
-
|
|
2662
2630
|
//#endregion
|
|
2663
2631
|
//#region src/tools/UseToolTool.ts
|
|
2664
2632
|
/**
|
|
@@ -2691,7 +2659,7 @@ var UseToolTool = class UseToolTool {
|
|
|
2691
2659
|
this.clientManager = clientManager;
|
|
2692
2660
|
this.skillService = skillService;
|
|
2693
2661
|
this.definitionsCacheService = definitionsCacheService || new DefinitionsCacheService(clientManager, skillService);
|
|
2694
|
-
this.serverId = serverId ||
|
|
2662
|
+
this.serverId = serverId || "unknown";
|
|
2695
2663
|
}
|
|
2696
2664
|
/**
|
|
2697
2665
|
* Returns the MCP tool definition with name, description, and input schema.
|
|
@@ -2786,8 +2754,8 @@ IMPORTANT: Only use tools discovered from describe_tools with id="${this.serverI
|
|
|
2786
2754
|
async execute(input) {
|
|
2787
2755
|
try {
|
|
2788
2756
|
const { toolName: inputToolName, toolArgs = {} } = input;
|
|
2789
|
-
if (inputToolName.startsWith(
|
|
2790
|
-
const skillName = inputToolName.slice(
|
|
2757
|
+
if (inputToolName.startsWith("skill__")) {
|
|
2758
|
+
const skillName = inputToolName.slice(7);
|
|
2791
2759
|
if (this.skillService) {
|
|
2792
2760
|
const skill = await this.skillService.getSkill(skillName);
|
|
2793
2761
|
if (skill) return this.executeSkill(skill);
|
|
@@ -2872,11 +2840,9 @@ IMPORTANT: Only use tools discovered from describe_tools with id="${this.serverI
|
|
|
2872
2840
|
}
|
|
2873
2841
|
}
|
|
2874
2842
|
};
|
|
2875
|
-
|
|
2876
2843
|
//#endregion
|
|
2877
2844
|
//#region package.json
|
|
2878
|
-
var version = "0.3.
|
|
2879
|
-
|
|
2845
|
+
var version = "0.3.19";
|
|
2880
2846
|
//#endregion
|
|
2881
2847
|
//#region src/server/index.ts
|
|
2882
2848
|
/**
|
|
@@ -3110,7 +3076,7 @@ async function initializeSharedServices(options) {
|
|
|
3110
3076
|
*/
|
|
3111
3077
|
async function createSessionServer(shared) {
|
|
3112
3078
|
const { clientManager, definitionsCacheService, skillService, describeTools, useTool: useToolWithCache, searchListTools, serverId, proxyMode } = shared;
|
|
3113
|
-
const server = new
|
|
3079
|
+
const server = new _modelcontextprotocol_sdk_server_index_js.Server({
|
|
3114
3080
|
name: "@agiflowai/one-mcp",
|
|
3115
3081
|
version: "0.1.0"
|
|
3116
3082
|
}, {
|
|
@@ -3121,7 +3087,7 @@ async function createSessionServer(shared) {
|
|
|
3121
3087
|
},
|
|
3122
3088
|
instructions: buildProxyInstructions(await definitionsCacheService.getServerDefinitions(), proxyMode, await hasAnySkills(definitionsCacheService, skillService))
|
|
3123
3089
|
});
|
|
3124
|
-
server.setRequestHandler(
|
|
3090
|
+
server.setRequestHandler(_modelcontextprotocol_sdk_types_js.ListToolsRequestSchema, async () => ({ tools: proxyMode === "flat" ? await (async () => {
|
|
3125
3091
|
const currentServerDefinitions = await definitionsCacheService.getServerDefinitions();
|
|
3126
3092
|
const shouldIncludeSkillsTool = await hasAnySkills(definitionsCacheService, skillService);
|
|
3127
3093
|
return [...buildFlatToolDefinitions(currentServerDefinitions), ...shouldIncludeSkillsTool ? [buildSkillsDescribeDefinition(currentServerDefinitions, serverId)] : []];
|
|
@@ -3132,7 +3098,7 @@ async function createSessionServer(shared) {
|
|
|
3132
3098
|
useToolWithCache.getDefinition()
|
|
3133
3099
|
];
|
|
3134
3100
|
})() : [await describeTools.getDefinition(), useToolWithCache.getDefinition()] }));
|
|
3135
|
-
server.setRequestHandler(
|
|
3101
|
+
server.setRequestHandler(_modelcontextprotocol_sdk_types_js.CallToolRequestSchema, async (request) => {
|
|
3136
3102
|
const { name, arguments: args } = request.params;
|
|
3137
3103
|
if (name === DescribeToolsTool.TOOL_NAME) try {
|
|
3138
3104
|
return await describeTools.execute(args);
|
|
@@ -3155,7 +3121,7 @@ async function createSessionServer(shared) {
|
|
|
3155
3121
|
});
|
|
3156
3122
|
throw new Error(`Unknown tool: ${name}`);
|
|
3157
3123
|
});
|
|
3158
|
-
server.setRequestHandler(
|
|
3124
|
+
server.setRequestHandler(_modelcontextprotocol_sdk_types_js.ListResourcesRequestSchema, async () => {
|
|
3159
3125
|
const currentServerDefinitions = await definitionsCacheService.getServerDefinitions();
|
|
3160
3126
|
const resourceToServers = /* @__PURE__ */ new Map();
|
|
3161
3127
|
for (const serverDefinition of currentServerDefinitions) for (const resource of serverDefinition.resources) {
|
|
@@ -3172,7 +3138,7 @@ async function createSessionServer(shared) {
|
|
|
3172
3138
|
}
|
|
3173
3139
|
return { resources };
|
|
3174
3140
|
});
|
|
3175
|
-
server.setRequestHandler(
|
|
3141
|
+
server.setRequestHandler(_modelcontextprotocol_sdk_types_js.ReadResourceRequestSchema, async (request) => {
|
|
3176
3142
|
const { uri } = request.params;
|
|
3177
3143
|
const { serverName, actualToolName: actualUri } = parseToolName(uri);
|
|
3178
3144
|
if (serverName) return await (await clientManager.ensureConnected(serverName)).readResource(actualUri);
|
|
@@ -3181,7 +3147,7 @@ async function createSessionServer(shared) {
|
|
|
3181
3147
|
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.`);
|
|
3182
3148
|
return await (await clientManager.ensureConnected(matchingServers[0])).readResource(actualUri);
|
|
3183
3149
|
});
|
|
3184
|
-
server.setRequestHandler(
|
|
3150
|
+
server.setRequestHandler(_modelcontextprotocol_sdk_types_js.ListPromptsRequestSchema, async () => {
|
|
3185
3151
|
const currentServerDefinitions = await definitionsCacheService.getServerDefinitions();
|
|
3186
3152
|
const promptToServers = /* @__PURE__ */ new Map();
|
|
3187
3153
|
const serverPromptsMap = /* @__PURE__ */ new Map();
|
|
@@ -3206,7 +3172,7 @@ async function createSessionServer(shared) {
|
|
|
3206
3172
|
}
|
|
3207
3173
|
return { prompts: aggregatedPrompts };
|
|
3208
3174
|
});
|
|
3209
|
-
server.setRequestHandler(
|
|
3175
|
+
server.setRequestHandler(_modelcontextprotocol_sdk_types_js.GetPromptRequestSchema, async (request) => {
|
|
3210
3176
|
const { name, arguments: args } = request.params;
|
|
3211
3177
|
const currentServerDefinitions = await definitionsCacheService.getServerDefinitions();
|
|
3212
3178
|
const { serverName, actualToolName: actualPromptName } = parseToolName(name);
|
|
@@ -3228,7 +3194,6 @@ async function createSessionServer(shared) {
|
|
|
3228
3194
|
async function createServer(options) {
|
|
3229
3195
|
return createSessionServer(await initializeSharedServices(options));
|
|
3230
3196
|
}
|
|
3231
|
-
|
|
3232
3197
|
//#endregion
|
|
3233
3198
|
//#region src/types/index.ts
|
|
3234
3199
|
/**
|
|
@@ -3239,7 +3204,6 @@ const TRANSPORT_MODE = {
|
|
|
3239
3204
|
HTTP: "http",
|
|
3240
3205
|
SSE: "sse"
|
|
3241
3206
|
};
|
|
3242
|
-
|
|
3243
3207
|
//#endregion
|
|
3244
3208
|
//#region src/transports/http.ts
|
|
3245
3209
|
/**
|
|
@@ -3269,6 +3233,7 @@ const TRANSPORT_MODE = {
|
|
|
3269
3233
|
*/
|
|
3270
3234
|
var HttpFullSessionManager = class {
|
|
3271
3235
|
sessions = /* @__PURE__ */ new Map();
|
|
3236
|
+
closingSessions = /* @__PURE__ */ new Set();
|
|
3272
3237
|
getSession(sessionId) {
|
|
3273
3238
|
return this.sessions.get(sessionId);
|
|
3274
3239
|
}
|
|
@@ -3279,26 +3244,35 @@ var HttpFullSessionManager = class {
|
|
|
3279
3244
|
});
|
|
3280
3245
|
}
|
|
3281
3246
|
async deleteSession(sessionId) {
|
|
3247
|
+
if (this.closingSessions.has(sessionId)) return;
|
|
3282
3248
|
const session = this.sessions.get(sessionId);
|
|
3283
|
-
if (session)
|
|
3249
|
+
if (!session) return;
|
|
3250
|
+
this.closingSessions.add(sessionId);
|
|
3251
|
+
this.sessions.delete(sessionId);
|
|
3252
|
+
try {
|
|
3284
3253
|
await session.server.close();
|
|
3285
3254
|
} catch (error) {
|
|
3286
3255
|
throw new Error(`Failed to close MCP server for session '${sessionId}': ${toErrorMessage$2(error)}`);
|
|
3256
|
+
} finally {
|
|
3257
|
+
this.closingSessions.delete(sessionId);
|
|
3287
3258
|
}
|
|
3288
|
-
this.sessions.delete(sessionId);
|
|
3289
3259
|
}
|
|
3290
3260
|
hasSession(sessionId) {
|
|
3291
3261
|
return this.sessions.has(sessionId);
|
|
3292
3262
|
}
|
|
3293
3263
|
async clear() {
|
|
3264
|
+
const sessions = Array.from(this.sessions.entries());
|
|
3265
|
+
this.sessions.clear();
|
|
3294
3266
|
try {
|
|
3295
|
-
await Promise.all(
|
|
3267
|
+
await Promise.all(sessions.map(async ([sessionId, session]) => {
|
|
3268
|
+
this.closingSessions.add(sessionId);
|
|
3296
3269
|
await session.server.close();
|
|
3297
3270
|
}));
|
|
3298
3271
|
} catch (error) {
|
|
3299
3272
|
throw new Error(`Failed to clear sessions: ${toErrorMessage$2(error)}`);
|
|
3273
|
+
} finally {
|
|
3274
|
+
for (const [sessionId] of sessions) this.closingSessions.delete(sessionId);
|
|
3300
3275
|
}
|
|
3301
|
-
this.sessions.clear();
|
|
3302
3276
|
}
|
|
3303
3277
|
};
|
|
3304
3278
|
function toErrorMessage$2(error) {
|
|
@@ -3428,21 +3402,21 @@ var HttpTransportHandler = class {
|
|
|
3428
3402
|
async handleAdminShutdownRequest(req, res) {
|
|
3429
3403
|
try {
|
|
3430
3404
|
if (!this.adminOptions?.onShutdownRequested) {
|
|
3431
|
-
const payload
|
|
3405
|
+
const payload = {
|
|
3432
3406
|
ok: false,
|
|
3433
3407
|
message: "Shutdown endpoint is not enabled for this server instance.",
|
|
3434
3408
|
serverId: this.adminOptions?.serverId
|
|
3435
3409
|
};
|
|
3436
|
-
res.status(404).json(payload
|
|
3410
|
+
res.status(404).json(payload);
|
|
3437
3411
|
return;
|
|
3438
3412
|
}
|
|
3439
3413
|
if (!this.isAuthorizedShutdownRequest(req)) {
|
|
3440
|
-
const payload
|
|
3414
|
+
const payload = {
|
|
3441
3415
|
ok: false,
|
|
3442
3416
|
message: "Unauthorized shutdown request: invalid or missing shutdown token.",
|
|
3443
3417
|
serverId: this.adminOptions?.serverId
|
|
3444
3418
|
};
|
|
3445
|
-
res.status(401).json(payload
|
|
3419
|
+
res.status(401).json(payload);
|
|
3446
3420
|
return;
|
|
3447
3421
|
}
|
|
3448
3422
|
const payload = {
|
|
@@ -3460,9 +3434,9 @@ var HttpTransportHandler = class {
|
|
|
3460
3434
|
const sessionId = req.headers["mcp-session-id"];
|
|
3461
3435
|
let transport;
|
|
3462
3436
|
if (sessionId && this.sessionManager.hasSession(sessionId)) transport = this.sessionManager.getSession(sessionId).transport;
|
|
3463
|
-
else if (!sessionId && (0,
|
|
3437
|
+
else if (!sessionId && (0, _modelcontextprotocol_sdk_types_js.isInitializeRequest)(req.body)) {
|
|
3464
3438
|
const mcpServer = await this.serverFactory();
|
|
3465
|
-
transport = new
|
|
3439
|
+
transport = new _modelcontextprotocol_sdk_server_streamableHttp_js.StreamableHTTPServerTransport({
|
|
3466
3440
|
sessionIdGenerator: () => (0, node_crypto.randomUUID)(),
|
|
3467
3441
|
enableJsonResponse: true,
|
|
3468
3442
|
onsessioninitialized: (initializedSessionId) => {
|
|
@@ -3566,7 +3540,6 @@ var HttpTransportHandler = class {
|
|
|
3566
3540
|
return this.config.host;
|
|
3567
3541
|
}
|
|
3568
3542
|
};
|
|
3569
|
-
|
|
3570
3543
|
//#endregion
|
|
3571
3544
|
//#region src/transports/sse.ts
|
|
3572
3545
|
/**
|
|
@@ -3639,7 +3612,7 @@ var SseTransportHandler = class {
|
|
|
3639
3612
|
async handleSseConnection(_req, res) {
|
|
3640
3613
|
try {
|
|
3641
3614
|
const mcpServer = this.serverFactory();
|
|
3642
|
-
const transport = new
|
|
3615
|
+
const transport = new _modelcontextprotocol_sdk_server_sse_js.SSEServerTransport("/messages", res);
|
|
3643
3616
|
this.sessionManager.setSession(transport.sessionId, transport, mcpServer);
|
|
3644
3617
|
res.on("close", () => {
|
|
3645
3618
|
this.sessionManager.deleteSession(transport.sessionId);
|
|
@@ -3670,14 +3643,14 @@ var SseTransportHandler = class {
|
|
|
3670
3643
|
}
|
|
3671
3644
|
}
|
|
3672
3645
|
async start() {
|
|
3673
|
-
return new Promise((resolve
|
|
3646
|
+
return new Promise((resolve, reject) => {
|
|
3674
3647
|
try {
|
|
3675
3648
|
this.server = this.app.listen(this.config.port, this.config.host, () => {
|
|
3676
3649
|
console.error(`@agiflowai/one-mcp MCP server started with SSE transport on http://${this.config.host}:${this.config.port}`);
|
|
3677
3650
|
console.error(`SSE endpoint: http://${this.config.host}:${this.config.port}/sse`);
|
|
3678
3651
|
console.error(`Messages endpoint: http://${this.config.host}:${this.config.port}/messages`);
|
|
3679
3652
|
console.error(`Health check: http://${this.config.host}:${this.config.port}/health`);
|
|
3680
|
-
resolve
|
|
3653
|
+
resolve();
|
|
3681
3654
|
});
|
|
3682
3655
|
this.server.on("error", (error) => {
|
|
3683
3656
|
reject(error);
|
|
@@ -3688,17 +3661,17 @@ var SseTransportHandler = class {
|
|
|
3688
3661
|
});
|
|
3689
3662
|
}
|
|
3690
3663
|
async stop() {
|
|
3691
|
-
return new Promise((resolve
|
|
3664
|
+
return new Promise((resolve, reject) => {
|
|
3692
3665
|
if (this.server) {
|
|
3693
3666
|
this.sessionManager.clear();
|
|
3694
3667
|
this.server.close((err) => {
|
|
3695
3668
|
if (err) reject(err);
|
|
3696
3669
|
else {
|
|
3697
3670
|
this.server = null;
|
|
3698
|
-
resolve
|
|
3671
|
+
resolve();
|
|
3699
3672
|
}
|
|
3700
3673
|
});
|
|
3701
|
-
} else resolve
|
|
3674
|
+
} else resolve();
|
|
3702
3675
|
});
|
|
3703
3676
|
}
|
|
3704
3677
|
getPort() {
|
|
@@ -3708,7 +3681,6 @@ var SseTransportHandler = class {
|
|
|
3708
3681
|
return this.config.host;
|
|
3709
3682
|
}
|
|
3710
3683
|
};
|
|
3711
|
-
|
|
3712
3684
|
//#endregion
|
|
3713
3685
|
//#region src/transports/stdio.ts
|
|
3714
3686
|
/**
|
|
@@ -3722,7 +3694,7 @@ var StdioTransportHandler = class {
|
|
|
3722
3694
|
this.server = server;
|
|
3723
3695
|
}
|
|
3724
3696
|
async start() {
|
|
3725
|
-
this.transport = new
|
|
3697
|
+
this.transport = new _modelcontextprotocol_sdk_server_stdio_js.StdioServerTransport();
|
|
3726
3698
|
await this.server.connect(this.transport);
|
|
3727
3699
|
console.error("@agiflowai/one-mcp MCP server started on stdio");
|
|
3728
3700
|
}
|
|
@@ -3733,7 +3705,6 @@ var StdioTransportHandler = class {
|
|
|
3733
3705
|
}
|
|
3734
3706
|
}
|
|
3735
3707
|
};
|
|
3736
|
-
|
|
3737
3708
|
//#endregion
|
|
3738
3709
|
//#region src/transports/stdio-http.ts
|
|
3739
3710
|
/**
|
|
@@ -3767,15 +3738,15 @@ var StdioHttpTransportHandler = class {
|
|
|
3767
3738
|
}
|
|
3768
3739
|
async start() {
|
|
3769
3740
|
try {
|
|
3770
|
-
const httpClientTransport = new
|
|
3771
|
-
const client = new
|
|
3741
|
+
const httpClientTransport = new _modelcontextprotocol_sdk_client_streamableHttp_js.StreamableHTTPClientTransport(this.endpoint);
|
|
3742
|
+
const client = new _modelcontextprotocol_sdk_client_index_js.Client({
|
|
3772
3743
|
name: "@agiflowai/one-mcp-stdio-http-proxy",
|
|
3773
3744
|
version: "0.1.0"
|
|
3774
3745
|
}, { capabilities: {} });
|
|
3775
3746
|
await client.connect(httpClientTransport);
|
|
3776
3747
|
this.httpClient = client;
|
|
3777
3748
|
this.stdioProxyServer = this.createProxyServer(client);
|
|
3778
|
-
this.stdioTransport = new
|
|
3749
|
+
this.stdioTransport = new _modelcontextprotocol_sdk_server_stdio_js.StdioServerTransport();
|
|
3779
3750
|
await this.stdioProxyServer.connect(this.stdioTransport);
|
|
3780
3751
|
console.error(`@agiflowai/one-mcp MCP stdio proxy connected to ${this.endpoint.toString()}`);
|
|
3781
3752
|
} catch (error) {
|
|
@@ -3817,7 +3788,7 @@ var StdioHttpTransportHandler = class {
|
|
|
3817
3788
|
if (cleanupErrors.length > 0) throw new Error(`Failed to stop stdio-http proxy transport: ${cleanupErrors.join("; ")}`);
|
|
3818
3789
|
}
|
|
3819
3790
|
createProxyServer(client) {
|
|
3820
|
-
const proxyServer = new
|
|
3791
|
+
const proxyServer = new _modelcontextprotocol_sdk_server_index_js.Server({
|
|
3821
3792
|
name: "@agiflowai/one-mcp-stdio-http-proxy",
|
|
3822
3793
|
version: "0.1.0"
|
|
3823
3794
|
}, { capabilities: {
|
|
@@ -3825,14 +3796,14 @@ var StdioHttpTransportHandler = class {
|
|
|
3825
3796
|
resources: {},
|
|
3826
3797
|
prompts: {}
|
|
3827
3798
|
} });
|
|
3828
|
-
proxyServer.setRequestHandler(
|
|
3799
|
+
proxyServer.setRequestHandler(_modelcontextprotocol_sdk_types_js.ListToolsRequestSchema, async () => {
|
|
3829
3800
|
try {
|
|
3830
3801
|
return await client.listTools();
|
|
3831
3802
|
} catch (error) {
|
|
3832
3803
|
throw new Error(`Failed forwarding tools/list to HTTP backend: ${error instanceof Error ? error.message : String(error)}`);
|
|
3833
3804
|
}
|
|
3834
3805
|
});
|
|
3835
|
-
proxyServer.setRequestHandler(
|
|
3806
|
+
proxyServer.setRequestHandler(_modelcontextprotocol_sdk_types_js.CallToolRequestSchema, async (request) => {
|
|
3836
3807
|
try {
|
|
3837
3808
|
return await client.callTool({
|
|
3838
3809
|
name: request.params.name,
|
|
@@ -3842,28 +3813,28 @@ var StdioHttpTransportHandler = class {
|
|
|
3842
3813
|
throw new Error(`Failed forwarding tools/call (${request.params.name}) to HTTP backend: ${error instanceof Error ? error.message : String(error)}`);
|
|
3843
3814
|
}
|
|
3844
3815
|
});
|
|
3845
|
-
proxyServer.setRequestHandler(
|
|
3816
|
+
proxyServer.setRequestHandler(_modelcontextprotocol_sdk_types_js.ListResourcesRequestSchema, async () => {
|
|
3846
3817
|
try {
|
|
3847
3818
|
return await client.listResources();
|
|
3848
3819
|
} catch (error) {
|
|
3849
3820
|
throw new Error(`Failed forwarding resources/list to HTTP backend: ${error instanceof Error ? error.message : String(error)}`);
|
|
3850
3821
|
}
|
|
3851
3822
|
});
|
|
3852
|
-
proxyServer.setRequestHandler(
|
|
3823
|
+
proxyServer.setRequestHandler(_modelcontextprotocol_sdk_types_js.ReadResourceRequestSchema, async (request) => {
|
|
3853
3824
|
try {
|
|
3854
3825
|
return await client.readResource({ uri: request.params.uri });
|
|
3855
3826
|
} catch (error) {
|
|
3856
3827
|
throw new Error(`Failed forwarding resources/read (${request.params.uri}) to HTTP backend: ${error instanceof Error ? error.message : String(error)}`);
|
|
3857
3828
|
}
|
|
3858
3829
|
});
|
|
3859
|
-
proxyServer.setRequestHandler(
|
|
3830
|
+
proxyServer.setRequestHandler(_modelcontextprotocol_sdk_types_js.ListPromptsRequestSchema, async () => {
|
|
3860
3831
|
try {
|
|
3861
3832
|
return await client.listPrompts();
|
|
3862
3833
|
} catch (error) {
|
|
3863
3834
|
throw new Error(`Failed forwarding prompts/list to HTTP backend: ${error instanceof Error ? error.message : String(error)}`);
|
|
3864
3835
|
}
|
|
3865
3836
|
});
|
|
3866
|
-
proxyServer.setRequestHandler(
|
|
3837
|
+
proxyServer.setRequestHandler(_modelcontextprotocol_sdk_types_js.GetPromptRequestSchema, async (request) => {
|
|
3867
3838
|
try {
|
|
3868
3839
|
return await client.getPrompt({
|
|
3869
3840
|
name: request.params.name,
|
|
@@ -3876,7 +3847,6 @@ var StdioHttpTransportHandler = class {
|
|
|
3876
3847
|
return proxyServer;
|
|
3877
3848
|
}
|
|
3878
3849
|
};
|
|
3879
|
-
|
|
3880
3850
|
//#endregion
|
|
3881
3851
|
//#region src/services/RuntimeStateService.ts
|
|
3882
3852
|
/**
|
|
@@ -3975,61 +3945,16 @@ var RuntimeStateService = class RuntimeStateService {
|
|
|
3975
3945
|
await (0, node_fs_promises.rm)(this.getRecordPath(serverId), { force: true });
|
|
3976
3946
|
}
|
|
3977
3947
|
};
|
|
3978
|
-
|
|
3979
|
-
//#endregion
|
|
3980
|
-
//#region src/services/StopServerService/constants.ts
|
|
3981
|
-
/**
|
|
3982
|
-
* StopServerService constants.
|
|
3983
|
-
*/
|
|
3984
|
-
/** Maximum time in milliseconds to wait for a shutdown to complete. */
|
|
3985
|
-
const DEFAULT_STOP_TIMEOUT_MS = 5e3;
|
|
3986
|
-
/** Minimum timeout in milliseconds for individual health check requests. */
|
|
3987
|
-
const HEALTH_REQUEST_TIMEOUT_FLOOR_MS = 250;
|
|
3988
|
-
/** Delay in milliseconds between shutdown polling attempts. */
|
|
3989
|
-
const SHUTDOWN_POLL_INTERVAL_MS = 200;
|
|
3990
3948
|
/** Path for the runtime health check endpoint. */
|
|
3991
3949
|
const HEALTH_CHECK_PATH = "/health";
|
|
3992
|
-
/** Path for the authenticated admin shutdown endpoint. */
|
|
3993
|
-
const ADMIN_SHUTDOWN_PATH = "/admin/shutdown";
|
|
3994
|
-
/** HTTP GET method identifier. */
|
|
3995
|
-
const HTTP_METHOD_GET = "GET";
|
|
3996
|
-
/** HTTP POST method identifier. */
|
|
3997
|
-
const HTTP_METHOD_POST = "POST";
|
|
3998
|
-
/** HTTP header name for bearer token authorization. */
|
|
3999
|
-
const AUTHORIZATION_HEADER_NAME = "Authorization";
|
|
4000
|
-
/** Prefix for bearer token values in the Authorization header. */
|
|
4001
|
-
const BEARER_TOKEN_PREFIX = "Bearer ";
|
|
4002
3950
|
/** HTTP protocol scheme prefix for URL construction. */
|
|
4003
3951
|
const HTTP_PROTOCOL = "http://";
|
|
4004
|
-
/** Separator between host and port in URL construction. */
|
|
4005
|
-
const URL_PORT_SEPARATOR = ":";
|
|
4006
|
-
/** Loopback hostname. */
|
|
4007
|
-
const LOOPBACK_HOST_LOCALHOST = "localhost";
|
|
4008
|
-
/** IPv4 loopback address. */
|
|
4009
|
-
const LOOPBACK_HOST_IPV4 = "127.0.0.1";
|
|
4010
|
-
/** IPv6 loopback address. */
|
|
4011
|
-
const LOOPBACK_HOST_IPV6 = "::1";
|
|
4012
3952
|
/** Hosts that are safe to send admin requests to (loopback only). */
|
|
4013
3953
|
const ALLOWED_HOSTS = new Set([
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
3954
|
+
"localhost",
|
|
3955
|
+
"127.0.0.1",
|
|
3956
|
+
"::1"
|
|
4017
3957
|
]);
|
|
4018
|
-
/** Expected status value in a healthy runtime response. */
|
|
4019
|
-
const HEALTH_STATUS_OK = "ok";
|
|
4020
|
-
/** Expected transport value in a healthy runtime response. */
|
|
4021
|
-
const HEALTH_TRANSPORT_HTTP = "http";
|
|
4022
|
-
/** Property key for status field in health responses. */
|
|
4023
|
-
const KEY_STATUS = "status";
|
|
4024
|
-
/** Property key for transport field in health responses. */
|
|
4025
|
-
const KEY_TRANSPORT = "transport";
|
|
4026
|
-
/** Property key for serverId field in runtime responses. */
|
|
4027
|
-
const KEY_SERVER_ID = "serverId";
|
|
4028
|
-
/** Property key for ok field in shutdown responses. */
|
|
4029
|
-
const KEY_OK = "ok";
|
|
4030
|
-
/** Property key for message field in shutdown responses. */
|
|
4031
|
-
const KEY_MESSAGE = "message";
|
|
4032
|
-
|
|
4033
3958
|
//#endregion
|
|
4034
3959
|
//#region src/services/StopServerService/types.ts
|
|
4035
3960
|
/**
|
|
@@ -4048,19 +3973,8 @@ function toRecord(value) {
|
|
|
4048
3973
|
function isHealthResponse(value) {
|
|
4049
3974
|
if (typeof value !== "object" || value === null) return false;
|
|
4050
3975
|
const record = toRecord(value);
|
|
4051
|
-
return
|
|
4052
|
-
}
|
|
4053
|
-
/**
|
|
4054
|
-
* Type guard for shutdown responses.
|
|
4055
|
-
* @param value - Candidate payload to validate
|
|
4056
|
-
* @returns True when payload matches shutdown response shape
|
|
4057
|
-
*/
|
|
4058
|
-
function isShutdownResponse(value) {
|
|
4059
|
-
if (typeof value !== "object" || value === null) return false;
|
|
4060
|
-
const record = toRecord(value);
|
|
4061
|
-
return KEY_OK in record && typeof record[KEY_OK] === "boolean" && KEY_MESSAGE in record && typeof record[KEY_MESSAGE] === "string" && (!(KEY_SERVER_ID in record) || record[KEY_SERVER_ID] === void 0 || typeof record[KEY_SERVER_ID] === "string");
|
|
3976
|
+
return "status" in record && record["status"] === "ok" && "transport" in record && record["transport"] === "http" && (!("serverId" in record) || record["serverId"] === void 0 || typeof record["serverId"] === "string");
|
|
4062
3977
|
}
|
|
4063
|
-
|
|
4064
3978
|
//#endregion
|
|
4065
3979
|
//#region src/services/StopServerService/StopServerService.ts
|
|
4066
3980
|
/**
|
|
@@ -4072,14 +3986,14 @@ function isShutdownResponse(value) {
|
|
|
4072
3986
|
*/
|
|
4073
3987
|
function buildRuntimeUrl(runtime, path) {
|
|
4074
3988
|
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.`);
|
|
4075
|
-
return `${HTTP_PROTOCOL}${runtime.host}
|
|
3989
|
+
return `${HTTP_PROTOCOL}${runtime.host}:${runtime.port}${path}`;
|
|
4076
3990
|
}
|
|
4077
3991
|
function toErrorMessage(error) {
|
|
4078
3992
|
return error instanceof Error ? error.message : String(error);
|
|
4079
3993
|
}
|
|
4080
3994
|
function sleep(delayMs) {
|
|
4081
|
-
return new Promise((resolve
|
|
4082
|
-
setTimeout(resolve
|
|
3995
|
+
return new Promise((resolve) => {
|
|
3996
|
+
setTimeout(resolve, delayMs);
|
|
4083
3997
|
});
|
|
4084
3998
|
}
|
|
4085
3999
|
/**
|
|
@@ -4096,7 +4010,7 @@ var StopServerService = class {
|
|
|
4096
4010
|
* @returns Stop result payload
|
|
4097
4011
|
*/
|
|
4098
4012
|
async stop(request) {
|
|
4099
|
-
const timeoutMs = request.timeoutMs ??
|
|
4013
|
+
const timeoutMs = request.timeoutMs ?? 5e3;
|
|
4100
4014
|
const runtime = await this.resolveRuntime(request);
|
|
4101
4015
|
const health = await this.fetchHealth(runtime, timeoutMs);
|
|
4102
4016
|
if (!health.reachable) {
|
|
@@ -4104,9 +4018,7 @@ var StopServerService = class {
|
|
|
4104
4018
|
throw new Error(`Runtime '${runtime.serverId}' is not reachable at http://${runtime.host}:${runtime.port}. Removed stale runtime record.`);
|
|
4105
4019
|
}
|
|
4106
4020
|
if (!request.force && health.payload?.serverId && health.payload.serverId !== runtime.serverId) throw new Error(`Refusing to stop runtime at http://${runtime.host}:${runtime.port}: expected server ID '${runtime.serverId}' but health endpoint reported '${health.payload.serverId}'. Use --force to override.`);
|
|
4107
|
-
|
|
4108
|
-
if (!shutdownToken) throw new Error(`No shutdown token available for runtime '${runtime.serverId}'.`);
|
|
4109
|
-
const shutdownResponse = await this.requestShutdown(runtime, shutdownToken, timeoutMs);
|
|
4021
|
+
this.requestLocalShutdown(runtime);
|
|
4110
4022
|
await this.waitForShutdown(runtime, timeoutMs);
|
|
4111
4023
|
await this.runtimeStateService.remove(runtime.serverId);
|
|
4112
4024
|
return {
|
|
@@ -4114,7 +4026,7 @@ var StopServerService = class {
|
|
|
4114
4026
|
serverId: runtime.serverId,
|
|
4115
4027
|
host: runtime.host,
|
|
4116
4028
|
port: runtime.port,
|
|
4117
|
-
message:
|
|
4029
|
+
message: `Sent SIGTERM to local process ${runtime.pid} and the runtime stopped gracefully.`
|
|
4118
4030
|
};
|
|
4119
4031
|
}
|
|
4120
4032
|
/**
|
|
@@ -4142,7 +4054,7 @@ var StopServerService = class {
|
|
|
4142
4054
|
*/
|
|
4143
4055
|
async fetchHealth(runtime, timeoutMs) {
|
|
4144
4056
|
try {
|
|
4145
|
-
const response = await this.fetchWithTimeout(buildRuntimeUrl(runtime, HEALTH_CHECK_PATH), { method:
|
|
4057
|
+
const response = await this.fetchWithTimeout(buildRuntimeUrl(runtime, HEALTH_CHECK_PATH), { method: "GET" }, timeoutMs);
|
|
4146
4058
|
if (!response.ok) return { reachable: false };
|
|
4147
4059
|
const payload = await response.json();
|
|
4148
4060
|
if (!isHealthResponse(payload)) throw new Error("Received invalid health response payload.");
|
|
@@ -4154,22 +4066,14 @@ var StopServerService = class {
|
|
|
4154
4066
|
return { reachable: false };
|
|
4155
4067
|
}
|
|
4156
4068
|
}
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
const response = await this.fetchWithTimeout(buildRuntimeUrl(runtime, ADMIN_SHUTDOWN_PATH), {
|
|
4166
|
-
method: HTTP_METHOD_POST,
|
|
4167
|
-
headers: { [AUTHORIZATION_HEADER_NAME]: `${BEARER_TOKEN_PREFIX}${shutdownToken}` }
|
|
4168
|
-
}, timeoutMs);
|
|
4169
|
-
const payload = await response.json();
|
|
4170
|
-
if (!isShutdownResponse(payload)) throw new Error("Received invalid shutdown response payload.");
|
|
4171
|
-
if (!response.ok || !payload.ok) throw new Error(payload.message);
|
|
4172
|
-
return payload;
|
|
4069
|
+
requestLocalShutdown(runtime) {
|
|
4070
|
+
try {
|
|
4071
|
+
process.kill(runtime.pid, "SIGTERM");
|
|
4072
|
+
} catch (error) {
|
|
4073
|
+
if (isNodeError(error) && error.code === "ESRCH") throw new Error(`Runtime '${runtime.serverId}' is not running anymore (pid ${runtime.pid} does not exist).`);
|
|
4074
|
+
if (isNodeError(error) && error.code === "EPERM") throw new Error(`Permission denied when signaling runtime '${runtime.serverId}' (pid ${runtime.pid}).`);
|
|
4075
|
+
throw new Error(`Failed to signal runtime '${runtime.serverId}' (pid ${runtime.pid}): ${toErrorMessage(error)}`);
|
|
4076
|
+
}
|
|
4173
4077
|
}
|
|
4174
4078
|
/**
|
|
4175
4079
|
* Poll until the target runtime is no longer reachable.
|
|
@@ -4180,8 +4084,8 @@ var StopServerService = class {
|
|
|
4180
4084
|
async waitForShutdown(runtime, timeoutMs) {
|
|
4181
4085
|
const deadline = Date.now() + timeoutMs;
|
|
4182
4086
|
while (Date.now() < deadline) {
|
|
4183
|
-
if (!(await this.fetchHealth(runtime, Math.max(
|
|
4184
|
-
await sleep(
|
|
4087
|
+
if (!(await this.fetchHealth(runtime, Math.max(250, deadline - Date.now()))).reachable) return;
|
|
4088
|
+
await sleep(200);
|
|
4185
4089
|
}
|
|
4186
4090
|
throw new Error(`Timed out waiting for runtime '${runtime.serverId}' to stop at http://${runtime.host}:${runtime.port}.`);
|
|
4187
4091
|
}
|
|
@@ -4209,131 +4113,133 @@ var StopServerService = class {
|
|
|
4209
4113
|
}
|
|
4210
4114
|
}
|
|
4211
4115
|
};
|
|
4212
|
-
|
|
4116
|
+
function isNodeError(error) {
|
|
4117
|
+
return typeof error === "object" && error !== null && "code" in error;
|
|
4118
|
+
}
|
|
4213
4119
|
//#endregion
|
|
4214
|
-
Object.defineProperty(exports,
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4120
|
+
Object.defineProperty(exports, "ConfigFetcherService", {
|
|
4121
|
+
enumerable: true,
|
|
4122
|
+
get: function() {
|
|
4123
|
+
return ConfigFetcherService;
|
|
4124
|
+
}
|
|
4219
4125
|
});
|
|
4220
|
-
Object.defineProperty(exports,
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4126
|
+
Object.defineProperty(exports, "DefinitionsCacheService", {
|
|
4127
|
+
enumerable: true,
|
|
4128
|
+
get: function() {
|
|
4129
|
+
return DefinitionsCacheService;
|
|
4130
|
+
}
|
|
4225
4131
|
});
|
|
4226
|
-
Object.defineProperty(exports,
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4132
|
+
Object.defineProperty(exports, "DescribeToolsTool", {
|
|
4133
|
+
enumerable: true,
|
|
4134
|
+
get: function() {
|
|
4135
|
+
return DescribeToolsTool;
|
|
4136
|
+
}
|
|
4231
4137
|
});
|
|
4232
|
-
Object.defineProperty(exports,
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4138
|
+
Object.defineProperty(exports, "HttpTransportHandler", {
|
|
4139
|
+
enumerable: true,
|
|
4140
|
+
get: function() {
|
|
4141
|
+
return HttpTransportHandler;
|
|
4142
|
+
}
|
|
4237
4143
|
});
|
|
4238
|
-
Object.defineProperty(exports,
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4144
|
+
Object.defineProperty(exports, "McpClientManagerService", {
|
|
4145
|
+
enumerable: true,
|
|
4146
|
+
get: function() {
|
|
4147
|
+
return McpClientManagerService;
|
|
4148
|
+
}
|
|
4243
4149
|
});
|
|
4244
|
-
Object.defineProperty(exports,
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4150
|
+
Object.defineProperty(exports, "RuntimeStateService", {
|
|
4151
|
+
enumerable: true,
|
|
4152
|
+
get: function() {
|
|
4153
|
+
return RuntimeStateService;
|
|
4154
|
+
}
|
|
4249
4155
|
});
|
|
4250
|
-
Object.defineProperty(exports,
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4156
|
+
Object.defineProperty(exports, "SearchListToolsTool", {
|
|
4157
|
+
enumerable: true,
|
|
4158
|
+
get: function() {
|
|
4159
|
+
return SearchListToolsTool;
|
|
4160
|
+
}
|
|
4255
4161
|
});
|
|
4256
|
-
Object.defineProperty(exports,
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4162
|
+
Object.defineProperty(exports, "SkillService", {
|
|
4163
|
+
enumerable: true,
|
|
4164
|
+
get: function() {
|
|
4165
|
+
return SkillService;
|
|
4166
|
+
}
|
|
4261
4167
|
});
|
|
4262
|
-
Object.defineProperty(exports,
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4168
|
+
Object.defineProperty(exports, "SseTransportHandler", {
|
|
4169
|
+
enumerable: true,
|
|
4170
|
+
get: function() {
|
|
4171
|
+
return SseTransportHandler;
|
|
4172
|
+
}
|
|
4267
4173
|
});
|
|
4268
|
-
Object.defineProperty(exports,
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4174
|
+
Object.defineProperty(exports, "StdioHttpTransportHandler", {
|
|
4175
|
+
enumerable: true,
|
|
4176
|
+
get: function() {
|
|
4177
|
+
return StdioHttpTransportHandler;
|
|
4178
|
+
}
|
|
4273
4179
|
});
|
|
4274
|
-
Object.defineProperty(exports,
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4180
|
+
Object.defineProperty(exports, "StdioTransportHandler", {
|
|
4181
|
+
enumerable: true,
|
|
4182
|
+
get: function() {
|
|
4183
|
+
return StdioTransportHandler;
|
|
4184
|
+
}
|
|
4279
4185
|
});
|
|
4280
|
-
Object.defineProperty(exports,
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4186
|
+
Object.defineProperty(exports, "StopServerService", {
|
|
4187
|
+
enumerable: true,
|
|
4188
|
+
get: function() {
|
|
4189
|
+
return StopServerService;
|
|
4190
|
+
}
|
|
4285
4191
|
});
|
|
4286
|
-
Object.defineProperty(exports,
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4192
|
+
Object.defineProperty(exports, "TRANSPORT_MODE", {
|
|
4193
|
+
enumerable: true,
|
|
4194
|
+
get: function() {
|
|
4195
|
+
return TRANSPORT_MODE;
|
|
4196
|
+
}
|
|
4291
4197
|
});
|
|
4292
|
-
Object.defineProperty(exports,
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4198
|
+
Object.defineProperty(exports, "UseToolTool", {
|
|
4199
|
+
enumerable: true,
|
|
4200
|
+
get: function() {
|
|
4201
|
+
return UseToolTool;
|
|
4202
|
+
}
|
|
4297
4203
|
});
|
|
4298
|
-
Object.defineProperty(exports,
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4204
|
+
Object.defineProperty(exports, "__toESM", {
|
|
4205
|
+
enumerable: true,
|
|
4206
|
+
get: function() {
|
|
4207
|
+
return __toESM;
|
|
4208
|
+
}
|
|
4209
|
+
});
|
|
4210
|
+
Object.defineProperty(exports, "createServer", {
|
|
4211
|
+
enumerable: true,
|
|
4212
|
+
get: function() {
|
|
4213
|
+
return createServer;
|
|
4214
|
+
}
|
|
4303
4215
|
});
|
|
4304
|
-
Object.defineProperty(exports,
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4216
|
+
Object.defineProperty(exports, "createSessionServer", {
|
|
4217
|
+
enumerable: true,
|
|
4218
|
+
get: function() {
|
|
4219
|
+
return createSessionServer;
|
|
4220
|
+
}
|
|
4309
4221
|
});
|
|
4310
|
-
Object.defineProperty(exports,
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4222
|
+
Object.defineProperty(exports, "findConfigFile", {
|
|
4223
|
+
enumerable: true,
|
|
4224
|
+
get: function() {
|
|
4225
|
+
return findConfigFile;
|
|
4226
|
+
}
|
|
4315
4227
|
});
|
|
4316
|
-
Object.defineProperty(exports,
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4228
|
+
Object.defineProperty(exports, "generateServerId", {
|
|
4229
|
+
enumerable: true,
|
|
4230
|
+
get: function() {
|
|
4231
|
+
return generateServerId;
|
|
4232
|
+
}
|
|
4321
4233
|
});
|
|
4322
|
-
Object.defineProperty(exports,
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4234
|
+
Object.defineProperty(exports, "initializeSharedServices", {
|
|
4235
|
+
enumerable: true,
|
|
4236
|
+
get: function() {
|
|
4237
|
+
return initializeSharedServices;
|
|
4238
|
+
}
|
|
4327
4239
|
});
|
|
4328
|
-
Object.defineProperty(exports,
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4240
|
+
Object.defineProperty(exports, "version", {
|
|
4241
|
+
enumerable: true,
|
|
4242
|
+
get: function() {
|
|
4243
|
+
return version;
|
|
4244
|
+
}
|
|
4333
4245
|
});
|
|
4334
|
-
Object.defineProperty(exports, 'version', {
|
|
4335
|
-
enumerable: true,
|
|
4336
|
-
get: function () {
|
|
4337
|
-
return version;
|
|
4338
|
-
}
|
|
4339
|
-
});
|