@bastani/atomic 0.10.1 → 0.10.2-alpha.1
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 +27 -0
- package/dist/builtin/intercom/CHANGELOG.md +6 -0
- package/dist/builtin/intercom/broker/watchdog.ts +4 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +16 -0
- package/dist/builtin/subagents/README.md +2 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/skills/subagent/SKILL.md +3 -3
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +269 -144
- package/dist/builtin/web-access/CHANGELOG.md +7 -0
- package/dist/builtin/web-access/index.bundle.mjs +9 -5
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +1 -14
- package/dist/cli/list-models.js.map +1 -1
- package/dist/core/agent-session-export.d.ts.map +1 -1
- package/dist/core/agent-session-export.js +13 -9
- package/dist/core/agent-session-export.js.map +1 -1
- package/dist/core/agent-session-message-queue.d.ts.map +1 -1
- package/dist/core/agent-session-message-queue.js +6 -3
- package/dist/core/agent-session-message-queue.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +3 -0
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-nested-tools.d.ts.map +1 -1
- package/dist/core/agent-session-nested-tools.js +2 -1
- package/dist/core/agent-session-nested-tools.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +12 -0
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-state.d.ts +6 -0
- package/dist/core/agent-session-state.d.ts.map +1 -1
- package/dist/core/agent-session-state.js +71 -4
- package/dist/core/agent-session-state.js.map +1 -1
- package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
- package/dist/core/agent-session-tool-hooks.js +9 -1
- package/dist/core/agent-session-tool-hooks.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +2 -0
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/agent-session.d.ts +3 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +7 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/cache-stats.d.ts +15 -0
- package/dist/core/cache-stats.d.ts.map +1 -1
- package/dist/core/cache-stats.js +40 -2
- package/dist/core/cache-stats.js.map +1 -1
- package/dist/core/diagnostic-writer.d.ts.map +1 -1
- package/dist/core/diagnostic-writer.js +2 -1
- package/dist/core/diagnostic-writer.js.map +1 -1
- package/dist/core/export-html/template.js +14 -4
- package/dist/core/extensions/context-types.d.ts +6 -0
- package/dist/core/extensions/context-types.d.ts.map +1 -1
- package/dist/core/extensions/context-types.js.map +1 -1
- package/dist/core/extensions/loader-api.d.ts.map +1 -1
- package/dist/core/extensions/loader-api.js +5 -2
- package/dist/core/extensions/loader-api.js.map +1 -1
- package/dist/core/queued-message-delivery.d.ts +100 -7
- package/dist/core/queued-message-delivery.d.ts.map +1 -1
- package/dist/core/queued-message-delivery.js +194 -4
- package/dist/core/queued-message-delivery.js.map +1 -1
- package/dist/core/resume-cache-checkpoint.d.ts +32 -0
- package/dist/core/resume-cache-checkpoint.d.ts.map +1 -0
- package/dist/core/resume-cache-checkpoint.js +67 -0
- package/dist/core/resume-cache-checkpoint.js.map +1 -0
- package/dist/core/sdk-types.d.ts +37 -0
- package/dist/core/sdk-types.d.ts.map +1 -1
- package/dist/core/sdk-types.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +57 -28
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +12 -3
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-entries.d.ts +13 -0
- package/dist/core/session-manager-entries.d.ts.map +1 -1
- package/dist/core/session-manager-entries.js +38 -6
- package/dist/core/session-manager-entries.js.map +1 -1
- package/dist/core/settings-lock-directory.d.ts.map +1 -1
- package/dist/core/settings-lock-directory.js +2 -1
- package/dist/core/settings-lock-directory.js.map +1 -1
- package/dist/core/storage/node-sqlite-file-gate.d.ts +173 -0
- package/dist/core/storage/node-sqlite-file-gate.d.ts.map +1 -0
- package/dist/core/storage/node-sqlite-file-gate.js +1033 -0
- package/dist/core/storage/node-sqlite-file-gate.js.map +1 -0
- package/dist/core/storage/node-sqlite-thread.d.ts +33 -6
- package/dist/core/storage/node-sqlite-thread.d.ts.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +72 -2
- package/dist/core/storage/node-sqlite-thread.js.map +1 -1
- package/dist/core/storage/node-sqlite.d.ts.map +1 -1
- package/dist/core/storage/node-sqlite.js +216 -15
- package/dist/core/storage/node-sqlite.js.map +1 -1
- package/dist/core/storage/session/entry-structure.d.ts.map +1 -1
- package/dist/core/storage/session/entry-structure.js +39 -2
- package/dist/core/storage/session/entry-structure.js.map +1 -1
- package/dist/core/storage/session/session-resume.d.ts.map +1 -1
- package/dist/core/storage/session/session-resume.js +1 -0
- package/dist/core/storage/session/session-resume.js.map +1 -1
- package/dist/core/storage/session/session-search-index.d.ts.map +1 -1
- package/dist/core/storage/session/session-search-index.js +56 -9
- package/dist/core/storage/session/session-search-index.js.map +1 -1
- package/dist/core/storage/statement-sequence.d.ts +36 -0
- package/dist/core/storage/statement-sequence.d.ts.map +1 -0
- package/dist/core/storage/statement-sequence.js +22 -0
- package/dist/core/storage/statement-sequence.js.map +1 -0
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +13 -4
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/heartbeat-notice.d.ts.map +1 -1
- package/dist/core/tasks/heartbeat-notice.js +2 -1
- package/dist/core/tasks/heartbeat-notice.js.map +1 -1
- package/dist/core/tool-loadout.d.ts +4 -2
- package/dist/core/tool-loadout.d.ts.map +1 -1
- package/dist/core/tool-loadout.js +27 -5
- package/dist/core/tool-loadout.js.map +1 -1
- package/dist/core/tools/history-regex-worker.d.ts.map +1 -1
- package/dist/core/tools/history-regex-worker.js +2 -1
- package/dist/core/tools/history-regex-worker.js.map +1 -1
- package/dist/core/tools/powershell.d.ts +22 -22
- package/dist/core/tools/sqlite-selector-connection.d.ts.map +1 -1
- package/dist/core/tools/sqlite-selector-connection.js +7 -0
- package/dist/core/tools/sqlite-selector-connection.js.map +1 -1
- package/dist/core/transformed-system-prompt.d.ts +92 -0
- package/dist/core/transformed-system-prompt.d.ts.map +1 -0
- package/dist/core/transformed-system-prompt.js +240 -0
- package/dist/core/transformed-system-prompt.js.map +1 -0
- package/dist/extensions/codemode/execute.js +1 -1
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/codemode/tool.d.ts.map +1 -1
- package/dist/extensions/codemode/tool.js +16 -3
- package/dist/extensions/codemode/tool.js.map +1 -1
- package/dist/extensions/llama/ui.d.ts.map +1 -1
- package/dist/extensions/llama/ui.js +13 -8
- package/dist/extensions/llama/ui.js.map +1 -1
- package/dist/extensions/mcp/config.d.ts +2 -0
- package/dist/extensions/mcp/config.d.ts.map +1 -1
- package/dist/extensions/mcp/config.js +5 -0
- package/dist/extensions/mcp/config.js.map +1 -1
- package/dist/extensions/mcp/index.d.ts +4 -0
- package/dist/extensions/mcp/index.d.ts.map +1 -1
- package/dist/extensions/mcp/index.js +289 -64
- package/dist/extensions/mcp/index.js.map +1 -1
- package/dist/extensions/mcp/runtime.d.ts +1 -1
- package/dist/extensions/mcp/runtime.d.ts.map +1 -1
- package/dist/extensions/mcp/runtime.js +2 -2
- package/dist/extensions/mcp/runtime.js.map +1 -1
- package/dist/extensions/mcp/tool-records.d.ts +58 -0
- package/dist/extensions/mcp/tool-records.d.ts.map +1 -0
- package/dist/extensions/mcp/tool-records.js +129 -0
- package/dist/extensions/mcp/tool-records.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/agent-panel.d.ts +2 -4
- package/dist/modes/interactive/components/agent-panel.d.ts.map +1 -1
- package/dist/modes/interactive/components/agent-panel.js +65 -80
- package/dist/modes/interactive/components/agent-panel.js.map +1 -1
- package/dist/modes/interactive/components/compaction-boundary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-boundary-message.js +3 -3
- package/dist/modes/interactive/components/compaction-boundary-message.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +35 -28
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/notice-line.d.ts +16 -0
- package/dist/modes/interactive/components/notice-line.d.ts.map +1 -1
- package/dist/modes/interactive/components/notice-line.js +7 -0
- package/dist/modes/interactive/components/notice-line.js.map +1 -1
- package/dist/modes/interactive/components/prompt-slot.d.ts +1 -0
- package/dist/modes/interactive/components/prompt-slot.d.ts.map +1 -1
- package/dist/modes/interactive/components/prompt-slot.js +8 -4
- package/dist/modes/interactive/components/prompt-slot.js.map +1 -1
- package/dist/modes/interactive/components/task-board.d.ts +0 -1
- package/dist/modes/interactive/components/task-board.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-board.js +6 -14
- package/dist/modes/interactive/components/task-board.js.map +1 -1
- package/dist/modes/interactive/components/task-row.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-row.js +7 -6
- package/dist/modes/interactive/components/task-row.js.map +1 -1
- package/dist/modes/interactive/components/token-segment.d.ts +2 -1
- package/dist/modes/interactive/components/token-segment.d.ts.map +1 -1
- package/dist/modes/interactive/components/token-segment.js +2 -4
- package/dist/modes/interactive/components/token-segment.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector-content.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-content.js +2 -2
- package/dist/modes/interactive/components/tree-selector-content.js.map +1 -1
- package/dist/modes/interactive/components/working-run-meter.d.ts +0 -1
- package/dist/modes/interactive/components/working-run-meter.d.ts.map +1 -1
- package/dist/modes/interactive/components/working-run-meter.js +0 -9
- package/dist/modes/interactive/components/working-run-meter.js.map +1 -1
- package/dist/modes/interactive/extension-command-hold.d.ts +25 -0
- package/dist/modes/interactive/extension-command-hold.d.ts.map +1 -0
- package/dist/modes/interactive/extension-command-hold.js +45 -0
- package/dist/modes/interactive/extension-command-hold.js.map +1 -0
- package/dist/modes/interactive/interactive-agent-events.js +2 -1
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-context.js +18 -10
- package/dist/modes/interactive/interactive-extension-context.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-custom-ui.js +3 -0
- package/dist/modes/interactive/interactive-extension-custom-ui.js.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.js +54 -13
- package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.d.ts +6 -0
- package/dist/modes/interactive/interactive-model-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.js +15 -9
- package/dist/modes/interactive/interactive-model-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-prompt-turn.js +4 -0
- package/dist/modes/interactive/interactive-prompt-turn.js.map +1 -1
- package/dist/modes/interactive/interactive-queueing.d.ts +7 -0
- package/dist/modes/interactive/interactive-queueing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-queueing.js +47 -1
- package/dist/modes/interactive/interactive-queueing.js.map +1 -1
- package/dist/modes/interactive/interactive-session-routing.js +6 -0
- package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.js +165 -65
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
- package/dist/modes/interactive/screen-hold.d.ts +3 -0
- package/dist/modes/interactive/screen-hold.d.ts.map +1 -1
- package/dist/modes/interactive/screen-hold.js +9 -1
- package/dist/modes/interactive/screen-hold.js.map +1 -1
- package/dist/modes/interactive-engine/engine-health.d.ts +11 -3
- package/dist/modes/interactive-engine/engine-health.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-health.js +5 -4
- package/dist/modes/interactive-engine/engine-health.js.map +1 -1
- package/dist/modes/interactive-engine/engine-quit-intent.d.ts +7 -0
- package/dist/modes/interactive-engine/engine-quit-intent.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-quit-intent.js +19 -0
- package/dist/modes/interactive-engine/engine-quit-intent.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +18 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +56 -4
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/interactive-engine/protocol.d.ts +7 -0
- package/dist/modes/interactive-engine/protocol.d.ts.map +1 -1
- package/dist/modes/interactive-engine/protocol.js +1 -0
- package/dist/modes/interactive-engine/protocol.js.map +1 -1
- package/dist/modes/rpc/agent-panel-bridge.d.ts.map +1 -1
- package/dist/modes/rpc/agent-panel-bridge.js +0 -13
- package/dist/modes/rpc/agent-panel-bridge.js.map +1 -1
- package/dist/modes/rpc/rpc-client-process.d.ts +14 -1
- package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client-process.js +74 -10
- package/dist/modes/rpc/rpc-client-process.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +27 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +81 -5
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-event-buffer.d.ts +2 -0
- package/dist/modes/rpc/rpc-event-buffer.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-event-buffer.js +9 -0
- package/dist/modes/rpc/rpc-event-buffer.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +16 -3
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-session-binding.d.ts +7 -1
- package/dist/modes/rpc/rpc-session-binding.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-session-binding.js +10 -2
- package/dist/modes/rpc/rpc-session-binding.js.map +1 -1
- package/dist/utils/image-resize.d.ts.map +1 -1
- package/dist/utils/image-resize.js +2 -1
- package/dist/utils/image-resize.js.map +1 -1
- package/dist/utils/interactive-engine-bootstrap.d.ts +2 -0
- package/dist/utils/interactive-engine-bootstrap.d.ts.map +1 -1
- package/dist/utils/interactive-engine-bootstrap.js +1 -0
- package/dist/utils/interactive-engine-bootstrap.js.map +1 -1
- package/dist/utils/interactive-engine-env.d.ts +2 -0
- package/dist/utils/interactive-engine-env.d.ts.map +1 -1
- package/dist/utils/interactive-engine-env.js +1 -0
- package/dist/utils/interactive-engine-env.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +2 -0
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/token-count.d.ts +8 -0
- package/dist/utils/token-count.d.ts.map +1 -0
- package/dist/utils/token-count.js +25 -0
- package/dist/utils/token-count.js.map +1 -0
- package/dist/utils/worker-threads.d.ts +18 -0
- package/dist/utils/worker-threads.d.ts.map +1 -0
- package/dist/utils/worker-threads.js +28 -0
- package/dist/utils/worker-threads.js.map +1 -0
- package/docs/background-tasks.md +13 -12
- package/docs/compaction.md +2 -2
- package/docs/development.md +1 -1
- package/docs/extensions/api-reference.md +5 -3
- package/docs/extensions/events.md +2 -0
- package/docs/mcp-servers.md +1 -1
- package/docs/settings.md +2 -0
- package/docs/storage.md +3 -1
- package/docs/subagents.md +6 -2
- package/docs/usage.md +1 -1
- package/npm-shrinkwrap.json +49 -49
- package/package.json +6 -6
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { type AuthProvider, type CallToolResult, type ListResourcesResult, type ListResourceTemplatesResult, McpClient, type McpRequestOptions, type Tool as McpTool, type McpTransport, type ReadResourceResult, type Resource, type ResourceTemplate } from "./client/index.js";
|
|
7
7
|
import { type OAuthChallenge } from "./client/oauth/index.js";
|
|
8
|
-
import type
|
|
8
|
+
import { type McpServerEntry } from "./config.ts";
|
|
9
9
|
import type { McpServerLog } from "./log.ts";
|
|
10
10
|
import { type McpOAuthCredentialStore, type McpOAuthSettings } from "./oauth.ts";
|
|
11
11
|
import type { McpResourceServer } from "./resources.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/extensions/mcp/runtime.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,cAAc,EAEnB,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAEhC,SAAS,EAIT,KAAK,iBAAiB,EAEtB,KAAK,IAAI,IAAI,OAAO,EACpB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACb,KAAK,gBAAgB,EAGrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEN,KAAK,cAAc,EAEnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/extensions/mcp/runtime.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,cAAc,EAEnB,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAEhC,SAAS,EAIT,KAAK,iBAAiB,EAEtB,KAAK,IAAI,IAAI,OAAO,EACpB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACb,KAAK,gBAAgB,EAGrB,MAAM,mB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AAwF;IACxF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAwBrB;CACD"}
|
|
@@ -13,10 +13,10 @@ import { resolveConfigValueOrThrowAsync, resolveHeadersOrThrowAsync } from "../.
|
|
|
13
13
|
import { sliceTail } from "../../core/tools/truncate.js";
|
|
14
14
|
import { JSON_RPC_ERROR_CODES, McpAuthRequiredError, McpClient, McpError, McpHttpError, McpSessionExpiredError, StdioTransport, StreamableHttpTransport, } from "./client/index.js";
|
|
15
15
|
import { McpOAuthAuthorizationRequiredError, OAuthTemporarilyUnavailableError, } from "./client/oauth/index.js";
|
|
16
|
+
import { mcpRequestTimeoutMs } from "./config.js";
|
|
16
17
|
import { createMcpAuthProvider, } from "./oauth.js";
|
|
17
18
|
export { McpServerLog } from "./log.js";
|
|
18
19
|
export { McpOAuthCredentialStore, McpSignInCancelledError, signInMcpServer } from "./oauth.js";
|
|
19
|
-
const DEFAULT_TIMEOUT_SECONDS = 60;
|
|
20
20
|
const STDERR_TAIL_CHARS = 2_000;
|
|
21
21
|
/** Delays between attempts to connect to an HTTP server that failed with a transient error. */
|
|
22
22
|
const CONNECT_RETRY_DELAYS_MS = [250, 1_000];
|
|
@@ -219,7 +219,7 @@ export class McpServerConnection {
|
|
|
219
219
|
return this.shutdown.signal.aborted;
|
|
220
220
|
}
|
|
221
221
|
get timeoutMs() {
|
|
222
|
-
return (this.entry.config
|
|
222
|
+
return mcpRequestTimeoutMs(this.entry.config);
|
|
223
223
|
}
|
|
224
224
|
/** Server URL when the server authenticates with OAuth. */
|
|
225
225
|
get oauthUrl() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/extensions/mcp/runtime.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,E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O,CAAC;QACtC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC;QACtB,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,MAAM,kBAAkB,GAAG,IAAI,CAAC,kBAAkB,CAAC;QACnD,MAAM,qBAAqB,GAAG,IAAI,CAAC,qBAAqB,CAAC;QACzD,uFAAuF;QACvF,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;YACrC,MAAM,EAAE,KAAK,EAAE;YACf,kBAAkB,EAAE,KAAK,EAAE;YAC3B,qBAAqB,EAAE,KAAK,EAAE;YAC9B,OAAO;YACP,GAAG,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;SAC7E,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,GAAG,CAAC,KAAK,IAAI,EAAE;YAC1B,MAAM,iBAAiB,CAAC,UAAU,CAAC,CAAC;YACpC,4DAA4D;YAC5D,MAAM,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE,CAAC;QACpC,CAAC,CAAC,EAAE,CAAC;QACL,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;CACD","sourcesContent":["/**\n * The part of the MCP integration that talks to servers: connections, transports, and OAuth\n * sign-in. It pulls in the MCP client, so index.ts loads it through runtime.lazy.ts only when a\n * server is configured.\n */\n\nimport { homedir } from \"node:os\";\nimport { basename, join, resolve } from \"node:path\";\nimport { setTimeout as sleep } from \"node:timers/promises\";\nimport { pathToFileURL } from \"node:url\";\nimport { VERSION } from \"../../config.js\";\nimport { resolveMcpServerUrl } from \"../../core/mcp-servers.ts\";\nimport { resolveConfigValueOrThrowAsync, resolveHeadersOrThrowAsync } from \"../../core/resolve-config-value.ts\";\nimport { sliceTail } from \"../../core/tools/truncate.ts\";\nimport {\n\ttype AuthProvider,\n\ttype CallToolResult,\n\tJSON_RPC_ERROR_CODES,\n\ttype ListResourcesResult,\n\ttype ListResourceTemplatesResult,\n\tMcpAuthRequiredError,\n\tMcpClient,\n\tMcpError,\n\ttype McpFetch,\n\tMcpHttpError,\n\ttype McpRequestOptions,\n\tMcpSessionExpiredError,\n\ttype Tool as McpTool,\n\ttype McpTransport,\n\ttype ReadResourceResult,\n\ttype Resource,\n\ttype ResourceTemplate,\n\tStdioTransport,\n\tStreamableHttpTransport,\n} from \"./client/index.js\";\nimport {\n\tMcpOAuthAuthorizationRequiredError,\n\ttype OAuthChallenge,\n\tOAuthTemporarilyUnavailableError,\n} from \"./client/oauth/index.js\";\nimport type { McpServerEntry } from \"./config.ts\";\nimport type { McpServerLog } from \"./log.ts\";\nimport {\n\tcreateMcpAuthProvider,\n\ttype McpAuthProvider,\n\ttype McpOAuthCredentialStore,\n\ttype McpOAuthSettings,\n} from \"./oauth.ts\";\nimport type { McpResourceServer } from \"./resources.js\";\nimport type { McpToolCaller } from \"./tools.ts\";\n\nexport { McpServerLog } from \"./log.ts\";\nexport { McpOAuthCredentialStore, McpSignInCancelledError, signInMcpServer } from \"./oauth.ts\";\n\nconst DEFAULT_TIMEOUT_SECONDS = 60;\nconst STDERR_TAIL_CHARS = 2_000;\n/** Delays between attempts to connect to an HTTP server that failed with a transient error. */\nconst CONNECT_RETRY_DELAYS_MS = [250, 1_000];\n/** Give canceled setup time to retire, without letting a broken transport block session cleanup. */\nconst OPENING_RETIREMENT_TIMEOUT_MS = 1_000;\n\nasync function boundedRetirement(retirement: Promise<unknown>): Promise<void> {\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\ttry {\n\t\tawait Promise.race([\n\t\t\tretirement.catch(() => undefined),\n\t\t\tnew Promise<void>((resolve) => {\n\t\t\t\ttimer = setTimeout(resolve, OPENING_RETIREMENT_TIMEOUT_MS);\n\t\t\t}),\n\t\t]);\n\t} finally {\n\t\tclearTimeout(timer);\n\t}\n}\n\n/**\n * `disconnected`: the connection dropped (for example the stdio server exited); the next call\n * reconnects.\n */\ntype ServerState = \"connecting\" | \"connected\" | \"disconnected\" | \"needs-auth\" | \"failed\" | \"closed\";\n\nexport type McpTransportFactory = (\n\tentry: McpServerEntry,\n\tcwd: string,\n\tauthProvider: AuthProvider | undefined,\n) => McpTransport | Promise<McpTransport>;\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\n/**\n * Network failures and overloaded or restarting servers, which are worth another attempt. This\n * includes an OAuth authorization server that failed to refresh the tokens for such a reason.\n */\nfunction isTransientError(error: unknown): boolean {\n\tif (error instanceof McpHttpError) {\n\t\treturn error.status === 408 || error.status === 429 || (error.status >= 500 && error.status !== 501);\n\t}\n\treturn error instanceof TypeError || error instanceof OAuthTemporarilyUnavailableError;\n}\n\nfunction providerAuthName(entry: McpServerEntry): string | undefined {\n\treturn \"url\" in entry.config ? entry.config.auth?.provider : undefined;\n}\n\nfunction validateProviderDestination(serverUrl: string): void {\n\tconst url = new URL(serverUrl);\n\tif (\n\t\turl.protocol !== \"https:\" &&\n\t\t!(url.protocol === \"http:\" && [\"localhost\", \"127.0.0.1\", \"[::1]\"].includes(url.hostname))\n\t) {\n\t\tthrow new Error(\"MCP provider credentials require HTTPS or exact loopback HTTP\");\n\t}\n}\n\n/** A provider token is granted to this configured origin, never to a redirect destination. */\nfunction providerFetch(serverUrl: string): McpFetch {\n\tconst origin = new URL(serverUrl).origin;\n\treturn async (input, init) => {\n\t\tlet url = new URL(input);\n\t\tlet request = { ...init, redirect: \"manual\" as const };\n\t\tfor (let redirects = 0; ; redirects++) {\n\t\t\tif (url.origin !== origin) throw new Error(\"MCP provider request cannot cross origins\");\n\t\t\tconst response = await fetch(url, request);\n\t\t\tconst location = response.headers.get(\"location\");\n\t\t\tif (![301, 302, 303, 307, 308].includes(response.status) || !location) return response;\n\t\t\tawait response.body?.cancel();\n\t\t\tif (redirects >= 10) throw new Error(\"Too many MCP provider redirects\");\n\t\t\turl = new URL(location, url);\n\t\t\tconst method = request.method?.toUpperCase() ?? \"GET\";\n\t\t\tif (\n\t\t\t\t(response.status === 303 && method !== \"HEAD\") ||\n\t\t\t\t([301, 302].includes(response.status) && method === \"POST\")\n\t\t\t) {\n\t\t\t\tconst headers = new Headers(request.headers);\n\t\t\t\tfor (const header of [\n\t\t\t\t\t\"content-type\",\n\t\t\t\t\t\"content-length\",\n\t\t\t\t\t\"content-encoding\",\n\t\t\t\t\t\"content-language\",\n\t\t\t\t\t\"content-location\",\n\t\t\t\t])\n\t\t\t\t\theaders.delete(header);\n\t\t\t\trequest = { ...request, method: \"GET\", body: undefined, headers };\n\t\t\t}\n\t\t}\n\t};\n}\n\nfunction signInRequiredMessage(entry: McpServerEntry): string {\n\tconst provider = providerAuthName(entry);\n\treturn `MCP server \"${entry.name}\" requires sign-in. Run ${provider ? `/login ${provider}` : \"/mcp\"} to sign in.`;\n}\n\n/** HTTP servers authenticate with OAuth unless they supply Authorization or a provider. */\nfunction usesOAuth(entry: McpServerEntry): boolean {\n\tconst { config } = entry;\n\tif (!(\"url\" in config) || config.auth) return false;\n\treturn !Object.keys(config.headers ?? {}).some((header) => header.toLowerCase() === \"authorization\");\n}\n\n/** `~` and `~/…` (also `~\\…` on Windows) name the home directory, like in a shell. */\nfunction expandHome(value: string): string {\n\tif (value === \"~\") return homedir();\n\tif (value.startsWith(\"~/\") || (process.platform === \"win32\" && value.startsWith(\"~\\\\\"))) {\n\t\treturn join(homedir(), value.slice(2));\n\t}\n\treturn value;\n}\n\nexport async function createDefaultTransport(\n\tentry: McpServerEntry,\n\tcwd: string,\n\tauthProvider: AuthProvider | undefined,\n): Promise<McpTransport> {\n\tconst { config, name } = entry;\n\tif (\"url\" in config) {\n\t\tconst url = resolveMcpServerUrl(config.url);\n\t\tif (config.auth) validateProviderDestination(url);\n\t\treturn new StreamableHttpTransport({\n\t\t\turl,\n\t\t\theaders: await resolveHeadersOrThrowAsync(config.headers, `MCP server \"${name}\"`),\n\t\t\tauthProvider,\n\t\t\tfetch: config.auth ? providerFetch(url) : undefined,\n\t\t});\n\t}\n\tif (!config.command) throw new Error(`MCP server \"${name}\" has no command or url`);\n\tconst env: Record<string, string> = {};\n\tfor (const [key, value] of Object.entries(config.env ?? {})) {\n\t\tenv[key] = await resolveConfigValueOrThrowAsync(value, `MCP server \"${name}\" env \"${key}\"`);\n\t}\n\treturn new StdioTransport({\n\t\tcommand: expandHome(config.command),\n\t\targs: config.args?.map(expandHome),\n\t\tcwd: resolve(cwd, expandHome(config.cwd ?? \".\")),\n\t\tenv,\n\t\tstderr: \"pipe\",\n\t});\n}\n\n/** Servers that do not implement `resources/templates/list` have no templates. */\nasync function withoutTemplates<T>(list: () => Promise<T>, empty: T): Promise<T> {\n\ttry {\n\t\treturn await list();\n\t} catch (error) {\n\t\tif (error instanceof McpError && error.code === JSON_RPC_ERROR_CODES.methodNotFound) return empty;\n\t\tthrow error;\n\t}\n}\n\nfunction listTemplates(client: McpClient, options: McpRequestOptions = {}): Promise<ResourceTemplate[]> {\n\treturn withoutTemplates(() => client.listResourceTemplates(options), []);\n}\n\n/** One configured server. Reconnects lazily when a call finds the connection gone. */\nexport class McpServerConnection implements McpToolCaller, McpResourceServer {\n\treadonly entry: McpServerEntry;\n\tstate: ServerState = \"connecting\";\n\terror: string | undefined;\n\ttools: McpTool[] = [];\n\thasResources = false;\n\t/** Server instructions from `initialize`, describing its tools as a group. */\n\tinstructions: string | undefined;\n\t/** Last OAuth challenge from the server; sign-in uses its resource metadata URL and scope. */\n\tchallenge: OAuthChallenge | undefined;\n\tprivate client: McpClient | undefined;\n\tprivate opening: Promise<McpClient> | undefined;\n\tprivate initializingClient: McpClient | undefined;\n\tprivate initializingTransport: McpTransport | undefined;\n\tprivate closing: Promise<void> | undefined;\n\tprivate readonly activeRequests = new Map<McpClient, number>();\n\tprivate readonly retiringClients = new Map<McpClient, { promise: Promise<void>; close: () => Promise<void> }>();\n\t/** Aborted by `close()`; cancels setup and the wait between connection retries. */\n\tprivate readonly shutdown = new AbortController();\n\t/** Stderr of the last stdio server that failed to connect. */\n\tprivate stderrTail: string | undefined;\n\tprivate readonly cwd: string;\n\tprivate readonly createTransport: McpTransportFactory;\n\tprivate readonly authProvider: McpAuthProvider | undefined;\n\tprivate readonly onTools: (connection: McpServerConnection) => void;\n\tprivate readonly onChange: ((connection: McpServerConnection) => void) | undefined;\n\tprivate readonly log: McpServerLog | undefined;\n\n\tconstructor(options: {\n\t\tentry: McpServerEntry;\n\t\tcwd: string;\n\t\tcreateTransport: McpTransportFactory;\n\t\tcredentials: McpOAuthCredentialStore;\n\t\t/** The current token of a pi provider, for servers with `auth.provider`. */\n\t\tproviderToken?: (provider: string) => Promise<string | undefined>;\n\t\tonTools: (connection: McpServerConnection) => void;\n\t\t/** Called when `state`, `error`, or `tools` change. */\n\t\tonChange?: (connection: McpServerConnection) => void;\n\t\t/** Receives the server's log messages (`notifications/message`). */\n\t\tlog?: McpServerLog;\n\t}) {\n\t\tconst config = options.entry.config;\n\t\t// Resolve once so the credential key, destination check, and transport use the same URL.\n\t\tthis.entry =\n\t\t\t\"url\" in config\n\t\t\t\t? { ...options.entry, config: { ...config, url: resolveMcpServerUrl(config.url) } }\n\t\t\t\t: options.entry;\n\t\tthis.cwd = options.cwd;\n\t\tthis.createTransport = options.createTransport;\n\t\tthis.onTools = options.onTools;\n\t\tthis.onChange = options.onChange;\n\t\tthis.log = options.log;\n\t\tconst url = this.oauthUrl;\n\t\tconst provider = providerAuthName(this.entry);\n\t\tif (provider && \"url\" in this.entry.config) validateProviderDestination(this.entry.config.url);\n\t\tthis.authProvider = url\n\t\t\t? createMcpAuthProvider({\n\t\t\t\t\tserverUrl: url,\n\t\t\t\t\tstore: options.credentials.forServer(this.entry.name, url),\n\t\t\t\t\tsettings: () => this.oauthSettings(),\n\t\t\t\t\tonChallenge: (challenge) => {\n\t\t\t\t\t\tthis.challenge = challenge;\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t: provider\n\t\t\t\t? // Read on every request, so the provider's refreshes apply; MCP stores no copy.\n\t\t\t\t\t{ token: async () => options.providerToken?.(provider), settled: async () => {} }\n\t\t\t\t: undefined;\n\t}\n\n\tget name(): string {\n\t\treturn this.entry.name;\n\t}\n\n\tprivate get closed(): boolean {\n\t\treturn this.shutdown.signal.aborted;\n\t}\n\n\tget timeoutMs(): number {\n\t\treturn (this.entry.config.timeout ?? DEFAULT_TIMEOUT_SECONDS) * 1000;\n\t}\n\n\t/** Server URL when the server authenticates with OAuth. */\n\tget oauthUrl(): string | undefined {\n\t\treturn \"url\" in this.entry.config && usesOAuth(this.entry) ? this.entry.config.url : undefined;\n\t}\n\n\tasync oauthSettings(): Promise<McpOAuthSettings> {\n\t\tconst oauth = \"url\" in this.entry.config ? this.entry.config.oauth : undefined;\n\t\tif (!oauth) return {};\n\t\treturn {\n\t\t\tclientId: oauth.clientId,\n\t\t\tclientSecret:\n\t\t\t\toauth.clientSecret === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: await resolveConfigValueOrThrowAsync(\n\t\t\t\t\t\t\toauth.clientSecret,\n\t\t\t\t\t\t\t`MCP server \"${this.entry.name}\" oauth.clientSecret`,\n\t\t\t\t\t\t),\n\t\t\tcallbackPort: oauth.callbackPort,\n\t\t\tcallbackUrl: oauth.callbackUrl,\n\t\t\tscope: oauth.scope,\n\t\t\tclientName: oauth.clientName,\n\t\t\tauthServerMetadataUrl: oauth.authServerMetadataUrl ? new URL(oauth.authServerMetadataUrl) : undefined,\n\t\t};\n\t}\n\n\tgetClient(): Promise<McpClient> {\n\t\tif (this.closed) return Promise.reject(new Error(`MCP server \"${this.entry.name}\" is shut down`));\n\t\tif (this.client?.connectionState === \"connected\") return Promise.resolve(this.client);\n\t\tthis.opening ??= this.open().finally(() => {\n\t\t\tthis.opening = undefined;\n\t\t});\n\t\treturn this.opening;\n\t}\n\n\tcallTool(name: string, args: Record<string, unknown>, options: McpRequestOptions): Promise<CallToolResult> {\n\t\treturn this.withClient((client) => client.callTool(name, args, options));\n\t}\n\n\treadResource(uri: string, options: McpRequestOptions): Promise<ReadResourceResult> {\n\t\treturn this.withClient((client) => client.readResource(uri, options), true);\n\t}\n\n\tresourcesPage(cursor: string | undefined, options: McpRequestOptions): Promise<ListResourcesResult> {\n\t\treturn this.withClient((client) => client.listResourcesPage(cursor, options), true);\n\t}\n\n\tresourceTemplatesPage(cursor: string | undefined, options: McpRequestOptions): Promise<ListResourceTemplatesResult> {\n\t\treturn this.withClient(\n\t\t\t(client) =>\n\t\t\t\twithoutTemplates(() => client.listResourceTemplatesPage(cursor, options), { resourceTemplates: [] }),\n\t\t\ttrue,\n\t\t);\n\t}\n\n\tallResources(options: McpRequestOptions): Promise<Resource[]> {\n\t\treturn this.withClient((client) => client.listResources(options), true);\n\t}\n\n\tallResourceTemplates(options: McpRequestOptions): Promise<ResourceTemplate[]> {\n\t\treturn this.withClient((client) => listTemplates(client, options), true);\n\t}\n\n\t/**\n\t * Run a request, reconnecting when needed. `readOnly` requests are retried once after a transient\n\t * HTTP error; tool calls are not, since they may have run.\n\t */\n\tprivate async withClient<T>(run: (client: McpClient) => Promise<T>, readOnly = false): Promise<T> {\n\t\tfor (let attempt = 1; ; attempt++) {\n\t\t\tconst client = await this.getClient();\n\t\t\ttry {\n\t\t\t\treturn await this.runWithClient(client, run);\n\t\t\t} catch (error) {\n\t\t\t\tif (readOnly && attempt === 1 && error instanceof McpHttpError && isTransientError(error)) {\n\t\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, CONNECT_RETRY_DELAYS_MS[0]));\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (error instanceof McpSessionExpiredError && attempt === 1) {\n\t\t\t\t\tif (this.closed) throw error;\n\t\t\t\t\tconst retirement = this.dropClient(client, true);\n\t\t\t\t\tif (!this.activeRequests.has(client)) await retirement;\n\t\t\t\t\tif (this.closed) throw error;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (!this.needsSignIn(error)) throw error;\n\t\t\t\tawait this.dropClient(client);\n\t\t\t\tthis.markNeedsAuth();\n\t\t\t\tthrow new Error(signInRequiredMessage(this.entry));\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async runWithClient<T>(client: McpClient, run: (client: McpClient) => Promise<T>): Promise<T> {\n\t\tthis.activeRequests.set(client, (this.activeRequests.get(client) ?? 0) + 1);\n\t\ttry {\n\t\t\treturn await run(client);\n\t\t} finally {\n\t\t\tconst remaining = (this.activeRequests.get(client) ?? 1) - 1;\n\t\t\tif (remaining > 0) {\n\t\t\t\tthis.activeRequests.set(client, remaining);\n\t\t\t} else {\n\t\t\t\tthis.activeRequests.delete(client);\n\t\t\t\tvoid this.retiringClients.get(client)?.close();\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Connect again with fresh credentials, for example after signing in. */\n\tasync reconnect(): Promise<void> {\n\t\tawait this.opening?.catch(() => undefined);\n\t\tif (this.client) await this.dropClient(this.client);\n\t\tawait this.getClient();\n\t}\n\n\t/** Disconnect after the stored credentials were removed. */\n\tasync signOut(): Promise<void> {\n\t\tawait this.opening?.catch(() => undefined);\n\t\tif (this.client) await this.dropClient(this.client);\n\t\tif (!this.closed) this.markNeedsAuth();\n\t}\n\n\t/** OAuth servers that still reject the request after a refresh need the user to sign in again. */\n\tprivate needsSignIn(error: unknown): boolean {\n\t\treturn (\n\t\t\terror instanceof McpOAuthAuthorizationRequiredError ||\n\t\t\t(this.authProvider !== undefined && error instanceof McpAuthRequiredError)\n\t\t);\n\t}\n\n\tprivate markNeedsAuth(): void {\n\t\tthis.state = \"needs-auth\";\n\t\tthis.error = undefined;\n\t\tthis.changed();\n\t}\n\n\tprivate changed(): void {\n\t\tthis.onChange?.(this);\n\t}\n\n\tprivate dropClient(client: McpClient, drainRequests = false): Promise<void> {\n\t\tif (this.client === client) this.client = undefined;\n\t\tconst pending = this.retiringClients.get(client);\n\t\tif (pending) {\n\t\t\tif (!drainRequests) void pending.close();\n\t\t\treturn pending.promise;\n\t\t}\n\t\tlet resolve!: () => void;\n\t\tconst promise = new Promise<void>((done) => {\n\t\t\tresolve = done;\n\t\t});\n\t\tlet closing: Promise<void> | undefined;\n\t\tconst close = () => {\n\t\t\tclosing ??= client\n\t\t\t\t.close()\n\t\t\t\t.catch(() => undefined)\n\t\t\t\t.finally(() => {\n\t\t\t\t\tthis.retiringClients.delete(client);\n\t\t\t\t\tresolve();\n\t\t\t\t});\n\t\t\treturn closing;\n\t\t};\n\t\tthis.retiringClients.set(client, { promise, close });\n\t\tif (!drainRequests || !this.activeRequests.has(client)) void close();\n\t\treturn promise;\n\t}\n\n\tprivate async open(): Promise<McpClient> {\n\t\tthis.state = \"connecting\";\n\t\tthis.changed();\n\t\tconst retries = \"url\" in this.entry.config ? CONNECT_RETRY_DELAYS_MS : [];\n\t\tlet sessionExpired = false;\n\t\tfor (let attempt = 0; ; attempt++) {\n\t\t\tthis.stderrTail = undefined;\n\t\t\ttry {\n\t\t\t\treturn await this.connectOnce();\n\t\t\t} catch (error) {\n\t\t\t\t// The server dropped the session it just created: initialize once more, as an established client does.\n\t\t\t\tif (error instanceof McpSessionExpiredError && !sessionExpired && !this.closed) {\n\t\t\t\t\tsessionExpired = true;\n\t\t\t\t\tattempt--;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst delay = retries[attempt];\n\t\t\t\tif (this.closed || delay === undefined || !isTransientError(error)) {\n\t\t\t\t\tthrow this.connectFailed(error);\n\t\t\t\t}\n\t\t\t\tawait sleep(delay, undefined, { signal: this.shutdown.signal }).catch(() => undefined);\n\t\t\t\tif (this.closed) throw this.connectFailed(error);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async connectOnce(): Promise<McpClient> {\n\t\tif (this.closed) throw new Error(\"shut down while connecting\");\n\t\tconst client = new McpClient({\n\t\t\tname: \"pi\",\n\t\t\tversion: VERSION,\n\t\t\trequestTimeoutMs: this.timeoutMs,\n\t\t\troots: [{ uri: pathToFileURL(this.cwd).href, name: basename(this.cwd) }],\n\t\t});\n\t\tthis.initializingClient = client;\n\t\tconst log = this.log;\n\t\tif (log) client.onNotification(\"notifications/message\", (params) => log.write(this.entry.name, params));\n\t\t// A second client.close() can return before its transport has finished closing.\n\t\tlet closing: Promise<void> | undefined;\n\t\tconst closeClient = () => {\n\t\t\tclosing ??= client.close().catch(() => undefined);\n\t\t\treturn closing;\n\t\t};\n\t\tthis.shutdown.signal.addEventListener(\"abort\", closeClient, { once: true });\n\t\tlet transport: McpTransport | undefined;\n\t\ttry {\n\t\t\ttransport = await this.createTransport(this.entry, this.cwd, this.authProvider);\n\t\t\tthis.initializingTransport = transport;\n\t\t\tif (this.closed) throw new Error(\"shut down while connecting\");\n\t\t\tawait client.connect(transport);\n\t\t\tclient.onNotification(\"notifications/tools/list_changed\", () => {\n\t\t\t\tvoid this.refreshTools(client);\n\t\t\t});\n\t\t\tconst stdio = transport instanceof StdioTransport ? transport : undefined;\n\t\t\tclient.onClose(() => this.handleClientClose(client, stdio));\n\t\t\t// Servers without the tools capability (prompts or resources only) do not answer tools/list.\n\t\t\tconst tools = client.serverCapabilities?.tools ? await client.listTools() : [];\n\t\t\tif (this.closed) throw new Error(\"shut down while connecting\");\n\t\t\tif (client.connectionState !== \"connected\") throw new Error(\"connection closed during setup\");\n\t\t\tthis.client = client;\n\t\t\tthis.tools = tools;\n\t\t\tthis.hasResources = client.serverCapabilities?.resources !== undefined;\n\t\t\tthis.instructions = client.instructions?.trim() || undefined;\n\t\t\tthis.state = \"connected\";\n\t\t\tthis.error = undefined;\n\t\t\tthis.onTools(this);\n\t\t\tthis.changed();\n\t\t\treturn client;\n\t\t} catch (error) {\n\t\t\tawait closeClient();\n\t\t\tif (transport instanceof StdioTransport) {\n\t\t\t\tthis.stderrTail = sliceTail(transport.stderr.trim(), STDERR_TAIL_CHARS) || undefined;\n\t\t\t}\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tthis.shutdown.signal.removeEventListener(\"abort\", closeClient);\n\t\t\t// A delayed start may allocate resources after its first close. Retire them too.\n\t\t\tif (this.closed) await transport?.close().catch(() => undefined);\n\t\t\tif (this.initializingClient === client) {\n\t\t\t\tthis.initializingClient = undefined;\n\t\t\t\tthis.initializingTransport = undefined;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate connectFailed(error: unknown): Error {\n\t\tif (this.needsSignIn(error) && !this.closed) {\n\t\t\tthis.markNeedsAuth();\n\t\t\treturn new Error(signInRequiredMessage(this.entry));\n\t\t}\n\t\tthis.state = this.closed ? \"closed\" : \"failed\";\n\t\tthis.error = this.stderrTail ? `${errorMessage(error)}\\n${this.stderrTail}` : errorMessage(error);\n\t\tthis.changed();\n\t\treturn new Error(`MCP server \"${this.entry.name}\" failed to connect: ${this.error}`);\n\t}\n\n\t/** The transport dropped. The next call reconnects; until then the status shows why. */\n\tprivate handleClientClose(client: McpClient, stdio: StdioTransport | undefined): void {\n\t\tif (this.client !== client || this.closed) return;\n\t\tthis.client = undefined;\n\t\tthis.state = \"disconnected\";\n\t\tconst stderr = stdio ? sliceTail(stdio.stderr.trim(), STDERR_TAIL_CHARS) : undefined;\n\t\tthis.error = stderr ? `Connection closed\\n${stderr}` : \"Connection closed\";\n\t\tthis.changed();\n\t}\n\n\tprivate async refreshTools(client: McpClient): Promise<void> {\n\t\ttry {\n\t\t\tconst tools = await this.runWithClient(client, (client) => client.listTools());\n\t\t\tif (this.client !== client || this.closed) return;\n\t\t\tthis.tools = tools;\n\t\t\tthis.onTools(this);\n\t\t} catch (error) {\n\t\t\tthis.error = `Failed to refresh tools: ${errorMessage(error)}`;\n\t\t}\n\t\tthis.changed();\n\t}\n\n\t/** Retires connected and still-connecting transports, bounded for broken transports. */\n\tclose(): Promise<void> {\n\t\tif (this.closing) return this.closing;\n\t\tthis.shutdown.abort();\n\t\tthis.state = \"closed\";\n\t\tthis.changed();\n\t\tconst client = this.client;\n\t\tthis.client = undefined;\n\t\tconst opening = this.opening;\n\t\tconst initializingClient = this.initializingClient;\n\t\tconst initializingTransport = this.initializingTransport;\n\t\t// Close immediately, before waiting for setup: start itself may need close to unblock.\n\t\tconst retirement = Promise.allSettled([\n\t\t\tclient?.close(),\n\t\t\tinitializingClient?.close(),\n\t\t\tinitializingTransport?.close(),\n\t\t\topening,\n\t\t\t...[...this.retiringClients.values()].map((retirement) => retirement.close()),\n\t\t]);\n\t\tthis.closing = (async () => {\n\t\t\tawait boundedRetirement(retirement);\n\t\t\t// Preserve an already-rotated refresh token before exiting.\n\t\t\tawait this.authProvider?.settled();\n\t\t})();\n\t\treturn this.closing;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/extensions/mcp/runtime.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,8BAA8B,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChH,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAGN,oBAAoB,EAGpB,oBAAoB,EACpB,SAAS,EACT,QAAQ,EAER,YAAY,EAEZ,sBAAsB,EAMtB,cAAc,EACd,uBAAuB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,kCAAkC,EAElC,gCAAgC,G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AE,KAAK,EAAE;YAC9B,OAAO;YACP,GAAG,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;SAC7E,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,GAAG,CAAC,KAAK,IAAI,EAAE;YAC1B,MAAM,iBAAiB,CAAC,UAAU,CAAC,CAAC;YACpC,4DAA4D;YAC5D,MAAM,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE,CAAC;QACpC,CAAC,CAAC,EAAE,CAAC;QACL,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;CACD","sourcesContent":["/**\n * The part of the MCP integration that talks to servers: connections, transports, and OAuth\n * sign-in. It pulls in the MCP client, so index.ts loads it through runtime.lazy.ts only when a\n * server is configured.\n */\n\nimport { homedir } from \"node:os\";\nimport { basename, join, resolve } from \"node:path\";\nimport { setTimeout as sleep } from \"node:timers/promises\";\nimport { pathToFileURL } from \"node:url\";\nimport { VERSION } from \"../../config.js\";\nimport { resolveMcpServerUrl } from \"../../core/mcp-servers.ts\";\nimport { resolveConfigValueOrThrowAsync, resolveHeadersOrThrowAsync } from \"../../core/resolve-config-value.ts\";\nimport { sliceTail } from \"../../core/tools/truncate.ts\";\nimport {\n\ttype AuthProvider,\n\ttype CallToolResult,\n\tJSON_RPC_ERROR_CODES,\n\ttype ListResourcesResult,\n\ttype ListResourceTemplatesResult,\n\tMcpAuthRequiredError,\n\tMcpClient,\n\tMcpError,\n\ttype McpFetch,\n\tMcpHttpError,\n\ttype McpRequestOptions,\n\tMcpSessionExpiredError,\n\ttype Tool as McpTool,\n\ttype McpTransport,\n\ttype ReadResourceResult,\n\ttype Resource,\n\ttype ResourceTemplate,\n\tStdioTransport,\n\tStreamableHttpTransport,\n} from \"./client/index.js\";\nimport {\n\tMcpOAuthAuthorizationRequiredError,\n\ttype OAuthChallenge,\n\tOAuthTemporarilyUnavailableError,\n} from \"./client/oauth/index.js\";\nimport { type McpServerEntry, mcpRequestTimeoutMs } from \"./config.ts\";\nimport type { McpServerLog } from \"./log.ts\";\nimport {\n\tcreateMcpAuthProvider,\n\ttype McpAuthProvider,\n\ttype McpOAuthCredentialStore,\n\ttype McpOAuthSettings,\n} from \"./oauth.ts\";\nimport type { McpResourceServer } from \"./resources.js\";\nimport type { McpToolCaller } from \"./tools.ts\";\n\nexport { McpServerLog } from \"./log.ts\";\nexport { McpOAuthCredentialStore, McpSignInCancelledError, signInMcpServer } from \"./oauth.ts\";\n\nconst STDERR_TAIL_CHARS = 2_000;\n/** Delays between attempts to connect to an HTTP server that failed with a transient error. */\nconst CONNECT_RETRY_DELAYS_MS = [250, 1_000];\n/** Give canceled setup time to retire, without letting a broken transport block session cleanup. */\nconst OPENING_RETIREMENT_TIMEOUT_MS = 1_000;\n\nasync function boundedRetirement(retirement: Promise<unknown>): Promise<void> {\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\ttry {\n\t\tawait Promise.race([\n\t\t\tretirement.catch(() => undefined),\n\t\t\tnew Promise<void>((resolve) => {\n\t\t\t\ttimer = setTimeout(resolve, OPENING_RETIREMENT_TIMEOUT_MS);\n\t\t\t}),\n\t\t]);\n\t} finally {\n\t\tclearTimeout(timer);\n\t}\n}\n\n/**\n * `disconnected`: the connection dropped (for example the stdio server exited); the next call\n * reconnects.\n */\ntype ServerState = \"connecting\" | \"connected\" | \"disconnected\" | \"needs-auth\" | \"failed\" | \"closed\";\n\nexport type McpTransportFactory = (\n\tentry: McpServerEntry,\n\tcwd: string,\n\tauthProvider: AuthProvider | undefined,\n) => McpTransport | Promise<McpTransport>;\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\n/**\n * Network failures and overloaded or restarting servers, which are worth another attempt. This\n * includes an OAuth authorization server that failed to refresh the tokens for such a reason.\n */\nfunction isTransientError(error: unknown): boolean {\n\tif (error instanceof McpHttpError) {\n\t\treturn error.status === 408 || error.status === 429 || (error.status >= 500 && error.status !== 501);\n\t}\n\treturn error instanceof TypeError || error instanceof OAuthTemporarilyUnavailableError;\n}\n\nfunction providerAuthName(entry: McpServerEntry): string | undefined {\n\treturn \"url\" in entry.config ? entry.config.auth?.provider : undefined;\n}\n\nfunction validateProviderDestination(serverUrl: string): void {\n\tconst url = new URL(serverUrl);\n\tif (\n\t\turl.protocol !== \"https:\" &&\n\t\t!(url.protocol === \"http:\" && [\"localhost\", \"127.0.0.1\", \"[::1]\"].includes(url.hostname))\n\t) {\n\t\tthrow new Error(\"MCP provider credentials require HTTPS or exact loopback HTTP\");\n\t}\n}\n\n/** A provider token is granted to this configured origin, never to a redirect destination. */\nfunction providerFetch(serverUrl: string): McpFetch {\n\tconst origin = new URL(serverUrl).origin;\n\treturn async (input, init) => {\n\t\tlet url = new URL(input);\n\t\tlet request = { ...init, redirect: \"manual\" as const };\n\t\tfor (let redirects = 0; ; redirects++) {\n\t\t\tif (url.origin !== origin) throw new Error(\"MCP provider request cannot cross origins\");\n\t\t\tconst response = await fetch(url, request);\n\t\t\tconst location = response.headers.get(\"location\");\n\t\t\tif (![301, 302, 303, 307, 308].includes(response.status) || !location) return response;\n\t\t\tawait response.body?.cancel();\n\t\t\tif (redirects >= 10) throw new Error(\"Too many MCP provider redirects\");\n\t\t\turl = new URL(location, url);\n\t\t\tconst method = request.method?.toUpperCase() ?? \"GET\";\n\t\t\tif (\n\t\t\t\t(response.status === 303 && method !== \"HEAD\") ||\n\t\t\t\t([301, 302].includes(response.status) && method === \"POST\")\n\t\t\t) {\n\t\t\t\tconst headers = new Headers(request.headers);\n\t\t\t\tfor (const header of [\n\t\t\t\t\t\"content-type\",\n\t\t\t\t\t\"content-length\",\n\t\t\t\t\t\"content-encoding\",\n\t\t\t\t\t\"content-language\",\n\t\t\t\t\t\"content-location\",\n\t\t\t\t])\n\t\t\t\t\theaders.delete(header);\n\t\t\t\trequest = { ...request, method: \"GET\", body: undefined, headers };\n\t\t\t}\n\t\t}\n\t};\n}\n\nfunction signInRequiredMessage(entry: McpServerEntry): string {\n\tconst provider = providerAuthName(entry);\n\treturn `MCP server \"${entry.name}\" requires sign-in. Run ${provider ? `/login ${provider}` : \"/mcp\"} to sign in.`;\n}\n\n/** HTTP servers authenticate with OAuth unless they supply Authorization or a provider. */\nfunction usesOAuth(entry: McpServerEntry): boolean {\n\tconst { config } = entry;\n\tif (!(\"url\" in config) || config.auth) return false;\n\treturn !Object.keys(config.headers ?? {}).some((header) => header.toLowerCase() === \"authorization\");\n}\n\n/** `~` and `~/…` (also `~\\…` on Windows) name the home directory, like in a shell. */\nfunction expandHome(value: string): string {\n\tif (value === \"~\") return homedir();\n\tif (value.startsWith(\"~/\") || (process.platform === \"win32\" && value.startsWith(\"~\\\\\"))) {\n\t\treturn join(homedir(), value.slice(2));\n\t}\n\treturn value;\n}\n\nexport async function createDefaultTransport(\n\tentry: McpServerEntry,\n\tcwd: string,\n\tauthProvider: AuthProvider | undefined,\n): Promise<McpTransport> {\n\tconst { config, name } = entry;\n\tif (\"url\" in config) {\n\t\tconst url = resolveMcpServerUrl(config.url);\n\t\tif (config.auth) validateProviderDestination(url);\n\t\treturn new StreamableHttpTransport({\n\t\t\turl,\n\t\t\theaders: await resolveHeadersOrThrowAsync(config.headers, `MCP server \"${name}\"`),\n\t\t\tauthProvider,\n\t\t\tfetch: config.auth ? providerFetch(url) : undefined,\n\t\t});\n\t}\n\tif (!config.command) throw new Error(`MCP server \"${name}\" has no command or url`);\n\tconst env: Record<string, string> = {};\n\tfor (const [key, value] of Object.entries(config.env ?? {})) {\n\t\tenv[key] = await resolveConfigValueOrThrowAsync(value, `MCP server \"${name}\" env \"${key}\"`);\n\t}\n\treturn new StdioTransport({\n\t\tcommand: expandHome(config.command),\n\t\targs: config.args?.map(expandHome),\n\t\tcwd: resolve(cwd, expandHome(config.cwd ?? \".\")),\n\t\tenv,\n\t\tstderr: \"pipe\",\n\t});\n}\n\n/** Servers that do not implement `resources/templates/list` have no templates. */\nasync function withoutTemplates<T>(list: () => Promise<T>, empty: T): Promise<T> {\n\ttry {\n\t\treturn await list();\n\t} catch (error) {\n\t\tif (error instanceof McpError && error.code === JSON_RPC_ERROR_CODES.methodNotFound) return empty;\n\t\tthrow error;\n\t}\n}\n\nfunction listTemplates(client: McpClient, options: McpRequestOptions = {}): Promise<ResourceTemplate[]> {\n\treturn withoutTemplates(() => client.listResourceTemplates(options), []);\n}\n\n/** One configured server. Reconnects lazily when a call finds the connection gone. */\nexport class McpServerConnection implements McpToolCaller, McpResourceServer {\n\treadonly entry: McpServerEntry;\n\tstate: ServerState = \"connecting\";\n\terror: string | undefined;\n\ttools: McpTool[] = [];\n\thasResources = false;\n\t/** Server instructions from `initialize`, describing its tools as a group. */\n\tinstructions: string | undefined;\n\t/** Last OAuth challenge from the server; sign-in uses its resource metadata URL and scope. */\n\tchallenge: OAuthChallenge | undefined;\n\tprivate client: McpClient | undefined;\n\tprivate opening: Promise<McpClient> | undefined;\n\tprivate initializingClient: McpClient | undefined;\n\tprivate initializingTransport: McpTransport | undefined;\n\tprivate closing: Promise<void> | undefined;\n\tprivate readonly activeRequests = new Map<McpClient, number>();\n\tprivate readonly retiringClients = new Map<McpClient, { promise: Promise<void>; close: () => Promise<void> }>();\n\t/** Aborted by `close()`; cancels setup and the wait between connection retries. */\n\tprivate readonly shutdown = new AbortController();\n\t/** Stderr of the last stdio server that failed to connect. */\n\tprivate stderrTail: string | undefined;\n\tprivate readonly cwd: string;\n\tprivate readonly createTransport: McpTransportFactory;\n\tprivate readonly authProvider: McpAuthProvider | undefined;\n\tprivate readonly onTools: (connection: McpServerConnection) => void;\n\tprivate readonly onChange: ((connection: McpServerConnection) => void) | undefined;\n\tprivate readonly log: McpServerLog | undefined;\n\n\tconstructor(options: {\n\t\tentry: McpServerEntry;\n\t\tcwd: string;\n\t\tcreateTransport: McpTransportFactory;\n\t\tcredentials: McpOAuthCredentialStore;\n\t\t/** The current token of a pi provider, for servers with `auth.provider`. */\n\t\tproviderToken?: (provider: string) => Promise<string | undefined>;\n\t\tonTools: (connection: McpServerConnection) => void;\n\t\t/** Called when `state`, `error`, or `tools` change. */\n\t\tonChange?: (connection: McpServerConnection) => void;\n\t\t/** Receives the server's log messages (`notifications/message`). */\n\t\tlog?: McpServerLog;\n\t}) {\n\t\tconst config = options.entry.config;\n\t\t// Resolve once so the credential key, destination check, and transport use the same URL.\n\t\tthis.entry =\n\t\t\t\"url\" in config\n\t\t\t\t? { ...options.entry, config: { ...config, url: resolveMcpServerUrl(config.url) } }\n\t\t\t\t: options.entry;\n\t\tthis.cwd = options.cwd;\n\t\tthis.createTransport = options.createTransport;\n\t\tthis.onTools = options.onTools;\n\t\tthis.onChange = options.onChange;\n\t\tthis.log = options.log;\n\t\tconst url = this.oauthUrl;\n\t\tconst provider = providerAuthName(this.entry);\n\t\tif (provider && \"url\" in this.entry.config) validateProviderDestination(this.entry.config.url);\n\t\tthis.authProvider = url\n\t\t\t? createMcpAuthProvider({\n\t\t\t\t\tserverUrl: url,\n\t\t\t\t\tstore: options.credentials.forServer(this.entry.name, url),\n\t\t\t\t\tsettings: () => this.oauthSettings(),\n\t\t\t\t\tonChallenge: (challenge) => {\n\t\t\t\t\t\tthis.challenge = challenge;\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t: provider\n\t\t\t\t? // Read on every request, so the provider's refreshes apply; MCP stores no copy.\n\t\t\t\t\t{ token: async () => options.providerToken?.(provider), settled: async () => {} }\n\t\t\t\t: undefined;\n\t}\n\n\tget name(): string {\n\t\treturn this.entry.name;\n\t}\n\n\tprivate get closed(): boolean {\n\t\treturn this.shutdown.signal.aborted;\n\t}\n\n\tget timeoutMs(): number {\n\t\treturn mcpRequestTimeoutMs(this.entry.config);\n\t}\n\n\t/** Server URL when the server authenticates with OAuth. */\n\tget oauthUrl(): string | undefined {\n\t\treturn \"url\" in this.entry.config && usesOAuth(this.entry) ? this.entry.config.url : undefined;\n\t}\n\n\tasync oauthSettings(): Promise<McpOAuthSettings> {\n\t\tconst oauth = \"url\" in this.entry.config ? this.entry.config.oauth : undefined;\n\t\tif (!oauth) return {};\n\t\treturn {\n\t\t\tclientId: oauth.clientId,\n\t\t\tclientSecret:\n\t\t\t\toauth.clientSecret === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: await resolveConfigValueOrThrowAsync(\n\t\t\t\t\t\t\toauth.clientSecret,\n\t\t\t\t\t\t\t`MCP server \"${this.entry.name}\" oauth.clientSecret`,\n\t\t\t\t\t\t),\n\t\t\tcallbackPort: oauth.callbackPort,\n\t\t\tcallbackUrl: oauth.callbackUrl,\n\t\t\tscope: oauth.scope,\n\t\t\tclientName: oauth.clientName,\n\t\t\tauthServerMetadataUrl: oauth.authServerMetadataUrl ? new URL(oauth.authServerMetadataUrl) : undefined,\n\t\t};\n\t}\n\n\tgetClient(): Promise<McpClient> {\n\t\tif (this.closed) return Promise.reject(new Error(`MCP server \"${this.entry.name}\" is shut down`));\n\t\tif (this.client?.connectionState === \"connected\") return Promise.resolve(this.client);\n\t\tthis.opening ??= this.open().finally(() => {\n\t\t\tthis.opening = undefined;\n\t\t});\n\t\treturn this.opening;\n\t}\n\n\tcallTool(name: string, args: Record<string, unknown>, options: McpRequestOptions): Promise<CallToolResult> {\n\t\treturn this.withClient((client) => client.callTool(name, args, options));\n\t}\n\n\treadResource(uri: string, options: McpRequestOptions): Promise<ReadResourceResult> {\n\t\treturn this.withClient((client) => client.readResource(uri, options), true);\n\t}\n\n\tresourcesPage(cursor: string | undefined, options: McpRequestOptions): Promise<ListResourcesResult> {\n\t\treturn this.withClient((client) => client.listResourcesPage(cursor, options), true);\n\t}\n\n\tresourceTemplatesPage(cursor: string | undefined, options: McpRequestOptions): Promise<ListResourceTemplatesResult> {\n\t\treturn this.withClient(\n\t\t\t(client) =>\n\t\t\t\twithoutTemplates(() => client.listResourceTemplatesPage(cursor, options), { resourceTemplates: [] }),\n\t\t\ttrue,\n\t\t);\n\t}\n\n\tallResources(options: McpRequestOptions): Promise<Resource[]> {\n\t\treturn this.withClient((client) => client.listResources(options), true);\n\t}\n\n\tallResourceTemplates(options: McpRequestOptions): Promise<ResourceTemplate[]> {\n\t\treturn this.withClient((client) => listTemplates(client, options), true);\n\t}\n\n\t/**\n\t * Run a request, reconnecting when needed. `readOnly` requests are retried once after a transient\n\t * HTTP error; tool calls are not, since they may have run.\n\t */\n\tprivate async withClient<T>(run: (client: McpClient) => Promise<T>, readOnly = false): Promise<T> {\n\t\tfor (let attempt = 1; ; attempt++) {\n\t\t\tconst client = await this.getClient();\n\t\t\ttry {\n\t\t\t\treturn await this.runWithClient(client, run);\n\t\t\t} catch (error) {\n\t\t\t\tif (readOnly && attempt === 1 && error instanceof McpHttpError && isTransientError(error)) {\n\t\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, CONNECT_RETRY_DELAYS_MS[0]));\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (error instanceof McpSessionExpiredError && attempt === 1) {\n\t\t\t\t\tif (this.closed) throw error;\n\t\t\t\t\tconst retirement = this.dropClient(client, true);\n\t\t\t\t\tif (!this.activeRequests.has(client)) await retirement;\n\t\t\t\t\tif (this.closed) throw error;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (!this.needsSignIn(error)) throw error;\n\t\t\t\tawait this.dropClient(client);\n\t\t\t\tthis.markNeedsAuth();\n\t\t\t\tthrow new Error(signInRequiredMessage(this.entry));\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async runWithClient<T>(client: McpClient, run: (client: McpClient) => Promise<T>): Promise<T> {\n\t\tthis.activeRequests.set(client, (this.activeRequests.get(client) ?? 0) + 1);\n\t\ttry {\n\t\t\treturn await run(client);\n\t\t} finally {\n\t\t\tconst remaining = (this.activeRequests.get(client) ?? 1) - 1;\n\t\t\tif (remaining > 0) {\n\t\t\t\tthis.activeRequests.set(client, remaining);\n\t\t\t} else {\n\t\t\t\tthis.activeRequests.delete(client);\n\t\t\t\tvoid this.retiringClients.get(client)?.close();\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Connect again with fresh credentials, for example after signing in. */\n\tasync reconnect(): Promise<void> {\n\t\tawait this.opening?.catch(() => undefined);\n\t\tif (this.client) await this.dropClient(this.client);\n\t\tawait this.getClient();\n\t}\n\n\t/** Disconnect after the stored credentials were removed. */\n\tasync signOut(): Promise<void> {\n\t\tawait this.opening?.catch(() => undefined);\n\t\tif (this.client) await this.dropClient(this.client);\n\t\tif (!this.closed) this.markNeedsAuth();\n\t}\n\n\t/** OAuth servers that still reject the request after a refresh need the user to sign in again. */\n\tprivate needsSignIn(error: unknown): boolean {\n\t\treturn (\n\t\t\terror instanceof McpOAuthAuthorizationRequiredError ||\n\t\t\t(this.authProvider !== undefined && error instanceof McpAuthRequiredError)\n\t\t);\n\t}\n\n\tprivate markNeedsAuth(): void {\n\t\tthis.state = \"needs-auth\";\n\t\tthis.error = undefined;\n\t\tthis.changed();\n\t}\n\n\tprivate changed(): void {\n\t\tthis.onChange?.(this);\n\t}\n\n\tprivate dropClient(client: McpClient, drainRequests = false): Promise<void> {\n\t\tif (this.client === client) this.client = undefined;\n\t\tconst pending = this.retiringClients.get(client);\n\t\tif (pending) {\n\t\t\tif (!drainRequests) void pending.close();\n\t\t\treturn pending.promise;\n\t\t}\n\t\tlet resolve!: () => void;\n\t\tconst promise = new Promise<void>((done) => {\n\t\t\tresolve = done;\n\t\t});\n\t\tlet closing: Promise<void> | undefined;\n\t\tconst close = () => {\n\t\t\tclosing ??= client\n\t\t\t\t.close()\n\t\t\t\t.catch(() => undefined)\n\t\t\t\t.finally(() => {\n\t\t\t\t\tthis.retiringClients.delete(client);\n\t\t\t\t\tresolve();\n\t\t\t\t});\n\t\t\treturn closing;\n\t\t};\n\t\tthis.retiringClients.set(client, { promise, close });\n\t\tif (!drainRequests || !this.activeRequests.has(client)) void close();\n\t\treturn promise;\n\t}\n\n\tprivate async open(): Promise<McpClient> {\n\t\tthis.state = \"connecting\";\n\t\tthis.changed();\n\t\tconst retries = \"url\" in this.entry.config ? CONNECT_RETRY_DELAYS_MS : [];\n\t\tlet sessionExpired = false;\n\t\tfor (let attempt = 0; ; attempt++) {\n\t\t\tthis.stderrTail = undefined;\n\t\t\ttry {\n\t\t\t\treturn await this.connectOnce();\n\t\t\t} catch (error) {\n\t\t\t\t// The server dropped the session it just created: initialize once more, as an established client does.\n\t\t\t\tif (error instanceof McpSessionExpiredError && !sessionExpired && !this.closed) {\n\t\t\t\t\tsessionExpired = true;\n\t\t\t\t\tattempt--;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst delay = retries[attempt];\n\t\t\t\tif (this.closed || delay === undefined || !isTransientError(error)) {\n\t\t\t\t\tthrow this.connectFailed(error);\n\t\t\t\t}\n\t\t\t\tawait sleep(delay, undefined, { signal: this.shutdown.signal }).catch(() => undefined);\n\t\t\t\tif (this.closed) throw this.connectFailed(error);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async connectOnce(): Promise<McpClient> {\n\t\tif (this.closed) throw new Error(\"shut down while connecting\");\n\t\tconst client = new McpClient({\n\t\t\tname: \"pi\",\n\t\t\tversion: VERSION,\n\t\t\trequestTimeoutMs: this.timeoutMs,\n\t\t\troots: [{ uri: pathToFileURL(this.cwd).href, name: basename(this.cwd) }],\n\t\t});\n\t\tthis.initializingClient = client;\n\t\tconst log = this.log;\n\t\tif (log) client.onNotification(\"notifications/message\", (params) => log.write(this.entry.name, params));\n\t\t// A second client.close() can return before its transport has finished closing.\n\t\tlet closing: Promise<void> | undefined;\n\t\tconst closeClient = () => {\n\t\t\tclosing ??= client.close().catch(() => undefined);\n\t\t\treturn closing;\n\t\t};\n\t\tthis.shutdown.signal.addEventListener(\"abort\", closeClient, { once: true });\n\t\tlet transport: McpTransport | undefined;\n\t\ttry {\n\t\t\ttransport = await this.createTransport(this.entry, this.cwd, this.authProvider);\n\t\t\tthis.initializingTransport = transport;\n\t\t\tif (this.closed) throw new Error(\"shut down while connecting\");\n\t\t\tawait client.connect(transport);\n\t\t\tclient.onNotification(\"notifications/tools/list_changed\", () => {\n\t\t\t\tvoid this.refreshTools(client);\n\t\t\t});\n\t\t\tconst stdio = transport instanceof StdioTransport ? transport : undefined;\n\t\t\tclient.onClose(() => this.handleClientClose(client, stdio));\n\t\t\t// Servers without the tools capability (prompts or resources only) do not answer tools/list.\n\t\t\tconst tools = client.serverCapabilities?.tools ? await client.listTools() : [];\n\t\t\tif (this.closed) throw new Error(\"shut down while connecting\");\n\t\t\tif (client.connectionState !== \"connected\") throw new Error(\"connection closed during setup\");\n\t\t\tthis.client = client;\n\t\t\tthis.tools = tools;\n\t\t\tthis.hasResources = client.serverCapabilities?.resources !== undefined;\n\t\t\tthis.instructions = client.instructions?.trim() || undefined;\n\t\t\tthis.state = \"connected\";\n\t\t\tthis.error = undefined;\n\t\t\tthis.onTools(this);\n\t\t\tthis.changed();\n\t\t\treturn client;\n\t\t} catch (error) {\n\t\t\tawait closeClient();\n\t\t\tif (transport instanceof StdioTransport) {\n\t\t\t\tthis.stderrTail = sliceTail(transport.stderr.trim(), STDERR_TAIL_CHARS) || undefined;\n\t\t\t}\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tthis.shutdown.signal.removeEventListener(\"abort\", closeClient);\n\t\t\t// A delayed start may allocate resources after its first close. Retire them too.\n\t\t\tif (this.closed) await transport?.close().catch(() => undefined);\n\t\t\tif (this.initializingClient === client) {\n\t\t\t\tthis.initializingClient = undefined;\n\t\t\t\tthis.initializingTransport = undefined;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate connectFailed(error: unknown): Error {\n\t\tif (this.needsSignIn(error) && !this.closed) {\n\t\t\tthis.markNeedsAuth();\n\t\t\treturn new Error(signInRequiredMessage(this.entry));\n\t\t}\n\t\tthis.state = this.closed ? \"closed\" : \"failed\";\n\t\tthis.error = this.stderrTail ? `${errorMessage(error)}\\n${this.stderrTail}` : errorMessage(error);\n\t\tthis.changed();\n\t\treturn new Error(`MCP server \"${this.entry.name}\" failed to connect: ${this.error}`);\n\t}\n\n\t/** The transport dropped. The next call reconnects; until then the status shows why. */\n\tprivate handleClientClose(client: McpClient, stdio: StdioTransport | undefined): void {\n\t\tif (this.client !== client || this.closed) return;\n\t\tthis.client = undefined;\n\t\tthis.state = \"disconnected\";\n\t\tconst stderr = stdio ? sliceTail(stdio.stderr.trim(), STDERR_TAIL_CHARS) : undefined;\n\t\tthis.error = stderr ? `Connection closed\\n${stderr}` : \"Connection closed\";\n\t\tthis.changed();\n\t}\n\n\tprivate async refreshTools(client: McpClient): Promise<void> {\n\t\ttry {\n\t\t\tconst tools = await this.runWithClient(client, (client) => client.listTools());\n\t\t\tif (this.client !== client || this.closed) return;\n\t\t\tthis.tools = tools;\n\t\t\tthis.onTools(this);\n\t\t} catch (error) {\n\t\t\tthis.error = `Failed to refresh tools: ${errorMessage(error)}`;\n\t\t}\n\t\tthis.changed();\n\t}\n\n\t/** Retires connected and still-connecting transports, bounded for broken transports. */\n\tclose(): Promise<void> {\n\t\tif (this.closing) return this.closing;\n\t\tthis.shutdown.abort();\n\t\tthis.state = \"closed\";\n\t\tthis.changed();\n\t\tconst client = this.client;\n\t\tthis.client = undefined;\n\t\tconst opening = this.opening;\n\t\tconst initializingClient = this.initializingClient;\n\t\tconst initializingTransport = this.initializingTransport;\n\t\t// Close immediately, before waiting for setup: start itself may need close to unblock.\n\t\tconst retirement = Promise.allSettled([\n\t\t\tclient?.close(),\n\t\t\tinitializingClient?.close(),\n\t\t\tinitializingTransport?.close(),\n\t\t\topening,\n\t\t\t...[...this.retiringClients.values()].map((retirement) => retirement.close()),\n\t\t]);\n\t\tthis.closing = (async () => {\n\t\t\tawait boundedRetirement(retirement);\n\t\t\t// Preserve an already-rotated refresh token before exiting.\n\t\t\tawait this.authProvider?.settled();\n\t\t})();\n\t\treturn this.closing;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Records of the MCP tools a session declared to the model, kept in the session so a resumed session can keep
|
|
3
|
+
* declaring them while their servers reconnect.
|
|
4
|
+
*
|
|
5
|
+
* A session declares an MCP tool with its server's listing of it. When the session is resumed, the servers start
|
|
6
|
+
* again and list their tools only once connected. Without a record, the first request after the resume would declare
|
|
7
|
+
* those tools removed and the next one declare them again, which changes the tool list the provider has cached. With
|
|
8
|
+
* the record, the resumed session registers the tool from it until the server reconnects, and a call to it waits for
|
|
9
|
+
* the server and runs only when the server lists the same tool again.
|
|
10
|
+
*/
|
|
11
|
+
import type { SessionEntry } from "../../core/session-manager.ts";
|
|
12
|
+
import type { Tool as McpTool } from "./client/index.js";
|
|
13
|
+
import type { McpServerEntry } from "./config.ts";
|
|
14
|
+
/** The built-in tools that reach the servers' resources; they are declared while a server has resources. */
|
|
15
|
+
export declare const RESOURCE_TOOL_NAMES: ReadonlySet<string>;
|
|
16
|
+
/** Custom entry type of the records. Kept with the branch when a long session resumes from a later window. */
|
|
17
|
+
export declare const MCP_TOOL_RECORD_ENTRY_TYPE = "atomic.mcp-tool-definitions";
|
|
18
|
+
/** One declared MCP tool: the name it was declared under, its server, and the server's listing of it. */
|
|
19
|
+
export interface McpToolRecord {
|
|
20
|
+
name: string;
|
|
21
|
+
server: string;
|
|
22
|
+
/** Fingerprint of the server's URL or command, so a record is not used for a server that now points elsewhere. */
|
|
23
|
+
transport: string;
|
|
24
|
+
tool: McpTool;
|
|
25
|
+
}
|
|
26
|
+
/** A server the resource tools reached when they were declared. */
|
|
27
|
+
export interface McpResourceServerRecord {
|
|
28
|
+
server: string;
|
|
29
|
+
transport: string;
|
|
30
|
+
}
|
|
31
|
+
export interface McpToolRecordData {
|
|
32
|
+
tools: McpToolRecord[];
|
|
33
|
+
/** The servers with resources, when the resource tools are declared and the set changed. */
|
|
34
|
+
resourceServers?: McpResourceServerRecord[];
|
|
35
|
+
}
|
|
36
|
+
/** What the branch's records say: the latest record of each tool name, and of the servers with resources. */
|
|
37
|
+
export interface McpToolRecords {
|
|
38
|
+
tools: Map<string, McpToolRecord>;
|
|
39
|
+
resourceServers: McpResourceServerRecord[] | undefined;
|
|
40
|
+
}
|
|
41
|
+
/** The fields of a listed tool that its declaration and calls depend on. */
|
|
42
|
+
export declare function recordableTool(tool: McpTool): McpTool;
|
|
43
|
+
/** Whether two listings of a tool describe the same tool. */
|
|
44
|
+
export declare function sameListedTool(left: McpTool, right: McpTool): boolean;
|
|
45
|
+
/** Whether two records describe the same tool of the same server under the same name. */
|
|
46
|
+
export declare function sameToolRecord(left: McpToolRecord, right: McpToolRecord): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* A hash of what the server connects to. It leaves out the credentials a URL, headers or environment may hold, so
|
|
49
|
+
* the session stores nothing derived from them.
|
|
50
|
+
*/
|
|
51
|
+
export declare function transportFingerprint(entry: McpServerEntry): string;
|
|
52
|
+
/** The latest records on the branch. Malformed records are ignored. */
|
|
53
|
+
export declare function readToolRecords(branch: readonly SessionEntry[]): McpToolRecords;
|
|
54
|
+
/** Whether the MCP integration records the declaration of a tool of this name. */
|
|
55
|
+
export declare function isRecordedToolName(name: string): boolean;
|
|
56
|
+
/** Names of the MCP tools and resource tools the branch's transcript declares now. */
|
|
57
|
+
export declare function declaredMcpToolNames(branch: readonly SessionEntry[]): Set<string>;
|
|
58
|
+
//# sourceMappingURL=tool-records.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-records.d.ts","sourceRoot":"","sources":["../../../src/extensions/mcp/tool-records.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,4GAA4G;AAC5G,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,MAAM,CAIlD,CAAC;AAEH,8GAA8G;AAC9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AAC,CAWjF"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Records of the MCP tools a session declared to the model, kept in the session so a resumed session can keep
|
|
3
|
+
* declaring them while their servers reconnect.
|
|
4
|
+
*
|
|
5
|
+
* A session declares an MCP tool with its server's listing of it. When the session is resumed, the servers start
|
|
6
|
+
* again and list their tools only once connected. Without a record, the first request after the resume would declare
|
|
7
|
+
* those tools removed and the next one declare them again, which changes the tool list the provider has cached. With
|
|
8
|
+
* the record, the resumed session registers the tool from it until the server reconnects, and a call to it waits for
|
|
9
|
+
* the server and runs only when the server lists the same tool again.
|
|
10
|
+
*/
|
|
11
|
+
import { createHash } from "node:crypto";
|
|
12
|
+
import { getCurrentTools } from "@bastani/atomic-ai";
|
|
13
|
+
import { LIST_MCP_RESOURCE_TEMPLATES_TOOL, LIST_MCP_RESOURCES_TOOL, READ_MCP_RESOURCE_TOOL } from "./resources.js";
|
|
14
|
+
/** The built-in tools that reach the servers' resources; they are declared while a server has resources. */
|
|
15
|
+
export const RESOURCE_TOOL_NAMES = new Set([
|
|
16
|
+
LIST_MCP_RESOURCES_TOOL,
|
|
17
|
+
LIST_MCP_RESOURCE_TEMPLATES_TOOL,
|
|
18
|
+
READ_MCP_RESOURCE_TOOL,
|
|
19
|
+
]);
|
|
20
|
+
/** Custom entry type of the records. Kept with the branch when a long session resumes from a later window. */
|
|
21
|
+
export const MCP_TOOL_RECORD_ENTRY_TYPE = "atomic.mcp-tool-definitions";
|
|
22
|
+
/** The fields of a listed tool that its declaration and calls depend on. */
|
|
23
|
+
export function recordableTool(tool) {
|
|
24
|
+
return {
|
|
25
|
+
name: tool.name,
|
|
26
|
+
...(tool.title === undefined ? {} : { title: tool.title }),
|
|
27
|
+
...(tool.description === undefined ? {} : { description: tool.description }),
|
|
28
|
+
inputSchema: tool.inputSchema,
|
|
29
|
+
...(tool.outputSchema === undefined ? {} : { outputSchema: tool.outputSchema }),
|
|
30
|
+
...(tool.annotations === undefined ? {} : { annotations: tool.annotations }),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** JSON with object keys sorted, so the order a server writes them in does not matter. Arrays keep their order. */
|
|
34
|
+
function canonicalJson(value) {
|
|
35
|
+
if (Array.isArray(value))
|
|
36
|
+
return `[${value.map(canonicalJson).join(",")}]`;
|
|
37
|
+
if (typeof value !== "object" || value === null)
|
|
38
|
+
return JSON.stringify(value) ?? "null";
|
|
39
|
+
const keys = Object.keys(value)
|
|
40
|
+
.filter((key) => value[key] !== undefined)
|
|
41
|
+
.sort();
|
|
42
|
+
return `{${keys.map((key) => `${JSON.stringify(key)}:${canonicalJson(value[key])}`).join(",")}}`;
|
|
43
|
+
}
|
|
44
|
+
/** Whether two listings of a tool describe the same tool. */
|
|
45
|
+
export function sameListedTool(left, right) {
|
|
46
|
+
return canonicalJson(recordableTool(left)) === canonicalJson(recordableTool(right));
|
|
47
|
+
}
|
|
48
|
+
/** Whether two records describe the same tool of the same server under the same name. */
|
|
49
|
+
export function sameToolRecord(left, right) {
|
|
50
|
+
return (left.name === right.name &&
|
|
51
|
+
left.server === right.server &&
|
|
52
|
+
left.transport === right.transport &&
|
|
53
|
+
sameListedTool(left.tool, right.tool));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The scheme, host, port and path of a server URL. Credentials, the query and the fragment are left out: they may
|
|
57
|
+
* hold secrets, and a call to a recorded tool runs only if the server lists the same tool again anyway.
|
|
58
|
+
*/
|
|
59
|
+
function urlTarget(url) {
|
|
60
|
+
if (URL.canParse(url)) {
|
|
61
|
+
const { protocol, host, pathname } = new URL(url);
|
|
62
|
+
return `${protocol}//${host}${pathname}`;
|
|
63
|
+
}
|
|
64
|
+
// Not a URL until its placeholders are filled in, such as `${MCP_URL}`: cut the same parts out of the text.
|
|
65
|
+
const [beforeQuery = ""] = url.split(/[?#]/, 1);
|
|
66
|
+
return beforeQuery.replace(/^([A-Za-z][A-Za-z0-9+.-]*:\/\/)[^/]*@/, "$1");
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A hash of what the server connects to. It leaves out the credentials a URL, headers or environment may hold, so
|
|
70
|
+
* the session stores nothing derived from them.
|
|
71
|
+
*/
|
|
72
|
+
export function transportFingerprint(entry) {
|
|
73
|
+
const { config } = entry;
|
|
74
|
+
const target = "url" in config
|
|
75
|
+
? { url: urlTarget(config.url) }
|
|
76
|
+
: { command: config.command, args: config.args ?? [], ...(config.cwd ? { cwd: config.cwd } : {}) };
|
|
77
|
+
return createHash("sha256").update(JSON.stringify(target)).digest("hex").slice(0, 16);
|
|
78
|
+
}
|
|
79
|
+
function isRecord(value) {
|
|
80
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
81
|
+
}
|
|
82
|
+
function isToolRecord(value) {
|
|
83
|
+
if (!isRecord(value) || !isRecord(value.tool))
|
|
84
|
+
return false;
|
|
85
|
+
return (typeof value.name === "string" &&
|
|
86
|
+
value.name.startsWith("mcp__") &&
|
|
87
|
+
typeof value.server === "string" &&
|
|
88
|
+
typeof value.transport === "string" &&
|
|
89
|
+
typeof value.tool.name === "string" &&
|
|
90
|
+
isRecord(value.tool.inputSchema));
|
|
91
|
+
}
|
|
92
|
+
function isResourceServerRecord(value) {
|
|
93
|
+
return isRecord(value) && typeof value.server === "string" && typeof value.transport === "string";
|
|
94
|
+
}
|
|
95
|
+
/** The latest records on the branch. Malformed records are ignored. */
|
|
96
|
+
export function readToolRecords(branch) {
|
|
97
|
+
const tools = new Map();
|
|
98
|
+
let resourceServers;
|
|
99
|
+
for (const entry of branch) {
|
|
100
|
+
if (entry.type !== "custom" || entry.customType !== MCP_TOOL_RECORD_ENTRY_TYPE || !isRecord(entry.data))
|
|
101
|
+
continue;
|
|
102
|
+
const { data } = entry;
|
|
103
|
+
if (Array.isArray(data.tools))
|
|
104
|
+
for (const record of data.tools)
|
|
105
|
+
if (isToolRecord(record))
|
|
106
|
+
tools.set(record.name, record);
|
|
107
|
+
if (Array.isArray(data.resourceServers))
|
|
108
|
+
resourceServers = data.resourceServers.filter(isResourceServerRecord);
|
|
109
|
+
}
|
|
110
|
+
return { tools, resourceServers };
|
|
111
|
+
}
|
|
112
|
+
/** Whether the MCP integration records the declaration of a tool of this name. */
|
|
113
|
+
export function isRecordedToolName(name) {
|
|
114
|
+
return name.startsWith("mcp__") || RESOURCE_TOOL_NAMES.has(name);
|
|
115
|
+
}
|
|
116
|
+
/** Names of the MCP tools and resource tools the branch's transcript declares now. */
|
|
117
|
+
export function declaredMcpToolNames(branch) {
|
|
118
|
+
const systemMessages = [];
|
|
119
|
+
for (const entry of branch) {
|
|
120
|
+
if (entry.type === "message" && entry.message.role === "system")
|
|
121
|
+
systemMessages.push(entry.message);
|
|
122
|
+
else if (entry.type === "compaction" && entry.systemMessage)
|
|
123
|
+
systemMessages.push(entry.systemMessage);
|
|
124
|
+
}
|
|
125
|
+
return new Set(getCurrentTools(systemMessages)
|
|
126
|
+
.map((tool) => tool.name)
|
|
127
|
+
.filter(isRecordedToolName));
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=tool-records.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-records.js","sourceRoot":"","sources":["../../../src/extensions/mcp/tool-records.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAsB,MAAM,oBAAoB,CAAC;AAIzE,OAAO,EAAE,gCAAgC,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAEnH,4GAA4G;AAC5G,MAAM,CAAC,MAAM,mBAAmB,GAAwB,IAAI,GAAG,CAAC;IAC/D,uBAAuB;IACvB,gCAAgC;IAChC,sBAAsB;CACtB,CAAC,CAAC;AAEH,8GAA8G;AAC9G,MAAM,CAAC,MAAM,0BAA0B,GAAG,6BAA6B,CAAC;AA6BxE,4EAA4E;AAC5E,MAAM,UAAU,cAA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AC;QAC5B,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,QAAQ;YAAE,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;aAC/F,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,IAAI,KAAK,CAAC,aAAa;YAAE,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IACvG,CAAC;IACD,OAAO,IAAI,GAAG,CACb,eAAe,CAAC,cAAc,CAAC;SAC7B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;SACxB,MAAM,CAAC,kBAAkB,CAAC,CAC5B,CAAC;AACH,CAAC","sourcesContent":["/**\n * Records of the MCP tools a session declared to the model, kept in the session so a resumed session can keep\n * declaring them while their servers reconnect.\n *\n * A session declares an MCP tool with its server's listing of it. When the session is resumed, the servers start\n * again and list their tools only once connected. Without a record, the first request after the resume would declare\n * those tools removed and the next one declare them again, which changes the tool list the provider has cached. With\n * the record, the resumed session registers the tool from it until the server reconnects, and a call to it waits for\n * the server and runs only when the server lists the same tool again.\n */\n\nimport { createHash } from \"node:crypto\";\nimport { getCurrentTools, type SystemMessage } from \"@bastani/atomic-ai\";\nimport type { SessionEntry } from \"../../core/session-manager.ts\";\nimport type { Tool as McpTool } from \"./client/index.js\";\nimport type { McpServerEntry } from \"./config.ts\";\nimport { LIST_MCP_RESOURCE_TEMPLATES_TOOL, LIST_MCP_RESOURCES_TOOL, READ_MCP_RESOURCE_TOOL } from \"./resources.js\";\n\n/** The built-in tools that reach the servers' resources; they are declared while a server has resources. */\nexport const RESOURCE_TOOL_NAMES: ReadonlySet<string> = new Set([\n\tLIST_MCP_RESOURCES_TOOL,\n\tLIST_MCP_RESOURCE_TEMPLATES_TOOL,\n\tREAD_MCP_RESOURCE_TOOL,\n]);\n\n/** Custom entry type of the records. Kept with the branch when a long session resumes from a later window. */\nexport const MCP_TOOL_RECORD_ENTRY_TYPE = \"atomic.mcp-tool-definitions\";\n\n/** One declared MCP tool: the name it was declared under, its server, and the server's listing of it. */\nexport interface McpToolRecord {\n\tname: string;\n\tserver: string;\n\t/** Fingerprint of the server's URL or command, so a record is not used for a server that now points elsewhere. */\n\ttransport: string;\n\ttool: McpTool;\n}\n\n/** A server the resource tools reached when they were declared. */\nexport interface McpResourceServerRecord {\n\tserver: string;\n\ttransport: string;\n}\n\nexport interface McpToolRecordData {\n\ttools: McpToolRecord[];\n\t/** The servers with resources, when the resource tools are declared and the set changed. */\n\tresourceServers?: McpResourceServerRecord[];\n}\n\n/** What the branch's records say: the latest record of each tool name, and of the servers with resources. */\nexport interface McpToolRecords {\n\ttools: Map<string, McpToolRecord>;\n\tresourceServers: McpResourceServerRecord[] | undefined;\n}\n\n/** The fields of a listed tool that its declaration and calls depend on. */\nexport function recordableTool(tool: McpTool): McpTool {\n\treturn {\n\t\tname: tool.name,\n\t\t...(tool.title === undefined ? {} : { title: tool.title }),\n\t\t...(tool.description === undefined ? {} : { description: tool.description }),\n\t\tinputSchema: tool.inputSchema,\n\t\t...(tool.outputSchema === undefined ? {} : { outputSchema: tool.outputSchema }),\n\t\t...(tool.annotations === undefined ? {} : { annotations: tool.annotations }),\n\t};\n}\n\n/** JSON with object keys sorted, so the order a server writes them in does not matter. Arrays keep their order. */\nfunction canonicalJson(value: unknown): string {\n\tif (Array.isArray(value)) return `[${value.map(canonicalJson).join(\",\")}]`;\n\tif (typeof value !== \"object\" || value === null) return JSON.stringify(value) ?? \"null\";\n\tconst keys = Object.keys(value)\n\t\t.filter((key) => (value as Record<string, unknown>)[key] !== undefined)\n\t\t.sort();\n\treturn `{${keys.map((key) => `${JSON.stringify(key)}:${canonicalJson((value as Record<string, unknown>)[key])}`).join(\",\")}}`;\n}\n\n/** Whether two listings of a tool describe the same tool. */\nexport function sameListedTool(left: McpTool, right: McpTool): boolean {\n\treturn canonicalJson(recordableTool(left)) === canonicalJson(recordableTool(right));\n}\n\n/** Whether two records describe the same tool of the same server under the same name. */\nexport function sameToolRecord(left: McpToolRecord, right: McpToolRecord): boolean {\n\treturn (\n\t\tleft.name === right.name &&\n\t\tleft.server === right.server &&\n\t\tleft.transport === right.transport &&\n\t\tsameListedTool(left.tool, right.tool)\n\t);\n}\n\n/**\n * The scheme, host, port and path of a server URL. Credentials, the query and the fragment are left out: they may\n * hold secrets, and a call to a recorded tool runs only if the server lists the same tool again anyway.\n */\nfunction urlTarget(url: string): string {\n\tif (URL.canParse(url)) {\n\t\tconst { protocol, host, pathname } = new URL(url);\n\t\treturn `${protocol}//${host}${pathname}`;\n\t}\n\t// Not a URL until its placeholders are filled in, such as `${MCP_URL}`: cut the same parts out of the text.\n\tconst [beforeQuery = \"\"] = url.split(/[?#]/, 1);\n\treturn beforeQuery.replace(/^([A-Za-z][A-Za-z0-9+.-]*:\\/\\/)[^/]*@/, \"$1\");\n}\n\n/**\n * A hash of what the server connects to. It leaves out the credentials a URL, headers or environment may hold, so\n * the session stores nothing derived from them.\n */\nexport function transportFingerprint(entry: McpServerEntry): string {\n\tconst { config } = entry;\n\tconst target =\n\t\t\"url\" in config\n\t\t\t? { url: urlTarget(config.url) }\n\t\t\t: { command: config.command, args: config.args ?? [], ...(config.cwd ? { cwd: config.cwd } : {}) };\n\treturn createHash(\"sha256\").update(JSON.stringify(target)).digest(\"hex\").slice(0, 16);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isToolRecord(value: unknown): value is McpToolRecord {\n\tif (!isRecord(value) || !isRecord(value.tool)) return false;\n\treturn (\n\t\ttypeof value.name === \"string\" &&\n\t\tvalue.name.startsWith(\"mcp__\") &&\n\t\ttypeof value.server === \"string\" &&\n\t\ttypeof value.transport === \"string\" &&\n\t\ttypeof value.tool.name === \"string\" &&\n\t\tisRecord(value.tool.inputSchema)\n\t);\n}\n\nfunction isResourceServerRecord(value: unknown): value is McpResourceServerRecord {\n\treturn isRecord(value) && typeof value.server === \"string\" && typeof value.transport === \"string\";\n}\n\n/** The latest records on the branch. Malformed records are ignored. */\nexport function readToolRecords(branch: readonly SessionEntry[]): McpToolRecords {\n\tconst tools = new Map<string, McpToolRecord>();\n\tlet resourceServers: McpResourceServerRecord[] | undefined;\n\tfor (const entry of branch) {\n\t\tif (entry.type !== \"custom\" || entry.customType !== MCP_TOOL_RECORD_ENTRY_TYPE || !isRecord(entry.data)) continue;\n\t\tconst { data } = entry;\n\t\tif (Array.isArray(data.tools))\n\t\t\tfor (const record of data.tools) if (isToolRecord(record)) tools.set(record.name, record);\n\t\tif (Array.isArray(data.resourceServers)) resourceServers = data.resourceServers.filter(isResourceServerRecord);\n\t}\n\treturn { tools, resourceServers };\n}\n\n/** Whether the MCP integration records the declaration of a tool of this name. */\nexport function isRecordedToolName(name: string): boolean {\n\treturn name.startsWith(\"mcp__\") || RESOURCE_TOOL_NAMES.has(name);\n}\n\n/** Names of the MCP tools and resource tools the branch's transcript declares now. */\nexport function declaredMcpToolNames(branch: readonly SessionEntry[]): Set<string> {\n\tconst systemMessages: SystemMessage[] = [];\n\tfor (const entry of branch) {\n\t\tif (entry.type === \"message\" && entry.message.role === \"system\") systemMessages.push(entry.message);\n\t\telse if (entry.type === \"compaction\" && entry.systemMessage) systemMessages.push(entry.systemMessage);\n\t}\n\treturn new Set(\n\t\tgetCurrentTools(systemMessages)\n\t\t\t.map((tool) => tool.name)\n\t\t\t.filter(isRecordedToolName),\n\t);\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export { bindTaskResumer, type TaskResumer } from "./core/tasks/task-resumer.ts"
|
|
|
34
34
|
export { bindTaskTranscriptFragments, ownerTaskViewSource, type TaskCommandCatalog, type TaskDetailText, type TaskOutputView, type TaskTranscriptFollow, type TaskTranscriptFragments, type TaskTranscriptView, type TaskViewResult, type TaskViewSource, taskTranscriptFragments, withTaskTranscriptArchive, } from "./core/tasks/task-view-source.js";
|
|
35
35
|
export { formatReadLineRange, formatToolCallWithArgs } from "./core/tools/render-utils.ts";
|
|
36
36
|
export { createTranscript, type Transcript, type TranscriptOptions, type TranscriptPart, type TranscriptTextPart, type TranscriptThinkingPart, type TranscriptToolCallPart, type TranscriptToolResult, type TranscriptToolResultFormat, } from "./core/transcript.js";
|
|
37
|
+
export { hasRecordedTransformedPrompt, startedAsFork } from "./core/transformed-system-prompt.ts";
|
|
37
38
|
export * from "./core/worktree-snapshot/index.ts";
|
|
38
39
|
export { type CodemodeExtensionOptions, createCodemodeExtension } from "./extensions/codemode/index.js";
|
|
39
40
|
export { type CodemodeToolDetails, type CodemodeToolOptions, createCodemodeDescription, createCodemodeTool, createCodemodeToolDefinition, } from "./extensions/codemode/tool.js";
|