@herbertgao/pi-extensions 2026.9.16 → 2026.9.18
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 +14 -15
- package/node_modules/@herbertgao/pi-bark/package.json +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +4 -1
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +4 -1
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +75 -75
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-subagents/package.json +7 -7
- package/node_modules/@herbertgao/resume-from/package.json +4 -2
- package/node_modules/@herbertgao/sol-pi/package.json +6 -6
- package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/online-context-compact/extension.ts +11 -53
- package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +99 -99
- package/node_modules/@pi-plugins/fast-mode/package.json +1 -1
- package/node_modules/@tifan/pi-handoff/package.json +1 -1
- package/node_modules/@tifan/pi-handoff/src/index.ts +56 -26
- package/node_modules/@tifan/pi-mermaid-open/package.json +1 -1
- package/node_modules/@tifan/pi-preferred-thinking/package.json +1 -1
- package/node_modules/@tifan/pi-recap/package.json +1 -1
- package/node_modules/@tifan/pi-rename/package.json +1 -1
- package/node_modules/pi-antigravity/package.json +2 -2
- package/node_modules/pi-lens/package.json +158 -158
- package/node_modules/pi-multi-account/package.json +2 -2
- package/node_modules/pi-typesafe/README.md +1 -1
- package/node_modules/pi-typesafe/dist/auth.d.ts +9 -5
- package/node_modules/pi-typesafe/dist/auth.js +7 -3
- package/node_modules/pi-typesafe/dist/backends.d.ts +33 -3
- package/node_modules/pi-typesafe/dist/backends.js +95 -1
- package/node_modules/pi-typesafe/dist/client.d.ts +5 -5
- package/node_modules/pi-typesafe/dist/client.js +12 -9
- package/node_modules/pi-typesafe/dist/credentials.d.ts +14 -8
- package/node_modules/pi-typesafe/dist/credentials.js +10 -7
- package/node_modules/pi-typesafe/dist/errors.d.ts +2 -2
- package/node_modules/pi-typesafe/dist/index.d.ts +2 -2
- package/node_modules/pi-typesafe/dist/index.js +1 -1
- package/node_modules/pi-typesafe/dist/login.d.ts +2 -2
- package/node_modules/pi-typesafe/dist/login.js +2 -2
- package/node_modules/pi-typesafe/package.json +5 -5
- package/node_modules/pi-web-access/package.json +2 -2
- package/node_modules/remote-pi/package.json +5 -1
- package/package.json +16 -28
- package/node_modules/pi-mcp-adapter/CHANGELOG.md +0 -1013
- package/node_modules/pi-mcp-adapter/LICENSE +0 -21
- package/node_modules/pi-mcp-adapter/OAUTH.md +0 -369
- package/node_modules/pi-mcp-adapter/README.md +0 -1021
- package/node_modules/pi-mcp-adapter/abort.ts +0 -34
- package/node_modules/pi-mcp-adapter/agent-dir.ts +0 -68
- package/node_modules/pi-mcp-adapter/agent-plugin-loader.ts +0 -416
- package/node_modules/pi-mcp-adapter/agent-plugin-provenance.ts +0 -36
- package/node_modules/pi-mcp-adapter/app-bridge.bundle.js +0 -67
- package/node_modules/pi-mcp-adapter/banner.png +0 -0
- package/node_modules/pi-mcp-adapter/bearer-command-resolver.ts +0 -193
- package/node_modules/pi-mcp-adapter/claude-plugin-loader.ts +0 -365
- package/node_modules/pi-mcp-adapter/cli.js +0 -454
- package/node_modules/pi-mcp-adapter/commands.ts +0 -861
- package/node_modules/pi-mcp-adapter/config.ts +0 -1565
- package/node_modules/pi-mcp-adapter/consent-manager.ts +0 -95
- package/node_modules/pi-mcp-adapter/direct-tool-surface.ts +0 -244
- package/node_modules/pi-mcp-adapter/direct-tools.ts +0 -428
- package/node_modules/pi-mcp-adapter/dist/abort.d.ts +0 -2
- package/node_modules/pi-mcp-adapter/dist/abort.js +0 -36
- package/node_modules/pi-mcp-adapter/dist/abort.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/agent-dir.d.ts +0 -10
- package/node_modules/pi-mcp-adapter/dist/agent-dir.js +0 -63
- package/node_modules/pi-mcp-adapter/dist/agent-dir.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.d.ts +0 -8
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js +0 -398
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.d.ts +0 -1
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js +0 -31
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.d.ts +0 -6
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js +0 -194
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.d.ts +0 -9
- package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js +0 -362
- package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/config.d.ts +0 -134
- package/node_modules/pi-mcp-adapter/dist/config.js +0 -1361
- package/node_modules/pi-mcp-adapter/dist/config.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/consent-manager.d.ts +0 -18
- package/node_modules/pi-mcp-adapter/dist/consent-manager.js +0 -88
- package/node_modules/pi-mcp-adapter/dist/consent-manager.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.d.ts +0 -17
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js +0 -316
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/errors.d.ts +0 -131
- package/node_modules/pi-mcp-adapter/dist/errors.js +0 -278
- package/node_modules/pi-mcp-adapter/dist/errors.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/http-ca.d.ts +0 -8
- package/node_modules/pi-mcp-adapter/dist/http-ca.js +0 -88
- package/node_modules/pi-mcp-adapter/dist/http-ca.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/jev-client.d.ts +0 -14
- package/node_modules/pi-mcp-adapter/dist/jev-client.js +0 -367
- package/node_modules/pi-mcp-adapter/dist/jev-client.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.d.ts +0 -77
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.js +0 -2
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.d.ts +0 -51
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.js +0 -205
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.d.ts +0 -2
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js +0 -68
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/lifecycle.d.ts +0 -56
- package/node_modules/pi-mcp-adapter/dist/lifecycle.js +0 -410
- package/node_modules/pi-mcp-adapter/dist/lifecycle.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/logger.d.ts +0 -51
- package/node_modules/pi-mcp-adapter/dist/logger.js +0 -131
- package/node_modules/pi-mcp-adapter/dist/logger.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.d.ts +0 -26
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js +0 -103
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.d.ts +0 -118
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js +0 -1097
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.d.ts +0 -170
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.js +0 -1142
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.d.ts +0 -24
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +0 -203
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.d.ts +0 -53
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js +0 -441
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.d.ts +0 -148
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js +0 -689
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.d.ts +0 -6
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.js +0 -166
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.d.ts +0 -102
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js +0 -369
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.d.ts +0 -95
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.js +0 -242
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/metadata-cache.d.ts +0 -19
- package/node_modules/pi-mcp-adapter/dist/metadata-cache.js +0 -301
- package/node_modules/pi-mcp-adapter/dist/metadata-cache.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.d.ts +0 -6
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.js +0 -505
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.d.ts +0 -2
- package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js +0 -144
- package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.d.ts +0 -10
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.js +0 -312
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/resource-tools.d.ts +0 -1
- package/node_modules/pi-mcp-adapter/dist/resource-tools.js +0 -15
- package/node_modules/pi-mcp-adapter/dist/resource-tools.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.d.ts +0 -13
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.js +0 -97
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.d.ts +0 -17
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.js +0 -203
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.d.ts +0 -11
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.js +0 -172
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/server-manager.d.ts +0 -157
- package/node_modules/pi-mcp-adapter/dist/server-manager.js +0 -1745
- package/node_modules/pi-mcp-adapter/dist/server-manager.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/session-approvals.d.ts +0 -34
- package/node_modules/pi-mcp-adapter/dist/session-approvals.js +0 -140
- package/node_modules/pi-mcp-adapter/dist/session-approvals.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/session-recovery.d.ts +0 -26
- package/node_modules/pi-mcp-adapter/dist/session-recovery.js +0 -142
- package/node_modules/pi-mcp-adapter/dist/session-recovery.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/state.d.ts +0 -73
- package/node_modules/pi-mcp-adapter/dist/state.js +0 -2
- package/node_modules/pi-mcp-adapter/dist/state.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/types.d.ts +0 -642
- package/node_modules/pi-mcp-adapter/dist/types.js +0 -331
- package/node_modules/pi-mcp-adapter/dist/types.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.d.ts +0 -6
- package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js +0 -37
- package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.d.ts +0 -17
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js +0 -219
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/ui-stream-types.d.ts +0 -104
- package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js +0 -59
- package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.d.ts +0 -4
- package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js +0 -27
- package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.d.ts +0 -15
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js +0 -85
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/utils.d.ts +0 -41
- package/node_modules/pi-mcp-adapter/dist/utils.js +0 -417
- package/node_modules/pi-mcp-adapter/dist/utils.js.map +0 -1
- package/node_modules/pi-mcp-adapter/elicitation-handler.ts +0 -358
- package/node_modules/pi-mcp-adapter/error-signal.ts +0 -32
- package/node_modules/pi-mcp-adapter/errors.ts +0 -364
- package/node_modules/pi-mcp-adapter/examples/jev-accessibility-loop.mjs +0 -85
- package/node_modules/pi-mcp-adapter/examples/jev-semantic-filter.mjs +0 -34
- package/node_modules/pi-mcp-adapter/failure-backoff.ts +0 -23
- package/node_modules/pi-mcp-adapter/glimpse-ui.ts +0 -80
- package/node_modules/pi-mcp-adapter/host-html-template.ts +0 -515
- package/node_modules/pi-mcp-adapter/http-ca.ts +0 -84
- package/node_modules/pi-mcp-adapter/index.ts +0 -2106
- package/node_modules/pi-mcp-adapter/init.ts +0 -721
- package/node_modules/pi-mcp-adapter/jev-client.ts +0 -300
- package/node_modules/pi-mcp-adapter/jev-contracts.ts +0 -53
- package/node_modules/pi-mcp-adapter/jev-key-store.ts +0 -192
- package/node_modules/pi-mcp-adapter/json-schema-validator.ts +0 -83
- package/node_modules/pi-mcp-adapter/lazy-loader.ts +0 -7
- package/node_modules/pi-mcp-adapter/lifecycle.ts +0 -457
- package/node_modules/pi-mcp-adapter/logger.ts +0 -169
- package/node_modules/pi-mcp-adapter/mcp-auth-fetch.ts +0 -113
- package/node_modules/pi-mcp-adapter/mcp-auth-flow.ts +0 -1296
- package/node_modules/pi-mcp-adapter/mcp-auth.ts +0 -1287
- package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +0 -250
- package/node_modules/pi-mcp-adapter/mcp-callback-server.ts +0 -534
- package/node_modules/pi-mcp-adapter/mcp-code.ts +0 -495
- package/node_modules/pi-mcp-adapter/mcp-install.ts +0 -60
- package/node_modules/pi-mcp-adapter/mcp-keyring-helper.cjs +0 -89
- package/node_modules/pi-mcp-adapter/mcp-oauth-provider.ts +0 -819
- package/node_modules/pi-mcp-adapter/mcp-output-guard.ts +0 -511
- package/node_modules/pi-mcp-adapter/mcp-panel-theme.ts +0 -104
- package/node_modules/pi-mcp-adapter/mcp-panel.ts +0 -1099
- package/node_modules/pi-mcp-adapter/mcp-probe.ts +0 -201
- package/node_modules/pi-mcp-adapter/mcp-references.ts +0 -373
- package/node_modules/pi-mcp-adapter/mcp-script-worker.mjs +0 -137
- package/node_modules/pi-mcp-adapter/mcp-setup-panel.ts +0 -747
- package/node_modules/pi-mcp-adapter/mcp-status.ts +0 -105
- package/node_modules/pi-mcp-adapter/mcp-tasks.ts +0 -467
- package/node_modules/pi-mcp-adapter/mcp-trace.ts +0 -306
- package/node_modules/pi-mcp-adapter/metadata-cache.ts +0 -362
- package/node_modules/pi-mcp-adapter/namespace-tools.ts +0 -334
- package/node_modules/pi-mcp-adapter/npx-resolver.ts +0 -543
- package/node_modules/pi-mcp-adapter/oauth-handler.ts +0 -30
- package/node_modules/pi-mcp-adapter/oauth.ts +0 -52
- package/node_modules/pi-mcp-adapter/onboarding-state.ts +0 -76
- package/node_modules/pi-mcp-adapter/package-mcp-loader.ts +0 -156
- package/node_modules/pi-mcp-adapter/package.json +0 -219
- package/node_modules/pi-mcp-adapter/panel-keys.ts +0 -53
- package/node_modules/pi-mcp-adapter/prompts.ts +0 -385
- package/node_modules/pi-mcp-adapter/proxy-modes.ts +0 -1735
- package/node_modules/pi-mcp-adapter/request-headers-command.ts +0 -333
- package/node_modules/pi-mcp-adapter/resource-tools.ts +0 -17
- package/node_modules/pi-mcp-adapter/runtime-owner.ts +0 -106
- package/node_modules/pi-mcp-adapter/sampling-handler.ts +0 -261
- package/node_modules/pi-mcp-adapter/sandbox-proxy-template.ts +0 -144
- package/node_modules/pi-mcp-adapter/search-ranking.ts +0 -309
- package/node_modules/pi-mcp-adapter/secure-keyring.ts +0 -170
- package/node_modules/pi-mcp-adapter/semantic-search.ts +0 -186
- package/node_modules/pi-mcp-adapter/server-manager.ts +0 -2088
- package/node_modules/pi-mcp-adapter/session-approvals.ts +0 -201
- package/node_modules/pi-mcp-adapter/session-recovery.ts +0 -158
- package/node_modules/pi-mcp-adapter/skills/mcp-scripting/SKILL.md +0 -49
- package/node_modules/pi-mcp-adapter/state.ts +0 -71
- package/node_modules/pi-mcp-adapter/tool-approval.ts +0 -205
- package/node_modules/pi-mcp-adapter/tool-metadata.ts +0 -302
- package/node_modules/pi-mcp-adapter/tool-registrar.ts +0 -255
- package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +0 -573
- package/node_modules/pi-mcp-adapter/ts-shape.ts +0 -149
- package/node_modules/pi-mcp-adapter/types.ts +0 -1120
- package/node_modules/pi-mcp-adapter/ui-app-bridge-helpers.ts +0 -40
- package/node_modules/pi-mcp-adapter/ui-resource-handler.ts +0 -266
- package/node_modules/pi-mcp-adapter/ui-server.ts +0 -993
- package/node_modules/pi-mcp-adapter/ui-session.ts +0 -624
- package/node_modules/pi-mcp-adapter/ui-stream-types.ts +0 -89
- package/node_modules/pi-mcp-adapter/ui-tool-visibility.ts +0 -25
- package/node_modules/pi-mcp-adapter/unix-socket-transport.ts +0 -85
- package/node_modules/pi-mcp-adapter/utils.ts +0 -464
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import type { McpExtensionState } from "./state.ts";
|
|
3
|
-
import type { ToolMetadata } from "./types.ts";
|
|
4
|
-
import { logger } from "./logger.ts";
|
|
5
|
-
import { stableStringify } from "./utils.ts";
|
|
6
|
-
|
|
7
|
-
export const MCP_APPROVAL_CUSTOM_TYPE = "mcp-approval-v1";
|
|
8
|
-
|
|
9
|
-
export type SessionApprovalEntry =
|
|
10
|
-
| {
|
|
11
|
-
version: 1;
|
|
12
|
-
kind: "tool";
|
|
13
|
-
decision: "allow_for_session";
|
|
14
|
-
serverName: string;
|
|
15
|
-
originalToolName: string;
|
|
16
|
-
definitionHash: string;
|
|
17
|
-
argsHash: string;
|
|
18
|
-
}
|
|
19
|
-
| {
|
|
20
|
-
version: 1;
|
|
21
|
-
kind: "iframe";
|
|
22
|
-
decision: "allow" | "deny";
|
|
23
|
-
serverName: string;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type SessionApprovalWriter = (record: SessionApprovalEntry) => void;
|
|
27
|
-
|
|
28
|
-
const TOOL_APPROVAL_KEYS = [
|
|
29
|
-
"version",
|
|
30
|
-
"kind",
|
|
31
|
-
"decision",
|
|
32
|
-
"serverName",
|
|
33
|
-
"originalToolName",
|
|
34
|
-
"definitionHash",
|
|
35
|
-
"argsHash",
|
|
36
|
-
] as const;
|
|
37
|
-
const IFRAME_APPROVAL_KEYS = ["version", "kind", "decision", "serverName"] as const;
|
|
38
|
-
const SHA256_HEX = /^[0-9a-f]{64}$/;
|
|
39
|
-
|
|
40
|
-
export function computeToolArgumentsHash(args: unknown): string {
|
|
41
|
-
return createHash("sha256").update(stableStringify(args ?? {})).digest("hex");
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function computeToolDefinitionHash(
|
|
45
|
-
toolMeta: Pick<ToolMetadata, "originalName" | "inputSchema" | "resourceUri" | "uiResourceUri">,
|
|
46
|
-
): string {
|
|
47
|
-
return createHash("sha256").update(stableStringify({
|
|
48
|
-
originalName: toolMeta.originalName,
|
|
49
|
-
inputSchema: toolMeta.inputSchema ?? null,
|
|
50
|
-
resourceUri: toolMeta.resourceUri ?? null,
|
|
51
|
-
uiResourceUri: toolMeta.uiResourceUri ?? null,
|
|
52
|
-
})).digest("hex");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function makeToolApprovalKey(
|
|
56
|
-
serverName: string,
|
|
57
|
-
originalToolName: string,
|
|
58
|
-
definitionHash: string,
|
|
59
|
-
argsHash: string,
|
|
60
|
-
): string {
|
|
61
|
-
return `${serverName}\u0000${originalToolName}\u0000${definitionHash}\u0000${argsHash}`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function getToolApprovalIdentity(
|
|
65
|
-
serverName: string,
|
|
66
|
-
toolMeta: Pick<ToolMetadata, "originalName" | "inputSchema" | "resourceUri" | "uiResourceUri">,
|
|
67
|
-
args: unknown,
|
|
68
|
-
): { definitionHash: string; argsHash: string; cacheKey: string } {
|
|
69
|
-
const definitionHash = computeToolDefinitionHash(toolMeta);
|
|
70
|
-
const argsHash = computeToolArgumentsHash(args);
|
|
71
|
-
return {
|
|
72
|
-
definitionHash,
|
|
73
|
-
argsHash,
|
|
74
|
-
cacheKey: makeToolApprovalKey(serverName, toolMeta.originalName, definitionHash, argsHash),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
79
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function hasExactKeys(value: Record<string, unknown>, keys: readonly string[]): boolean {
|
|
83
|
-
const actualKeys = Object.keys(value);
|
|
84
|
-
return actualKeys.length === keys.length && keys.every(key => Object.hasOwn(value, key));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function isNonEmptyString(value: unknown): value is string {
|
|
88
|
-
return typeof value === "string" && value.length > 0;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function isSha256(value: unknown): value is string {
|
|
92
|
-
return typeof value === "string" && SHA256_HEX.test(value);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function isSessionApprovalEntry(value: unknown): value is SessionApprovalEntry {
|
|
96
|
-
if (!isRecord(value) || value.version !== 1 || !isNonEmptyString(value.serverName)) return false;
|
|
97
|
-
|
|
98
|
-
if (value.kind === "tool") {
|
|
99
|
-
return hasExactKeys(value, TOOL_APPROVAL_KEYS)
|
|
100
|
-
&& value.decision === "allow_for_session"
|
|
101
|
-
&& isNonEmptyString(value.originalToolName)
|
|
102
|
-
&& isSha256(value.definitionHash)
|
|
103
|
-
&& isSha256(value.argsHash);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (value.kind === "iframe") {
|
|
107
|
-
return hasExactKeys(value, IFRAME_APPROVAL_KEYS)
|
|
108
|
-
&& (value.decision === "allow" || value.decision === "deny");
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function isApprovalCustomEntry(entry: unknown): entry is { type: "custom"; data?: unknown } {
|
|
115
|
-
return isRecord(entry)
|
|
116
|
-
&& entry.type === "custom"
|
|
117
|
-
&& entry.customType === MCP_APPROVAL_CUSTOM_TYPE;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export function createSessionApprovalWriter(
|
|
121
|
-
appendEntry: (customType: string, data?: unknown) => void,
|
|
122
|
-
canAppend: (() => boolean) | undefined = undefined,
|
|
123
|
-
): SessionApprovalWriter {
|
|
124
|
-
return (record) => {
|
|
125
|
-
if (canAppend && !canAppend()) return;
|
|
126
|
-
try {
|
|
127
|
-
appendEntry(MCP_APPROVAL_CUSTOM_TYPE, record);
|
|
128
|
-
} catch (error) {
|
|
129
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
130
|
-
logger.debug(`MCP: failed to persist session approval: ${detail}`);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export function rememberToolApproval(
|
|
136
|
-
state: McpExtensionState,
|
|
137
|
-
serverName: string,
|
|
138
|
-
toolMeta: Pick<ToolMetadata, "originalName" | "inputSchema" | "resourceUri" | "uiResourceUri">,
|
|
139
|
-
args: unknown,
|
|
140
|
-
): void {
|
|
141
|
-
const { definitionHash, argsHash, cacheKey } = getToolApprovalIdentity(serverName, toolMeta, args);
|
|
142
|
-
const approvedToolCalls = state.approvedToolCalls ??= new Map<string, true>();
|
|
143
|
-
if (approvedToolCalls.has(cacheKey)) return;
|
|
144
|
-
|
|
145
|
-
approvedToolCalls.set(cacheKey, true);
|
|
146
|
-
const record: SessionApprovalEntry = {
|
|
147
|
-
version: 1,
|
|
148
|
-
kind: "tool",
|
|
149
|
-
decision: "allow_for_session",
|
|
150
|
-
serverName,
|
|
151
|
-
originalToolName: toolMeta.originalName,
|
|
152
|
-
definitionHash,
|
|
153
|
-
argsHash,
|
|
154
|
-
};
|
|
155
|
-
try {
|
|
156
|
-
state.persistSessionApproval?.(record);
|
|
157
|
-
} catch (error) {
|
|
158
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
159
|
-
logger.debug(`MCP: session approval persistence callback failed: ${detail}`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/** Bind broad consent to this configured server, not a replacement with the same name. */
|
|
164
|
-
export function getServerApprovalIdentity(state: McpExtensionState, serverName: string) {
|
|
165
|
-
if (!Object.hasOwn(state.config.mcpServers, serverName)) return undefined;
|
|
166
|
-
const definition = state.config.mcpServers[serverName];
|
|
167
|
-
if (!definition) return undefined;
|
|
168
|
-
return {
|
|
169
|
-
definition,
|
|
170
|
-
hash: createHash("sha256").update(stableStringify(definition)).digest("hex"),
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export function restoreSessionApprovalState(
|
|
175
|
-
state: McpExtensionState,
|
|
176
|
-
branchEntries: readonly unknown[],
|
|
177
|
-
): void {
|
|
178
|
-
const approvedToolCalls = state.approvedToolCalls ??= new Map<string, true>();
|
|
179
|
-
approvedToolCalls.clear();
|
|
180
|
-
// Replace the map so an approval dialog opened on the old branch cannot grant
|
|
181
|
-
// server-wide authority after navigation, resume, or session replacement.
|
|
182
|
-
state.approvedServers = new Map();
|
|
183
|
-
state.consentManager.clear();
|
|
184
|
-
|
|
185
|
-
for (const entry of branchEntries) {
|
|
186
|
-
if (!isApprovalCustomEntry(entry)) continue;
|
|
187
|
-
if (!isSessionApprovalEntry(entry.data)) continue;
|
|
188
|
-
|
|
189
|
-
if (entry.data.kind === "tool") {
|
|
190
|
-
approvedToolCalls.set(makeToolApprovalKey(
|
|
191
|
-
entry.data.serverName,
|
|
192
|
-
entry.data.originalToolName,
|
|
193
|
-
entry.data.definitionHash,
|
|
194
|
-
entry.data.argsHash,
|
|
195
|
-
), true);
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
state.consentManager.restoreDecision(entry.data.serverName, entry.data.decision === "allow");
|
|
200
|
-
}
|
|
201
|
-
}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
// session-recovery.ts
|
|
2
|
-
//
|
|
3
|
-
// Streamable HTTP session recovery.
|
|
4
|
-
//
|
|
5
|
-
// Per the MCP spec (Streamable HTTP transport):
|
|
6
|
-
// "When a client receives HTTP 404 in response to a request containing an
|
|
7
|
-
// Mcp-Session-Id, it MUST start a new session by sending a new
|
|
8
|
-
// InitializeRequest without a session ID attached."
|
|
9
|
-
//
|
|
10
|
-
// A 404 for a request that carried a session ID is therefore the spec's own
|
|
11
|
-
// definition of "this session no longer exists" (e.g. the remote server
|
|
12
|
-
// process restarted and lost its in-memory session table). Because the spec
|
|
13
|
-
// requires the server to reject the request *before* processing it, retrying
|
|
14
|
-
// the same call against a freshly initialized session cannot double-execute
|
|
15
|
-
// the original request.
|
|
16
|
-
//
|
|
17
|
-
// This module intentionally does NOT:
|
|
18
|
-
// - match broad error messages without a prior session id
|
|
19
|
-
// - match generic HTTP 400 responses, which are ambiguous and can mean
|
|
20
|
-
// many things other than "your session is gone"
|
|
21
|
-
// - treat generic -32000/ConnectionClosed errors as session expiry
|
|
22
|
-
// - treat AbortError/cancellation as a session failure
|
|
23
|
-
import { ProtocolError, SdkHttpError, UnauthorizedError } from "@modelcontextprotocol/client";
|
|
24
|
-
import { logger } from "./logger.ts";
|
|
25
|
-
import { throwIfAborted } from "./abort.ts";
|
|
26
|
-
import { isServerDisabled, type McpConfig } from "./types.ts";
|
|
27
|
-
import { supportsOAuth } from "./mcp-auth-flow.ts";
|
|
28
|
-
import { invalidateAuthEntryCache } from "./mcp-auth.ts";
|
|
29
|
-
import type { McpServerManager, ServerConnection } from "./server-manager.ts";
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* True when `err` is a stale Streamable HTTP session signal for a request
|
|
33
|
-
* sent while carrying an `Mcp-Session-Id`: the spec's 404 transport
|
|
34
|
-
* response, or the narrowly-known `-32000 Server not initialized` protocol
|
|
35
|
-
* gate response some servers emit before dispatching to a handler.
|
|
36
|
-
*
|
|
37
|
-
* `hadSessionId` must reflect the transport's session id from *before* the
|
|
38
|
-
* call that produced `err` was made. Callers must capture it before the call
|
|
39
|
-
* rather than rely on catch-time transport state.
|
|
40
|
-
*/
|
|
41
|
-
const CONNECTION_CLOSED_PROTOCOL_CODE = -32000;
|
|
42
|
-
const SERVER_NOT_INITIALIZED_MCP_MESSAGES = new Set([
|
|
43
|
-
"Server not initialized",
|
|
44
|
-
"Bad Request: Server not initialized",
|
|
45
|
-
]);
|
|
46
|
-
|
|
47
|
-
export function isTerminatedSession(err: unknown, hadSessionId: boolean): boolean {
|
|
48
|
-
if (!hadSessionId) return false;
|
|
49
|
-
if (err instanceof SdkHttpError) {
|
|
50
|
-
return err.status === 404
|
|
51
|
-
|| (err.status === 400
|
|
52
|
-
&& /"code"\s*:\s*-32000/.test(err.message)
|
|
53
|
-
&& /"message"\s*:\s*"Bad Request: Server not initialized"/.test(err.message));
|
|
54
|
-
}
|
|
55
|
-
return err instanceof ProtocolError
|
|
56
|
-
&& err.code === CONNECTION_CLOSED_PROTOCOL_CODE
|
|
57
|
-
&& SERVER_NOT_INITIALIZED_MCP_MESSAGES.has(err.message);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function hasSessionId(connection: ServerConnection): boolean {
|
|
61
|
-
// Only StreamableHTTPClientTransport exposes `sessionId`; stdio/SSE
|
|
62
|
-
// transports (and test doubles that omit `transport` entirely) simply
|
|
63
|
-
// read as `undefined` here.
|
|
64
|
-
const transport = connection.transport as { sessionId?: string } | undefined;
|
|
65
|
-
return transport?.sessionId != null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export class SessionRecoveryAuthRequiredError extends Error {
|
|
69
|
-
constructor(readonly serverName: string, readonly authMessage?: string) {
|
|
70
|
-
super(authMessage ?? `MCP server "${serverName}" requires OAuth authentication after reconnect.`);
|
|
71
|
-
this.name = "SessionRecoveryAuthRequiredError";
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface SessionRecoveryDeps {
|
|
76
|
-
manager: McpServerManager;
|
|
77
|
-
config: McpConfig;
|
|
78
|
-
signal?: AbortSignal;
|
|
79
|
-
onNeedsAuth?: (serverName: string) => Promise<ServerConnection | undefined>;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Runs `fn` against the current connection for `serverName`. If it fails
|
|
84
|
-
* with a terminated Streamable HTTP session (see `isTerminatedSession`),
|
|
85
|
-
* reconnects exactly once via `McpServerManager.reconnect` (single-flight,
|
|
86
|
-
* identity-guarded — see server-manager.ts) and retries `fn` exactly once
|
|
87
|
-
* against the fresh connection.
|
|
88
|
-
*
|
|
89
|
-
* Any other failure — including a second failure after reconnecting, or the
|
|
90
|
-
* server having been removed from config in the meantime — propagates
|
|
91
|
-
* unchanged through the caller's existing error handling.
|
|
92
|
-
*/
|
|
93
|
-
export async function withSessionRecovery<T>(
|
|
94
|
-
deps: SessionRecoveryDeps,
|
|
95
|
-
serverName: string,
|
|
96
|
-
fn: (conn: ServerConnection) => Promise<T>,
|
|
97
|
-
): Promise<T> {
|
|
98
|
-
if (isServerDisabled(deps.config.mcpServers[serverName])) {
|
|
99
|
-
throw new Error(`MCP server "${serverName}" is disabled`);
|
|
100
|
-
}
|
|
101
|
-
const connection = deps.manager.getConnection(serverName);
|
|
102
|
-
if (!connection) {
|
|
103
|
-
throw new Error(`Server "${serverName}" is not connected`);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const hadSessionId = hasSessionId(connection);
|
|
107
|
-
|
|
108
|
-
try {
|
|
109
|
-
return await fn(connection);
|
|
110
|
-
} catch (err) {
|
|
111
|
-
const definition = deps.config.mcpServers[serverName];
|
|
112
|
-
if (definition && supportsOAuth(definition)
|
|
113
|
-
&& (err instanceof UnauthorizedError || (err instanceof SdkHttpError && err.status === 401))) {
|
|
114
|
-
invalidateAuthEntryCache(serverName);
|
|
115
|
-
}
|
|
116
|
-
if (!isTerminatedSession(err, hadSessionId)) {
|
|
117
|
-
throw err;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Re-read the live definition rather than reusing the stale
|
|
121
|
-
// connection's definition, in case config changed since connect. If the
|
|
122
|
-
// server was removed from config in the meantime there is nothing to
|
|
123
|
-
// reconnect to, so surface the original error.
|
|
124
|
-
if (!definition) {
|
|
125
|
-
throw err;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
throwIfAborted(deps.signal);
|
|
129
|
-
logger.debug(`MCP session for "${serverName}" expired; reconnecting`, {
|
|
130
|
-
server: serverName,
|
|
131
|
-
});
|
|
132
|
-
let freshConnection = deps.signal
|
|
133
|
-
? await deps.manager.reconnect(serverName, definition, connection, deps.signal)
|
|
134
|
-
: await deps.manager.reconnect(serverName, definition, connection);
|
|
135
|
-
throwIfAborted(deps.signal);
|
|
136
|
-
|
|
137
|
-
if (freshConnection.status === "needs-auth") {
|
|
138
|
-
freshConnection = await deps.onNeedsAuth?.(serverName) ?? freshConnection;
|
|
139
|
-
throwIfAborted(deps.signal);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (freshConnection.status === "needs-auth") {
|
|
143
|
-
throw new SessionRecoveryAuthRequiredError(serverName);
|
|
144
|
-
}
|
|
145
|
-
if (freshConnection.status !== "connected") {
|
|
146
|
-
throw err;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
try {
|
|
150
|
-
deps.manager.publishMetadataChanged(serverName, freshConnection, "session-reconnect");
|
|
151
|
-
} catch (publicationError) {
|
|
152
|
-
const message = publicationError instanceof Error ? publicationError.message : String(publicationError);
|
|
153
|
-
logger.debug(`MCP metadata publication after reconnect failed for "${serverName}": ${message}`);
|
|
154
|
-
}
|
|
155
|
-
throwIfAborted(deps.signal);
|
|
156
|
-
return fn(freshConnection);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: mcp-scripting
|
|
3
|
-
description: Write mcpScript JavaScript for discovering, inspecting, and calling MCP tools.
|
|
4
|
-
disable-model-invocation: true
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# MCP scripting
|
|
8
|
-
|
|
9
|
-
For multi-call MCP work, write ordinary JavaScript with loops, filtering, chaining, fan-out, or other logic between calls. Run that source with `mcpScript`; it is the primary MCP orchestration surface. For a single MCP search, describe, status check, auth action, or tool call, use `mcp` instead.
|
|
10
|
-
|
|
11
|
-
Write the source naturally, then pass it as `mcpScript`'s `code` argument:
|
|
12
|
-
|
|
13
|
-
```js
|
|
14
|
-
const { items } = await tools.search({ query: "search issues", server: "github" });
|
|
15
|
-
const candidate = items[0];
|
|
16
|
-
if (!candidate) return { error: "No matching tool" };
|
|
17
|
-
|
|
18
|
-
const details = await tools.describe({ path: candidate.path });
|
|
19
|
-
if (details.error) return details;
|
|
20
|
-
|
|
21
|
-
const result = await tools.call(details.path, { query: "is:open label:bug" });
|
|
22
|
-
if (!result.ok) return result;
|
|
23
|
-
emit({ tool: details.path, completed: true });
|
|
24
|
-
return result.data;
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Workflow
|
|
28
|
-
|
|
29
|
-
1. Find candidate tools with `await tools.search({ query, server?, limit?, offset? })`.
|
|
30
|
-
2. Inspect the exact returned path with `await tools.describe({ path })`.
|
|
31
|
-
3. Call it with `tools.call(path, args)`.
|
|
32
|
-
|
|
33
|
-
Descriptors include `inputTypeScript` (a compact parameter shape, or formatted schema fallback). When a compact shape would omit documented fields, `inputGuidance` preserves their descriptions, including formats and units. Undocumented inputs stay compact.
|
|
34
|
-
|
|
35
|
-
When advertised by the server, `outputSchema` is the original JSON Schema and `outputSchemaTarget` is `"data.structuredContent"`: it describes structured output inside the successful `{ ok: true, data }` call envelope, not the envelope itself. Inspect this schema for result fields and constraints; unsupported constructs remain intact rather than being presented as an approximate TypeScript type. Both output fields are absent when no output schema is advertised. Discovery and cache refresh preserve these optional schemas; old cache entries gain them on the next server metadata refresh. Ordinary search results do not include schemas.
|
|
36
|
-
|
|
37
|
-
Calls resolve to `{ ok: true, data }` or `{ ok: false, error }`; handle failed calls instead of expecting them to stop the script. `emit(value)` adds user-visible output before the final `return` value. `console` output is captured too.
|
|
38
|
-
|
|
39
|
-
With `settings.jev.scriptEvaluation` enabled, call `jev.evaluate({ state, questions, sources })`; declare every MCP server represented in state. The host conservatively taints the whole script with every server-attributed call result or error, so every declared or observed source must remain enabled and allowed for later direct evaluations and semantic searches. Semantic search requires `searchMode: "semantic"`. Direct and semantic attempts share count, UTF-8 request-byte, deadline, and provider-reported token budgets. Scores do not bypass `tools.call` approval. Action loops must use fresh observations, positive step/time/evaluation budgets, validated operations and targets, and stop on uncertainty, staleness, no progress, no match, or missing information. Do not retry a possibly side-effectful action.
|
|
40
|
-
|
|
41
|
-
On success, `data` may still be the raw MCP `CallToolResult` envelope rather than the domain payload. Check `data.structuredContent` for the fields your script expects; if they are absent, inspect text blocks in `data.content` too (some servers emit newline-delimited JSON). If neither shape is understood, return or emit the envelope for inspection instead of coercing it to `[]` or `{}`.
|
|
42
|
-
|
|
43
|
-
`tools` is a non-enumerable proxy: `Object.keys(tools)` throws. Always use `tools.search` for discovery. When a known flat path is a valid identifier, direct calls such as `tools.github_search_issues(args)` are supported; use bracket syntax for hyphenated names: `tools["server_tool-name"](args)`. `search`, `call`, `describe`, and promise/serialization names (`then`, `catch`, `finally`, `toJSON`, `toString`, `valueOf`) are reserved on the proxy; if a flat path collides with one, call it via `tools.call("exact-path", args)`.
|
|
44
|
-
|
|
45
|
-
Successful intermediate data bypasses presentation truncation, summarization, and artifact spill until the script emits, logs, or returns it. A fixed, non-configurable **16 MiB cumulative UTF-8 JSON transfer budget per script** covers sequential and parallel calls. A result exceeding the remaining budget returns `{ ok: false, error: { code: "intermediate_result_too_large", message } }` with a failed call trace; rejected calls do not consume the budget, but upstream side effects may already have happened. Resource calls retain transformed text or `"(empty resource)"`; emitted, logged, or returned output and ordinary MCP calls remain guarded. This is not a memory limit: responses, serialization, copies, concurrency, and script values still allocate memory, and synchronous serialization can delay deadline handling.
|
|
46
|
-
|
|
47
|
-
`tools.search` and `tools.describe` are asynchronous and must be awaited. The default script timeout is 30 seconds; the worker is terminated at the deadline, including for infinite loops. Every invocation still uses normal lazy connection, authentication, and approval gates. Result details contain a concise `calls` trace with every search, describe, and call operation; each entry includes its query or path, outcome, and duration.
|
|
48
|
-
|
|
49
|
-
Use plain JavaScript loops and Promise utilities for composition. Fluent helpers such as `tools.find(...).one()`, `tools.parallel(...)`, and `tools.retry(...)` are not provided.
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type { ConsentManager } from "./consent-manager.ts";
|
|
3
|
-
import type { McpLifecycleManager } from "./lifecycle.ts";
|
|
4
|
-
import type { McpServerManager } from "./server-manager.ts";
|
|
5
|
-
import type { AuthStorageOptions } from "./mcp-auth.ts";
|
|
6
|
-
import type { ServerDefinition, ToolMetadata, PromptMetadata, McpConfig, UiSessionMessages, UiStreamSummary, McpStatusEventBus, UiServerHandle } from "./types.ts";
|
|
7
|
-
import type { UiResourceHandler } from "./ui-resource-handler.ts";
|
|
8
|
-
import type { McpRuntimeOwner } from "./runtime-owner.ts";
|
|
9
|
-
import type { McpOAuthRuntime } from "./mcp-auth-flow.ts";
|
|
10
|
-
import type { SessionApprovalWriter } from "./session-approvals.ts";
|
|
11
|
-
|
|
12
|
-
export interface CompletedUiSession {
|
|
13
|
-
serverName: string;
|
|
14
|
-
toolName: string;
|
|
15
|
-
completedAt: Date;
|
|
16
|
-
reason: string;
|
|
17
|
-
messages: UiSessionMessages;
|
|
18
|
-
stream?: UiStreamSummary;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type SendMessageFn = (
|
|
22
|
-
message: {
|
|
23
|
-
customType: string;
|
|
24
|
-
content: Array<{ type: "text"; text: string }>;
|
|
25
|
-
display?: string;
|
|
26
|
-
details?: unknown;
|
|
27
|
-
},
|
|
28
|
-
options?: { triggerTurn?: boolean }
|
|
29
|
-
) => void;
|
|
30
|
-
|
|
31
|
-
export interface McpExtensionState {
|
|
32
|
-
owner: McpRuntimeOwner;
|
|
33
|
-
manager: McpServerManager;
|
|
34
|
-
lifecycle: McpLifecycleManager;
|
|
35
|
-
toolMetadata: Map<string, ToolMetadata[]>;
|
|
36
|
-
/** Number of tools currently registered directly with Pi, by server. */
|
|
37
|
-
directToolCounts: Map<string, number>;
|
|
38
|
-
/** Resource counts retained separately because tool metadata includes resource tools. */
|
|
39
|
-
resourceCounts: Map<string, number>;
|
|
40
|
-
promptMetadata: Map<string, PromptMetadata[]>;
|
|
41
|
-
/** Servers whose prompt inventory came from successful live discovery. */
|
|
42
|
-
promptMetadataLive: Set<string>;
|
|
43
|
-
serverInstructions: Map<string, string>;
|
|
44
|
-
config: McpConfig;
|
|
45
|
-
programmaticConfig?: boolean;
|
|
46
|
-
/** Install validations must not publish durable cache entries before config persistence. */
|
|
47
|
-
provisionalInstalls?: Set<string>;
|
|
48
|
-
oauthRuntime: McpOAuthRuntime;
|
|
49
|
-
authStorageOptions: AuthStorageOptions;
|
|
50
|
-
failureTracker: Map<string, number>;
|
|
51
|
-
failureMessages: Map<string, string>;
|
|
52
|
-
/** Session-only approvals keyed by server, tool definition, and arguments. */
|
|
53
|
-
approvedToolCalls: Map<string, true>;
|
|
54
|
-
/** Runtime-only server grants. Never persisted or restored from session entries. */
|
|
55
|
-
approvedServers?: Map<string, { definition: ServerDefinition; hash: string }>;
|
|
56
|
-
/** Optional active-session sink for approval decisions. */
|
|
57
|
-
persistSessionApproval?: SessionApprovalWriter;
|
|
58
|
-
/** Session manager used to reject stale session-tree contexts. */
|
|
59
|
-
sessionManager?: ExtensionContext["sessionManager"];
|
|
60
|
-
/** Shared event bus used by permission extensions to broker MCP approvals. */
|
|
61
|
-
approvalEvents?: ExtensionAPI["events"];
|
|
62
|
-
uiResourceHandler: UiResourceHandler;
|
|
63
|
-
consentManager: ConsentManager;
|
|
64
|
-
uiServer: UiServerHandle | null;
|
|
65
|
-
completedUiSessions: CompletedUiSession[];
|
|
66
|
-
openBrowser: (url: string) => Promise<void>;
|
|
67
|
-
ui?: ExtensionContext["ui"];
|
|
68
|
-
sendMessage?: SendMessageFn;
|
|
69
|
-
onToolMetadataUpdated?: (serverName: string, reason: string) => void | Promise<void>;
|
|
70
|
-
statusEvents?: McpStatusEventBus;
|
|
71
|
-
}
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { abortable } from "./abort.ts";
|
|
3
|
-
import { combineAbortSignals } from "./runtime-owner.ts";
|
|
4
|
-
import type { McpExtensionState } from "./state.ts";
|
|
5
|
-
import { getServerApprovalIdentity, getToolApprovalIdentity, rememberToolApproval } from "./session-approvals.ts";
|
|
6
|
-
import {
|
|
7
|
-
getToolNameCandidates,
|
|
8
|
-
matchesToolPattern,
|
|
9
|
-
resolveToolPrefix,
|
|
10
|
-
MCP_TOOL_APPROVAL_REQUEST_EVENT,
|
|
11
|
-
type McpConfig,
|
|
12
|
-
type McpToolApprovalDecision,
|
|
13
|
-
type McpToolApprovalHandler,
|
|
14
|
-
type McpToolApprovalOrigin,
|
|
15
|
-
type McpToolApprovalRequest,
|
|
16
|
-
type ToolMetadata,
|
|
17
|
-
} from "./types.ts";
|
|
18
|
-
import { sanitizeTerminalText } from "./utils.ts";
|
|
19
|
-
|
|
20
|
-
export type ToolCallApprovalResult =
|
|
21
|
-
| { ok: true }
|
|
22
|
-
| { ok: false; reason: "denied" | "approval_required_headless" };
|
|
23
|
-
|
|
24
|
-
export function isToolCallApprovalRequired(
|
|
25
|
-
config: McpConfig,
|
|
26
|
-
serverName: string,
|
|
27
|
-
toolMeta: Pick<ToolMetadata, "originalName">,
|
|
28
|
-
toolMetadata?: ReadonlyMap<string, readonly ToolMetadata[]>,
|
|
29
|
-
): boolean {
|
|
30
|
-
const definition = config.mcpServers[serverName];
|
|
31
|
-
const serverApproval = definition?.approveTools;
|
|
32
|
-
const approval = serverApproval !== undefined ? serverApproval : config.settings?.approveTools;
|
|
33
|
-
|
|
34
|
-
if (approval === true) return true;
|
|
35
|
-
if (!Array.isArray(approval) || approval.length === 0) return false;
|
|
36
|
-
|
|
37
|
-
const prefix = resolveToolPrefix(definition, config.settings?.toolPrefix);
|
|
38
|
-
const currentCandidates = getToolNameCandidates(toolMeta.originalName, serverName, prefix, false);
|
|
39
|
-
if (serverApproval !== undefined) {
|
|
40
|
-
if (matchesToolPattern(currentCandidates, approval)) return true;
|
|
41
|
-
if (!toolMetadata) return matchesToolPattern(getToolNameCandidates(toolMeta.originalName, serverName, prefix), approval);
|
|
42
|
-
const legacyCandidates = getToolNameCandidates(toolMeta.originalName, serverName, prefix);
|
|
43
|
-
const legacyEmittedName = [...currentCandidates].find(candidate => candidate !== toolMeta.originalName)?.replace(/-/g, "_");
|
|
44
|
-
if (legacyEmittedName) legacyCandidates.add(legacyEmittedName);
|
|
45
|
-
for (const candidate of currentCandidates) legacyCandidates.delete(candidate);
|
|
46
|
-
const otherCurrentCandidates = new Set<string>();
|
|
47
|
-
for (const tool of toolMetadata.get(serverName) ?? []) {
|
|
48
|
-
for (const candidate of getToolNameCandidates(tool.originalName, serverName, prefix, false)) {
|
|
49
|
-
otherCurrentCandidates.add(candidate);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
for (const candidate of currentCandidates) otherCurrentCandidates.delete(candidate);
|
|
53
|
-
return approval.some(pattern =>
|
|
54
|
-
matchesToolPattern(legacyCandidates, [pattern])
|
|
55
|
-
&& !matchesToolPattern(otherCurrentCandidates, [pattern]),
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (matchesToolPattern(currentCandidates, approval)) return true;
|
|
61
|
-
if (!toolMetadata) return false;
|
|
62
|
-
|
|
63
|
-
const legacyCandidates = getToolNameCandidates(toolMeta.originalName, serverName, prefix);
|
|
64
|
-
const legacyEmittedName = [...currentCandidates].find(candidate => candidate !== toolMeta.originalName)?.replace(/-/g, "_");
|
|
65
|
-
if (legacyEmittedName) legacyCandidates.add(legacyEmittedName);
|
|
66
|
-
for (const candidate of currentCandidates) legacyCandidates.delete(candidate);
|
|
67
|
-
const otherCurrentCandidates = new Set<string>();
|
|
68
|
-
for (const [name, metadata] of toolMetadata) {
|
|
69
|
-
const otherPrefix = resolveToolPrefix(config.mcpServers[name], config.settings?.toolPrefix);
|
|
70
|
-
for (const tool of metadata) {
|
|
71
|
-
for (const candidate of getToolNameCandidates(tool.originalName, name, otherPrefix, false)) {
|
|
72
|
-
otherCurrentCandidates.add(candidate);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
for (const candidate of currentCandidates) otherCurrentCandidates.delete(candidate);
|
|
77
|
-
|
|
78
|
-
return approval.some(pattern =>
|
|
79
|
-
matchesToolPattern(legacyCandidates, [pattern])
|
|
80
|
-
&& !matchesToolPattern(otherCurrentCandidates, [pattern]),
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function isMcpToolApprovalDecision(value: unknown): value is McpToolApprovalDecision {
|
|
85
|
-
return value === "allow_once"
|
|
86
|
-
|| value === "allow_for_session"
|
|
87
|
-
|| value === "deny"
|
|
88
|
-
|| value === "abstain";
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async function requestBrokerApproval(
|
|
92
|
-
state: McpExtensionState,
|
|
93
|
-
serverName: string,
|
|
94
|
-
toolMeta: ToolMetadata,
|
|
95
|
-
args: Record<string, unknown> | undefined,
|
|
96
|
-
origin: McpToolApprovalOrigin,
|
|
97
|
-
signal?: AbortSignal,
|
|
98
|
-
): Promise<McpToolApprovalDecision> {
|
|
99
|
-
if (!state.approvalEvents) return "abstain";
|
|
100
|
-
|
|
101
|
-
let acceptingClaim = true;
|
|
102
|
-
let handler: McpToolApprovalHandler | undefined;
|
|
103
|
-
const request: McpToolApprovalRequest = {
|
|
104
|
-
requestId: randomUUID(),
|
|
105
|
-
serverName,
|
|
106
|
-
originalToolName: toolMeta.originalName,
|
|
107
|
-
prefixedToolName: toolMeta.name,
|
|
108
|
-
args: args ?? {},
|
|
109
|
-
origin,
|
|
110
|
-
...(signal !== undefined ? { signal } : {}),
|
|
111
|
-
claim(candidate: McpToolApprovalHandler) {
|
|
112
|
-
if (!acceptingClaim || handler) return false;
|
|
113
|
-
handler = candidate;
|
|
114
|
-
return true;
|
|
115
|
-
},
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
state.approvalEvents.emit(MCP_TOOL_APPROVAL_REQUEST_EVENT, request);
|
|
119
|
-
acceptingClaim = false;
|
|
120
|
-
if (!handler) return "abstain";
|
|
121
|
-
|
|
122
|
-
try {
|
|
123
|
-
const decision = await abortable(Promise.resolve().then(handler), signal);
|
|
124
|
-
return isMcpToolApprovalDecision(decision) ? decision : "deny";
|
|
125
|
-
} catch (error) {
|
|
126
|
-
if (signal?.aborted) throw error;
|
|
127
|
-
return "deny";
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export async function ensureToolCallApproved(
|
|
132
|
-
state: McpExtensionState,
|
|
133
|
-
serverName: string,
|
|
134
|
-
toolMeta: ToolMetadata,
|
|
135
|
-
args: Record<string, unknown> | undefined,
|
|
136
|
-
signal?: AbortSignal,
|
|
137
|
-
origin: McpToolApprovalOrigin = toolMeta.resourceUri ? "resource" : "proxy",
|
|
138
|
-
approvalMetadata?: ReadonlyMap<string, readonly ToolMetadata[]>,
|
|
139
|
-
): Promise<ToolCallApprovalResult> {
|
|
140
|
-
const ownedSignal = combineAbortSignals(state.owner?.signal, signal);
|
|
141
|
-
const approvedServers = state.approvedServers ??= new Map();
|
|
142
|
-
const serverIdentity = getServerApprovalIdentity(state, serverName);
|
|
143
|
-
const brokerDecision = await requestBrokerApproval(state, serverName, toolMeta, args, origin, signal);
|
|
144
|
-
if (brokerDecision === "allow_once") return { ok: true };
|
|
145
|
-
if (brokerDecision === "allow_for_session") {
|
|
146
|
-
rememberToolApproval(state, serverName, toolMeta, args);
|
|
147
|
-
return { ok: true };
|
|
148
|
-
}
|
|
149
|
-
if (brokerDecision === "deny") return { ok: false, reason: "denied" };
|
|
150
|
-
|
|
151
|
-
const serverGrant = approvedServers.get(serverName);
|
|
152
|
-
const liveServerIdentity = getServerApprovalIdentity(state, serverName);
|
|
153
|
-
if (serverGrant && state.approvedServers === approvedServers
|
|
154
|
-
&& serverGrant.definition === liveServerIdentity?.definition && serverGrant.hash === liveServerIdentity?.hash) {
|
|
155
|
-
ownedSignal?.throwIfAborted();
|
|
156
|
-
return { ok: true };
|
|
157
|
-
}
|
|
158
|
-
approvedServers.delete(serverName);
|
|
159
|
-
|
|
160
|
-
const { cacheKey } = getToolApprovalIdentity(serverName, toolMeta, args);
|
|
161
|
-
const approvedToolCalls = state.approvedToolCalls ??= new Map<string, true>();
|
|
162
|
-
if (approvedToolCalls.has(cacheKey)) {
|
|
163
|
-
return { ok: true };
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (!isToolCallApprovalRequired(state.config, serverName, toolMeta, approvalMetadata ?? state.toolMetadata)) {
|
|
167
|
-
return { ok: true };
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (!state.ui) {
|
|
171
|
-
return { ok: false, reason: "approval_required_headless" };
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const json = JSON.stringify(args ?? {}, null, 2);
|
|
175
|
-
const sanitized = sanitizeTerminalText(json);
|
|
176
|
-
const preview = sanitized.length > 500 ? `${sanitized.slice(0, 500)}...` : sanitized;
|
|
177
|
-
const title = `MCP: ${sanitizeTerminalText(serverName)} wants to run ${sanitizeTerminalText(toolMeta.originalName)}`;
|
|
178
|
-
const serverScope = "Allow server for this session permits all tools and arguments on this server until reload or session/branch change. Other security and UI consent checks still apply.";
|
|
179
|
-
const decision = await abortable(
|
|
180
|
-
state.ui.select(
|
|
181
|
-
`${title}\n\nArguments:\n${preview}\n\n${serverScope}`,
|
|
182
|
-
["Allow once", "Allow for session", "Allow server for this session", "Deny"],
|
|
183
|
-
),
|
|
184
|
-
ownedSignal,
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
if (decision === "Allow server for this session") {
|
|
188
|
-
ownedSignal?.throwIfAborted();
|
|
189
|
-
const currentIdentity = getServerApprovalIdentity(state, serverName);
|
|
190
|
-
if (!serverIdentity || state.approvedServers !== approvedServers
|
|
191
|
-
|| currentIdentity?.definition !== serverIdentity.definition || currentIdentity.hash !== serverIdentity.hash) {
|
|
192
|
-
return { ok: false, reason: "denied" };
|
|
193
|
-
}
|
|
194
|
-
approvedServers.set(serverName, serverIdentity);
|
|
195
|
-
return { ok: true };
|
|
196
|
-
}
|
|
197
|
-
if (decision === "Allow once") {
|
|
198
|
-
return { ok: true };
|
|
199
|
-
}
|
|
200
|
-
if (decision === "Allow for session") {
|
|
201
|
-
rememberToolApproval(state, serverName, toolMeta, args);
|
|
202
|
-
return { ok: true };
|
|
203
|
-
}
|
|
204
|
-
return { ok: false, reason: "denied" };
|
|
205
|
-
}
|