limixbot 0.3.129 → 0.3.130
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/assets/{ActivityPanel-C092xjIk.js → ActivityPanel-CswemPGx.js} +1 -1
- package/dist/assets/{App-CFt1bVwj.js → App-CeGk9O7P.js} +135 -134
- package/dist/assets/{AppEventEditor-C00_DMLy.js → AppEventEditor-lydjfKAA.js} +1 -1
- package/dist/assets/{BotSettingsDialog-81Yk4G56.js → BotSettingsDialog-BGO7s2Sa.js} +4 -4
- package/dist/assets/{BrowserPanel-BZiZr6JO.js → BrowserPanel-WFfhXRW4.js} +1 -1
- package/dist/assets/{BrowserProfilesManager-CIDDGvM_.js → BrowserProfilesManager-DAI3EyaZ.js} +1 -1
- package/dist/assets/{CloudAddDialog-bLdejHsc.js → CloudAddDialog-Lo18f6GE.js} +1 -1
- package/dist/assets/{ComputerFilesPane-Ce9ODuX8.js → ComputerFilesPane-LtL8VMhS.js} +1 -1
- package/dist/assets/{ComputerPanel-Dpekp0Z2.js → ComputerPanel-mEdoL4Dh.js} +2 -2
- package/dist/assets/{DataPanel-i5mxANER.js → DataPanel-HeNk8eOt.js} +1 -1
- package/dist/assets/{DesktopViewer-B9mw98xI.js → DesktopViewer-DCC-jq_j.js} +1 -1
- package/dist/assets/{GrokMoveDialog-DYarhzxZ.js → GrokMoveDialog-I9x5B1Kv.js} +1 -1
- package/dist/assets/{InspectorPanel-D5ulGIOz.js → InspectorPanel-C-ocpaf1.js} +1 -1
- package/dist/assets/{KeyboardShortcutsModal-BVDKAY0o.js → KeyboardShortcutsModal-D73O8To_.js} +1 -1
- package/dist/assets/{LimixResizeHandles-Jjthi0zS.js → LimixResizeHandles-kOyb_U62.js} +1 -1
- package/dist/assets/{LiveDesktop-CFqHs50a.js → LiveDesktop-DYg8H5rp.js} +1 -1
- package/dist/assets/{LocalVmWorkspace-DbB_ec11.js → LocalVmWorkspace-BsGviUnb.js} +1 -1
- package/dist/assets/{MacLocalControl-DoWLhevV.js → MacLocalControl-Db0f-6Gc.js} +1 -1
- package/dist/assets/{MarkdownFilePreview-CCaYi8EP.js → MarkdownFilePreview-Dj8Z6Mm0.js} +1 -1
- package/dist/assets/{MenuMotion-DG5tk0i3.js → MenuMotion-CgVWckHz.js} +1 -1
- package/dist/assets/{NewBotDialog-CWbeGI3M.js → NewBotDialog-Bp8-zb5M.js} +1 -1
- package/dist/assets/{PhoneAppDialog-BErSSwmM.js → PhoneAppDialog-BWtFp9EN.js} +1 -1
- package/dist/assets/{PlacesRail-CAV7kW3Y.js → PlacesRail-CKR79j8d.js} +1 -1
- package/dist/assets/{PluginsPanel-BKQ4in_K.js → PluginsPanel-BZe968J8.js} +2 -2
- package/dist/assets/{ProIntroduction-DgDPOYzn.js → ProIntroduction-CZGUC6Ms.js} +1 -1
- package/dist/assets/{RemoteAgentSettingsPanel-BsD_TT_T.js → RemoteAgentSettingsPanel-CCOe2O1O.js} +1 -1
- package/dist/assets/{RoomPanel-UR35p-lT.js → RoomPanel-jgyrxLn2.js} +1 -1
- package/dist/assets/{RoutinesPage-Cims3t6g.js → RoutinesPage-D5Z3pmtB.js} +2 -2
- package/dist/assets/{SettingsModal-2S8H2h_g.js → SettingsModal-CeKynb83.js} +2 -2
- package/dist/assets/{ShareTeamDialog-org_7J0x.js → ShareTeamDialog-D7qwIwXJ.js} +1 -1
- package/dist/assets/{SignedInSites-Dp2PSLBK.js → SignedInSites-Dh9imU42.js} +1 -1
- package/dist/assets/{TeamLibraryPanel-Ch-zZVWY.js → TeamLibraryPanel-nz4rcGmz.js} +1 -1
- package/dist/assets/{TeamMapPage-Ba7y1YPZ.js → TeamMapPage-CLdRh0ZK.js} +1 -1
- package/dist/assets/{TriggersPage-qUNQ79Nb.js → TriggersPage-BByyX4CZ.js} +1 -1
- package/dist/assets/VisibilitySection-BNhdo2-L.js +22 -0
- package/dist/assets/{WebhookTrigger-DjYDUzGP.js → WebhookTrigger-DxDhbnYz.js} +1 -1
- package/dist/assets/{WorksOnGrid-wPPuMbjR.js → WorksOnGrid-CUh8CexO.js} +1 -1
- package/dist/assets/{abnfDiagram-YUKMZFIV-v0NjYm2N.js → abnfDiagram-YUKMZFIV-uSJsuKuD.js} +1 -1
- package/dist/assets/{activity-DONzM_Hr.js → activity-CmQeVvqw.js} +1 -1
- package/dist/assets/{architectureDiagram-47P4ROYG-C9p47RSg.js → architectureDiagram-47P4ROYG-Br4Cv9sO.js} +1 -1
- package/dist/assets/{blockDiagram-E7TT5TSB-BjCDCsDZ.js → blockDiagram-E7TT5TSB-CzcaYs_s.js} +1 -1
- package/dist/assets/{c4Diagram-CRA5TL53-BwcLeGrs.js → c4Diagram-CRA5TL53-CDGjKlxD.js} +1 -1
- package/dist/assets/{calendar-days-C0163EM9.js → calendar-days-DSUOH-dL.js} +1 -1
- package/dist/assets/channel-N74fzi1P.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-DkMrEZ1P.js → chunk-2Q5K7J3B-CvuZ4KJD.js} +1 -1
- package/dist/assets/{chunk-5VM5RSS4-BvT5jzrf.js → chunk-5VM5RSS4-negAvO9N.js} +1 -1
- package/dist/assets/{chunk-7TKQ45FW-BPY6DMgY.js → chunk-7TKQ45FW-DA_OVnE1.js} +1 -1
- package/dist/assets/{chunk-AW2ZBBNX-CA02FkCe.js → chunk-AW2ZBBNX-Dbtemotq.js} +1 -1
- package/dist/assets/{chunk-FVRAUYC3-DR_HIm4k.js → chunk-FVRAUYC3-Cnt25BNn.js} +2 -2
- package/dist/assets/{chunk-HTAEGDNF--Q5YJ5qq.js → chunk-HTAEGDNF-CtrZ11_G.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-CdUxnp0z.js → chunk-JWPE2WC7-DKZW0s8n.js} +1 -1
- package/dist/assets/{chunk-KQW6MTUR-CZ_kOJX4.js → chunk-KQW6MTUR-DLg5U6as.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-Baw_LI4a.js → chunk-XXDRQBXY-pkGzgUQb.js} +1 -1
- package/dist/assets/{classDiagram-v2-K4WV4PDN-C3p6RSXv.js → classDiagram-v2-K4WV4PDN-BUBR3HPE.js} +1 -1
- package/dist/assets/{coins-CRTGCu3d.js → coins-Dbmac6SO.js} +1 -1
- package/dist/assets/{core-C6iWxuTj.js → core-BA6DGyEo.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-DexASxvw.js → cose-bilkent-JH36ORCC-BukDY2ET.js} +1 -1
- package/dist/assets/{cynefin-EF2NZ3EQ-CnBYCH8E.js → cynefin-EF2NZ3EQ-B3XBpINL.js} +1 -1
- package/dist/assets/{cynefinDiagram-3GCD6N5R-BxlPVTxc.js → cynefinDiagram-3GCD6N5R-BV0SrhK6.js} +1 -1
- package/dist/assets/{dagre-W4DXFKR2-DwHsGS35.js → dagre-W4DXFKR2-DzXXYwns.js} +1 -1
- package/dist/assets/{diagram-2UJZ2QOL-BitCWJhQ.js → diagram-2UJZ2QOL-BmOG88-j.js} +1 -1
- package/dist/assets/{diagram-OVF4WLC6-DVq8AK9P.js → diagram-OVF4WLC6-C9zP_sNp.js} +1 -1
- package/dist/assets/{diagram-PFPMY2P6-B1CGGTYD.js → diagram-PFPMY2P6-UzTTpwh8.js} +1 -1
- package/dist/assets/{diagram-UMYRVEAY-BJOrT_fX.js → diagram-UMYRVEAY-Bo-9jQh-.js} +1 -1
- package/dist/assets/{diagram-YEKJPTXX-CqTidMyp.js → diagram-YEKJPTXX-eNeARjiU.js} +1 -1
- package/dist/assets/{diagram-ZIFT7M5P-BrETFWbJ.js → diagram-ZIFT7M5P-Bp8Apm58.js} +1 -1
- package/dist/assets/{ebnfDiagram-VR2GEFS7-odzlCiG_.js → ebnfDiagram-VR2GEFS7-CThvAW5-.js} +1 -1
- package/dist/assets/{elk-IJKZMXRS-DOqejjFU.js → elk-IJKZMXRS-CIAQeuC1.js} +1 -1
- package/dist/assets/{erDiagram-O2IAPWRE-pus74-u1.js → erDiagram-O2IAPWRE-DJc0-QG5.js} +1 -1
- package/dist/assets/{file-up-VlqNWssp.js → file-up-uBDzou4C.js} +1 -1
- package/dist/assets/{flowDiagram-OXPTDLAJ-BoR02YXy.js → flowDiagram-OXPTDLAJ-CX1UCZsi.js} +1 -1
- package/dist/assets/{ganttDiagram-R7TSEDQI-DEWJjq9w.js → ganttDiagram-R7TSEDQI-CFCWgBLl.js} +1 -1
- package/dist/assets/{gitGraphDiagram-XJZIOB7I-A0Ut1vzJ.js → gitGraphDiagram-XJZIOB7I-BY59AEfH.js} +1 -1
- package/dist/assets/{import-name-Dzn9IajS.js → import-name-gQROrWbj.js} +1 -1
- package/dist/assets/{index-ByrnprY3.js → index-CkdvX5_R.js} +1 -1
- package/dist/assets/{index-DoClz3zG.js → index-a4OBw5ZS.js} +3 -3
- package/dist/assets/{infoDiagram-5W2HQ5XZ-IrI9xNS5.js → infoDiagram-5W2HQ5XZ-CiWYCcE-.js} +1 -1
- package/dist/assets/{ishikawaDiagram-K3B6WC7H-CcZaBkPV.js → ishikawaDiagram-K3B6WC7H-DXZKShaj.js} +1 -1
- package/dist/assets/{journeyDiagram-COXZFDF6-Lhq1JIrG.js → journeyDiagram-COXZFDF6-qrPSJHoF.js} +1 -1
- package/dist/assets/{kanban-definition-P3RFRI5V-Dpnd1w1Z.js → kanban-definition-P3RFRI5V-Ch9e9C4r.js} +1 -1
- package/dist/assets/{mermaid.core-CwYv1-pN.js → mermaid.core-DQALiqHr.js} +4 -4
- package/dist/assets/{mindmap-definition-LZFPQGKD-BQu-1VuI.js → mindmap-definition-LZFPQGKD-BirJD4xj.js} +1 -1
- package/dist/assets/{minimize-BRtvUvR3.js → minimize-DlAHYBEI.js} +1 -1
- package/dist/assets/{monitor-Gc_xwWHG.js → monitor-B-DfxCLW.js} +1 -1
- package/dist/assets/{new-bot-CMIOaWIO.js → new-bot-CAtQzQF1.js} +1 -1
- package/dist/assets/{org-library-CwIWLSKR.js → org-library-PVNP5n7J.js} +1 -1
- package/dist/assets/{package-format-C4Kbcf94.js → package-format-xp0kEF1i.js} +1 -1
- package/dist/assets/{pegDiagram-BGZESJAR-C2kBJx8q.js → pegDiagram-BGZESJAR-UzkL237f.js} +1 -1
- package/dist/assets/{pieDiagram-CAPJLFHJ-3IGf8-rd.js → pieDiagram-CAPJLFHJ-CPI42dPn.js} +1 -1
- package/dist/assets/{quadrantDiagram-GDMTTRAM-Ds0i1JJu.js → quadrantDiagram-GDMTTRAM-BEcjaKog.js} +1 -1
- package/dist/assets/{rail-BxO9nJ7b.js → rail-DzsIoRRT.js} +1 -1
- package/dist/assets/{railroadDiagram-SM67HX2B-C5HMZeLZ.js → railroadDiagram-SM67HX2B-B0KHoW-7.js} +1 -1
- package/dist/assets/{remote-desktop-panel-z23u6kyq.js → remote-desktop-panel-BtSv4c6E.js} +1 -1
- package/dist/assets/{requirementDiagram-X7JNWC4A-W7wEhXbS.js → requirementDiagram-X7JNWC4A-BdBqE5oc.js} +1 -1
- package/dist/assets/{sankeyDiagram-UM26HJRW-BIIvZEMK.js → sankeyDiagram-UM26HJRW-o-m5UnNV.js} +1 -1
- package/dist/assets/{sequenceDiagram-ZO4K6R2Y-B6ZAapb0.js → sequenceDiagram-ZO4K6R2Y-CS89JhnM.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-CijBtoJ-.js → sizeCapture-INFHLROL-u3jsM9rY.js} +1 -1
- package/dist/assets/{stateDiagram-v2-TBUQTH76-gVAJTp58.js → stateDiagram-v2-TBUQTH76-ZR8x5js6.js} +1 -1
- package/dist/assets/styles-_tGCSCNl.css +1 -0
- package/dist/assets/{swimlanes-N4OXWK64-1T5CmmoT.js → swimlanes-N4OXWK64-CxHXcQ4B.js} +1 -1
- package/dist/assets/swimlanesDiagram-K3J5GTZL-DJxa56rP.js +8 -0
- package/dist/assets/{team-share-DZ71boDj.js → team-share-DNj2KZjX.js} +1 -1
- package/dist/assets/{timeline-definition-YOQAKGHF-b2WZ1F71.js → timeline-definition-YOQAKGHF-Bhgot_xM.js} +1 -1
- package/dist/assets/{usecaseDiagram-VIAY4XPW-DvPVm705.js → usecaseDiagram-VIAY4XPW-C4T3EUA4.js} +1 -1
- package/dist/assets/{vennDiagram-BLWOH2XV-BG-PWVxl.js → vennDiagram-BLWOH2XV-B1Z8NDj7.js} +1 -1
- package/dist/assets/{wardleyDiagram-YMQ3BMBF-5xjAr3nW.js → wardleyDiagram-YMQ3BMBF-D3gNVcd7.js} +1 -1
- package/dist/assets/{xychartDiagram-TAQBALBS-DgoVlD5n.js → xychartDiagram-TAQBALBS-CM-Am2Dc.js} +1 -1
- package/dist/index.html +3 -3
- package/dist/rail.html +6 -6
- package/dist-server/bot-box/box-check.js +6 -6
- package/dist-server/drivers/agents-proxy.js +50 -48
- package/dist-server/hybrid-plugin-gateway.js +1489 -0
- package/dist-server/index.js +5546 -5454
- package/dist-server/limixbot.js +517 -508
- package/dist-server/mcp-gate.js +76 -61
- package/dist-server/mcp-remote-proxy.js +26 -23
- package/dist-server/mcp-server.js +28 -25
- package/dist-server/package.json +1 -1
- package/dist-server/pair-cli.js +517 -508
- package/dist-server/scripts/mcp-server.js +30 -27
- package/dist-server/server/agents-turn.js +1 -0
- package/dist-server/server/auto-approve.js +2 -0
- package/dist-server/server/bot-box/env.js +2 -2
- package/dist-server/server/cli-usage.js +2 -2
- package/dist-server/server/drivers/acp/native-process-sampler.js +84 -0
- package/dist-server/server/drivers/acp/quiet-status.js +12 -3
- package/dist-server/server/drivers/agents-call.js +4 -0
- package/dist-server/server/drivers/agents-catalog-profile.js +1 -0
- package/dist-server/server/drivers/agents-catalog.js +16 -1
- package/dist-server/server/drivers/agents-mcp-env.js +1 -1
- package/dist-server/server/drivers/claude-elicitation.js +21 -9
- package/dist-server/server/drivers/elicited-consent.js +24 -0
- package/dist-server/server/headless/client.js +10 -9
- package/dist-server/server/headless/main.js +1 -1
- package/dist-server/server/hybrid-plugin-gateway.js +162 -0
- package/dist-server/server/hybrid-plugin-manifest.js +99 -0
- package/dist-server/server/index.js +41 -3
- package/dist-server/server/limix-native-path.js +8 -0
- package/dist-server/server/mcp-app-connections.js +58 -5
- package/dist-server/server/mcp-gate-tasks.js +75 -0
- package/dist-server/server/mcp-gate.js +81 -5
- package/dist-server/server/mcp-http.js +34 -6
- package/dist-server/server/mcp-native-response.js +112 -0
- package/dist-server/server/mcp-skills.js +263 -0
- package/dist-server/server/mcp-trim.js +15 -8
- package/dist-server/server/plugin-hub.js +259 -25
- package/dist-server/server/plugin-passages.js +16 -0
- package/dist-server/server/routes/plugin-mcp.js +118 -0
- package/dist-server/server/routes/plugin-studio.js +50 -0
- package/dist-server/server/side-jobs.js +1 -1
- package/dist-server/shared/plugin-hub.js +6 -2
- package/dist-server/vps-container-mcp.js +6 -6
- package/package.json +1 -1
- package/skills/limix-bot-factory/SKILL.md +2 -0
- package/skills/limix-bot-factory/assets/schemas/bot-spec.schema.json +14 -0
- package/skills/limix-bot-factory/references/integration-blueprint.md +1 -1
- package/skills/limix-bot-factory/references/vi.md +4 -0
- package/skills/limix-bot-factory/scripts/factorylib/cli.py +2 -1
- package/skills/limix-bot-factory/scripts/factorylib/core.py +19 -1
- package/skills/limix-bot-factory/scripts/factorylib/engine.py +10 -1
- package/skills/limix-bot-factory/scripts/mcp_server.py +3 -3
- package/dist/assets/VisibilitySection-DdEr_5bZ.js +0 -22
- package/dist/assets/channel-BloV1v8U.js +0 -1
- package/dist/assets/mcp-servers-iT-sFJLT.js +0 -1
- package/dist/assets/styles-DiAFRlxu.css +0 -1
- package/dist/assets/swimlanesDiagram-K3J5GTZL-D0mOoyOD.js +0 -8
- /package/dist/assets/{styles-Be5qq6WR.js → styles-CE92r4H3.js} +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { clientRequestsTasks, createGateTasks, taskRevision } from "./mcp-gate-tasks.js";
|
|
1
2
|
// stdout is the MCP transport. Never log there.
|
|
2
3
|
import { spawn } from "node:child_process";
|
|
3
4
|
import { mkdirSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
@@ -10,7 +11,8 @@ import { APP_ONLY_REFUSAL, AppObserver, GATE_APPS_ENV, modelVisible, parseAppMou
|
|
|
10
11
|
import { directoryCallTarget, isDirectoryTool } from "./mcp-directory.js";
|
|
11
12
|
import { QUERY_TOOL, QUERY_TOOL_NAME, ResultStore, answerQuery, describeShape, exampleQuery } from "./mcp-shape.js";
|
|
12
13
|
import { fitToolList } from "./mcp-tool-schema.js";
|
|
13
|
-
import { DEFAULT_RESULT_BUDGET, trimResultText, trimStructured } from "./mcp-trim.js";
|
|
14
|
+
import { DEFAULT_RESULT_BUDGET, MIN_RESULT_BUDGET, trimPlainResultPrefix, trimResultText, trimStructured } from "./mcp-trim.js";
|
|
15
|
+
import { inspectLargeToolReply, readToolResponseFrames } from "./mcp-native-response.js";
|
|
14
16
|
import { killCliTree } from "./procs.js";
|
|
15
17
|
import { toolSchemaProfileFromEnv } from "./tool-schema-profile.js";
|
|
16
18
|
import { capToolListResult, toolLimitFromEnv } from "./tool-count-limit.js";
|
|
@@ -260,6 +262,7 @@ child.on("error", (error) => {
|
|
|
260
262
|
process.exit(1);
|
|
261
263
|
});
|
|
262
264
|
child.stderr.pipe(process.stderr);
|
|
265
|
+
const tasks = createGateTasks();
|
|
263
266
|
function callTarget(name, args) {
|
|
264
267
|
return DIRECTORY ? directoryCallTarget(name, args) : name;
|
|
265
268
|
}
|
|
@@ -282,6 +285,18 @@ createInterface({ input: process.stdin }).on("line", (line) => {
|
|
|
282
285
|
}
|
|
283
286
|
const id = requestKey(message?.id);
|
|
284
287
|
const params = isRecord(message?.params) ? message.params : undefined;
|
|
288
|
+
if (message && typeof message.method === "string" && message.method.startsWith("tasks/")) {
|
|
289
|
+
const poll = message.method === "tasks/get";
|
|
290
|
+
const handle = params?.taskId;
|
|
291
|
+
const task = tasks.resolve(handle, poll);
|
|
292
|
+
if (!id || typeof handle !== "string" || !task || !taskRevision(params) || (!poll && message.method !== "tasks/cancel") || appOnly.has(task.tool)) {
|
|
293
|
+
return rejectRequest(message.id, -32602, "This task operation is unavailable to this connection.");
|
|
294
|
+
}
|
|
295
|
+
if (pending.has(id))
|
|
296
|
+
return rejectRequest(message.id, -32600, "Duplicate in-flight request ID");
|
|
297
|
+
pending.set(id, poll ? { kind: "task-get", handle, task } : { kind: "other" });
|
|
298
|
+
return child.stdin.write(JSON.stringify({ ...message, params: { ...params, taskId: task.upstreamId } }) + "\n");
|
|
299
|
+
}
|
|
285
300
|
// The gate's own read-only tool: it reads a held result and never reaches upstream, so no selection or app rule applies.
|
|
286
301
|
if (BUDGET > 0 && message?.method === "tools/call" && params?.name === QUERY_TOOL_NAME) {
|
|
287
302
|
if (!id)
|
|
@@ -305,6 +320,14 @@ createInterface({ input: process.stdin }).on("line", (line) => {
|
|
|
305
320
|
}
|
|
306
321
|
}
|
|
307
322
|
if (message?.method === "tools/call" && typeof params?.name === "string") {
|
|
323
|
+
if (clientRequestsTasks(params) && !tasks.canRequest(params)) {
|
|
324
|
+
const meta = params._meta;
|
|
325
|
+
const client = meta["io.modelcontextprotocol/clientCapabilities"];
|
|
326
|
+
const extensions = { ...client.extensions };
|
|
327
|
+
delete extensions["io.modelcontextprotocol/tasks"];
|
|
328
|
+
params._meta = { ...meta, "io.modelcontextprotocol/clientCapabilities": { ...client, extensions } };
|
|
329
|
+
line = JSON.stringify(message);
|
|
330
|
+
}
|
|
308
331
|
const target = callTarget(params.name, params.arguments);
|
|
309
332
|
if (target !== undefined && appOnly.has(target))
|
|
310
333
|
return rejectRequest(message.id, -32602, APP_ONLY_REFUSAL);
|
|
@@ -313,12 +336,15 @@ createInterface({ input: process.stdin }).on("line", (line) => {
|
|
|
313
336
|
return rejectRequest(message.id, -32600, "Tool listing needs a request ID");
|
|
314
337
|
}
|
|
315
338
|
if (id && typeof message?.method === "string") {
|
|
316
|
-
if (
|
|
339
|
+
if (pending.has(id))
|
|
317
340
|
fail("duplicate request ID on a restricted connection");
|
|
318
341
|
if (message.method === "tools/call") {
|
|
319
342
|
const name = typeof params?.name === "string" ? params.name : "tool";
|
|
320
343
|
const target = callTarget(name, params?.arguments);
|
|
321
|
-
pending.set(id, { kind: "call", tool: target ?? name, trim: target !== undefined, ...(observer && params ? { params } : {}) });
|
|
344
|
+
pending.set(id, { kind: "call", tool: target ?? name, trim: target !== undefined, acceptsTask: tasks.canRequest(params), ...(observer && params ? { params } : {}) });
|
|
345
|
+
}
|
|
346
|
+
else if (message.method === "server/discover" && taskRevision(params)) {
|
|
347
|
+
pending.set(id, { kind: "discovery" });
|
|
322
348
|
}
|
|
323
349
|
else if (message.method === "initialize" && observer) {
|
|
324
350
|
if (observer.mount.extension) {
|
|
@@ -334,7 +360,7 @@ createInterface({ input: process.stdin }).on("line", (line) => {
|
|
|
334
360
|
child.stdin.write(`${line}\n`);
|
|
335
361
|
});
|
|
336
362
|
process.stdin.on("end", () => child.stdin.end());
|
|
337
|
-
|
|
363
|
+
function handleResponseLine(line) {
|
|
338
364
|
if (!line.trim())
|
|
339
365
|
return;
|
|
340
366
|
let message;
|
|
@@ -366,6 +392,23 @@ createInterface({ input: child.stdout }).on("line", (line) => {
|
|
|
366
392
|
if (id !== undefined)
|
|
367
393
|
pending.delete(id);
|
|
368
394
|
const result = message.result;
|
|
395
|
+
if (message.method === "notifications/tasks" || message.method === "notifications/tasks/status")
|
|
396
|
+
return;
|
|
397
|
+
if (request?.kind === "discovery")
|
|
398
|
+
tasks.discover(result);
|
|
399
|
+
if (request?.kind === "call" && isRecord(result) && result.resultType === "task") {
|
|
400
|
+
const handle = request.acceptsTask && tasks.issue(result, request.tool);
|
|
401
|
+
if (!handle)
|
|
402
|
+
return rejectRequest(message.id, -32603, "The server returned an unnegotiated or invalid task handle.");
|
|
403
|
+
result.taskId = handle;
|
|
404
|
+
}
|
|
405
|
+
if (request?.kind === "task-get" && message.error === undefined) {
|
|
406
|
+
if (!isRecord(result) || !tasks.polled(request.task, result))
|
|
407
|
+
return rejectRequest(message.id, -32603, "Invalid task status response");
|
|
408
|
+
result.taskId = request.handle;
|
|
409
|
+
if (result.status === "completed" && isRecord(result.result))
|
|
410
|
+
trimCallResult(result.result, request.task.tool);
|
|
411
|
+
}
|
|
369
412
|
if (request?.kind === "initialize")
|
|
370
413
|
observer?.initialized(result);
|
|
371
414
|
// A tool only an MCP app's view may call is never listed to the model, and a call to it is refused.
|
|
@@ -415,5 +458,38 @@ createInterface({ input: child.stdout }).on("line", (line) => {
|
|
|
415
458
|
}
|
|
416
459
|
}
|
|
417
460
|
process.stdout.write(`${JSON.stringify(message)}\n`);
|
|
418
|
-
}
|
|
461
|
+
}
|
|
462
|
+
function handleResponseFrame(frame) {
|
|
463
|
+
const reply = !observer && inspectLargeToolReply(frame, BUDGET);
|
|
464
|
+
if (reply) {
|
|
465
|
+
const id = requestKey(reply.id);
|
|
466
|
+
const request = pending.get(id);
|
|
467
|
+
if (request?.kind === "call") {
|
|
468
|
+
pending.delete(id);
|
|
469
|
+
if (process.env.LIMIX_TOOL_GATEWAY_TRACE === "1")
|
|
470
|
+
process.stderr.write("mcp-gate: Rust handled large response\n");
|
|
471
|
+
if (request.trim && BUDGET > 0 && reply.originalChars > BUDGET) {
|
|
472
|
+
const path = spill(request.tool, reply.text);
|
|
473
|
+
if (reply.originalChars > Math.max(MIN_RESULT_BUDGET, BUDGET)) {
|
|
474
|
+
const prefix = reply.text.toString("utf8", 0, reply.prefixBytes);
|
|
475
|
+
const trimmed = trimPlainResultPrefix({ text: prefix, budget: BUDGET, spillPath: path, spillHint: SPILL_HINT }, reply.originalChars);
|
|
476
|
+
const content = [{ type: "text", text: trimmed.text }];
|
|
477
|
+
process.stderr.write(`mcp-gate(${NAME}): trimmed ${request.tool} to ${BUDGET} chars\n`);
|
|
478
|
+
process.stdout.write(JSON.stringify({ jsonrpc: "2.0", id: reply.id, result: { content } }) + "\n");
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
process.stdout.write(frame);
|
|
483
|
+
process.stdout.write("\n");
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
handleResponseLine(frame.toString("utf8"));
|
|
488
|
+
}
|
|
489
|
+
if (process.env.LIMIX_TOOL_GATEWAY === "typescript") {
|
|
490
|
+
createInterface({ input: child.stdout }).on("line", handleResponseLine);
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
readToolResponseFrames(child.stdout, handleResponseFrame);
|
|
494
|
+
}
|
|
419
495
|
child.on("exit", (code, signal) => process.exit(code ?? (signal ? 1 : 0)));
|
|
@@ -14,6 +14,9 @@ export class McpHttpError extends Error {
|
|
|
14
14
|
this.wwwAuthenticate = wwwAuthenticate;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
+
export function modernProtocolError(code) {
|
|
18
|
+
return code === -32020 || code === -32021 || code === -32022;
|
|
19
|
+
}
|
|
17
20
|
export class McpRpcError extends McpHttpError {
|
|
18
21
|
code;
|
|
19
22
|
detail;
|
|
@@ -160,6 +163,7 @@ export class RemoteMcpClient {
|
|
|
160
163
|
target;
|
|
161
164
|
fetchImpl;
|
|
162
165
|
maxBytes;
|
|
166
|
+
discover;
|
|
163
167
|
onNotification;
|
|
164
168
|
sessionId = null;
|
|
165
169
|
protocolVersion = null;
|
|
@@ -170,6 +174,7 @@ export class RemoteMcpClient {
|
|
|
170
174
|
sseAbort = new AbortController();
|
|
171
175
|
constructor(target, options = {}) {
|
|
172
176
|
this.target = target;
|
|
177
|
+
this.discover = options.discover === true;
|
|
173
178
|
this.fetchImpl = options.fetch ?? fetch;
|
|
174
179
|
this.maxBytes = options.maxBytes ?? MAX_REMOTE_MCP_BYTES;
|
|
175
180
|
this.onNotification = options.onNotification;
|
|
@@ -209,6 +214,8 @@ export class RemoteMcpClient {
|
|
|
209
214
|
const id = this.nextId++;
|
|
210
215
|
const frame = { jsonrpc: "2.0", id, method, ...(params === undefined ? {} : { params }) };
|
|
211
216
|
const onAbort = () => {
|
|
217
|
+
if (this.discover && isRecord(params) && isRecord(params._meta) && params._meta["io.modelcontextprotocol/protocolVersion"] === "2026-07-28")
|
|
218
|
+
return;
|
|
212
219
|
void this.notify("notifications/cancelled", { requestId: id, reason: "Request cancelled" }, AbortSignal.timeout(2_000)).catch(() => { });
|
|
213
220
|
};
|
|
214
221
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
@@ -239,7 +246,7 @@ export class RemoteMcpClient {
|
|
|
239
246
|
try {
|
|
240
247
|
const headers = this.headers();
|
|
241
248
|
headers.set("mcp-session-id", this.sessionId);
|
|
242
|
-
const response = await this.fetchImpl(this.target.url, { method: "DELETE", headers, signal: AbortSignal.timeout(2_000) });
|
|
249
|
+
const response = await this.fetchImpl(this.target.url, { method: "DELETE", headers, signal: AbortSignal.timeout(2_000), ...(this.discover ? { redirect: "error" } : {}) });
|
|
243
250
|
drain(response);
|
|
244
251
|
}
|
|
245
252
|
catch {
|
|
@@ -259,10 +266,21 @@ export class RemoteMcpClient {
|
|
|
259
266
|
}
|
|
260
267
|
async post(url, frame, signal) {
|
|
261
268
|
const headers = this.headers();
|
|
269
|
+
const modern = this.discover && isRecord(frame) && isRecord(frame.params) && isRecord(frame.params._meta)
|
|
270
|
+
&& frame.params._meta["io.modelcontextprotocol/protocolVersion"] === "2026-07-28";
|
|
271
|
+
if (modern && isRecord(frame.params)) {
|
|
272
|
+
headers.set("mcp-protocol-version", "2026-07-28");
|
|
273
|
+
headers.set("mcp-method", String(frame.method));
|
|
274
|
+
if (frame.method === "resources/read" && typeof frame.params.uri === "string") {
|
|
275
|
+
const value = frame.params.uri;
|
|
276
|
+
const plain = /^[\x21-\x7e]+$/.test(value) && !/^=\?base64\?.*\?=$/.test(value);
|
|
277
|
+
headers.set("mcp-name", plain ? value : `=?base64?${Buffer.from(value).toString("base64")}?=`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
262
280
|
headers.set("content-type", "application/json");
|
|
263
281
|
let response;
|
|
264
282
|
try {
|
|
265
|
-
response = await this.fetchImpl(url, { method: "POST", headers, body: JSON.stringify(frame), signal });
|
|
283
|
+
response = await this.fetchImpl(url, { method: "POST", headers, body: JSON.stringify(frame), signal, ...(this.discover ? { redirect: "error" } : {}) });
|
|
266
284
|
}
|
|
267
285
|
catch (error) {
|
|
268
286
|
if (signal.aborted)
|
|
@@ -270,11 +288,18 @@ export class RemoteMcpClient {
|
|
|
270
288
|
throw new McpHttpError("network", "request failed");
|
|
271
289
|
}
|
|
272
290
|
if (!response.ok) {
|
|
273
|
-
|
|
291
|
+
if (modern && response.status === 400) {
|
|
292
|
+
const reply = parseMessage(await readBounded(response, 16 * 1024));
|
|
293
|
+
if (reply && !Array.isArray(reply) && isRecord(reply.error) && modernProtocolError(reply.error.code)) {
|
|
294
|
+
throw new McpRpcError(reply.error.code, "MCP protocol negotiation failed");
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
else
|
|
298
|
+
drain(response);
|
|
274
299
|
throw new McpHttpError("status", `HTTP ${response.status}`, response.status, response.headers.get("www-authenticate") ?? undefined);
|
|
275
300
|
}
|
|
276
301
|
const session = response.headers.get("mcp-session-id");
|
|
277
|
-
if (session)
|
|
302
|
+
if (session && !modern)
|
|
278
303
|
this.sessionId = session;
|
|
279
304
|
return response;
|
|
280
305
|
}
|
|
@@ -329,7 +354,7 @@ export class RemoteMcpClient {
|
|
|
329
354
|
headers.set("accept", "text/event-stream");
|
|
330
355
|
// The caller's signal covers only the opening: later requests are answered on this stream.
|
|
331
356
|
const opening = AbortSignal.any([signal, this.sseAbort.signal]);
|
|
332
|
-
this.fetchImpl(this.target.url, { method: "GET", headers, signal: opening })
|
|
357
|
+
this.fetchImpl(this.target.url, { method: "GET", headers, signal: opening, ...(this.discover ? { redirect: "error" } : {}) })
|
|
333
358
|
.then(async (response) => {
|
|
334
359
|
if (!response.ok) {
|
|
335
360
|
drain(response);
|
|
@@ -340,7 +365,10 @@ export class RemoteMcpClient {
|
|
|
340
365
|
if (!settled) {
|
|
341
366
|
settled = true;
|
|
342
367
|
try {
|
|
343
|
-
|
|
368
|
+
const endpoint = new URL(event.data, this.target.url);
|
|
369
|
+
if (this.discover && endpoint.origin !== new URL(this.target.url).origin)
|
|
370
|
+
throw new Error("origin");
|
|
371
|
+
resolveEndpoint(endpoint.toString());
|
|
344
372
|
}
|
|
345
373
|
catch {
|
|
346
374
|
rejectEndpoint(new McpHttpError("protocol", "invalid endpoint event"));
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { limixNativeResource } from "./limix-native-path.js";
|
|
3
|
+
import { MIN_RESULT_BUDGET } from "./mcp-trim.js";
|
|
4
|
+
const MIN_FRAME = 64 * 1024;
|
|
5
|
+
const MAX_FRAME = 16 * 1024 * 1024;
|
|
6
|
+
let decoder;
|
|
7
|
+
let retrievalDecoder;
|
|
8
|
+
let compiled;
|
|
9
|
+
function createDecoder() {
|
|
10
|
+
try {
|
|
11
|
+
compiled ??= new WebAssembly.Module(readFileSync(limixNativeResource("limix_tool_gateway.wasm")));
|
|
12
|
+
return new WebAssembly.Instance(compiled).exports;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
let passageKey;
|
|
19
|
+
export function nativePassages(key, normalized, query) {
|
|
20
|
+
if (retrievalDecoder === undefined)
|
|
21
|
+
retrievalDecoder = createDecoder();
|
|
22
|
+
const native = retrievalDecoder;
|
|
23
|
+
if (!native?.index_passages || !native.find_passages)
|
|
24
|
+
return;
|
|
25
|
+
const write = (text) => {
|
|
26
|
+
const bytes = Buffer.from(text);
|
|
27
|
+
const ptr = native.reserve_frame(bytes.length);
|
|
28
|
+
new Uint8Array(native.memory.buffer, ptr, bytes.length).set(bytes);
|
|
29
|
+
};
|
|
30
|
+
try {
|
|
31
|
+
if (key !== passageKey) {
|
|
32
|
+
passageKey = undefined;
|
|
33
|
+
write(normalized());
|
|
34
|
+
if (!native.index_passages())
|
|
35
|
+
return;
|
|
36
|
+
passageKey = key;
|
|
37
|
+
}
|
|
38
|
+
write(query);
|
|
39
|
+
const layout = native.find_passages();
|
|
40
|
+
const [count, ptr] = new Uint32Array(native.memory.buffer, layout, 2);
|
|
41
|
+
return Array.from(new Uint32Array(native.memory.buffer, ptr, count));
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
passageKey = undefined;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function inspectLargeToolReply(frame, budget) {
|
|
49
|
+
if (frame.length < MIN_FRAME || frame.length > MAX_FRAME)
|
|
50
|
+
return;
|
|
51
|
+
if (decoder === undefined)
|
|
52
|
+
decoder = createDecoder();
|
|
53
|
+
const native = decoder;
|
|
54
|
+
if (!native)
|
|
55
|
+
return;
|
|
56
|
+
try {
|
|
57
|
+
const input = native.reserve_frame(frame.length);
|
|
58
|
+
new Uint8Array(native.memory.buffer, input, frame.length).set(frame);
|
|
59
|
+
const prefixBudget = budget > 0 ? Math.min(MAX_FRAME, Math.max(MIN_RESULT_BUDGET, Math.floor(budget))) : 0;
|
|
60
|
+
const layout = native.inspect_reply(prefixBudget);
|
|
61
|
+
if (!layout)
|
|
62
|
+
return;
|
|
63
|
+
const memory = native.memory.buffer;
|
|
64
|
+
const [idAt, idBytes, textAt, textBytes, originalChars, prefixBytes, structured] = new Uint32Array(memory, layout, 7);
|
|
65
|
+
if (structured && originalChars > budget)
|
|
66
|
+
return;
|
|
67
|
+
const id = JSON.parse(Buffer.from(memory, idAt, idBytes).toString("utf8"));
|
|
68
|
+
if (typeof id !== "string" && !(typeof id === "number" && Number.isFinite(id)))
|
|
69
|
+
return;
|
|
70
|
+
const text = Buffer.from(memory, textAt, textBytes);
|
|
71
|
+
return { id, originalChars, text, prefixBytes };
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export function readToolResponseFrames(stream, accept) {
|
|
78
|
+
let parts = [];
|
|
79
|
+
let bytes = 0;
|
|
80
|
+
function finish(tail) {
|
|
81
|
+
if (bytes === 0) {
|
|
82
|
+
if (tail.length)
|
|
83
|
+
accept(tail);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
parts.push(tail);
|
|
87
|
+
const frame = Buffer.concat(parts, bytes + tail.length);
|
|
88
|
+
parts = [];
|
|
89
|
+
bytes = 0;
|
|
90
|
+
accept(frame);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
stream.on("data", (chunk) => {
|
|
94
|
+
let start = 0;
|
|
95
|
+
let cr = chunk.indexOf(13);
|
|
96
|
+
let lf = chunk.indexOf(10);
|
|
97
|
+
while (cr >= 0 || lf >= 0) {
|
|
98
|
+
const end = lf < 0 || (cr >= 0 && cr < lf) ? cr : lf;
|
|
99
|
+
finish(chunk.subarray(start, end));
|
|
100
|
+
start = end + 1;
|
|
101
|
+
if (cr === end)
|
|
102
|
+
cr = chunk.indexOf(13, start);
|
|
103
|
+
else
|
|
104
|
+
lf = chunk.indexOf(10, start);
|
|
105
|
+
}
|
|
106
|
+
if (start < chunk.length) {
|
|
107
|
+
parts.push(chunk.subarray(start));
|
|
108
|
+
bytes += chunk.length - start;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
stream.once("end", () => finish(Buffer.alloc(0)));
|
|
112
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { createHash, createHmac, randomBytes } from "node:crypto";
|
|
2
|
+
import { linkSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { isDeepStrictEqual } from "node:util";
|
|
5
|
+
import { parseDocument } from "yaml";
|
|
6
|
+
import { canonicalJson } from "../shared/package-format.js";
|
|
7
|
+
import { DESCRIPTION_MAX, isSkillName, SKILL_FILE_MAX_BYTES } from "../shared/skill-md.js";
|
|
8
|
+
import { openSkillConnection } from "./mcp-app-connections.js";
|
|
9
|
+
const EXTENSION = "io.modelcontextprotocol/skills";
|
|
10
|
+
const MAX_ENTRIES = 1000;
|
|
11
|
+
const MAX_PAGES = 32;
|
|
12
|
+
const MAX_FILES = 1024;
|
|
13
|
+
const MAX_RESOURCE_BYTES = 2 * 1024 * 1024;
|
|
14
|
+
const MAX_CACHE_BYTES = 8 * 1024 * 1024;
|
|
15
|
+
const ephemeralKey = randomBytes(32);
|
|
16
|
+
const cache = new Map();
|
|
17
|
+
let cacheBytes = 0;
|
|
18
|
+
function object(value) {
|
|
19
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
20
|
+
}
|
|
21
|
+
function revisionKey(dataDir) {
|
|
22
|
+
if (!dataDir)
|
|
23
|
+
return ephemeralKey;
|
|
24
|
+
const path = join(dataDir, "mcp-skills-origin.key");
|
|
25
|
+
const read = () => {
|
|
26
|
+
const key = readFileSync(path);
|
|
27
|
+
if (key.length !== 32)
|
|
28
|
+
throw new Error("Invalid MCP skill origin key");
|
|
29
|
+
return key;
|
|
30
|
+
};
|
|
31
|
+
try {
|
|
32
|
+
return read();
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
if (err.code !== "ENOENT")
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
const temp = path + "." + randomBytes(16).toString("hex");
|
|
39
|
+
writeFileSync(temp, randomBytes(32), { mode: 0o600, flag: "wx" });
|
|
40
|
+
try {
|
|
41
|
+
linkSync(temp, path);
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
if (err.code !== "EEXIST")
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
unlinkSync(temp);
|
|
49
|
+
}
|
|
50
|
+
return read();
|
|
51
|
+
}
|
|
52
|
+
function capabilities(raw) {
|
|
53
|
+
const extensions = object(raw.extensions) ? raw.extensions : {};
|
|
54
|
+
const config = extensions[EXTENSION];
|
|
55
|
+
const resources = object(raw.resources);
|
|
56
|
+
const skills = resources && object(config);
|
|
57
|
+
return { resources, skills, directoryRead: skills && config.directoryRead === true,
|
|
58
|
+
tools: object(raw.tools), prompts: object(raw.prompts), tasks: object(extensions["io.modelcontextprotocol/tasks"]) || object(raw.tasks) };
|
|
59
|
+
}
|
|
60
|
+
function hasControl(text) {
|
|
61
|
+
for (const char of text) {
|
|
62
|
+
const code = char.charCodeAt(0);
|
|
63
|
+
if (code < 32 || code === 127)
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
function validUri(value) {
|
|
69
|
+
if (typeof value !== "string" || value.length > 4096 || !/^[a-z][a-z\d+.-]*:\/\//i.test(value))
|
|
70
|
+
return false;
|
|
71
|
+
try {
|
|
72
|
+
return !hasControl(value) && !/[?#\\\s]/.test(value) && value.slice(value.indexOf("://") + 3).split("/").every(part => {
|
|
73
|
+
const decoded = decodeURIComponent(part);
|
|
74
|
+
return decoded !== "." && decoded !== ".." && !hasControl(decoded) && !/[/\\]/.test(decoded);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function entryOf(value) {
|
|
82
|
+
if (!object(value) || !validUri(value.uri) || !object(value.frontmatter))
|
|
83
|
+
throw new Error("Invalid MCP skill entry");
|
|
84
|
+
const { uri, frontmatter } = value;
|
|
85
|
+
const { name, description } = frontmatter;
|
|
86
|
+
if (typeof name !== "string" || !isSkillName(name) || !uri.endsWith("/" + name + "/SKILL.md")
|
|
87
|
+
|| typeof description !== "string" || !description.trim() || description.length > DESCRIPTION_MAX)
|
|
88
|
+
throw new Error("Invalid MCP skill metadata");
|
|
89
|
+
const root = uri.slice(0, -"SKILL.md".length);
|
|
90
|
+
let files = null;
|
|
91
|
+
if (value.resources !== "dynamic") {
|
|
92
|
+
if (!Array.isArray(value.resources) || value.resources.length > MAX_FILES)
|
|
93
|
+
throw new Error("Invalid MCP skill manifest");
|
|
94
|
+
const seen = new Set();
|
|
95
|
+
files = value.resources.map((file) => {
|
|
96
|
+
if (!object(file) || !validUri(file.uri) || !file.uri.startsWith(root) || file.uri === root || seen.has(file.uri)
|
|
97
|
+
|| typeof file.digest !== "string" || !/^sha256:[a-f0-9]{64}$/.test(file.digest)
|
|
98
|
+
|| typeof file.size !== "number" || !Number.isSafeInteger(file.size) || file.size < 0)
|
|
99
|
+
throw new Error("Invalid MCP skill file");
|
|
100
|
+
seen.add(file.uri);
|
|
101
|
+
return { uri: file.uri, digest: file.digest, size: file.size };
|
|
102
|
+
});
|
|
103
|
+
if (!seen.has(uri))
|
|
104
|
+
throw new Error("MCP skill manifest is missing SKILL.md");
|
|
105
|
+
files.sort((a, b) => a.uri < b.uri ? -1 : a.uri > b.uri ? 1 : 0);
|
|
106
|
+
}
|
|
107
|
+
return { uri, name, description, frontmatter, files, root };
|
|
108
|
+
}
|
|
109
|
+
function summarize(entry, identity) {
|
|
110
|
+
const { uri, name, description, files } = entry;
|
|
111
|
+
const revision = files && createHash("sha256").update(canonicalJson([identity, uri, files])).digest("hex");
|
|
112
|
+
return { uri, name, description, revision, fileCount: files?.length ?? 0 };
|
|
113
|
+
}
|
|
114
|
+
async function connected(origin, server, as, run) {
|
|
115
|
+
const identity = createHmac("sha256", revisionKey(as.dataDir)).update(canonicalJson([origin, server])).digest("hex");
|
|
116
|
+
const connection = await openSkillConnection(server, AbortSignal.timeout(30_000), as);
|
|
117
|
+
try {
|
|
118
|
+
return await run(connection, identity);
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
await connection.close();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async function pages(c, method, field, params) {
|
|
125
|
+
const all = [];
|
|
126
|
+
const seen = new Set();
|
|
127
|
+
let cursor;
|
|
128
|
+
let bytes = 0;
|
|
129
|
+
for (let page = 0; page < MAX_PAGES; page++) {
|
|
130
|
+
const response = await c.request(method, cursor === undefined ? params : { ...params, cursor });
|
|
131
|
+
if (!object(response) || !Array.isArray(response[field]))
|
|
132
|
+
throw new Error("Invalid MCP listing");
|
|
133
|
+
if (all.length + response[field].length > MAX_ENTRIES)
|
|
134
|
+
throw new Error("MCP listing exceeds the item limit");
|
|
135
|
+
bytes += Buffer.byteLength(JSON.stringify(response[field]));
|
|
136
|
+
if (bytes > 8 * 1024 * 1024)
|
|
137
|
+
throw new Error("MCP listing exceeds the byte limit");
|
|
138
|
+
all.push(...response[field]);
|
|
139
|
+
const next = response.nextCursor;
|
|
140
|
+
if (next === undefined)
|
|
141
|
+
return all;
|
|
142
|
+
if (typeof next !== "string" || !next || next.length > 4096 || seen.has(next))
|
|
143
|
+
throw new Error("Invalid MCP pagination cursor");
|
|
144
|
+
cursor = next;
|
|
145
|
+
seen.add(next);
|
|
146
|
+
}
|
|
147
|
+
throw new Error("MCP listing exceeds the page limit");
|
|
148
|
+
}
|
|
149
|
+
export async function discoverMcpSkills(origin, server, as = {}) {
|
|
150
|
+
return connected(origin, server, as, async (client, identity) => {
|
|
151
|
+
const caps = capabilities(client.capabilities);
|
|
152
|
+
const skills = caps.skills ? (await pages(client, "skills/list", "skills", {})).map(value => summarize(entryOf(value), identity)) : [];
|
|
153
|
+
if (new Set(skills.map(skill => skill.uri)).size !== skills.length)
|
|
154
|
+
throw new Error("Duplicate MCP skill URI");
|
|
155
|
+
return { origin, capabilities: caps, skills };
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
export async function listMcpInventory(origin, server, kind, as = {}) {
|
|
159
|
+
return connected(origin, server, as, async (client) => {
|
|
160
|
+
if (!capabilities(client.capabilities)[kind])
|
|
161
|
+
throw new Error("Capability unavailable on this MCP server");
|
|
162
|
+
const listed = await pages(client, kind + "/list", kind, {});
|
|
163
|
+
const items = listed.map(value => {
|
|
164
|
+
if (!object(value) || typeof value.name !== "string" || !value.name || value.name.length > 1024)
|
|
165
|
+
throw new Error("Invalid MCP inventory entry");
|
|
166
|
+
if (kind === "resources" && (typeof value.uri !== "string" || !value.uri || value.uri.length > 4096))
|
|
167
|
+
throw new Error("Invalid MCP resource URI");
|
|
168
|
+
return {
|
|
169
|
+
name: value.name,
|
|
170
|
+
...(typeof value.description === "string" ? { description: value.description.slice(0, 4096) } : {}),
|
|
171
|
+
...(kind === "resources" && typeof value.uri === "string" ? { uri: value.uri } : {}),
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
return { origin, kind, items };
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
export class McpSkillChanged extends Error {
|
|
178
|
+
}
|
|
179
|
+
async function heldEntry(c, identity, uri, revision) {
|
|
180
|
+
if (!capabilities(c.capabilities).skills)
|
|
181
|
+
throw new Error("MCP server does not advertise Skills");
|
|
182
|
+
if (!validUri(uri) || !uri.endsWith("/SKILL.md") || !/^[a-f0-9]{64}$/.test(revision))
|
|
183
|
+
throw new Error("Invalid MCP skill selection");
|
|
184
|
+
const response = await c.request("skills/get", { uri });
|
|
185
|
+
const entry = entryOf(object(response) && response.skill);
|
|
186
|
+
if (entry.uri !== uri || !entry.files || summarize(entry, identity).revision !== revision)
|
|
187
|
+
throw new McpSkillChanged("MCP skill changed. Review its current manifest.");
|
|
188
|
+
return { ...entry, files: entry.files };
|
|
189
|
+
}
|
|
190
|
+
function discard(key) {
|
|
191
|
+
const file = cache.get(key);
|
|
192
|
+
if (file) {
|
|
193
|
+
cacheBytes -= file.bytes.length;
|
|
194
|
+
cache.delete(key);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async function readFile(c, file, key, limit) {
|
|
198
|
+
if (file.size > limit)
|
|
199
|
+
throw new Error("MCP skill resource exceeds the size limit");
|
|
200
|
+
const cached = cache.get(key);
|
|
201
|
+
if (cached && cached.until > Date.now())
|
|
202
|
+
return cached.bytes;
|
|
203
|
+
discard(key);
|
|
204
|
+
const response = await c.request("resources/read", { uri: file.uri });
|
|
205
|
+
if (!object(response) || !Array.isArray(response.contents) || response.contents.length !== 1)
|
|
206
|
+
throw new Error("Invalid MCP resource result");
|
|
207
|
+
const part = response.contents[0];
|
|
208
|
+
if (!object(part) || part.uri !== file.uri || (typeof part.text === "string") === (typeof part.blob === "string"))
|
|
209
|
+
throw new Error("Invalid MCP resource content");
|
|
210
|
+
const bytes = typeof part.text === "string" ? Buffer.from(part.text) : Buffer.from(part.blob, "base64");
|
|
211
|
+
if ((typeof part.blob === "string" && bytes.toString("base64") !== part.blob) || bytes.length !== file.size
|
|
212
|
+
|| "sha256:" + createHash("sha256").update(bytes).digest("hex") !== file.digest)
|
|
213
|
+
throw new McpSkillChanged("MCP skill resource failed its integrity check");
|
|
214
|
+
if (typeof response.ttlMs === "number" && response.ttlMs > 0 && Number.isFinite(response.ttlMs)) {
|
|
215
|
+
discard(key);
|
|
216
|
+
while (cacheBytes + bytes.length > MAX_CACHE_BYTES || cache.size >= 256)
|
|
217
|
+
discard(cache.keys().next().value);
|
|
218
|
+
cache.set(key, { bytes, until: Date.now() + Math.min(response.ttlMs, 300_000) });
|
|
219
|
+
cacheBytes += bytes.length;
|
|
220
|
+
}
|
|
221
|
+
return bytes;
|
|
222
|
+
}
|
|
223
|
+
export async function previewMcpSkill(origin, server, uri, revision, as = {}) {
|
|
224
|
+
return connected(origin, server, as, async (c, identity) => {
|
|
225
|
+
const entry = await heldEntry(c, identity, uri, revision);
|
|
226
|
+
const file = entry.files.find(resource => resource.uri === uri);
|
|
227
|
+
const key = JSON.stringify([as.id, identity, revision, uri]);
|
|
228
|
+
const bytes = await readFile(c, file, key, SKILL_FILE_MAX_BYTES);
|
|
229
|
+
const text = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
230
|
+
const yaml = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(text);
|
|
231
|
+
const doc = yaml && parseDocument(yaml[1], { schema: "core", uniqueKeys: true });
|
|
232
|
+
if (!doc || doc.errors.length || doc.warnings.length || !isDeepStrictEqual(doc.toJS({ maxAliasCount: 0 }), entry.frontmatter)) {
|
|
233
|
+
discard(key);
|
|
234
|
+
throw new McpSkillChanged("MCP skill frontmatter differs from its manifest");
|
|
235
|
+
}
|
|
236
|
+
return { origin, uri, revision, text, name: entry.name, description: entry.description,
|
|
237
|
+
...(typeof entry.frontmatter.license === "string" ? { license: entry.frontmatter.license } : {}) };
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
export async function readMcpSkillResource(origin, server, uri, revision, resource, as = {}) {
|
|
241
|
+
return connected(origin, server, as, async (c, identity) => {
|
|
242
|
+
const entry = await heldEntry(c, identity, uri, revision);
|
|
243
|
+
const file = entry.files.find(f => f.uri === resource);
|
|
244
|
+
if (!file || resource.endsWith("/SKILL.md"))
|
|
245
|
+
throw new Error("Select the skill itself or a listed supporting file");
|
|
246
|
+
const key = JSON.stringify([as.id, identity, revision, resource]);
|
|
247
|
+
const bytes = await readFile(c, file, key, MAX_RESOURCE_BYTES);
|
|
248
|
+
return { origin, uri: resource, revision, blob: bytes.toString("base64") };
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
export async function listMcpSkillDirectory(origin, server, uri, revision, directory, as = {}) {
|
|
252
|
+
return connected(origin, server, as, async (client, identity) => {
|
|
253
|
+
if (!capabilities(client.capabilities).directoryRead)
|
|
254
|
+
throw new Error("MCP server does not advertise directory reads");
|
|
255
|
+
const entry = await heldEntry(client, identity, uri, revision);
|
|
256
|
+
const prefix = directory + "/";
|
|
257
|
+
if (!validUri(directory) || !prefix.startsWith(entry.root) || !entry.files.some(file => file.uri.startsWith(prefix)))
|
|
258
|
+
throw new Error("Directory outside the held MCP skill");
|
|
259
|
+
const listed = await pages(client, "resources/directory/read", "resources", { uri: directory });
|
|
260
|
+
const children = new Set(entry.files.filter(f => f.uri.startsWith(prefix)).map(f => prefix + f.uri.slice(prefix.length).split("/")[0]));
|
|
261
|
+
return { origin, uri: directory, revision, resources: listed.flatMap(r => object(r) && typeof r.uri === "string" && children.has(r.uri) ? [{ uri: r.uri }] : []) };
|
|
262
|
+
});
|
|
263
|
+
}
|