@geohar/pi-mcp-combiner 0.16.0-dev.3 → 0.16.0-dev.4
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/README.md +7 -0
- package/dist/client/types.d.ts +6 -1
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/types.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -52
- package/dist/index.js.map +1 -1
- package/dist/native/combiner-connection.d.ts +31 -9
- package/dist/native/combiner-connection.d.ts.map +1 -1
- package/dist/native/combiner-connection.js +131 -80
- package/dist/native/combiner-connection.js.map +1 -1
- package/dist/native/index.d.ts +8 -4
- package/dist/native/index.d.ts.map +1 -1
- package/dist/native/index.js +24 -18
- package/dist/native/index.js.map +1 -1
- package/dist/native/resources.d.ts +7 -2
- package/dist/native/resources.d.ts.map +1 -1
- package/dist/native/resources.js +21 -3
- package/dist/native/resources.js.map +1 -1
- package/dist/native/tool-surface.d.ts +24 -11
- package/dist/native/tool-surface.d.ts.map +1 -1
- package/dist/native/tool-surface.js +71 -34
- package/dist/native/tool-surface.js.map +1 -1
- package/dist/pi.d.ts +9 -1
- package/dist/pi.d.ts.map +1 -1
- package/package.json +6 -2
- package/src/client/types.ts +4 -1
- package/src/index.ts +31 -51
- package/src/native/combiner-connection.ts +155 -83
- package/src/native/index.ts +34 -24
- package/src/native/resources.ts +34 -5
- package/src/native/tool-surface.ts +103 -46
- package/src/pi.ts +5 -1
|
@@ -5,22 +5,35 @@ export type NativeToolSurfaceOptions = {
|
|
|
5
5
|
/** The resolved combiner connection (owns elicitation, filters, caches). */
|
|
6
6
|
connection: NativeCombinerConnection;
|
|
7
7
|
/** The per-project server filter (same object index.ts passes to applyFilter);
|
|
8
|
-
* applied defensively here too so a filter race never widens surface exposure.
|
|
9
|
-
|
|
8
|
+
* applied defensively here too so a filter race never widens surface exposure.
|
|
9
|
+
* A GETTER resolves per call — worktrees/project switches re-resolve session
|
|
10
|
+
* config, and a load-time snapshot would apply the wrong allow/deny set. */
|
|
11
|
+
serverFilter?: ServerFilter | (() => ServerFilter | undefined);
|
|
10
12
|
/** The combiner block's directTools spec, as resolved from the ladder: a glob
|
|
11
|
-
* allowlist → "direct" exposure for matches; "search" → everything codemode.
|
|
12
|
-
|
|
13
|
+
* allowlist → "direct" exposure for matches; "search" → everything codemode.
|
|
14
|
+
* A getter resolves per call (same reason as serverFilter). */
|
|
15
|
+
directSpec?: string[] | "search" | (() => string[] | "search" | undefined);
|
|
16
|
+
/** Cross-pass registration state (see activateNativeTools). A fresh object on
|
|
17
|
+
* first call; the SAME object on every pass so the diffing + hidden-removal
|
|
18
|
+
* work. native/index.ts owns one per activation. */
|
|
19
|
+
state?: NativeToolSurfaceState;
|
|
13
20
|
/** Warn when the direct-exposure set grows large (every declared schema rides in
|
|
14
21
|
* every request). Settings kill-switch: warnLargeDirectExposure (default true). */
|
|
15
22
|
warnLargeDirectExposure?: boolean;
|
|
16
|
-
/** Namespace shown in codemode's grouped listing (pi normalizes -/_ alike). */
|
|
17
|
-
namespaceName?: string;
|
|
18
|
-
/** Names that must never be shadowed by a combiner tool (pi builtins + ours). */
|
|
19
|
-
reserved?: readonly string[];
|
|
20
23
|
log: (level: "info" | "warn" | "error", message: string) => void;
|
|
21
24
|
};
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
+
/** Registration memory across passes: currently-declared names + each tool's schema
|
|
26
|
+
* signature, so a changed schema re-registers and an unchanged one doesn't (pi's
|
|
27
|
+
* re-register = replace-with-warning; skipping unchanged declarations avoids the
|
|
28
|
+
* warning churn and keeps pi's tool identity stable). */
|
|
29
|
+
export type NativeToolSurfaceState = {
|
|
30
|
+
names: Set<string>;
|
|
31
|
+
signatures: Map<string, string | null>;
|
|
32
|
+
};
|
|
33
|
+
/** Register the combiner's tools natively, DIFFING against `state` (which the caller
|
|
34
|
+
* reuses across passes): unchanged declarations are skipped (pi.registerTool
|
|
35
|
+
* replaces-by-name with a warning — churn on every list_changed would spam), changed
|
|
36
|
+
* schemas re-register, and removed tools are re-registered hidden. Returns the names
|
|
37
|
+
* currently active (for status/panel surfaces). */
|
|
25
38
|
export declare function activateNativeTools(pi: ExtensionAPI, opts: NativeToolSurfaceOptions): Promise<string[]>;
|
|
26
39
|
//# sourceMappingURL=tool-surface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-surface.d.ts","sourceRoot":"","sources":["../../src/native/tool-surface.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tool-surface.d.ts","sourceRoot":"","sources":["../../src/native/tool-surface.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,YAAY,EAAkC,MAAM,UAAU,CAAA;AAC5E,OAAO,KAAK,EAAE,wBAAwB,EAAe,MAAM,0BAA0B,CAAA;AAIrF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D,MAAM,MAAM,wBAAwB,GAAG;IACnC,4EAA4E;IAC5E,UAAU,EAAE,wBAAwB,CAAA;IACpC;;;iFAG6E;IAC7E,YAAY,CAAC,EAAE,YAAY,GAAG,CAAC,MAAM,YAAY,GAAG,SAAS,CAAC,CAAA;IAC9D;;oEAEgE;IAChE,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,QAAQ,GAAG,CAAC,MAAM,MAAM,EAAE,GAAG,QAAQ,GAAG,SAAS,CAAC,CAAA;IAC1E;;yDAEqD;IACrD,KAAK,CAAC,EAAE,sBAAsB,CAAA;IAC9B;wFACoF;IACpF,uBAAuB,CAAC,EAAE,OAAO,CAAA;IACjC,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CACnE,CAAA;AAED;;;0DAG0D;AAC1D,MAAM,MAAM,sBAAsB,GAAG;IACjC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAClB,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;CACzC,CAAA;AA4ED;;;;oDAIoD;AACpD,wBAAsB,mBAAmB,CAAC,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,wBAAwB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAwD7G"}
|
|
@@ -21,28 +21,25 @@
|
|
|
21
21
|
// replaces it). Per-project allow/deny keeps flowing combiner-side via applyFilter.
|
|
22
22
|
//
|
|
23
23
|
// Wire shape: register once at session_start (tools list is stable modulo
|
|
24
|
-
// list_changed, which re-registers
|
|
25
|
-
//
|
|
24
|
+
// list_changed, which re-registers through this module again). Each pass diffs
|
|
25
|
+
// against the previous registration (schema signatures) so only CHANGED tools hit
|
|
26
|
+
// pi.registerTool (pi's replace-by-name path logs a warning per re-registration —
|
|
27
|
+
// a full re-register on every list_changed would churn hundreds of warnings);
|
|
28
|
+
// tools the server REMOVED are re-registered `hidden` so they stop being
|
|
29
|
+
// callable/declared rather than lingering as broken names.
|
|
26
30
|
import { applyServerFilter, matchesGlob, RESERVED_TOOL_NAMES } from "../client/tool-matching.js";
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
import { renderSchemaSignature } from "../client/schema-signature.js";
|
|
32
|
+
import { toLlmContent } from "@earendil-works/pi-mcp";
|
|
33
|
+
const COMBINER_NAMESPACE = { name: "mcp_combiner", description: "mcp-combiner aggregated tools" };
|
|
34
|
+
function resolveFilter(f) {
|
|
35
|
+
return typeof f === "function" ? f() : f;
|
|
29
36
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* full result rides `details` for renderers (same shape the SDK client half uses). */
|
|
33
|
-
function textBlockOf(b) {
|
|
34
|
-
const block = isRecord(b) ? b : undefined;
|
|
35
|
-
if (block && block.type === "text") {
|
|
36
|
-
return { type: "text", text: String(block.text) };
|
|
37
|
-
}
|
|
38
|
-
const kind = block?.type ?? (block ? "content" : b);
|
|
39
|
-
return { type: "text", text: `[${String(kind)} block]` };
|
|
37
|
+
function resolveDirectSpec(d) {
|
|
38
|
+
return typeof d === "function" ? d() : d;
|
|
40
39
|
}
|
|
41
40
|
function toToolResult(call) {
|
|
42
|
-
|
|
43
|
-
return { content: blocks.map((b) => textBlockOf(b)) };
|
|
41
|
+
return { content: toLlmContent(call) };
|
|
44
42
|
}
|
|
45
|
-
/** Register the combiner's tools natively. */
|
|
46
43
|
const DIRECT_EXPOSURE_WARN_THRESHOLD = 50;
|
|
47
44
|
/** Turn one combiner ToolSummary into pi's ToolDefinition, plus the native-only fields
|
|
48
45
|
* pi 1.0 accepts on registerTool (exposure/namespace/annotations). */
|
|
@@ -58,14 +55,14 @@ function toNativeTool(sum, conn, exposure) {
|
|
|
58
55
|
// pi-permission-system's classification. Kept optional on ToolDefinition so the
|
|
59
56
|
// extension stays load-compatible with pi 0.99.x where these fields are ignored.
|
|
60
57
|
exposure,
|
|
61
|
-
namespace:
|
|
58
|
+
namespace: COMBINER_NAMESPACE,
|
|
62
59
|
annotations: sum.annotations,
|
|
63
60
|
execute: async (_toolCallId, params, signal) => {
|
|
64
|
-
// The abort signal rides into the transport
|
|
65
|
-
// upstream work, and widget holds respect it
|
|
66
|
-
|
|
61
|
+
// The abort signal rides into the transport (callTool's options.signal):
|
|
62
|
+
// cancellation cancels upstream work, and widget holds respect it
|
|
63
|
+
// (notifications/cancelled).
|
|
67
64
|
try {
|
|
68
|
-
const result = await conn.callTool(name, params);
|
|
65
|
+
const result = await conn.callTool(name, params, { signal });
|
|
69
66
|
return { ...toToolResult(result), details: result };
|
|
70
67
|
}
|
|
71
68
|
catch (e) {
|
|
@@ -76,16 +73,35 @@ function toNativeTool(sum, conn, exposure) {
|
|
|
76
73
|
},
|
|
77
74
|
};
|
|
78
75
|
}
|
|
79
|
-
/**
|
|
80
|
-
*
|
|
81
|
-
* a
|
|
76
|
+
/** Registration for a tool the combiner no longer offers: same name (replaces the old
|
|
77
|
+
* declaration), exposure `hidden` (not declared to the model/codemode; calling it
|
|
78
|
+
* surfaces a clear error instead of a stale upstream call). */
|
|
79
|
+
function removedToolDefinition(name) {
|
|
80
|
+
return {
|
|
81
|
+
name,
|
|
82
|
+
label: name,
|
|
83
|
+
description: "(unavailable: the combiner no longer offers this tool)",
|
|
84
|
+
parameters: { type: "object", properties: {} },
|
|
85
|
+
exposure: "hidden",
|
|
86
|
+
namespace: COMBINER_NAMESPACE,
|
|
87
|
+
execute: async () => {
|
|
88
|
+
throw new Error(`"${name}" is no longer offered by the combiner; use tool_search or the mcp discovery tool to find its replacement`);
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** Register the combiner's tools natively, DIFFING against `state` (which the caller
|
|
93
|
+
* reuses across passes): unchanged declarations are skipped (pi.registerTool
|
|
94
|
+
* replaces-by-name with a warning — churn on every list_changed would spam), changed
|
|
95
|
+
* schemas re-register, and removed tools are re-registered hidden. Returns the names
|
|
96
|
+
* currently active (for status/panel surfaces). */
|
|
82
97
|
export async function activateNativeTools(pi, opts) {
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const
|
|
98
|
+
const state = opts.state ?? { names: new Set(), signatures: new Map() };
|
|
99
|
+
const tools = applyServerFilter(await opts.connection.listTools(true), resolveFilter(opts.serverFilter));
|
|
100
|
+
const allowlist = Array.isArray(resolveDirectSpec(opts.directSpec)) ? resolveDirectSpec(opts.directSpec) : [];
|
|
101
|
+
const reserved = new Set(RESERVED_TOOL_NAMES);
|
|
102
|
+
const currentNames = new Set(tools.map((t) => t.name));
|
|
88
103
|
const directNames = [];
|
|
104
|
+
let fresh = 0;
|
|
89
105
|
for (const sum of tools) {
|
|
90
106
|
if (reserved.has(sum.name)) {
|
|
91
107
|
opts.log("warn", `skipping combiner tool "${sum.name}" — collides with a reserved name`);
|
|
@@ -96,10 +112,29 @@ export async function activateNativeTools(pi, opts) {
|
|
|
96
112
|
// near-zero declaration cost. "search" degrades to the same codemode mapping
|
|
97
113
|
// (pi's tool_search replaces the adapter's search-promote semantics).
|
|
98
114
|
const exposure = allowlist.some((p) => matchesGlob(sum.name, p)) ? "direct" : "codemode";
|
|
115
|
+
// Diff: skip the re-register when the schema signature is unchanged (pi keeps
|
|
116
|
+
// the existing declaration; re-registering would log its warning for nothing).
|
|
117
|
+
const sig = renderSchemaSignature(sum.inputSchema);
|
|
118
|
+
if (state.names.has(sum.name) && state.signatures.get(sum.name) === sig) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
pi.registerTool(toNativeTool(sum, opts.connection, exposure));
|
|
122
|
+
state.signatures.set(sum.name, sig);
|
|
123
|
+
state.names.add(sum.name);
|
|
124
|
+
fresh++;
|
|
99
125
|
if (exposure === "direct")
|
|
100
126
|
directNames.push(sum.name);
|
|
101
|
-
|
|
102
|
-
|
|
127
|
+
}
|
|
128
|
+
// Removals: hide them (never unregister silently — pi has no unregister; a hidden
|
|
129
|
+
// re-register at the same name retires the declaration).
|
|
130
|
+
let removed = 0;
|
|
131
|
+
for (const goneName of [...state.names]) {
|
|
132
|
+
if (currentNames.has(goneName))
|
|
133
|
+
continue;
|
|
134
|
+
pi.registerTool(removedToolDefinition(goneName));
|
|
135
|
+
state.names.delete(goneName);
|
|
136
|
+
state.signatures.delete(goneName);
|
|
137
|
+
removed++;
|
|
103
138
|
}
|
|
104
139
|
if (directNames.length > DIRECT_EXPOSURE_WARN_THRESHOLD &&
|
|
105
140
|
opts.warnLargeDirectExposure !== false) {
|
|
@@ -107,7 +142,9 @@ export async function activateNativeTools(pi, opts) {
|
|
|
107
142
|
`request. Consider trimming the allowlist (directTools) or disabling this warning ` +
|
|
108
143
|
`with "warnLargeDirectExposure": false in extensions/mcp-combiner.json.`);
|
|
109
144
|
}
|
|
110
|
-
|
|
111
|
-
|
|
145
|
+
if (fresh || removed) {
|
|
146
|
+
opts.log("info", `native tool surface: ${fresh} registered, ${removed} hidden (removed), ${state.names.size} active`);
|
|
147
|
+
}
|
|
148
|
+
return [...state.names];
|
|
112
149
|
}
|
|
113
150
|
//# sourceMappingURL=tool-surface.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-surface.js","sourceRoot":"","sources":["../../src/native/tool-surface.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,mFAAmF;AACnF,uFAAuF;AACvF,EAAE;AACF,uDAAuD;AACvD,EAAE;AACF,iFAAiF;AACjF,wCAAwC;AACxC,qFAAqF;AACrF,oFAAoF;AACpF,kFAAkF;AAClF,8DAA8D;AAC9D,mFAAmF;AACnF,iFAAiF;AACjF,mFAAmF;AACnF,6DAA6D;AAC7D,EAAE;AACF,qFAAqF;AACrF,qFAAqF;AACrF,sFAAsF;AACtF,oFAAoF;AACpF,EAAE;AACF,0EAA0E;AAC1E,
|
|
1
|
+
{"version":3,"file":"tool-surface.js","sourceRoot":"","sources":["../../src/native/tool-surface.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,mFAAmF;AACnF,uFAAuF;AACvF,EAAE;AACF,uDAAuD;AACvD,EAAE;AACF,iFAAiF;AACjF,wCAAwC;AACxC,qFAAqF;AACrF,oFAAoF;AACpF,kFAAkF;AAClF,8DAA8D;AAC9D,mFAAmF;AACnF,iFAAiF;AACjF,mFAAmF;AACnF,6DAA6D;AAC7D,EAAE;AACF,qFAAqF;AACrF,qFAAqF;AACrF,sFAAsF;AACtF,oFAAoF;AACpF,EAAE;AACF,0EAA0E;AAC1E,+EAA+E;AAC/E,kFAAkF;AAClF,kFAAkF;AAClF,8EAA8E;AAC9E,yEAAyE;AACzE,2DAA2D;AAI3D,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAChG,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AACrE,OAAO,EAAE,YAAY,EAAuB,MAAM,wBAAwB,CAAA;AAkC1E,MAAM,kBAAkB,GAAG,EAAE,IAAI,EAAE,cAAc,E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G,CAAC,IAAI,CAAC,CAAA;QACzB,KAAK,EAAE,CAAA;QACP,IAAI,QAAQ,KAAK,QAAQ;YAAE,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACzD,CAAC;IACD,kFAAkF;IAClF,yDAAyD;IACzD,IAAI,OAAO,GAAG,CAAC,CAAA;IACf,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACtC,IAAI,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC;YAAE,SAAQ;QACxC,EAAE,CAAC,YAAY,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAA;QAChD,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QAC5B,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QACjC,OAAO,EAAE,CAAA;IACb,CAAC;IACD,IACI,WAAW,CAAC,MAAM,GAAG,8BAA8B;QACnD,IAAI,CAAC,uBAAuB,KAAK,KAAK,EACxC,CAAC;QACC,IAAI,CAAC,GAAG,CACJ,MAAM,EACN,gBAAgB,WAAW,CAAC,MAAM,yDAAyD;YACvF,mFAAmF;YACnF,wEAAwE,CAC/E,CAAA;IACL,CAAC;IACD,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;QACnB,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,wBAAwB,KAAK,gBAAgB,OAAO,sBAAsB,KAAK,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,CAAA;IACzH,CAAC;IACD,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;AAC3B,CAAC"}
|
package/dist/pi.d.ts
CHANGED
|
@@ -79,6 +79,12 @@ export type TextBlock = {
|
|
|
79
79
|
type: "text";
|
|
80
80
|
text: string;
|
|
81
81
|
};
|
|
82
|
+
/** Image block as pi-ai accepts it (tool results may carry images — see toLlmContent). */
|
|
83
|
+
export type ImageBlock = {
|
|
84
|
+
type: "image";
|
|
85
|
+
data: string;
|
|
86
|
+
mimeType: string;
|
|
87
|
+
};
|
|
82
88
|
/** pi's TUI Component contract (pi-tui's Component). invalidate() is REQUIRED,
|
|
83
89
|
* not optional: MouseRegion.invalidate calls it unconditionally, and a component
|
|
84
90
|
* missing it crashes pi with "this.child.invalidate is not a function" the first
|
|
@@ -101,7 +107,9 @@ export type ToolRenderResultOptions = {
|
|
|
101
107
|
/** pi's real tool-result contract: content is an ARRAY of blocks; the error flag is
|
|
102
108
|
* set by THROWING from execute, never by returning a property. */
|
|
103
109
|
export type ToolResult = {
|
|
104
|
-
|
|
110
|
+
/** SAFETY: content blocks follow pi-ai's block union — text or base64 image. The
|
|
111
|
+
* wider-than-TextBlock shape keeps MCP image results lossless (toLlmContent). */
|
|
112
|
+
content: (TextBlock | ImageBlock)[];
|
|
105
113
|
details?: unknown;
|
|
106
114
|
terminate?: boolean;
|
|
107
115
|
};
|
package/dist/pi.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi.d.ts","sourceRoot":"","sources":["../src/pi.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAA;AACjF,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAA;AAEjF,MAAM,MAAM,iBAAiB,GAAG;IAAE,MAAM,EAAE,kBAAkB,CAAC;IAAC,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAC5F,MAAM,MAAM,oBAAoB,GAAG;IAAE,MAAM,EAAE,qBAAqB,CAAC;IAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAChG,MAAM,MAAM,qBAAqB,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,CAAA;AAC5D,MA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B,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC,GAC9D,IAAI,CAAA;IACP,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAAA;IACtD;0DACsD;IACtD,YAAY,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAAA;IACxC,sFAAsF;IACtF,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IACjF,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAA;CACxE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geohar/pi-mcp-combiner",
|
|
3
|
-
"version": "0.16.0-dev.
|
|
3
|
+
"version": "0.16.0-dev.4",
|
|
4
4
|
"description": "Pi extension: run the mcp-combiner MCP aggregator via sharedserver and inject its tool-discovery directive. Pairs with pi-mcp-adapter, which makes the combiner's tools reachable from Pi.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -54,7 +54,6 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@earendil-works/pi-mcp": "^1.0.0",
|
|
58
57
|
"@earendil-works/pi-tui": "^0.85.1",
|
|
59
58
|
"@types/node": "^22.0.0",
|
|
60
59
|
"typescript": "^5.6.0",
|
|
@@ -67,6 +66,11 @@
|
|
|
67
66
|
"@earendil-works/pi-mcp": "^1.0.2",
|
|
68
67
|
"@earendil-works/pi-tui": "^0.85.1"
|
|
69
68
|
},
|
|
69
|
+
"peerDependenciesMeta": {
|
|
70
|
+
"@earendil-works/pi-mcp": {
|
|
71
|
+
"optional": true
|
|
72
|
+
}
|
|
73
|
+
},
|
|
70
74
|
"dependencies": {
|
|
71
75
|
"@earendil-works/pi-mcp": "^1.0.2"
|
|
72
76
|
}
|
package/src/client/types.ts
CHANGED
|
@@ -59,7 +59,10 @@ export interface CombinerConnection {
|
|
|
59
59
|
getPrompt(name: string, args: Record<string, string>): Promise<unknown>
|
|
60
60
|
listResources(force?: boolean): Promise<ResourceSummary[]>
|
|
61
61
|
readResource(uri: string): Promise<unknown>
|
|
62
|
-
|
|
62
|
+
/** Call a combiner tool. `options.signal` rides into the transport — pi's cancel
|
|
63
|
+
* aborts upstream work and widget holds. Throws on transport failure (with a
|
|
64
|
+
* recovery hint) and on server-marked tool errors (result.isError). */
|
|
65
|
+
callTool(name: string, args: Record<string, unknown> | undefined, options?: { signal?: AbortSignal }): Promise<unknown>
|
|
63
66
|
controlOrigin(): string
|
|
64
67
|
uiUrlFor(resourceUri: string): string
|
|
65
68
|
applyFilter(filter: ServerFilter): Promise<void>
|
package/src/index.ts
CHANGED
|
@@ -409,20 +409,16 @@ export default function mcpCombiner(pi: ExtensionAPI): void {
|
|
|
409
409
|
// without a grouping token); list_changed re-syncs ride resyncAll below.
|
|
410
410
|
nativeSurface = activateNativeMode(pi, {
|
|
411
411
|
connection,
|
|
412
|
-
|
|
413
|
-
|
|
412
|
+
// Getters, not snapshots: worktrees / project switches re-resolve
|
|
413
|
+
// sessionCfg per session_start, and a load-time value would apply the
|
|
414
|
+
// wrong allow/deny set and directTools spec to later sessions.
|
|
415
|
+
directSpec: () => sessionCfg?.directSpec,
|
|
416
|
+
serverFilter: () => sessionCfg?.serverFilter,
|
|
414
417
|
exposeResources: settings.exposeResources !== false,
|
|
415
418
|
uiAutoOpen: settings.uiAutoOpen !== false,
|
|
416
419
|
warnLargeDirectExposure: settings.warnLargeDirectExposure,
|
|
417
420
|
log: clientLog,
|
|
418
421
|
})
|
|
419
|
-
if (sessionCfg.otherServers.length && !adapterPackageInstalled()) {
|
|
420
|
-
clientLog(
|
|
421
|
-
"info",
|
|
422
|
-
`note: ${sessionCfg.otherServers.length} non-combiner server(s) in the mcp.json ladder are not ` +
|
|
423
|
-
`connected by this extension (${sessionCfg.otherServers.join(", ")})`,
|
|
424
|
-
)
|
|
425
|
-
}
|
|
426
422
|
}
|
|
427
423
|
|
|
428
424
|
if (!adapterEnabled && notify) {
|
|
@@ -491,10 +487,12 @@ export default function mcpCombiner(pi: ExtensionAPI): void {
|
|
|
491
487
|
|
|
492
488
|
pi.on("session_start", (event, ctx) => {
|
|
493
489
|
try {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
const ctxUi = ctx.ui
|
|
497
|
-
|
|
490
|
+
// SAFETY: capture ctx.ui ONCE, first — the getter asserts staleness,
|
|
491
|
+
// the object does not; every async closure below uses the object only.
|
|
492
|
+
const ctxUi = ctx.ui
|
|
493
|
+
uiNotify = notify && ctx.hasUI && ctxUi?.notify ? (m, l) => ctxUi?.notify?.(m, l) : undefined
|
|
494
|
+
uiCtx = ctxUi
|
|
495
|
+
conn.bindUi({ hasUI: ctx.hasUI && Boolean(ctxUi?.select && ctxUi?.input), ui: ctxUi })
|
|
498
496
|
// Per-session config re-resolution: worktrees and project switches read
|
|
499
497
|
// THEIR project layers (.mcp.json / .pi/mcp.json); a changed URL rebinds.
|
|
500
498
|
sessionCfg = resolveSessionConfig({
|
|
@@ -594,6 +592,16 @@ export default function mcpCombiner(pi: ExtensionAPI): void {
|
|
|
594
592
|
// not — capture once, use the object in async paths (stale after a
|
|
595
593
|
// reload is a no-op render, not a crash).
|
|
596
594
|
const ctxUi = ctx.ui
|
|
595
|
+
// SAFETY: the shared async-notify shape (notify via the captured object,
|
|
596
|
+
// degrade to stderr) — a catch must never re-enter the same stale ctx it
|
|
597
|
+
// is handling, so every async .then/.catch funnels through here.
|
|
598
|
+
const uiNotifySafe = (msg: string, level: "info" | "warn" | "error"): void => {
|
|
599
|
+
try {
|
|
600
|
+
ctxUi?.notify?.(msg, level)
|
|
601
|
+
} catch {
|
|
602
|
+
process.stderr.write(`mcp-combiner: ${msg}\n`)
|
|
603
|
+
}
|
|
604
|
+
}
|
|
597
605
|
if (v === "panel") {
|
|
598
606
|
if (!connection) {
|
|
599
607
|
ctx.ui?.notify?.(
|
|
@@ -602,7 +610,9 @@ export default function mcpCombiner(pi: ExtensionAPI): void {
|
|
|
602
610
|
)
|
|
603
611
|
return
|
|
604
612
|
}
|
|
605
|
-
|
|
613
|
+
// Async (it opens a held tool session); its rejection must be handled
|
|
614
|
+
// via STDERR — not via the stale getter this handler was entered for.
|
|
615
|
+
void openCombinerPanel(
|
|
606
616
|
{
|
|
607
617
|
connection,
|
|
608
618
|
toolName,
|
|
@@ -611,7 +621,7 @@ export default function mcpCombiner(pi: ExtensionAPI): void {
|
|
|
611
621
|
notify: (m, l) => ctxUi?.notify?.(m, l),
|
|
612
622
|
},
|
|
613
623
|
ctxUi,
|
|
614
|
-
)
|
|
624
|
+
).catch((e) => process.stderr.write(`mcp-combiner: panel failed (${e instanceof Error ? e.message : String(e)})\n`))
|
|
615
625
|
return
|
|
616
626
|
}
|
|
617
627
|
if (v === "" || v === "status") {
|
|
@@ -622,27 +632,11 @@ export default function mcpCombiner(pi: ExtensionAPI): void {
|
|
|
622
632
|
)
|
|
623
633
|
return
|
|
624
634
|
}
|
|
625
|
-
// SAFETY: capture ctx.ui ONCE synchronously (the getter asserts
|
|
626
|
-
// staleness; the OBJECT it returns does not) — an async callback
|
|
627
|
-
// must never re-enter the getter, and a catch must never touch
|
|
628
|
-
// the same stale ctx it's handling.
|
|
629
|
-
const ctxUi = ctx.ui
|
|
630
635
|
void controlStatusText(connection, ctx.cwd)
|
|
631
|
-
.then((t) =>
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
process.stderr.write(`${t}\n`)
|
|
636
|
-
}
|
|
637
|
-
})
|
|
638
|
-
.catch((e) => {
|
|
639
|
-
const msg = `mcp-combiner: status failed (${e instanceof Error ? e.message : String(e)})`
|
|
640
|
-
try {
|
|
641
|
-
ctxUi?.notify?.(msg, "error")
|
|
642
|
-
} catch {
|
|
643
|
-
process.stderr.write(`${msg}\n`)
|
|
644
|
-
}
|
|
645
|
-
})
|
|
636
|
+
.then((t) => uiNotifySafe(t, "info"))
|
|
637
|
+
.catch((e) =>
|
|
638
|
+
uiNotifySafe(`status failed (${e instanceof Error ? e.message : String(e)})`, "error"),
|
|
639
|
+
)
|
|
646
640
|
return
|
|
647
641
|
}
|
|
648
642
|
if (v === "enable" || v === "disable" || v === "restart-server") {
|
|
@@ -655,23 +649,9 @@ export default function mcpCombiner(pi: ExtensionAPI): void {
|
|
|
655
649
|
ctx.ui?.notify?.(`mcp-combiner: ${v} needs a server name`, "warn")
|
|
656
650
|
return
|
|
657
651
|
}
|
|
658
|
-
const ctxUi = ctx.ui
|
|
659
652
|
void metaToolCall(connection, v, server)
|
|
660
|
-
.then((t) =>
|
|
661
|
-
|
|
662
|
-
ctxUi?.notify?.(t, "info")
|
|
663
|
-
} catch {
|
|
664
|
-
process.stderr.write(`${t}\n`)
|
|
665
|
-
}
|
|
666
|
-
})
|
|
667
|
-
.catch((e) => {
|
|
668
|
-
const msg = `mcp-combiner: ${v} failed (${e instanceof Error ? e.message : String(e)})`
|
|
669
|
-
try {
|
|
670
|
-
ctxUi?.notify?.(msg, "error")
|
|
671
|
-
} catch {
|
|
672
|
-
process.stderr.write(`${msg}\n`)
|
|
673
|
-
}
|
|
674
|
-
})
|
|
653
|
+
.then((t) => uiNotifySafe(t, "info"))
|
|
654
|
+
.catch((e) => uiNotifySafe(`${v} failed (${e instanceof Error ? e.message : String(e)})`, "error"))
|
|
675
655
|
return
|
|
676
656
|
}
|
|
677
657
|
if (v === "system-prompt") {
|