@fitchmultz/pi-mcp-adapter 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +750 -0
- package/LICENSE +21 -0
- package/OAUTH.md +462 -0
- package/README.md +820 -0
- package/abort.ts +34 -0
- package/agent-dir.ts +24 -0
- package/app-bridge.bundle.js +67 -0
- package/banner.png +0 -0
- package/checkpoint.ts +55 -0
- package/cli.js +222 -0
- package/commands.ts +619 -0
- package/config.ts +1204 -0
- package/consent-manager.ts +25 -0
- package/direct-tools.ts +408 -0
- package/dist/abort.d.ts +2 -0
- package/dist/abort.js +35 -0
- package/dist/agent-dir.d.ts +3 -0
- package/dist/agent-dir.js +21 -0
- package/dist/app-bridge.bundle.js +67 -0
- package/dist/checkpoint.d.ts +18 -0
- package/dist/checkpoint.js +53 -0
- package/dist/commands.d.ts +20 -0
- package/dist/commands.js +521 -0
- package/dist/config.d.ts +109 -0
- package/dist/config.js +1013 -0
- package/dist/consent-manager.d.ts +8 -0
- package/dist/consent-manager.js +21 -0
- package/dist/direct-tools.d.ts +10 -0
- package/dist/direct-tools.js +350 -0
- package/dist/docs/client-metadata.json +14 -0
- package/dist/elicitation-handler.d.ts +17 -0
- package/dist/elicitation-handler.js +308 -0
- package/dist/error-signal.d.ts +15 -0
- package/dist/error-signal.js +21 -0
- package/dist/glimpse-ui.d.ts +9 -0
- package/dist/glimpse-ui.js +75 -0
- package/dist/host-html-template.d.ts +15 -0
- package/dist/host-html-template.js +429 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +840 -0
- package/dist/init.d.ts +25 -0
- package/dist/init.js +562 -0
- package/dist/legacy-migration.d.ts +18 -0
- package/dist/legacy-migration.js +45 -0
- package/dist/lifecycle.d.ts +40 -0
- package/dist/lifecycle.js +167 -0
- package/dist/logger.d.ts +38 -0
- package/dist/logger.js +102 -0
- package/dist/mcp-auth-flow.d.ts +113 -0
- package/dist/mcp-auth-flow.js +834 -0
- package/dist/mcp-auth.d.ts +127 -0
- package/dist/mcp-auth.js +658 -0
- package/dist/mcp-callback-server.d.ts +56 -0
- package/dist/mcp-callback-server.js +371 -0
- package/dist/mcp-code.d.ts +51 -0
- package/dist/mcp-code.js +366 -0
- package/dist/mcp-keyring-helper.cjs +89 -0
- package/dist/mcp-oauth-provider.d.ts +154 -0
- package/dist/mcp-oauth-provider.js +672 -0
- package/dist/mcp-output-guard.d.ts +59 -0
- package/dist/mcp-output-guard.js +332 -0
- package/dist/mcp-panel.d.ts +66 -0
- package/dist/mcp-panel.js +889 -0
- package/dist/mcp-script-worker.mjs +128 -0
- package/dist/mcp-setup-panel.d.ts +84 -0
- package/dist/mcp-setup-panel.js +561 -0
- package/dist/mcp-status.d.ts +11 -0
- package/dist/mcp-status.js +96 -0
- package/dist/mcp-trace.d.ts +95 -0
- package/dist/mcp-trace.js +233 -0
- package/dist/metadata-cache.d.ts +18 -0
- package/dist/metadata-cache.js +277 -0
- package/dist/npx-resolver.d.ts +6 -0
- package/dist/npx-resolver.js +448 -0
- package/dist/onboarding-state.d.ts +11 -0
- package/dist/onboarding-state.js +47 -0
- package/dist/panel-keys.d.ts +16 -0
- package/dist/panel-keys.js +15 -0
- package/dist/prompts.d.ts +56 -0
- package/dist/prompts.js +284 -0
- package/dist/proxy-modes.d.ts +38 -0
- package/dist/proxy-modes.js +1235 -0
- package/dist/resource-tools.d.ts +1 -0
- package/dist/resource-tools.js +14 -0
- package/dist/runtime-owner.d.ts +18 -0
- package/dist/runtime-owner.js +117 -0
- package/dist/sampling-handler.d.ts +15 -0
- package/dist/sampling-handler.js +211 -0
- package/dist/search-ranking.d.ts +20 -0
- package/dist/search-ranking.js +180 -0
- package/dist/server-manager.d.ts +114 -0
- package/dist/server-manager.js +1175 -0
- package/dist/session-recovery.d.ts +31 -0
- package/dist/session-recovery.js +310 -0
- package/dist/state.d.ts +63 -0
- package/dist/state.js +1 -0
- package/dist/tool-approval.d.ts +10 -0
- package/dist/tool-approval.js +42 -0
- package/dist/tool-metadata.d.ts +9 -0
- package/dist/tool-metadata.js +193 -0
- package/dist/tool-registrar.d.ts +10 -0
- package/dist/tool-registrar.js +64 -0
- package/dist/tool-result-renderer.d.ts +45 -0
- package/dist/tool-result-renderer.js +224 -0
- package/dist/ts-shape.d.ts +2 -0
- package/dist/ts-shape.js +147 -0
- package/dist/types.d.ts +516 -0
- package/dist/types.js +168 -0
- package/dist/ui-resource-handler.d.ts +17 -0
- package/dist/ui-resource-handler.js +209 -0
- package/dist/ui-server.d.ts +51 -0
- package/dist/ui-server.js +669 -0
- package/dist/ui-session.d.ts +39 -0
- package/dist/ui-session.js +463 -0
- package/dist/ui-stream-types.d.ts +104 -0
- package/dist/ui-stream-types.js +58 -0
- package/dist/ui-tool-visibility.d.ts +4 -0
- package/dist/ui-tool-visibility.js +26 -0
- package/dist/unix-socket-transport.d.ts +15 -0
- package/dist/unix-socket-transport.js +84 -0
- package/dist/utils.d.ts +30 -0
- package/dist/utils.js +276 -0
- package/docs/client-metadata.json +14 -0
- package/elicitation-handler.ts +349 -0
- package/error-signal.ts +21 -0
- package/glimpse-ui.ts +80 -0
- package/host-html-template.ts +456 -0
- package/index.ts +900 -0
- package/init.ts +627 -0
- package/legacy-migration.ts +47 -0
- package/lifecycle.ts +165 -0
- package/logger.ts +127 -0
- package/mcp-auth-flow.ts +975 -0
- package/mcp-auth.ts +793 -0
- package/mcp-callback-server.ts +450 -0
- package/mcp-code.ts +386 -0
- package/mcp-keyring-helper.cjs +89 -0
- package/mcp-oauth-provider.ts +774 -0
- package/mcp-output-guard.ts +412 -0
- package/mcp-panel.ts +978 -0
- package/mcp-script-worker.mjs +128 -0
- package/mcp-setup-panel.ts +666 -0
- package/mcp-status.ts +109 -0
- package/mcp-trace.ts +295 -0
- package/metadata-cache.ts +333 -0
- package/npx-resolver.ts +488 -0
- package/onboarding-state.ts +58 -0
- package/package.json +182 -0
- package/panel-keys.ts +37 -0
- package/prompts.ts +337 -0
- package/proxy-modes.ts +1361 -0
- package/resource-tools.ts +17 -0
- package/runtime-owner.ts +123 -0
- package/sampling-handler.ts +273 -0
- package/scripts/build.mjs +131 -0
- package/scripts/prepare.mjs +102 -0
- package/search-ranking.ts +196 -0
- package/server-manager.ts +1320 -0
- package/session-recovery.ts +316 -0
- package/skills/mcp-scripting/SKILL.md +38 -0
- package/state.ts +64 -0
- package/tool-approval.ts +78 -0
- package/tool-metadata.ts +235 -0
- package/tool-registrar.ts +69 -0
- package/tool-result-renderer.ts +286 -0
- package/ts-shape.ts +145 -0
- package/tsconfig.build.json +13 -0
- package/tsconfig.json +16 -0
- package/types.ts +810 -0
- package/ui-resource-handler.ts +249 -0
- package/ui-server.ts +808 -0
- package/ui-session.ts +568 -0
- package/ui-stream-types.ts +89 -0
- package/ui-tool-visibility.ts +25 -0
- package/unix-socket-transport.ts +85 -0
- package/utils.ts +309 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
2
|
+
import { formatWithOptions } from "node:util";
|
|
3
|
+
import vm from "node:vm";
|
|
4
|
+
|
|
5
|
+
const TOOLS_ENUMERATION_ERROR = "tools is not enumerable — use tools.search({ query })";
|
|
6
|
+
const RESERVED_TOOL_PROPS = new Set(["then", "catch", "finally", "toJSON", "toString", "valueOf"]);
|
|
7
|
+
|
|
8
|
+
// Keep this formatting logic in sync with mcp-code.ts; the standalone worker cannot import the TypeScript host module.
|
|
9
|
+
function needsInspectableFormatting(value, stack = new WeakSet()) {
|
|
10
|
+
if (value === undefined || typeof value === "bigint" || typeof value === "function" || typeof value === "symbol") return true;
|
|
11
|
+
if (typeof value !== "object" || value === null) return false;
|
|
12
|
+
if (stack.has(value)) return true;
|
|
13
|
+
if (value instanceof Map || value instanceof Set || value instanceof WeakMap || value instanceof WeakSet) return true;
|
|
14
|
+
stack.add(value);
|
|
15
|
+
try {
|
|
16
|
+
return Object.values(value).some((entry) => needsInspectableFormatting(entry, stack));
|
|
17
|
+
} finally {
|
|
18
|
+
stack.delete(value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function formatValue(value) {
|
|
23
|
+
if (typeof value === "string") return value;
|
|
24
|
+
try {
|
|
25
|
+
if (!needsInspectableFormatting(value)) {
|
|
26
|
+
const json = JSON.stringify(value, null, 2);
|
|
27
|
+
if (json !== undefined) return json;
|
|
28
|
+
}
|
|
29
|
+
return formatWithOptions({ colors: false, depth: 6 }, value);
|
|
30
|
+
} catch {
|
|
31
|
+
return "[unserializable value]";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function toContentBlock(value) {
|
|
36
|
+
if (typeof value === "object" && value !== null) {
|
|
37
|
+
if (value.type === "text" && typeof value.text === "string") {
|
|
38
|
+
return { type: "text", text: value.text };
|
|
39
|
+
}
|
|
40
|
+
if (value.type === "image" && typeof value.data === "string" && typeof value.mimeType === "string") {
|
|
41
|
+
return { type: "image", data: value.data, mimeType: value.mimeType };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return { type: "text", text: formatValue(value) };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let nextRequestId = 0;
|
|
48
|
+
const pending = new Map();
|
|
49
|
+
|
|
50
|
+
parentPort.on("message", (message) => {
|
|
51
|
+
if (message?.type !== "result" || typeof message.id !== "number") return;
|
|
52
|
+
const resolve = pending.get(message.id);
|
|
53
|
+
if (!resolve) return;
|
|
54
|
+
pending.delete(message.id);
|
|
55
|
+
resolve(message.envelope);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
function request(type, payload) {
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
const id = ++nextRequestId;
|
|
61
|
+
pending.set(id, resolve);
|
|
62
|
+
parentPort.postMessage({ type, id, ...payload });
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const tools = new Proxy(Object.create(null), {
|
|
67
|
+
get(_target, property) {
|
|
68
|
+
if (property === "search") {
|
|
69
|
+
return async (input) => request("search", { input });
|
|
70
|
+
}
|
|
71
|
+
if (property === "call") {
|
|
72
|
+
return async (path, args) => {
|
|
73
|
+
// Invalid paths never reach dispatch and therefore never appear in the call trace.
|
|
74
|
+
if (typeof path !== "string" || path.trim() === "") {
|
|
75
|
+
return {
|
|
76
|
+
ok: false,
|
|
77
|
+
error: {
|
|
78
|
+
code: "invalid_tool_path",
|
|
79
|
+
message: "tools.call(path, args) requires a non-empty tool path.",
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return request("call", { path, args });
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (property === "describe") {
|
|
87
|
+
return async (input) => request("describe", { input });
|
|
88
|
+
}
|
|
89
|
+
if (typeof property !== "string" || RESERVED_TOOL_PROPS.has(property)) return undefined;
|
|
90
|
+
return (args) => request("call", { path: property, args });
|
|
91
|
+
},
|
|
92
|
+
ownKeys() {
|
|
93
|
+
throw new Error(TOOLS_ENUMERATION_ERROR);
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const emit = (value) => {
|
|
98
|
+
parentPort.postMessage({ type: "emit", block: toContentBlock(value) });
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const capturedConsole = Object.freeze({
|
|
102
|
+
log: (...args) => emit(`[console.log] ${formatWithOptions({ colors: false, depth: 4 }, ...args)}`),
|
|
103
|
+
info: (...args) => emit(`[console.info] ${formatWithOptions({ colors: false, depth: 4 }, ...args)}`),
|
|
104
|
+
warn: (...args) => emit(`[console.warn] ${formatWithOptions({ colors: false, depth: 4 }, ...args)}`),
|
|
105
|
+
error: (...args) => emit(`[console.error] ${formatWithOptions({ colors: false, depth: 4 }, ...args)}`),
|
|
106
|
+
debug: (...args) => emit(`[console.debug] ${formatWithOptions({ colors: false, depth: 4 }, ...args)}`),
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
const context = vm.createContext(Object.assign(Object.create(null), {
|
|
111
|
+
tools,
|
|
112
|
+
emit,
|
|
113
|
+
console: capturedConsole,
|
|
114
|
+
}), {
|
|
115
|
+
codeGeneration: { strings: false, wasm: false },
|
|
116
|
+
name: "mcp_script",
|
|
117
|
+
});
|
|
118
|
+
const script = new vm.Script(`(async () => {\n${workerData.code}\n})()`, { filename: "mcp_script.js" });
|
|
119
|
+
const returnValue = await Promise.resolve(script.runInContext(context));
|
|
120
|
+
parentPort.postMessage(returnValue === undefined
|
|
121
|
+
? { type: "done" }
|
|
122
|
+
: { type: "done", returnBlock: toContentBlock(returnValue) });
|
|
123
|
+
} catch (error) {
|
|
124
|
+
parentPort.postMessage({
|
|
125
|
+
type: "error",
|
|
126
|
+
message: error instanceof Error ? error.message : String(error),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type PanelKeybindings } from "./panel-keys.ts";
|
|
2
|
+
import type { ImportKind } from "./types.ts";
|
|
3
|
+
import { type ConfigWritePreview, type KnownServerPreset, type McpDiscoverySummary } from "./config.ts";
|
|
4
|
+
import type { McpOnboardingState } from "./onboarding-state.ts";
|
|
5
|
+
export interface SetupPanelCallbacks {
|
|
6
|
+
previewImports: (imports: ImportKind[]) => ConfigWritePreview;
|
|
7
|
+
previewStarterProject: () => ConfigWritePreview;
|
|
8
|
+
previewRepoPrompt: () => ConfigWritePreview | null;
|
|
9
|
+
previewKnownServer: (preset: KnownServerPreset) => ConfigWritePreview;
|
|
10
|
+
adoptImports: (imports: ImportKind[]) => Promise<{
|
|
11
|
+
added: ImportKind[];
|
|
12
|
+
path: string;
|
|
13
|
+
}>;
|
|
14
|
+
scaffoldProjectConfig: () => Promise<{
|
|
15
|
+
path: string;
|
|
16
|
+
}>;
|
|
17
|
+
addRepoPrompt: () => Promise<{
|
|
18
|
+
path: string;
|
|
19
|
+
serverName: string;
|
|
20
|
+
}>;
|
|
21
|
+
addKnownServer: (preset: KnownServerPreset) => Promise<{
|
|
22
|
+
path: string;
|
|
23
|
+
serverName: string;
|
|
24
|
+
}>;
|
|
25
|
+
openPath: (path: string) => Promise<void>;
|
|
26
|
+
markSetupCompleted: () => void;
|
|
27
|
+
}
|
|
28
|
+
export interface SetupPanelOptions {
|
|
29
|
+
mode: "empty" | "setup";
|
|
30
|
+
onboardingState: McpOnboardingState;
|
|
31
|
+
keybindings?: PanelKeybindings;
|
|
32
|
+
}
|
|
33
|
+
export declare class McpSetupPanel {
|
|
34
|
+
private discovery;
|
|
35
|
+
private callbacks;
|
|
36
|
+
private options;
|
|
37
|
+
private done;
|
|
38
|
+
private screen;
|
|
39
|
+
private actionCursor;
|
|
40
|
+
private importCursor;
|
|
41
|
+
private pathCursor;
|
|
42
|
+
private selectedImports;
|
|
43
|
+
private busy;
|
|
44
|
+
private notice;
|
|
45
|
+
private tui;
|
|
46
|
+
private t;
|
|
47
|
+
private keys;
|
|
48
|
+
private inactivityTimeout;
|
|
49
|
+
private static readonly INACTIVITY_MS;
|
|
50
|
+
constructor(discovery: McpDiscoverySummary, callbacks: SetupPanelCallbacks, options: SetupPanelOptions, tui: {
|
|
51
|
+
requestRender(): void;
|
|
52
|
+
}, done: () => void);
|
|
53
|
+
private resetInactivityTimeout;
|
|
54
|
+
private cleanup;
|
|
55
|
+
private getActions;
|
|
56
|
+
private getDetectedPaths;
|
|
57
|
+
private getSelectedAction;
|
|
58
|
+
handleInput(data: string): void;
|
|
59
|
+
private handleImportsInput;
|
|
60
|
+
private handlePathsInput;
|
|
61
|
+
private runAction;
|
|
62
|
+
private applySelectedImports;
|
|
63
|
+
private runBusy;
|
|
64
|
+
render(width: number): string[];
|
|
65
|
+
private renderActions;
|
|
66
|
+
private renderImports;
|
|
67
|
+
private renderPaths;
|
|
68
|
+
private discoverySummaryLine;
|
|
69
|
+
private secondarySummaryLine;
|
|
70
|
+
private visibleActionRange;
|
|
71
|
+
private contentWidth;
|
|
72
|
+
private previewWidth;
|
|
73
|
+
private getActionPreview;
|
|
74
|
+
private formatPreview;
|
|
75
|
+
private formatWritePreview;
|
|
76
|
+
private padLine;
|
|
77
|
+
invalidate(): void;
|
|
78
|
+
dispose(): void;
|
|
79
|
+
}
|
|
80
|
+
export declare function createMcpSetupPanel(discovery: McpDiscoverySummary, callbacks: SetupPanelCallbacks, options: SetupPanelOptions, tui: {
|
|
81
|
+
requestRender(): void;
|
|
82
|
+
}, done: () => void): McpSetupPanel & {
|
|
83
|
+
dispose(): void;
|
|
84
|
+
};
|