limixbot 0.3.128 → 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-CHKvr2ME.js → ActivityPanel-CswemPGx.js} +1 -1
- package/dist/assets/{App-Qdd4Etr0.js → App-CeGk9O7P.js} +135 -134
- package/dist/assets/{AppEventEditor-Csl8OvHJ.js → AppEventEditor-lydjfKAA.js} +1 -1
- package/dist/assets/{BotSettingsDialog-Dn7V8EPs.js → BotSettingsDialog-BGO7s2Sa.js} +4 -4
- package/dist/assets/{BrowserPanel-DYrgjhY2.js → BrowserPanel-WFfhXRW4.js} +1 -1
- package/dist/assets/{BrowserProfilesManager-DwXg-QiX.js → BrowserProfilesManager-DAI3EyaZ.js} +1 -1
- package/dist/assets/{CloudAddDialog-BQjw6clv.js → CloudAddDialog-Lo18f6GE.js} +1 -1
- package/dist/assets/{ComputerFilesPane-BIzdtDkx.js → ComputerFilesPane-LtL8VMhS.js} +1 -1
- package/dist/assets/{ComputerPanel-CKZMmU5N.js → ComputerPanel-mEdoL4Dh.js} +2 -2
- package/dist/assets/{DataPanel-CJCYQhq6.js → DataPanel-HeNk8eOt.js} +1 -1
- package/dist/assets/{DesktopViewer-B9mw98xI.js → DesktopViewer-DCC-jq_j.js} +1 -1
- package/dist/assets/{GrokMoveDialog-CxxR6jXV.js → GrokMoveDialog-I9x5B1Kv.js} +1 -1
- package/dist/assets/{InspectorPanel-k_9WS8hD.js → InspectorPanel-C-ocpaf1.js} +1 -1
- package/dist/assets/{KeyboardShortcutsModal-9xKBwfgq.js → KeyboardShortcutsModal-D73O8To_.js} +1 -1
- package/dist/assets/{LimixResizeHandles-D4x0jvkS.js → LimixResizeHandles-kOyb_U62.js} +1 -1
- package/dist/assets/{LiveDesktop-p14AEwq0.js → LiveDesktop-DYg8H5rp.js} +1 -1
- package/dist/assets/{LocalVmWorkspace-CB6dGKzv.js → LocalVmWorkspace-BsGviUnb.js} +1 -1
- package/dist/assets/{MacLocalControl-BxHl2r5v.js → MacLocalControl-Db0f-6Gc.js} +1 -1
- package/dist/assets/{MarkdownFilePreview-CxQMvU7b.js → MarkdownFilePreview-Dj8Z6Mm0.js} +1 -1
- package/dist/assets/{MenuMotion-DG5tk0i3.js → MenuMotion-CgVWckHz.js} +1 -1
- package/dist/assets/{NewBotDialog-CUUNMAJe.js → NewBotDialog-Bp8-zb5M.js} +1 -1
- package/dist/assets/{PhoneAppDialog-DD2dlPAo.js → PhoneAppDialog-BWtFp9EN.js} +1 -1
- package/dist/assets/{PlacesRail-CAV7kW3Y.js → PlacesRail-CKR79j8d.js} +1 -1
- package/dist/assets/{PluginsPanel-8exPvXZV.js → PluginsPanel-BZe968J8.js} +2 -2
- package/dist/assets/{ProIntroduction-BkNqiByI.js → ProIntroduction-CZGUC6Ms.js} +1 -1
- package/dist/assets/{RemoteAgentSettingsPanel-CgZvA4c3.js → RemoteAgentSettingsPanel-CCOe2O1O.js} +1 -1
- package/dist/assets/{RoomPanel-DU0mkU7E.js → RoomPanel-jgyrxLn2.js} +1 -1
- package/dist/assets/{RoutinesPage-D13_xSg1.js → RoutinesPage-D5Z3pmtB.js} +2 -2
- package/dist/assets/{SettingsModal-CcZSHI1Q.js → SettingsModal-CeKynb83.js} +2 -2
- package/dist/assets/{ShareTeamDialog-B6YC_fNs.js → ShareTeamDialog-D7qwIwXJ.js} +1 -1
- package/dist/assets/{SignedInSites-DhGidV0n.js → SignedInSites-Dh9imU42.js} +1 -1
- package/dist/assets/{TeamLibraryPanel-BbEiwnZ3.js → TeamLibraryPanel-nz4rcGmz.js} +1 -1
- package/dist/assets/{TeamMapPage-KMzRj_VW.js → TeamMapPage-CLdRh0ZK.js} +1 -1
- package/dist/assets/{TriggersPage-HTxYYCjT.js → TriggersPage-BByyX4CZ.js} +1 -1
- package/dist/assets/VisibilitySection-BNhdo2-L.js +22 -0
- package/dist/assets/{WebhookTrigger-oZ3yokI_.js → WebhookTrigger-DxDhbnYz.js} +1 -1
- package/dist/assets/{WorksOnGrid-CTR6tAQZ.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-CC13tV5g.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-N3p-c6pH.js → import-name-gQROrWbj.js} +1 -1
- package/dist/assets/{index-DGGq7mDN.js → index-CkdvX5_R.js} +1 -1
- package/dist/assets/{index-98brgMNT.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-DhIjBWvQ.js → new-bot-CAtQzQF1.js} +1 -1
- package/dist/assets/{org-library-CmwcxARS.js → org-library-PVNP5n7J.js} +1 -1
- package/dist/assets/{package-format-BWl-RWvM.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-CVj-6tJX.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 +5689 -5583
- 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/app-settings/registry-bots.js +3 -3
- package/dist-server/server/app-settings/registry-window.js +2 -2
- package/dist-server/server/auto-approve.js +2 -0
- package/dist-server/server/bot-box/env.js +2 -2
- package/dist-server/server/bot-channels/engine.js +2 -1
- package/dist-server/server/bot-channels/messenger.js +6 -6
- 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/host/trust-answers.js +34 -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 +120 -5
- 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/outbound-hold.js +13 -2
- package/dist-server/server/outbound-requests.js +71 -0
- package/dist-server/server/plugin-hub.js +259 -25
- package/dist-server/server/plugin-passages.js +16 -0
- package/dist-server/server/routes/app-settings.js +2 -2
- package/dist-server/server/routes/bot-messages.js +2 -2
- package/dist-server/server/routes/plugin-mcp.js +118 -0
- package/dist-server/server/routes/plugin-studio.js +50 -0
- package/dist-server/server/runtime/tree.js +1 -1
- 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-CZiqicF5.js +0 -22
- package/dist/assets/channel-BloV1v8U.js +0 -1
- package/dist/assets/mcp-servers-z68ouwLN.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
|
@@ -6,13 +6,14 @@ import { APP_EXTENSION_KEY } from "../shared/app.js";
|
|
|
6
6
|
import { botBox } from "./bot-box/box.js";
|
|
7
7
|
import { createLineSplitter } from "./mcp-bridge.js";
|
|
8
8
|
import { UI_EXTENSION, withUiExtension } from "./mcp-app-observer.js";
|
|
9
|
-
import { MAX_REMOTE_MCP_BYTES, McpHttpError, McpRpcError, REMOTE_MCP_STARTUP_MS, RemoteMcpClient } from "./mcp-http.js";
|
|
9
|
+
import { MAX_REMOTE_MCP_BYTES, McpHttpError, McpRpcError, REMOTE_MCP_STARTUP_MS, modernProtocolError, RemoteMcpClient } from "./mcp-http.js";
|
|
10
10
|
import { probeEnvironment } from "./mcp-probe.js";
|
|
11
11
|
import { killCliTree, spawnCli } from "./procs.js";
|
|
12
12
|
export const APP_CONNECTION_IDLE_MS = 5 * 60_000;
|
|
13
13
|
export const APP_CONNECTIONS_MAX = 6;
|
|
14
14
|
export const APP_TOOLS_CACHE_MS = 60_000;
|
|
15
15
|
const TOOL_PAGES = 100;
|
|
16
|
+
const SKILLS_MESSAGE_BYTES = 4 * 1024 * 1024;
|
|
16
17
|
function isRecord(value) {
|
|
17
18
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
18
19
|
}
|
|
@@ -24,7 +25,8 @@ class StdioAppClient {
|
|
|
24
25
|
closed = false;
|
|
25
26
|
extensions;
|
|
26
27
|
serverInfo;
|
|
27
|
-
|
|
28
|
+
capabilities;
|
|
29
|
+
constructor(server, hooks, as = {}, maxBytes = MAX_REMOTE_MCP_BYTES) {
|
|
28
30
|
// With the box off `box` changes nothing, and the server starts where it always did.
|
|
29
31
|
this.child = spawnCli(server.command, server.args, {
|
|
30
32
|
...(botBox.enabled() ? (as.cwd ? { cwd: as.cwd } : {}) : { cwd: process.cwd() }),
|
|
@@ -35,7 +37,7 @@ class StdioAppClient {
|
|
|
35
37
|
this.child.stdout.on("data", (chunk) => {
|
|
36
38
|
// A connection lives for minutes; the bound is per message, not total.
|
|
37
39
|
this.stdoutBytes += chunk.byteLength;
|
|
38
|
-
if (this.stdoutBytes >
|
|
40
|
+
if (this.stdoutBytes > maxBytes) {
|
|
39
41
|
this.fail(new McpHttpError("protocol", "message too large"));
|
|
40
42
|
return;
|
|
41
43
|
}
|
|
@@ -140,6 +142,8 @@ class StdioAppClient {
|
|
|
140
142
|
else {
|
|
141
143
|
result = await this.request("initialize", params, signal);
|
|
142
144
|
}
|
|
145
|
+
if (isRecord(result) && isRecord(result.capabilities))
|
|
146
|
+
this.capabilities = result.capabilities;
|
|
143
147
|
this.serverInfo = isRecord(result) && isRecord(result.serverInfo) ? result.serverInfo : undefined;
|
|
144
148
|
this.write({ jsonrpc: "2.0", method: "notifications/initialized" });
|
|
145
149
|
}
|
|
@@ -150,10 +154,11 @@ class StdioAppClient {
|
|
|
150
154
|
class RemoteAppClient {
|
|
151
155
|
client;
|
|
152
156
|
serverInfo;
|
|
157
|
+
capabilities;
|
|
153
158
|
closed = false;
|
|
154
|
-
constructor(server, hooks) {
|
|
159
|
+
constructor(server, hooks, discover = false) {
|
|
155
160
|
this.client = new RemoteMcpClient(server, {
|
|
156
|
-
maxBytes: MAX_REMOTE_MCP_BYTES,
|
|
161
|
+
maxBytes: discover ? SKILLS_MESSAGE_BYTES : MAX_REMOTE_MCP_BYTES, discover,
|
|
157
162
|
onNotification: (message) => { if (typeof message.method === "string")
|
|
158
163
|
hooks.onNotification(message.method); },
|
|
159
164
|
});
|
|
@@ -161,6 +166,8 @@ class RemoteAppClient {
|
|
|
161
166
|
get extensions() { return this.client.extensions; }
|
|
162
167
|
async initialize(signal, extension) {
|
|
163
168
|
const result = await this.client.initialize("Limix Bot", signal, extension ? { extensions: { [APP_EXTENSION_KEY]: UI_EXTENSION } } : {});
|
|
169
|
+
if (isRecord(result) && isRecord(result.capabilities))
|
|
170
|
+
this.capabilities = result.capabilities;
|
|
164
171
|
this.serverInfo = isRecord(result) && isRecord(result.serverInfo) ? result.serverInfo : undefined;
|
|
165
172
|
}
|
|
166
173
|
request(method, params, signal) {
|
|
@@ -182,6 +189,52 @@ export async function openAppClient(server, hooks, extension, signal, as = {}) {
|
|
|
182
189
|
throw error;
|
|
183
190
|
}
|
|
184
191
|
}
|
|
192
|
+
export async function openSkillConnection(server, signal, as = {}) {
|
|
193
|
+
const hooks = { onNotification() { } };
|
|
194
|
+
const client = "url" in server ? new RemoteAppClient(server, hooks, true) : new StdioAppClient(server, hooks, as, SKILLS_MESSAGE_BYTES);
|
|
195
|
+
const modern = async (method, params, requestSignal = signal) => {
|
|
196
|
+
const result = await client.request(method, {
|
|
197
|
+
...params, _meta: {
|
|
198
|
+
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
|
|
199
|
+
"io.modelcontextprotocol/clientInfo": { name: "Limix Bot", version: "1" },
|
|
200
|
+
"io.modelcontextprotocol/clientCapabilities": {},
|
|
201
|
+
},
|
|
202
|
+
}, requestSignal);
|
|
203
|
+
if (!isRecord(result) || result.resultType !== "complete")
|
|
204
|
+
throw new Error("MCP request did not return a complete result");
|
|
205
|
+
return result;
|
|
206
|
+
};
|
|
207
|
+
try {
|
|
208
|
+
if (!("type" in server && server.type === "sse")) {
|
|
209
|
+
const discoveryTimeout = "url" in server ? signal : AbortSignal.any([signal, AbortSignal.timeout(3500)]);
|
|
210
|
+
try {
|
|
211
|
+
const discovery = await modern("server/discover", {}, discoveryTimeout);
|
|
212
|
+
if (!Array.isArray(discovery.supportedVersions) || !discovery.supportedVersions.includes("2026-07-28") || !isRecord(discovery.capabilities)) {
|
|
213
|
+
throw new Error("Invalid MCP discovery result");
|
|
214
|
+
}
|
|
215
|
+
return { capabilities: discovery.capabilities, request: modern, close: () => client.close() };
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
if (signal.aborted || (error instanceof McpRpcError && modernProtocolError(error.code)))
|
|
219
|
+
throw error;
|
|
220
|
+
const legacyRequest = error instanceof McpRpcError || discoveryTimeout.aborted;
|
|
221
|
+
const legacyStatus = error instanceof McpHttpError && error.status === 400;
|
|
222
|
+
if (!legacyRequest && !legacyStatus)
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
await client.initialize(signal, false);
|
|
227
|
+
return {
|
|
228
|
+
capabilities: { ...client.capabilities, extensions: undefined },
|
|
229
|
+
request: (method, params) => client.request(method, params, signal),
|
|
230
|
+
close: () => client.close(),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
await client.close();
|
|
235
|
+
throw error;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
185
238
|
function connectionLost(error) {
|
|
186
239
|
return !(error instanceof McpRpcError);
|
|
187
240
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
const record = (value) => Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
3
|
+
const revision = "2026-07-28";
|
|
4
|
+
const extension = "io.modelcontextprotocol/tasks";
|
|
5
|
+
const MAX_HANDLES = 256;
|
|
6
|
+
const statuses = new Set(["working", "input_required", "completed", "failed", "cancelled"]);
|
|
7
|
+
export function taskRevision(params) {
|
|
8
|
+
return record(params?._meta) && params._meta["io.modelcontextprotocol/protocolVersion"] === revision;
|
|
9
|
+
}
|
|
10
|
+
function supportsTasks(caps) {
|
|
11
|
+
return record(caps) && record(caps.extensions) && record(caps.extensions[extension]);
|
|
12
|
+
}
|
|
13
|
+
export function clientRequestsTasks(params) {
|
|
14
|
+
return taskRevision(params) && record(params?._meta) && supportsTasks(params._meta["io.modelcontextprotocol/clientCapabilities"]);
|
|
15
|
+
}
|
|
16
|
+
function timing(result) {
|
|
17
|
+
const { ttlMs, pollIntervalMs = 0, createdAt, lastUpdatedAt, status } = result;
|
|
18
|
+
if (typeof status !== "string" || !statuses.has(status) ||
|
|
19
|
+
typeof createdAt !== "string" || !Number.isFinite(Date.parse(createdAt)) ||
|
|
20
|
+
typeof lastUpdatedAt !== "string" || !Number.isFinite(Date.parse(lastUpdatedAt)) ||
|
|
21
|
+
(ttlMs !== null && !(typeof ttlMs === "number" && Number.isSafeInteger(ttlMs) && ttlMs >= 0)) ||
|
|
22
|
+
typeof pollIntervalMs !== "number" || !Number.isSafeInteger(pollIntervalMs) || pollIntervalMs < 0)
|
|
23
|
+
return null;
|
|
24
|
+
return { expires: ttlMs === null ? Infinity : Date.parse(createdAt) + ttlMs, interval: pollIntervalMs };
|
|
25
|
+
}
|
|
26
|
+
export function createGateTasks() {
|
|
27
|
+
const held = new Map();
|
|
28
|
+
let supported = false;
|
|
29
|
+
const sweep = (now) => {
|
|
30
|
+
for (const [key, task] of held)
|
|
31
|
+
if (task.expires <= now)
|
|
32
|
+
held.delete(key);
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
discover(result) {
|
|
36
|
+
supported = record(result) && result.resultType === "complete" && Array.isArray(result.supportedVersions)
|
|
37
|
+
&& result.supportedVersions.includes(revision) && supportsTasks(result.capabilities);
|
|
38
|
+
if (!supported)
|
|
39
|
+
held.clear();
|
|
40
|
+
},
|
|
41
|
+
canRequest(params) {
|
|
42
|
+
return supported && clientRequestsTasks(params);
|
|
43
|
+
},
|
|
44
|
+
issue(result, tool) {
|
|
45
|
+
const now = Date.now();
|
|
46
|
+
sweep(now);
|
|
47
|
+
const schedule = timing(result);
|
|
48
|
+
const upstreamId = result.taskId;
|
|
49
|
+
if (!supported || held.size >= MAX_HANDLES || !schedule || typeof upstreamId !== "string" || !upstreamId || upstreamId.length > 2048)
|
|
50
|
+
return null;
|
|
51
|
+
const handle = randomUUID();
|
|
52
|
+
held.set(handle, { upstreamId, tool, ...schedule, nextPoll: now + schedule.interval });
|
|
53
|
+
return handle;
|
|
54
|
+
},
|
|
55
|
+
resolve(handle, poll) {
|
|
56
|
+
const now = Date.now();
|
|
57
|
+
sweep(now);
|
|
58
|
+
if (!supported || typeof handle !== "string")
|
|
59
|
+
return null;
|
|
60
|
+
const task = held.get(handle);
|
|
61
|
+
if (!task || (poll && now < task.nextPoll))
|
|
62
|
+
return null;
|
|
63
|
+
if (poll)
|
|
64
|
+
task.nextPoll = now + task.interval;
|
|
65
|
+
return task;
|
|
66
|
+
},
|
|
67
|
+
polled(task, result) {
|
|
68
|
+
const schedule = timing(result);
|
|
69
|
+
if (!schedule || result.resultType !== "complete" || result.taskId !== task.upstreamId)
|
|
70
|
+
return false;
|
|
71
|
+
Object.assign(task, schedule, { nextPoll: Date.now() + schedule.interval });
|
|
72
|
+
return true;
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -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
|
+
}
|