@sema-agent/core 7.56.0 → 7.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +926 -0
- package/LICENSE +1 -1
- package/dist/agents/org-delivery-gate.js +3 -4
- package/dist/agents/peer-held-queue.d.ts +69 -49
- package/dist/agents/peer-held-queue.js +255 -106
- package/dist/agents/peer-session-drain.js +63 -43
- package/dist/agents/send-message-tool.js +3 -2
- package/dist/agents/subagent-steps.js +2 -4
- package/dist/agents/subagent.js +8 -8
- package/dist/brain/anthropic.js +16 -8
- package/dist/brain/open-responses.js +10 -8
- package/dist/brain/openai.js +11 -9
- package/dist/brain/provider-dialect.d.ts +3 -2
- package/dist/brain/provider-dialect.js +2 -2
- package/dist/brain/request-params.d.ts +6 -0
- package/dist/brain/request-params.js +14 -1
- package/dist/brain/route-adjudicator.js +2 -1
- package/dist/brain/stream-engine.d.ts +9 -0
- package/dist/brain/stream-engine.js +24 -10
- package/dist/brain/stream-shared.d.ts +5 -4
- package/dist/brain/stream-shared.js +4 -4
- package/dist/core/a2a.d.ts +2 -1
- package/dist/core/a2a.js +23 -10
- package/dist/core/allow-entry.d.ts +5 -11
- package/dist/core/allow-entry.js +19 -26
- package/dist/core/approval-object.d.ts +21 -5
- package/dist/core/approval-object.js +44 -17
- package/dist/core/ask-origin.d.ts +23 -4
- package/dist/core/ask-origin.js +5 -1
- package/dist/core/auto-compaction.d.ts +75 -6
- package/dist/core/auto-compaction.js +43 -27
- package/dist/core/auto-mode-directive.d.ts +29 -5
- package/dist/core/auto-mode-directive.js +38 -8
- package/dist/core/background-agent-store.d.ts +6 -2
- package/dist/core/background-agent-store.js +1 -1
- package/dist/core/checkpoint-requirements.d.ts +13 -1
- package/dist/core/checkpoint-requirements.js +4 -0
- package/dist/core/checkpoint-store.d.ts +44 -40
- package/dist/core/checkpoint-store.js +32 -14
- package/dist/core/cross-boundary-taint.js +4 -2
- package/dist/core/engine-notice.d.ts +4 -3
- package/dist/core/engine-notice.js +6 -0
- package/dist/core/file-history-store.d.ts +14 -8
- package/dist/core/file-history-store.js +14 -4
- package/dist/core/fs-write-gate-policy.d.ts +4 -2
- package/dist/core/fs-write-gate-policy.js +7 -3
- package/dist/core/gate-fold.js +6 -3
- package/dist/core/gate-lanes.js +13 -5
- package/dist/core/git-worktree-env.d.ts +53 -11
- package/dist/core/git-worktree-env.js +96 -12
- package/dist/core/hooks.d.ts +6 -3
- package/dist/core/hooks.js +12 -5
- package/dist/core/human-input-projection.d.ts +1 -0
- package/dist/core/human-input-projection.js +3 -0
- package/dist/core/locked-config.d.ts +15 -1
- package/dist/core/locked-config.js +38 -2
- package/dist/core/mailbox-store.d.ts +62 -1
- package/dist/core/mailbox-store.js +59 -0
- package/dist/core/mcp-call-meta.d.ts +66 -0
- package/dist/core/mcp-call-meta.js +103 -0
- package/dist/core/mcp-connection-pool.d.ts +3 -1
- package/dist/core/mcp-connection-pool.js +3 -1
- package/dist/core/mcp-failure.d.ts +7 -1
- package/dist/core/mcp-failure.js +10 -0
- package/dist/core/mcp-name-judge.d.ts +46 -0
- package/dist/core/mcp-name-judge.js +61 -0
- package/dist/core/mcp-probe.d.ts +5 -1
- package/dist/core/mcp-probe.js +3 -6
- package/dist/core/mcp-server-link.d.ts +5 -2
- package/dist/core/mcp-server-spec.d.ts +46 -18
- package/dist/core/mcp-server-spec.js +1 -18
- package/dist/core/mcp.d.ts +6 -14
- package/dist/core/mcp.js +85 -65
- package/dist/core/memory-engine/consolidation-driver.js +4 -3
- package/dist/core/memory-engine/distiller.js +26 -17
- package/dist/core/memory-engine/layout.js +5 -2
- package/dist/core/memory-engine/scope-contract.d.ts +45 -4
- package/dist/core/memory-engine/scope-contract.js +80 -11
- package/dist/core/mode-policy.d.ts +8 -5
- package/dist/core/mode-policy.js +5 -4
- package/dist/core/mods/host.js +1 -1
- package/dist/core/mods/kernel/dispatch.d.ts +3 -0
- package/dist/core/mods/kernel/dispatch.js +10 -8
- package/dist/core/mods/kernel/events.d.ts +5 -1
- package/dist/core/mods/kernel/events.js +1 -1
- package/dist/core/mods/kernel/registration.d.ts +5 -1
- package/dist/core/mods/kernel/site-rules.d.ts +3 -0
- package/dist/core/mods/kernel/site-rules.js +10 -0
- package/dist/core/mods/package.d.ts +23 -0
- package/dist/core/mods/package.js +118 -0
- package/dist/core/mods/stations.d.ts +2 -2
- package/dist/core/mods/stations.js +1 -1
- package/dist/core/mods/tool-call.d.ts +5 -1
- package/dist/core/mods/tool-call.js +12 -3
- package/dist/core/park-selfcheck.js +2 -0
- package/dist/core/path-guard-rows.d.ts +20 -0
- package/dist/core/path-guard-rows.js +11 -0
- package/dist/core/peer-seat.d.ts +186 -0
- package/dist/core/peer-seat.js +307 -0
- package/dist/core/permission-rule-consent.d.ts +5 -3
- package/dist/core/permission-rule-consent.js +20 -15
- package/dist/core/permission-rule-model.d.ts +43 -2
- package/dist/core/permission-rule-model.js +52 -8
- package/dist/core/permission-rule-org.js +1 -1
- package/dist/core/present-plan-tool.d.ts +10 -1
- package/dist/core/present-plan-tool.js +46 -2
- package/dist/core/protocol-http-auth.d.ts +56 -31
- package/dist/core/protocol-http-auth.js +71 -42
- package/dist/core/protocol-naming.d.ts +20 -0
- package/dist/core/protocol-naming.js +20 -3
- package/dist/core/read-only-shell.d.ts +20 -5
- package/dist/core/read-only-shell.js +29 -14
- package/dist/core/redaction-marks.d.ts +16 -0
- package/dist/core/redaction-marks.js +16 -0
- package/dist/core/redaction-passes.js +8 -9
- package/dist/core/remote-env.d.ts +37 -1
- package/dist/core/remote-env.js +11 -0
- package/dist/core/resume-startup-cause.d.ts +24 -2
- package/dist/core/resume-startup-cause.js +20 -1
- package/dist/core/retention.d.ts +41 -15
- package/dist/core/retention.js +59 -12
- package/dist/core/rewrite-rejudge.d.ts +37 -0
- package/dist/core/rewrite-rejudge.js +40 -0
- package/dist/core/roles.js +50 -7
- package/dist/core/run-origin.d.ts +40 -0
- package/dist/core/run-origin.js +37 -0
- package/dist/core/runner/advertised-writable-dirs.d.ts +57 -38
- package/dist/core/runner/advertised-writable-dirs.js +126 -0
- package/dist/core/runner/compact-session.d.ts +10 -0
- package/dist/core/runner/compact-session.js +202 -0
- package/dist/core/runner/compaction-call-options.d.ts +2 -2
- package/dist/core/runner/compaction-restate.d.ts +15 -6
- package/dist/core/runner/compaction-restate.js +28 -2
- package/dist/core/runner/compaction-seams.d.ts +21 -1
- package/dist/core/runner/compaction-seams.js +11 -8
- package/dist/core/runner/contracts.d.ts +36 -21
- package/dist/core/runner/derived-route-fallback.d.ts +13 -0
- package/dist/core/runner/derived-route-fallback.js +6 -0
- package/dist/core/runner/env-capability-census.d.ts +3 -2
- package/dist/core/runner/env-capability-census.js +9 -3
- package/dist/core/runner/gate-exit.d.ts +18 -4
- package/dist/core/runner/gate-exit.js +5 -1
- package/dist/core/runner/permission-rule-lanes.d.ts +7 -7
- package/dist/core/runner/permission-rule-lanes.js +17 -11
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +3 -0
- package/dist/core/runner/prepare-acquire-reconcile.js +2 -1
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +2 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +1 -1
- package/dist/core/runner/prepare-config-doors.d.ts +14 -5
- package/dist/core/runner/prepare-config-doors.js +16 -13
- package/dist/core/runner/prepare-delegation-surface.d.ts +4 -0
- package/dist/core/runner/prepare-delegation-surface.js +15 -18
- package/dist/core/runner/prepare-gate-stations.js +1 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +10 -4
- package/dist/core/runner/prepare-hands-readface.js +6 -1
- package/dist/core/runner/prepare-memory.d.ts +3 -0
- package/dist/core/runner/prepare-memory.js +19 -23
- package/dist/core/runner/prepare-park-ask.d.ts +2 -0
- package/dist/core/runner/prepare-park-ask.js +2 -2
- package/dist/core/runner/prepare-policy-chain.d.ts +4 -4
- package/dist/core/runner/prepare-policy-chain.js +4 -6
- package/dist/core/runner/prepare-protocol-tools.d.ts +4 -2
- package/dist/core/runner/prepare-protocol-tools.js +3 -3
- package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
- package/dist/core/runner/prepare-suspend-saga.js +2 -1
- package/dist/core/runner/prepare-task.d.ts +4 -1
- package/dist/core/runner/prepare-task.js +46 -37
- package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +13 -0
- package/dist/core/runner/prepare-tool-disclosure-mount.js +13 -7
- package/dist/core/runner/prepare-wiring-manifest.d.ts +1 -0
- package/dist/core/runner/prepare-wiring-manifest.js +2 -2
- package/dist/core/runner/prepare-workspace-restore.d.ts +3 -0
- package/dist/core/runner/prepare-workspace-restore.js +4 -4
- package/dist/core/runner/resume-admission.js +1 -1
- package/dist/core/runner/resume-checkpoint-screen.js +2 -0
- package/dist/core/runner/rewind-files.d.ts +2 -5
- package/dist/core/runner/rewind-files.js +9 -51
- package/dist/core/runner/run-harness-handlers.d.ts +3 -4
- package/dist/core/runner/run-harness-handlers.js +1 -8
- package/dist/core/runner/run-identity-wiring.js +1 -0
- package/dist/core/runner/run-leg.js +15 -22
- package/dist/core/runner/run-notification-lane.d.ts +2 -0
- package/dist/core/runner/run-notification-lane.js +5 -2
- package/dist/core/runner/run-recovery-lanes.js +3 -4
- package/dist/core/runner/run-settle-and-teardown.js +5 -11
- package/dist/core/runner/run-terminal-adoption.js +3 -4
- package/dist/core/runner/run-turn-boundary.js +3 -5
- package/dist/core/runner/runtask.d.ts +8 -1
- package/dist/core/runner/runtask.js +28 -34
- package/dist/core/runner/send-message-continuation.js +1 -1
- package/dist/core/runner/session-verb-doors.d.ts +28 -0
- package/dist/core/runner/session-verb-doors.js +48 -0
- package/dist/core/runner/session-write-ledger.d.ts +30 -0
- package/dist/core/runner/session-write-ledger.js +101 -0
- package/dist/core/runner/stream-settle-backstop.js +11 -14
- package/dist/core/runner/sub-agent-deny-lists.d.ts +25 -3
- package/dist/core/runner/sub-agent-deny-lists.js +21 -10
- package/dist/core/runner/teardown-bounded.d.ts +1 -0
- package/dist/core/runner/teardown-bounded.js +1 -0
- package/dist/core/runner/terminal-account.js +3 -3
- package/dist/core/runner/tool-end-body.js +1 -0
- package/dist/core/runner/tool-occurrence.d.ts +4 -1
- package/dist/core/runner/tool-occurrence.js +2 -1
- package/dist/core/runner/write-protection-station.d.ts +8 -2
- package/dist/core/runner/write-protection-station.js +2 -0
- package/dist/core/runner-deps.d.ts +4 -4
- package/dist/core/secret-env.d.ts +4 -0
- package/dist/core/secret-env.js +3 -0
- package/dist/core/sensitive-path-policy.js +6 -7
- package/dist/core/session-log-transfer.d.ts +24 -0
- package/dist/core/session-log-transfer.js +166 -0
- package/dist/core/session-policy-store.d.ts +7 -2
- package/dist/core/session-policy-store.js +1 -1
- package/dist/core/session-store.d.ts +84 -19
- package/dist/core/session-store.js +162 -24
- package/dist/core/session.d.ts +92 -1
- package/dist/core/shell-read-silence.js +1 -0
- package/dist/core/shell-wrapper-projection.d.ts +1 -1
- package/dist/core/steer-replay.d.ts +4 -2
- package/dist/core/steer-replay.js +2 -1
- package/dist/core/store-contracts/background-agent-store-contract.js +1 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +19 -1
- package/dist/core/store-contracts/file-history-store-contract.js +9 -0
- package/dist/core/store-contracts/mailbox-store-contract.js +49 -1
- package/dist/core/store-contracts/session-repo-contract.js +112 -5
- package/dist/core/store-contracts/session-store-contract.d.ts +4 -1
- package/dist/core/store-contracts/session-store-contract.js +236 -2
- package/dist/core/task-event.d.ts +68 -8
- package/dist/core/task-registry-agent.d.ts +8 -4
- package/dist/core/task-registry-agent.js +14 -8
- package/dist/core/task-registry-shared.d.ts +36 -6
- package/dist/core/task-registry-shared.js +11 -0
- package/dist/core/task-registry.d.ts +1 -1
- package/dist/core/task-registry.js +1 -1
- package/dist/core/task-spec.d.ts +37 -0
- package/dist/core/task-stream.d.ts +2 -1
- package/dist/core/terminal-cause.d.ts +1 -1
- package/dist/core/tool-catalog-entries.d.ts +6 -0
- package/dist/core/tool-catalog-entries.js +2 -0
- package/dist/core/tool-name-aliases.d.ts +32 -2
- package/dist/core/tool-name-aliases.js +23 -0
- package/dist/core/tool-name-readings.d.ts +4 -0
- package/dist/core/tool-name-readings.js +1 -0
- package/dist/core/tool-policy.d.ts +10 -6
- package/dist/core/tool-policy.js +4 -7
- package/dist/core/tool-result-store.d.ts +17 -10
- package/dist/core/tool-result-store.js +3 -1
- package/dist/core/trace.d.ts +4 -1
- package/dist/core/trace.js +2 -1
- package/dist/core/types.d.ts +1 -1
- package/dist/core/untrusted-egress.d.ts +18 -0
- package/dist/core/untrusted-egress.js +82 -12
- package/dist/core/wiring-manifest.d.ts +12 -3
- package/dist/core/wiring-manifest.js +4 -3
- package/dist/core/workspace-snapshot.d.ts +44 -0
- package/dist/core/workspace-snapshot.js +34 -0
- package/dist/core/write-protect.d.ts +43 -3
- package/dist/core/write-protect.js +43 -16
- package/dist/engine/execution-env/node-execution-env.js +15 -11
- package/dist/engine/execution-env/symlink-chain.d.ts +7 -5
- package/dist/engine/harness/agent-harness.d.ts +12 -5
- package/dist/engine/harness/agent-harness.js +13 -2
- package/dist/engine/harness/types.d.ts +48 -7
- package/dist/engine/harness/types.js +5 -1
- package/dist/engine/llm/types.d.ts +12 -3
- package/dist/engine/llm/types.js +1 -1
- package/dist/engine/loop/agent-loop.d.ts +1 -4
- package/dist/engine/loop/agent-loop.js +26 -4
- package/dist/engine/session/import-validate.js +3 -0
- package/dist/engine/session/memory-repo.d.ts +17 -9
- package/dist/engine/session/memory-repo.js +44 -34
- package/dist/engine/session/repo-utils.d.ts +22 -4
- package/dist/engine/session/repo-utils.js +49 -1
- package/dist/engine/session/storage-base.d.ts +10 -1
- package/dist/engine/session/storage-base.js +7 -1
- package/dist/index.d.ts +23 -11
- package/dist/index.js +15 -6
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +4 -3
- package/dist/internal/harness.js +3 -2
- package/dist/stores/file/checkpoint-store.d.ts +0 -4
- package/dist/stores/file/checkpoint-store.js +0 -1
- package/dist/stores/file/file-history-store.js +12 -4
- package/dist/stores/file/index.d.ts +4 -1
- package/dist/stores/file/index.js +4 -1
- package/dist/stores/file/mailbox-store.d.ts +2 -1
- package/dist/stores/file/mailbox-store.js +26 -1
- package/dist/stores/file/session-store.d.ts +15 -8
- package/dist/stores/file/session-store.js +28 -13
- package/dist/tools/fs/bash-readonly-classifier.d.ts +15 -19
- package/dist/tools/fs/bash-readonly-classifier.js +5 -10
- package/dist/tools/fs/fs-bash.js +10 -3
- package/dist/tools/fs/fs-write.d.ts +6 -3
- package/dist/tools/fs/fs-write.js +8 -7
- package/dist/tools/fs/index.d.ts +3 -0
- package/dist/tools/fs/index.js +1 -1
- package/dist/tools/fs/pattern-kill-guard.d.ts +3 -2
- package/dist/tools/fs/pattern-kill-guard.js +68 -36
- package/dist/tools/fs/safety.js +40 -8
- package/dist/tools/fs/search.js +6 -24
- package/dist/tools/fs/shell-read-check.d.ts +18 -1
- package/dist/tools/fs/shell-read-check.js +66 -16
- package/dist/tools/fs/shell-read-establish.js +2 -1
- package/dist/tools/fs/shell-read-identity.d.ts +12 -9
- package/dist/tools/fs/shell-read-identity.js +10 -5
- package/dist/tools/fs/shell-read-judge.d.ts +10 -1
- package/dist/tools/web.js +9 -7
- package/dist/tools/worktree.d.ts +42 -15
- package/dist/tools/worktree.js +60 -32
- package/package.json +4 -2
- package/test/export-surface.snapshot.json +141 -3
- package/wire-changes/core-stores-sql@7.57.0.json +29 -0
- package/wire-changes/core-stores-sql@7.58.0.json +29 -0
- package/wire-changes/core@7.57.0.json +1487 -0
- package/wire-changes/core@7.58.0.json +2188 -0
- package/wire-changes/mods-kernel@7.57.0.json +29 -0
- package/wire-changes/mods-kernel@7.58.0.json +81 -0
- package/wire-changes/primitives@7.57.0.json +245 -0
- package/wire-changes/primitives@7.58.0.json +29 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ReceiptFault } from "./mods/kernel/receive.js";
|
|
2
|
+
import type { CredentialRef } from "@sema-agent/primitives";
|
|
2
3
|
import type { ToolContentOrigin, ToolEffect } from "./tool-spec.js";
|
|
3
4
|
import type { ToolFamily, ToolHostTarget, ToolPathTarget, ToolRenderHints, ToolRuleFace } from "./tool-face.js";
|
|
4
5
|
/** Definition of an MCP server to connect to for the duration of one task, then discard. */
|
|
@@ -13,24 +14,34 @@ export interface McpServerSpec {
|
|
|
13
14
|
* declaring tier without keeping a side table keyed on names. Optional; absent stays absent.
|
|
14
15
|
*/
|
|
15
16
|
source?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Who the server is: the whole start command (stdio) or endpoint (http), and at most one opaque credential reference
|
|
19
|
+
* (`credentials`, read by the one reader `readCredentialRef` at every entrance — an unknown kind refuses the entry with
|
|
20
|
+
* `config.credential_ref_invalid`; the engine resolves nothing). A declaration carries no value: the pieces a request
|
|
21
|
+
* carries — an http request's credential headers, a stdio child's environment — are answered per send by the deployment's
|
|
22
|
+
* peer seat ({@link RunnerDeps.peerSeat}). A `credentials` reference with no seat wired refuses the entry
|
|
23
|
+
* (`config.peer_seat_missing`); a declaration carrying the retired value members `headers` / `env` is refused at every
|
|
24
|
+
* entrance (`config.credential_in_declaration`).
|
|
25
|
+
*/
|
|
16
26
|
transport: {
|
|
17
27
|
kind: "stdio";
|
|
18
28
|
command: string;
|
|
19
29
|
args?: string[];
|
|
20
|
-
|
|
30
|
+
credentials?: CredentialRef;
|
|
21
31
|
} | {
|
|
22
32
|
kind: "http";
|
|
23
33
|
url: string;
|
|
24
|
-
|
|
25
|
-
headers?: Record<string, string>;
|
|
34
|
+
credentials?: CredentialRef;
|
|
26
35
|
/**
|
|
27
36
|
* Per-task **end-user principal** header (design/62). When set, the Runner injects the running task's
|
|
28
37
|
* authenticated {@link TaskSpec.principal} as this header (e.g. `"X-Agent-Principal"`) on every call to
|
|
29
38
|
* this server's tools, so the MCP server can enforce per-user RBAC. Absent {@link TaskSpec.principal}
|
|
30
|
-
* ⇒ the header is **not** sent (the MCP server must default to deny/public, never admin). A
|
|
31
|
-
*
|
|
32
|
-
* header names being case-insensitive). The principal is Runner-held and the
|
|
33
|
-
* nor set it (it is not a tool argument) — see {@link TaskSpec.principal}.
|
|
39
|
+
* ⇒ the header is **not** sent (the MCP server must default to deny/public, never admin). A header the
|
|
40
|
+
* peer seat answers under the same name in any case is the seat's fault, and that request is not sent
|
|
41
|
+
* (`config.protocol_header_collision`, header names being case-insensitive). The principal is Runner-held and the
|
|
42
|
+
* model/worker can neither read nor set it (it is not a tool argument) — see {@link TaskSpec.principal}. The name is
|
|
43
|
+
* neither the engine's own `MCP_ASSERTION_HEADER` nor a name the MCP transport writes itself (any case): naming one
|
|
44
|
+
* refuses this server at its dial.
|
|
34
45
|
*/
|
|
35
46
|
principalHeader?: string;
|
|
36
47
|
};
|
|
@@ -172,6 +183,21 @@ export interface McpServerSpec {
|
|
|
172
183
|
* The no-run probe has no clock of its own: each startup phase carries this same bound (a caller's `timeoutMs` is an overall ceiling beside it).
|
|
173
184
|
*/
|
|
174
185
|
startupTimeoutMs?: number;
|
|
186
|
+
/**
|
|
187
|
+
* Opt in to the sending leg's OWN session id on this server's requests: with a key declared, every `tools/call` and `resources/read` the
|
|
188
|
+
* engine sends this server carries `params._meta[key]` = that leg's `sessionId` (the id its events carry), over stdio and Streamable
|
|
189
|
+
* HTTP alike, so a connector can keep state per (principal, session). Absent ⇒ nothing is sent (a session id leaving the process is a
|
|
190
|
+
* correlation the deployment chooses). A delegated child is another session: its own calls carry its own id, and the engine does not
|
|
191
|
+
* guess a root — the principal ({@link TaskSpec.principal}) is shared by every session of one user, so it is not a tree key either.
|
|
192
|
+
*
|
|
193
|
+
* The key is judged once by {@link import("./mcp-call-meta.js").judgeSessionMetaKey} where the declaration is judged (the preparation door
|
|
194
|
+
* and `materializeMcpTools`): a non-string, an empty or over-long one, one outside the MCP `_meta` key-name format, one in a prefix MCP
|
|
195
|
+
* reserves (a prefix whose second label is `modelcontextprotocol` or `mcp`), `progressToken` (the SDK's own) or a key in the engine's
|
|
196
|
+
* `sema/` namespace refuses the entry with
|
|
197
|
+
* `config.invalid_argument` naming the key — never dropped, never defaulted. A dial with no leg (the library entrance, the no-run probe)
|
|
198
|
+
* has no session, so nothing rides.
|
|
199
|
+
*/
|
|
200
|
+
sessionMetaKey?: string;
|
|
175
201
|
}
|
|
176
202
|
type ToolAxes = NonNullable<McpServerSpec["toolAxes"]>;
|
|
177
203
|
/**
|
|
@@ -219,17 +245,17 @@ export type DeclarationRead = {
|
|
|
219
245
|
* path does not say which kind of container each name came from, so a segment of digits alone is read as a list index.
|
|
220
246
|
*/
|
|
221
247
|
export declare function declarationFaultOf(fault: ReceiptFault): DeclarationFault;
|
|
222
|
-
/** What a declaration's own type fixes at one path, beyond being plain data: a string there
|
|
248
|
+
/** What a declaration's own type fixes at one path, beyond being plain data: a string there. */
|
|
223
249
|
export interface DeclarationPathRule {
|
|
224
250
|
readonly path: readonly string[];
|
|
225
|
-
readonly holds: "a string"
|
|
251
|
+
readonly holds: "a string";
|
|
226
252
|
/** The member must be there (a declaration with no value at the path is refused, as one with a value of another kind is). */
|
|
227
253
|
readonly required?: true;
|
|
228
254
|
}
|
|
229
255
|
/**
|
|
230
|
-
* Per surface, every path its declaration's type fixes beyond plain data — the declarer's `name` (a string, always there)
|
|
231
|
-
*
|
|
232
|
-
*
|
|
256
|
+
* Per surface, every path its declaration's type fixes beyond plain data — the declarer's `name` (a string, always there). A declaration
|
|
257
|
+
* carries no record of values (its credential reference is judged by its own reader, the retired value members are refused by name —
|
|
258
|
+
* both after this receipt, src/core/peer-seat.ts). A path that is not its surface's (an A2A peer's `transport`) is not judged by another
|
|
233
259
|
* surface's row: it is a member the surface does not read.
|
|
234
260
|
*/
|
|
235
261
|
export declare const DECLARATION_PATH_RULES: Readonly<Record<ToolAxesSurface, readonly DeclarationPathRule[]>>;
|
|
@@ -349,16 +375,18 @@ export interface A2aServerSpec {
|
|
|
349
375
|
/** Explicit agent-card location, when the peer does not publish at a well-known path. Set ⇒ it is used
|
|
350
376
|
* ALONE (no well-known probing behind the operator's back). */
|
|
351
377
|
cardUrl?: string;
|
|
352
|
-
/**
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
|
|
378
|
+
/** At most one opaque credential reference, as on an MCP server's transport: the headers a send to this peer carries are
|
|
379
|
+
* answered per send by the deployment's peer seat ({@link RunnerDeps.peerSeat}), never declared (`headers` is retired and
|
|
380
|
+
* refused, `config.credential_in_declaration`). Pieces the seat answers travel only to the declared origins (`url`,
|
|
381
|
+
* `cardUrl`): a send carrying them to an endpoint on another origin is refused (`config.protocol_endpoint_unbound`), and it
|
|
382
|
+
* follows no redirect. */
|
|
383
|
+
credentials?: CredentialRef;
|
|
356
384
|
/**
|
|
357
385
|
* Per-task **end-user principal** header (design/62), same contract as the MCP side: when set, the
|
|
358
386
|
* Runner injects the running task's authenticated {@link TaskSpec.principal} under this header name on
|
|
359
387
|
* every call to this peer, so the peer can enforce per-user authorization. Absent principal ⇒ the
|
|
360
|
-
* header is not sent (the peer must then default to deny/public, never admin). A
|
|
361
|
-
*
|
|
388
|
+
* header is not sent (the peer must then default to deny/public, never admin). A header the peer seat
|
|
389
|
+
* answers under the same name in any case is the seat's fault, and that send is not made (`config.protocol_header_collision`).
|
|
362
390
|
* The principal is Runner-held: the model can neither read nor set it.
|
|
363
391
|
*/
|
|
364
392
|
principalHeader?: string;
|
|
@@ -68,12 +68,9 @@ export function declarationFaultOf(fault) {
|
|
|
68
68
|
export const DECLARATION_PATH_RULES = Object.freeze({
|
|
69
69
|
mcp: Object.freeze([
|
|
70
70
|
{ path: ["name"], holds: "a string", required: true },
|
|
71
|
-
{ path: ["transport", "env"], holds: "names to strings" },
|
|
72
|
-
{ path: ["transport", "headers"], holds: "names to strings" },
|
|
73
71
|
].map((rule) => Object.freeze({ ...rule, path: Object.freeze([...rule.path]) }))),
|
|
74
72
|
a2a: Object.freeze([
|
|
75
73
|
{ path: ["name"], holds: "a string", required: true },
|
|
76
|
-
{ path: ["headers"], holds: "names to strings" },
|
|
77
74
|
].map((rule) => Object.freeze({ ...rule, path: Object.freeze([...rule.path]) }))),
|
|
78
75
|
});
|
|
79
76
|
export const NO_DECLARATION_PATH_RULES = Object.freeze([]);
|
|
@@ -84,21 +81,7 @@ function declarationVocabularyFault(root, rules) {
|
|
|
84
81
|
const stack = [];
|
|
85
82
|
const ruleAt = () => rules.find((rule) => rule.path.length === path.length && rule.path.every((key, i) => key === path[i]));
|
|
86
83
|
const onRuleRoute = () => rules.some((rule) => rule.path.length > path.length && path.every((key, i) => key === rule.path[i]));
|
|
87
|
-
const ruleProblem = (
|
|
88
|
-
if (rule.holds === "a string")
|
|
89
|
-
return typeof value === "string" ? undefined : `it is ${dataKind(value)}, not a string`;
|
|
90
|
-
if (!isPlainRecord(value))
|
|
91
|
-
return `it is ${dataKind(value)}, not a record of names to strings`;
|
|
92
|
-
for (const [key, member] of Object.entries(value)) {
|
|
93
|
-
path.push(key);
|
|
94
|
-
if (key === "__proto__")
|
|
95
|
-
return PROTO_MEMBER;
|
|
96
|
-
if (member !== undefined && typeof member !== "string")
|
|
97
|
-
return `it is ${dataKind(member)}, not a string: this record maps names to strings`;
|
|
98
|
-
path.pop();
|
|
99
|
-
}
|
|
100
|
-
return undefined;
|
|
101
|
-
};
|
|
84
|
+
const ruleProblem = (_rule, value) => (typeof value === "string" ? undefined : `it is ${dataKind(value)}, not a string`);
|
|
102
85
|
const meet = (value) => {
|
|
103
86
|
if (typeof value !== "object" || value === null || (asked.has(value) && !onRuleRoute()))
|
|
104
87
|
return undefined;
|
package/dist/core/mcp.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PeerSeat } from "./peer-seat.js";
|
|
1
2
|
import { type McpInstructionsEntry, type PromptSectionDisposer } from "./prompt-section-seat.js";
|
|
2
3
|
import { McpConnectionPool } from "./mcp-connection-pool.js";
|
|
3
4
|
import { type McpDelivered, type McpFailureKind, type McpServerLiveness } from "./mcp-failure.js";
|
|
@@ -8,6 +9,7 @@ import type { McpServerSpec, OnElicit, ToolEffect } from "./types.js";
|
|
|
8
9
|
import type { McpRevocationLedger } from "./mcp-server-spec.js";
|
|
9
10
|
import { type HostFloor } from "./host-floor.js";
|
|
10
11
|
import { type ReminderDisclosureCounts } from "./reminder-disclosure.js";
|
|
12
|
+
import { type McpLegMetaReader } from "./mcp-call-meta.js";
|
|
11
13
|
export { resolveMcpDeclaredResultSize } from "./mcp-tool-meta.js";
|
|
12
14
|
/**
|
|
13
15
|
* The safety axes (design/77 §4 irreversibility, design/70 egress) derived from one materialized MCP
|
|
@@ -481,19 +483,6 @@ export * from "./image-downsample.js";
|
|
|
481
483
|
* type, ≤10 object entries then `, ...`.
|
|
482
484
|
*/
|
|
483
485
|
export declare function inferCompactSchema(value: unknown, depth?: number): string;
|
|
484
|
-
/** `kind` is the dial's ONE read of `spec.transport.kind` (taken by the caller beside the dial and threaded
|
|
485
|
-
* here, to the idle bucket and to the failure classifier alike): a nested `transport` object is the
|
|
486
|
-
* caller's, and a getter that answered differently to two readers would otherwise connect over one
|
|
487
|
-
* transport and be judged under another. An unknown kind takes the non-stdio branch, as it always did. */
|
|
488
|
-
/**
|
|
489
|
-
* The MCP HTTP transport's `fetch`: every request the transport makes — the POST, the SSE GET (initial and
|
|
490
|
-
* resumed), the DELETE, the auth flows — goes to the endpoint the declaration NAMED and follows no redirect.
|
|
491
|
-
* `fetch`'s default follows a 3xx silently and then reports only the last hop, which is the one shape under
|
|
492
|
-
* which the delivery verdict would lie (a connect refusal on the redirect target reading "never sent" while
|
|
493
|
-
* the declared endpoint had received the POST); a 3xx now surfaces as the SDK's HTTP-status error, and a
|
|
494
|
-
* body or a credential never travels to a host the declaration did not name. Exported for its pin only.
|
|
495
|
-
*/
|
|
496
|
-
export declare const declaredEndpointFetch: typeof fetch;
|
|
497
486
|
interface McpContentItem {
|
|
498
487
|
type: string;
|
|
499
488
|
text?: string;
|
|
@@ -617,7 +606,10 @@ reminderDisclosure?: {
|
|
|
617
606
|
}, poolOpts?: {
|
|
618
607
|
pool: McpConnectionPool;
|
|
619
608
|
ownsPool?: boolean;
|
|
620
|
-
}, promptSections?: PromptSectionDisposer, dialable?: (spec: McpServerSpec) => boolean, signal?: AbortSignal, hostFloor?: HostFloor): Promise<MaterializedMcp>;
|
|
609
|
+
}, promptSections?: PromptSectionDisposer, dialable?: (spec: McpServerSpec) => boolean, signal?: AbortSignal, hostFloor?: HostFloor, peerSeat?: PeerSeat): Promise<MaterializedMcp>;
|
|
610
|
+
/** The runner's materialization of one leg (not index-exported): every minted tool's `tools/call` reads the leg's request-meta seat
|
|
611
|
+
* (`mcp-call-meta.ts`) — the request meta's only source, written only by the `tool.call` station with what its judge passed. */
|
|
612
|
+
export declare function materializeLegMcpTools(seat: McpLegMetaReader | undefined, ...[specs, principal, onElicit, imageResizer, reminderDisclosure, mcpRevocations, poolOpts, promptSections, dialable, signal, hostFloor, peerSeat]: Parameters<typeof materializeMcpTools>): Promise<MaterializedMcp>;
|
|
621
613
|
/**
|
|
622
614
|
* Fold the caller's AUTHORITATIVE per-tool override (design F: caller = trust root) over the server-hint axis.
|
|
623
615
|
* Unlike server hints, the caller may RAISE or LOWER any axis: `effect` sets the repeat-safety class (lower to
|
package/dist/core/mcp.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { egressText } from "./untrusted-egress.js";
|
|
2
1
|
import { __resetEnvKnobAnnouncements } from "./env-knob-announce.js";
|
|
3
2
|
import { resolveEnvBudget } from "./env-budget.js";
|
|
4
3
|
import { MCP_NAMESPACE } from "./protocol-table.js";
|
|
5
|
-
import {
|
|
4
|
+
import { remoteWords, resolveProtocolHttpHeaders } from "./protocol-http-auth.js";
|
|
5
|
+
import { PeerCarrier, Reauthorized, answeredUnauthorized, carrierOf, inFlight, mcpPeerTarget, peerFetch, peerSeatMissing, recordCarrier, sentOnceMore, settledInFlight } from "./peer-seat.js";
|
|
6
6
|
import { disposeSectionEntry, sectionAnswerWarning } from "./prompt-section-seat.js";
|
|
7
|
-
import {
|
|
7
|
+
import { createToolNameClaims, mintNamespacePrefix, normalizeNameSegment } from "./protocol-naming.js";
|
|
8
|
+
import { mcpToolDropReason, refuseCollidingMcpServerNames } from "./mcp-name-judge.js";
|
|
8
9
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
9
10
|
import { McpConnectionPool } from "./mcp-connection-pool.js";
|
|
10
11
|
import { SessionEndingTransport, requestSite } from "./mcp-session-end.js";
|
|
11
12
|
import { mcpToolGate, UNPROVEN_GATE } from "./mcp-listing-drift.js";
|
|
12
|
-
import { ConnectionListing, Flights, IDLE_WATCHDOG_ABORT_REASON, Resendable, armMcpIdleWatchdog, callThroughLink, listingRefusal } from "./mcp-server-link.js";
|
|
13
|
+
import { ConnectionListing, Flights, IDLE_WATCHDOG_ABORT_REASON, Resendable, armMcpIdleWatchdog, callThroughLink, listingRefusal, reach } from "./mcp-server-link.js";
|
|
13
14
|
import { underStartupBound } from "./mcp-startup-request.js";
|
|
14
15
|
import { LIST_MCP_RESOURCES, MCP_RESOURCE_LIST_ALLOW, MCP_RESOURCE_READ_ALLOW, READ_MCP_RESOURCE, READ_MCP_RESOURCE_DIR, retractInstructions, tellInstructions, toldOnDial, unretractInstructions, withdrawInstructionAdds } from "./mounted-mcp.js";
|
|
15
16
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
@@ -27,6 +28,7 @@ import { delimitUntrusted, inlineUntrusted, sanitizeUntrustedText } from "./untr
|
|
|
27
28
|
import { discloseReminderShaped, observeReminderMarkEcho } from "./reminder-disclosure.js";
|
|
28
29
|
import { MARKED_BLOCK_AFTER_DATA } from "./reminder-mint.js";
|
|
29
30
|
import { resolveMcpDeclaredResultSize, resolveMcpRequiresUserInteraction } from "./mcp-tool-meta.js";
|
|
31
|
+
import { mcpCallMeta } from "./mcp-call-meta.js";
|
|
30
32
|
export { resolveMcpDeclaredResultSize } from "./mcp-tool-meta.js";
|
|
31
33
|
import { withContentOrigin } from "./memory-engine/content-origin.js";
|
|
32
34
|
import { judgeMcpEntryDeclarations, snapshotMcpEntries } from "./locked-config.js";
|
|
@@ -165,7 +167,7 @@ export function collapseMcpErrorPrefix(message) {
|
|
|
165
167
|
function sanitizeMcpErrorTextInPlace(err, declared) {
|
|
166
168
|
if (!(err instanceof Error))
|
|
167
169
|
return;
|
|
168
|
-
const sanitized =
|
|
170
|
+
const sanitized = remoteWords(err instanceof McpError ? collapseMcpErrorPrefix(err.message) : err.message, declared);
|
|
169
171
|
if (sanitized !== err.message)
|
|
170
172
|
err.message = sanitized;
|
|
171
173
|
}
|
|
@@ -176,10 +178,7 @@ function namedMcpFailureText(err, declared) {
|
|
|
176
178
|
}
|
|
177
179
|
function remoteErrorText(err, declared, opts) {
|
|
178
180
|
const raw = thrownText(err);
|
|
179
|
-
return
|
|
180
|
-
}
|
|
181
|
-
function mcpRemoteText(text, declared) {
|
|
182
|
-
return egressText("same-principal", scrubRequestEcho(text, declared));
|
|
181
|
+
return remoteWords(opts?.collapse === true ? collapseMcpErrorPrefix(raw) : raw, declared);
|
|
183
182
|
}
|
|
184
183
|
function writeEffectWarning(writeEffect) {
|
|
185
184
|
return writeEffect
|
|
@@ -248,6 +247,8 @@ function rethrowHonestMcpError(err, ctx) {
|
|
|
248
247
|
}
|
|
249
248
|
finish(markMcpFailure(err, details()));
|
|
250
249
|
}
|
|
250
|
+
case "credential_unavailable":
|
|
251
|
+
finish(markMcpFailure(new Error(`${ctx.what} was not sent to MCP server "${serverLabel}": ${inlineUntrusted(thrownText(err), 400)}. The request was not delivered, so the server did not execute it. This is the deployment's credential seat, not the server — do not retry the call until it is fixed; use an alternative if one exists.`), details()));
|
|
251
252
|
case "spawn_failed":
|
|
252
253
|
case "invalid_config":
|
|
253
254
|
case "unknown": {
|
|
@@ -363,8 +364,7 @@ export function inferCompactSchema(value, depth = 2) {
|
|
|
363
364
|
}
|
|
364
365
|
return typeof value;
|
|
365
366
|
}
|
|
366
|
-
|
|
367
|
-
function buildTransport(spec, principal, kind) {
|
|
367
|
+
function buildTransport(spec, principal, kind, carrier, pieces) {
|
|
368
368
|
const t = spec.transport;
|
|
369
369
|
if (kind === "stdio") {
|
|
370
370
|
if (!("command" in t))
|
|
@@ -372,16 +372,13 @@ function buildTransport(spec, principal, kind) {
|
|
|
372
372
|
return new StdioClientTransport({
|
|
373
373
|
command: t.command,
|
|
374
374
|
args: t.args,
|
|
375
|
-
env:
|
|
375
|
+
...(pieces?.env !== undefined ? { env: { ...pieces.env } } : {}),
|
|
376
376
|
});
|
|
377
377
|
}
|
|
378
378
|
if (!("url" in t))
|
|
379
379
|
throw new Error(`MCP server "${spec.name}": transport kind "${String(kind)}" carries no url`);
|
|
380
|
-
|
|
381
|
-
return new SessionEndingTransport(new URL(t.url), {
|
|
382
|
-
requestInit: headers ? { headers } : undefined,
|
|
383
|
-
fetch: declaredEndpointFetch,
|
|
384
|
-
});
|
|
380
|
+
resolveProtocolHttpHeaders(MCP_NAMESPACE.id, t.principalHeader !== undefined ? { principalHeader: t.principalHeader } : {}, principal);
|
|
381
|
+
return new SessionEndingTransport(new URL(t.url), { fetch: peerFetch(carrier, t.principalHeader, principal) });
|
|
385
382
|
}
|
|
386
383
|
let autoResizer;
|
|
387
384
|
export async function mapContent(content, serverName, imageResizer) {
|
|
@@ -645,7 +642,10 @@ export function mcpToolSchemaProblem(schema) {
|
|
|
645
642
|
}
|
|
646
643
|
return undefined;
|
|
647
644
|
}
|
|
648
|
-
export async function materializeMcpTools(specs, principal, onElicit, imageResizer, reminderDisclosure, mcpRevocations, poolOpts, promptSections, dialable, signal, hostFloor) {
|
|
645
|
+
export async function materializeMcpTools(specs, principal, onElicit, imageResizer, reminderDisclosure, mcpRevocations, poolOpts, promptSections, dialable, signal, hostFloor, peerSeat) {
|
|
646
|
+
return materializeLegMcpTools(undefined, specs, principal, onElicit, imageResizer, reminderDisclosure, mcpRevocations, poolOpts, promptSections, dialable, signal, hostFloor, peerSeat);
|
|
647
|
+
}
|
|
648
|
+
export async function materializeLegMcpTools(seat, ...[specs, principal, onElicit, imageResizer, reminderDisclosure, mcpRevocations, poolOpts, promptSections, dialable, signal, hostFloor, peerSeat]) {
|
|
649
649
|
const snapshot = snapshotMcpEntries(specs);
|
|
650
650
|
const axesRefused = new WeakMap();
|
|
651
651
|
const entries = snapshot.map((spec) => {
|
|
@@ -655,17 +655,7 @@ export async function materializeMcpTools(specs, principal, onElicit, imageResiz
|
|
|
655
655
|
axesRefused.set(spec, judged.error);
|
|
656
656
|
return spec;
|
|
657
657
|
});
|
|
658
|
-
|
|
659
|
-
const collision = findNamespacePrefixCollision(MCP_NAMESPACE, entries.map((s) => s.name));
|
|
660
|
-
if (collision) {
|
|
661
|
-
const [a, b] = collision.peers;
|
|
662
|
-
const e = new Error(a === b
|
|
663
|
-
? `MCP server "${inlineUntrusted(a, 120)}" is declared twice — each server needs its own name (both mount under "${collision.prefix}", so their tools would shadow each other and a refresh of one would unmount the other's).`
|
|
664
|
-
: `MCP server names "${inlineUntrusted(a, 120)}" and "${inlineUntrusted(b, 120)}" both mount under "${collision.prefix}" — the namespaced tool name keeps only [a-zA-Z0-9_-], so they are the same domain to this engine (their tools would shadow each other and a refresh of one would unmount the other's). Rename one.`);
|
|
665
|
-
e.code = "config.mcp_server_name_collision";
|
|
666
|
-
throw e;
|
|
667
|
-
}
|
|
668
|
-
}
|
|
658
|
+
refuseCollidingMcpServerNames(entries.map((s) => s.name));
|
|
669
659
|
let revocationProbeFailed = false;
|
|
670
660
|
const isServerRevoked = (serverName) => {
|
|
671
661
|
if (mcpRevocations === undefined)
|
|
@@ -771,12 +761,12 @@ export async function materializeMcpTools(specs, principal, onElicit, imageResiz
|
|
|
771
761
|
const gatesNow = (h) => {
|
|
772
762
|
const latest = h.listing.latest();
|
|
773
763
|
if (latest.at !== h.gatesAt.at)
|
|
774
|
-
h.gatesAt = { at: latest.at, gates: intakeListedTools({ tools: [...latest.entries], unproven: latest.unproven }, h.spec, linkOf(h.name), echoOf(h.spec), imageResizer, mcpDisclosure, isServerRevoked, h.transportKind).gates };
|
|
764
|
+
h.gatesAt = { at: latest.at, gates: intakeListedTools({ tools: [...latest.entries], unproven: latest.unproven }, h.spec, linkOf(h.name), echoOf(h.spec), imageResizer, mcpDisclosure, isServerRevoked, h.transportKind, seat).gates };
|
|
775
765
|
return h.gatesAt.gates;
|
|
776
766
|
};
|
|
777
767
|
const linkOf = (server) => ({
|
|
778
768
|
live: () => liveOf(server),
|
|
779
|
-
recover: (lost) => redialFlights.running(server) ?? (liveOf(server) === lost ? redialFlights.start(server, () => redialDial(server)) : Promise.resolve()),
|
|
769
|
+
recover: (lost, cause = "session") => redialFlights.running(server) ?? (liveOf(server) === lost ? redialFlights.start(server, () => redialDial(server, cause)) : Promise.resolve()),
|
|
780
770
|
});
|
|
781
771
|
const endpointRefusal = (spec, dialKind) => {
|
|
782
772
|
const transport = spec.transport;
|
|
@@ -792,12 +782,27 @@ export async function materializeMcpTools(specs, principal, onElicit, imageResiz
|
|
|
792
782
|
}
|
|
793
783
|
return peerRequestRefusal(`mcp: server "${inlineUntrusted(spec.name, 120)}"`, url, hostFloor);
|
|
794
784
|
};
|
|
795
|
-
const dialServer = (spec, dialKind, dialOpts) => {
|
|
796
|
-
const refusal = axesRefused.get(spec) ?? endpointRefusal(spec, dialKind);
|
|
797
|
-
|
|
785
|
+
const dialServer = async (spec, dialKind, dialOpts) => {
|
|
786
|
+
const refusal = axesRefused.get(spec) ?? peerSeatMissing(`mcp: server "${inlineUntrusted(spec.name, 120)}"`, spec.transport.credentials, peerSeat) ?? endpointRefusal(spec, dialKind);
|
|
787
|
+
if (refusal !== undefined)
|
|
788
|
+
throw refusal;
|
|
789
|
+
const carrier = new PeerCarrier(peerSeat, mcpPeerTarget(spec, dialKind), principal, dialKind === "stdio" ? "stdio" : "http", dialKind !== "stdio" && "principalHeader" in spec.transport && spec.transport.principalHeader !== undefined);
|
|
790
|
+
sentOf.set(spec.name, carrier.sent);
|
|
791
|
+
const dial = () => connectServer(spec, principal, onElicit, imageResizer, mcpDisclosure, isServerRevoked, dialKind, poolOpts?.pool, { ...dialOpts, link: linkOf(spec.name), carrier, ...(signal !== undefined ? { signal } : {}) }, seat);
|
|
792
|
+
const connected = await dial().catch(async (err) => {
|
|
793
|
+
if (typeof err === "object" && err !== null)
|
|
794
|
+
sentOf.set(spec.name, (carrierOf(err) ?? carrier).sent);
|
|
795
|
+
const dialing = (typeof err === "object" && err !== null ? carrierOf(err) : undefined) ?? carrier;
|
|
796
|
+
if (!(dialing.renewed && answeredUnauthorized(err)) || signal?.aborted === true)
|
|
797
|
+
throw err;
|
|
798
|
+
return dial();
|
|
799
|
+
});
|
|
800
|
+
sentOf.set(spec.name, (carrierOf(connected.client) ?? carrier).sent);
|
|
801
|
+
return connected;
|
|
798
802
|
};
|
|
799
803
|
const prefixOf = (name) => mintNamespacePrefix(MCP_NAMESPACE, name);
|
|
800
|
-
const
|
|
804
|
+
const sentOf = new Map();
|
|
805
|
+
const echoOf = (spec) => sentOf.get(spec.name) ?? [];
|
|
801
806
|
const heldCount = (name) => serverHandles.find((h) => h.name === name)?.tools.length ?? 0;
|
|
802
807
|
const reconcileInstructions = (name, after, connected) => {
|
|
803
808
|
if (!connected)
|
|
@@ -845,7 +850,7 @@ export async function materializeMcpTools(specs, principal, onElicit, imageResiz
|
|
|
845
850
|
const declineRedial = (server, outcome, reason) => ({ server, prefix: prefixOf(server), outcome, reason, toolCount: heldCount(server), added: [], removed: [] });
|
|
846
851
|
const redialFlights = new Flights();
|
|
847
852
|
const ownerStopped = () => (disposing ? "this materialization is being disposed — the task is tearing down" : signal?.aborted === true ? "the run was aborted" : undefined);
|
|
848
|
-
const redialDial = async (server) => {
|
|
853
|
+
const redialDial = async (server, cause = "session") => {
|
|
849
854
|
const prefix = prefixOf(server);
|
|
850
855
|
const declined = (outcome, reason) => declineRedial(server, outcome, reason);
|
|
851
856
|
const stopped = ownerStopped();
|
|
@@ -862,13 +867,20 @@ export async function materializeMcpTools(specs, principal, onElicit, imageResiz
|
|
|
862
867
|
if (prior) {
|
|
863
868
|
prior.announce.fn = undefined;
|
|
864
869
|
prior.health.observe = undefined;
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
870
|
+
if (cause !== "expired") {
|
|
871
|
+
serverHandles.splice(hIdx, 1);
|
|
872
|
+
const cIdx = connections.findIndex((c) => c.client === prior.client);
|
|
873
|
+
const priorConnection = cIdx === -1 ? undefined : connections.splice(cIdx, 1)[0];
|
|
874
|
+
await (priorConnection?.close() ?? prior.client.close()).catch(() => undefined);
|
|
875
|
+
}
|
|
869
876
|
}
|
|
870
877
|
const dialKind = readDialKind(spec);
|
|
871
|
-
const dialed = await dialServer(spec, dialKind, { fresh:
|
|
878
|
+
const dialed = await dialServer(spec, dialKind, { fresh: cause !== "expired", sections: promptSections, ...(prior !== undefined ? { carried: prior.listing.latest().entries } : {}) }).then((connected) => ({ connected }), (err) => ({ err }));
|
|
879
|
+
if (cause === "expired" && prior !== undefined) {
|
|
880
|
+
if (serverHandles.includes(prior))
|
|
881
|
+
serverHandles.splice(serverHandles.indexOf(prior), 1);
|
|
882
|
+
void settledInFlight(prior.client).then(() => (connections.find((c) => c.client === prior.client)?.close() ?? prior.client.close()).catch(() => undefined));
|
|
883
|
+
}
|
|
872
884
|
const stoppedLate = ownerStopped();
|
|
873
885
|
if (stoppedLate !== undefined) {
|
|
874
886
|
if ("connected" in dialed)
|
|
@@ -959,7 +971,7 @@ export async function materializeMcpTools(specs, principal, onElicit, imageResiz
|
|
|
959
971
|
results.push({ server: h.name, prefix: prefixOf(h.name), status: "failed", toolCount: h.tools.length, added: [], removed: [], error: "a later listing of this server was opened and applied while this one was in the air — this one was discarded" });
|
|
960
972
|
continue;
|
|
961
973
|
}
|
|
962
|
-
const { serverTools, serverAxes, gates, dropped, accepted } = intakeListedTools({ tools: [...mergedRaw], unproven: answered.unproven }, h.spec, linkOf(h.name), echoOf(h.spec), imageResizer, mcpDisclosure, isServerRevoked, h.transportKind);
|
|
974
|
+
const { serverTools, serverAxes, gates, dropped, accepted } = intakeListedTools({ tools: [...mergedRaw], unproven: answered.unproven }, h.spec, linkOf(h.name), echoOf(h.spec), imageResizer, mcpDisclosure, isServerRevoked, h.transportKind, seat);
|
|
963
975
|
cacheTools(accepted, answered.kept);
|
|
964
976
|
const priorNames = h.tools.map((t) => t.name);
|
|
965
977
|
const newNames = serverTools.map((t) => t.name);
|
|
@@ -1364,7 +1376,7 @@ function buildResourceTools(resourceServers, isServerRevoked = () => false) {
|
|
|
1364
1376
|
let res;
|
|
1365
1377
|
try {
|
|
1366
1378
|
res = await rs.client
|
|
1367
|
-
.readResource(
|
|
1379
|
+
.readResource(rs.readParams(uri), { signal: watchdog.combinedSignal, timeout: timeoutMs })
|
|
1368
1380
|
.catch((err) => rethrowHonestMcpError(err, { server, declared: rs.declared, what, timeoutMs, writeEffect: false, signal, attributeServer: true, site, idle: { signal: watchdog.idleSignal, idleMs }, liveness: rs.health }));
|
|
1369
1381
|
rs.health.observe?.("completed");
|
|
1370
1382
|
}
|
|
@@ -1540,7 +1552,7 @@ async function listToolsLenient(client, options, declared) {
|
|
|
1540
1552
|
});
|
|
1541
1553
|
return { tools: walk.items, ...(walk.incomplete !== undefined ? { incomplete: walk.incomplete } : {}) };
|
|
1542
1554
|
}
|
|
1543
|
-
async function connectServer(spec, principal, onElicit, imageResizer, reminderDisclosure, isServerRevoked, transportKind, pool, dialOpts) {
|
|
1555
|
+
async function connectServer(spec, principal, onElicit, imageResizer, reminderDisclosure, isServerRevoked, transportKind, pool, dialOpts, seat) {
|
|
1544
1556
|
const fp = spec.fingerprint;
|
|
1545
1557
|
if (fp !== undefined && !(typeof fp === "string" && fp.length > 0 && fp.length <= 128)) {
|
|
1546
1558
|
throw Object.assign(new Error(`MCP server "${inlineUntrusted(spec.name, 160)}": fingerprint must be a non-empty string of at most 128 characters (got ${typeof fp === "string" ? `${fp.length} characters` : typeof fp}) — not dialed`), { code: "config.mcp_fingerprint_invalid" });
|
|
@@ -1573,7 +1585,8 @@ async function connectServer(spec, principal, onElicit, imageResizer, reminderDi
|
|
|
1573
1585
|
}
|
|
1574
1586
|
});
|
|
1575
1587
|
}
|
|
1576
|
-
const
|
|
1588
|
+
const pieces = transportKind === "stdio" ? await dialOpts.carrier.next(stop) : undefined;
|
|
1589
|
+
const transport = buildTransport(spec, principal, transportKind, dialOpts.carrier, pieces);
|
|
1577
1590
|
const hangUp = () => void client.close().catch(() => undefined);
|
|
1578
1591
|
stop?.addEventListener("abort", hangUp, { once: true });
|
|
1579
1592
|
try {
|
|
@@ -1581,11 +1594,14 @@ async function connectServer(spec, principal, onElicit, imageResizer, reminderDi
|
|
|
1581
1594
|
}
|
|
1582
1595
|
catch (err) {
|
|
1583
1596
|
await client.close().catch(() => undefined);
|
|
1597
|
+
if (typeof err === "object" && err !== null)
|
|
1598
|
+
recordCarrier(err, dialOpts.carrier);
|
|
1584
1599
|
throw stop?.aborted === true ? stop.reason : err;
|
|
1585
1600
|
}
|
|
1586
1601
|
finally {
|
|
1587
1602
|
stop?.removeEventListener("abort", hangUp);
|
|
1588
1603
|
}
|
|
1604
|
+
recordCarrier(client, dialOpts.carrier);
|
|
1589
1605
|
return client;
|
|
1590
1606
|
};
|
|
1591
1607
|
const lease = pool !== undefined && !elicitOn ? await pool.acquire(McpConnectionPool.keyOf(spec, principal, transportKind, startupMs), dialClient, dialOpts) : undefined;
|
|
@@ -1607,10 +1623,10 @@ async function connectServer(spec, principal, onElicit, imageResizer, reminderDi
|
|
|
1607
1623
|
const listing = lease?.listing ?? new ConnectionListing();
|
|
1608
1624
|
const at = listing.open();
|
|
1609
1625
|
const cacheTools = openListing();
|
|
1610
|
-
const declared =
|
|
1626
|
+
const declared = (carrierOf(client) ?? dialOpts.carrier).sent;
|
|
1611
1627
|
const listed = await underStartupBound(startupMs, dialOpts?.signal, (options) => listToolsLenient(client, options, declared));
|
|
1612
1628
|
const answered = listing.answer(at, listed.tools, listed.incomplete !== undefined, dialOpts.carried);
|
|
1613
|
-
const { serverTools, serverAxes, gates, dropped, advisories, accepted } = intakeListedTools({ tools: [...answered.view], unproven: answered.unproven }, spec, dialOpts.link, declared, imageResizer, reminderDisclosure, isServerRevoked, transportKind);
|
|
1629
|
+
const { serverTools, serverAxes, gates, dropped, advisories, accepted } = intakeListedTools({ tools: [...answered.view], unproven: answered.unproven }, spec, dialOpts.link, declared, imageResizer, reminderDisclosure, isServerRevoked, transportKind, seat);
|
|
1614
1630
|
cacheTools(accepted, answered.kept);
|
|
1615
1631
|
const caps = client.getServerCapabilities();
|
|
1616
1632
|
const resourceInfo = caps?.resources
|
|
@@ -1648,15 +1664,17 @@ async function connectServer(spec, principal, onElicit, imageResizer, reminderDi
|
|
|
1648
1664
|
...(instructions ? { instructions } : {}),
|
|
1649
1665
|
...(disposed?.defect !== undefined ? { instructionsDefect: disposed.defect } : {}),
|
|
1650
1666
|
...(listed.incomplete !== undefined ? { listingIncomplete: listed.incomplete } : {}),
|
|
1651
|
-
...(resourceInfo && (resourceInfo.listAllowed || resourceInfo.readAllowed) ? { resourceServer: { server: spec.name, client, health, transportKind: idleKindOf(transportKind), declared, ...resourceInfo } } : {}),
|
|
1667
|
+
...(resourceInfo && (resourceInfo.listAllowed || resourceInfo.readAllowed) ? { resourceServer: { server: spec.name, client, health, transportKind: idleKindOf(transportKind), declared, readParams: (uri) => { const _meta = mcpCallMeta(undefined, undefined, spec.sessionMetaKey, seat?.sessionId); return { uri, ...(_meta !== undefined ? { _meta } : {}) }; }, ...resourceInfo } } : {}),
|
|
1652
1668
|
};
|
|
1653
1669
|
}
|
|
1654
1670
|
catch (err) {
|
|
1655
1671
|
await close().catch(() => undefined);
|
|
1672
|
+
if (typeof err === "object" && err !== null)
|
|
1673
|
+
recordCarrier(err, carrierOf(client) ?? dialOpts.carrier);
|
|
1656
1674
|
throw err;
|
|
1657
1675
|
}
|
|
1658
1676
|
}
|
|
1659
|
-
function intakeListedTools(listed, spec, link, declared, imageResizer, reminderDisclosure, isServerRevoked, transportKind) {
|
|
1677
|
+
function intakeListedTools(listed, spec, link, declared, imageResizer, reminderDisclosure, isServerRevoked, transportKind, seat) {
|
|
1660
1678
|
const declaredContentOrigin = spec.contentOrigin;
|
|
1661
1679
|
const serverTools = [];
|
|
1662
1680
|
const serverAxes = [];
|
|
@@ -1664,7 +1682,7 @@ function intakeListedTools(listed, spec, link, declared, imageResizer, reminderD
|
|
|
1664
1682
|
const dropped = [];
|
|
1665
1683
|
const accepted = [];
|
|
1666
1684
|
const advisories = [];
|
|
1667
|
-
const
|
|
1685
|
+
const claimToolName = createToolNameClaims(MCP_NAMESPACE, spec.name);
|
|
1668
1686
|
for (const t of listed.tools) {
|
|
1669
1687
|
if (spec.allowTools && !spec.allowTools.includes(t.name)) {
|
|
1670
1688
|
continue;
|
|
@@ -1704,18 +1722,11 @@ function intakeListedTools(listed, spec, link, declared, imageResizer, reminderD
|
|
|
1704
1722
|
}
|
|
1705
1723
|
const remoteName = t.name;
|
|
1706
1724
|
const taskRequired = t.execution !== null && typeof t.execution === "object" && t.execution.taskSupport === "required";
|
|
1707
|
-
const namespacedName =
|
|
1708
|
-
const mintedBy = mintedNames.get(namespacedName);
|
|
1725
|
+
const { minted: namespacedName, heldBy: mintedBy } = claimToolName(remoteName);
|
|
1709
1726
|
if (mintedBy !== undefined) {
|
|
1710
|
-
dropped.push({
|
|
1711
|
-
tool: inlineUntrusted(t.name),
|
|
1712
|
-
reason: mintedBy === t.name
|
|
1713
|
-
? `this server listed this tool name more than once in one listing; the first entry is mounted as "${namespacedName}" and the repeat is dropped (one name cannot denote two tools)`
|
|
1714
|
-
: `name collides with an earlier tool of this server: both mount as "${namespacedName}" after namespacing (only [a-zA-Z0-9_-] survives), and one name cannot denote two tools`,
|
|
1715
|
-
});
|
|
1727
|
+
dropped.push({ tool: inlineUntrusted(t.name), reason: mcpToolDropReason(namespacedName, mintedBy, t.name) });
|
|
1716
1728
|
continue;
|
|
1717
1729
|
}
|
|
1718
|
-
mintedNames.set(namespacedName, t.name);
|
|
1719
1730
|
const hintAxis = mcpAxisFor(namespacedName, t.annotations);
|
|
1720
1731
|
const axis = applyCallerAxisOverride(namespacedName, hintAxis, spec.toolAxes?.[remoteName]);
|
|
1721
1732
|
if (axis)
|
|
@@ -1739,7 +1750,7 @@ function intakeListedTools(listed, spec, link, declared, imageResizer, reminderD
|
|
|
1739
1750
|
...(mcpAlwaysLoad ? { mcpAlwaysLoad: true } : {}),
|
|
1740
1751
|
...gateFace,
|
|
1741
1752
|
mcpRemoteName: remoteName, ...boundaryFlowFace(spec.toolAxes?.[remoteName]), permissionSeat: "passthrough",
|
|
1742
|
-
execute: async (
|
|
1753
|
+
execute: async (toolCallId, params, signal) => {
|
|
1743
1754
|
const what = `The call to tool ${inlineUntrusted(remoteName)}`;
|
|
1744
1755
|
if (isServerRevoked?.(spec.name) === true) {
|
|
1745
1756
|
return {
|
|
@@ -1759,12 +1770,14 @@ function intakeListedTools(listed, spec, link, declared, imageResizer, reminderD
|
|
|
1759
1770
|
}
|
|
1760
1771
|
const timeoutMs = mcpToolTimeoutMs();
|
|
1761
1772
|
const idleMs = mcpIdleTimeoutMs(idleKindOf(transportKind));
|
|
1762
|
-
const
|
|
1773
|
+
const callMeta = mcpCallMeta(toolCallId, seat?.of(toolCallId), spec.sessionMetaKey, seat?.sessionId);
|
|
1774
|
+
let answeredWith = declared;
|
|
1775
|
+
const attempt = async (conn, resent) => {
|
|
1763
1776
|
const site = requestSite(conn.client);
|
|
1764
1777
|
const watchdog = armMcpIdleWatchdog(conn.health, idleMs, signal);
|
|
1765
1778
|
try {
|
|
1766
1779
|
const res = await conn.client
|
|
1767
|
-
.callTool({ name: remoteName, arguments: (params ?? {}) }, LENIENT_CALL_TOOL_RESULT_SCHEMA, {
|
|
1780
|
+
.callTool({ name: remoteName, arguments: (params ?? {}), ...(callMeta !== undefined ? { _meta: callMeta } : {}) }, LENIENT_CALL_TOOL_RESULT_SCHEMA, {
|
|
1768
1781
|
signal: watchdog.combinedSignal,
|
|
1769
1782
|
timeout: timeoutMs,
|
|
1770
1783
|
resetTimeoutOnProgress: true,
|
|
@@ -1775,7 +1788,7 @@ function intakeListedTools(listed, spec, link, declared, imageResizer, reminderD
|
|
|
1775
1788
|
try {
|
|
1776
1789
|
return rethrowHonestMcpError(err, {
|
|
1777
1790
|
server: spec.name,
|
|
1778
|
-
declared,
|
|
1791
|
+
declared: carrierOf(conn.client)?.sent ?? declared,
|
|
1779
1792
|
what,
|
|
1780
1793
|
timeoutMs,
|
|
1781
1794
|
writeEffect,
|
|
@@ -1792,18 +1805,25 @@ function intakeListedTools(listed, spec, link, declared, imageResizer, reminderD
|
|
|
1792
1805
|
catch (failure) {
|
|
1793
1806
|
if (sessionGone(err, site) && signal?.aborted !== true)
|
|
1794
1807
|
return new Resendable(conn, failure);
|
|
1808
|
+
if (!writeEffect && answeredUnauthorized(err) && carrierOf(conn.client)?.renewed === true && signal?.aborted !== true)
|
|
1809
|
+
return new Reauthorized(failure);
|
|
1795
1810
|
throw failure;
|
|
1796
1811
|
}
|
|
1797
1812
|
});
|
|
1798
|
-
if (res instanceof Resendable)
|
|
1813
|
+
if (res instanceof Resendable || res instanceof Reauthorized)
|
|
1799
1814
|
return res;
|
|
1800
1815
|
conn.health.observe?.("completed");
|
|
1816
|
+
answeredWith = carrierOf(conn.client)?.sent ?? declared;
|
|
1801
1817
|
return res;
|
|
1802
1818
|
}
|
|
1803
1819
|
finally {
|
|
1804
1820
|
watchdog.dispose();
|
|
1805
1821
|
}
|
|
1806
1822
|
};
|
|
1823
|
+
const send = (conn, resent) => inFlight(conn.client, () => sentOnceMore(() => attempt(conn, resent), () => isServerRevoked?.(spec.name) !== true && reach(link, namespacedName, gate) === conn && signal?.aborted !== true));
|
|
1824
|
+
const before = link.live();
|
|
1825
|
+
if (before !== undefined && carrierOf(before.client)?.expired() === true)
|
|
1826
|
+
await link.recover(before, "expired");
|
|
1807
1827
|
const res = await callThroughLink(link, namespacedName, gate, signal, send, () => throwDeadServer(spec.name, what));
|
|
1808
1828
|
if (typeof res === "string")
|
|
1809
1829
|
return listingRefusal(res, remoteName, spec.name);
|
|
@@ -1819,7 +1839,7 @@ function intakeListedTools(listed, spec, link, declared, imageResizer, reminderD
|
|
|
1819
1839
|
const errScLine = structuredContentErrorLine(res.structuredContent, parts.join("\n"));
|
|
1820
1840
|
if (errScLine !== undefined)
|
|
1821
1841
|
parts.push(errScLine);
|
|
1822
|
-
const body = truncateMcpErrorText(
|
|
1842
|
+
const body = truncateMcpErrorText(remoteWords(parts.join("\n").trim(), answeredWith));
|
|
1823
1843
|
const msg = body
|
|
1824
1844
|
? `MCP tool ${inlineUntrusted(remoteName)} reported an error. The server's error content follows as external/untrusted data:\n${delimitUntrusted(`${spec.name} tool error`, body)}`
|
|
1825
1845
|
: `MCP tool ${inlineUntrusted(remoteName)} reported an error`;
|
|
@@ -2,6 +2,7 @@ import { join } from "node:path";
|
|
|
2
2
|
import { uuidv7 } from "../../internal/harness.js";
|
|
3
3
|
import { atomicWriteFileSync, ensureDirExists, lockedStrictUpdate, readStrictSidecar, enqueueMemoryAnnouncement, ControlPlaneCorruptError } from "./layout.js";
|
|
4
4
|
import { inlineUntrusted } from "../untrusted-text.js";
|
|
5
|
+
import { extensionWords } from "../untrusted-egress.js";
|
|
5
6
|
import { deliverEngineNotice } from "../engine-notice.js";
|
|
6
7
|
import { CONSOLIDATION_FORCE_THROTTLE_FLOOR_MS, screenConsolidationOptions, supersessionFuseCeiling, updateConsolidationGate, recommendationUnconsumed, CONSOLIDATION_WRITE_REFUSED_CODE, ConsolidationRefusedError, } from "./consolidation.js";
|
|
7
8
|
import { memoryConsolidationIncompleteNotice, memoryConsolidationWithheldNotice } from "./engine.js";
|
|
@@ -510,15 +511,15 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
510
511
|
}
|
|
511
512
|
catch (err) {
|
|
512
513
|
if (err instanceof DriverMintFailure) {
|
|
513
|
-
announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} FAILED before any write: ${
|
|
514
|
+
announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} FAILED before any write: ${extensionWords(err.detail, 300)}`]);
|
|
514
515
|
return settle("driver_failed", undefined, err.detail);
|
|
515
516
|
}
|
|
516
517
|
if (err instanceof DriverPurityViolation) {
|
|
517
|
-
announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} REFUSED on the clean-arm purity gate (no writes): ${
|
|
518
|
+
announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} REFUSED on the clean-arm purity gate (no writes): ${extensionWords(err.detail, 300)}`]);
|
|
518
519
|
return settle("purity_violation", undefined, err.detail);
|
|
519
520
|
}
|
|
520
521
|
if (err instanceof MintInvalidated) {
|
|
521
|
-
announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} MINT INVALIDATED: ${
|
|
522
|
+
announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} MINT INVALIDATED: ${extensionWords(err.detail, 300)}`]);
|
|
522
523
|
if (run.residue === undefined && err.residue.length > 0)
|
|
523
524
|
run.residue = err.residue;
|
|
524
525
|
const partial = {
|