@sema-agent/core 5.20.0 → 5.21.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 +19 -0
- package/dist/agents/agent-definition.d.ts +7 -0
- package/dist/agents/agent-transcript-tool.d.ts +30 -0
- package/dist/agents/builtin-agents.d.ts +60 -0
- package/dist/agents/cascade.d.ts +107 -0
- package/dist/agents/cumulative-stats.d.ts +56 -0
- package/dist/agents/observer.d.ts +162 -0
- package/dist/agents/peer-admission.d.ts +95 -0
- package/dist/agents/repair-loop.d.ts +226 -0
- package/dist/agents/retain-ledger.d.ts +141 -0
- package/dist/agents/roster-store.d.ts +105 -0
- package/dist/agents/send-message-tool.d.ts +92 -0
- package/dist/agents/session-util.d.ts +5 -0
- package/dist/agents/subagent-steps.d.ts +66 -0
- package/dist/agents/subagent.d.ts +600 -0
- package/dist/agents/suspend-guard.d.ts +29 -0
- package/dist/agents/teacher.d.ts +75 -0
- package/dist/agents/team.d.ts +120 -1
- package/dist/agents/tool-filter.d.ts +34 -0
- package/dist/agents/verify.d.ts +198 -0
- package/dist/bench/metrics.d.ts +455 -0
- package/dist/brain/anthropic.d.ts +30 -0
- package/dist/brain/circuit-breaker.d.ts +33 -0
- package/dist/brain/context-overflow.d.ts +60 -3
- package/dist/brain/degrading.d.ts +67 -0
- package/dist/brain/errors.d.ts +42 -0
- package/dist/brain/failover.d.ts +15 -0
- package/dist/brain/media-degrade.d.ts +39 -0
- package/dist/brain/model-presets.d.ts +31 -0
- package/dist/brain/open-responses.d.ts +19 -0
- package/dist/brain/openai.d.ts +46 -0
- package/dist/brain/reasoning.d.ts +106 -1
- package/dist/brain/repetition.d.ts +83 -0
- package/dist/brain/request-params.d.ts +56 -0
- package/dist/brain/retry.d.ts +46 -0
- package/dist/brain/routing.d.ts +12 -0
- package/dist/brain/status-sink.d.ts +30 -1
- package/dist/brain/stream-engine.d.ts +147 -0
- package/dist/brain/stream-shared.d.ts +34 -0
- package/dist/brain/terminal-cause.d.ts +31 -0
- package/dist/brain/timeout.d.ts +107 -0
- package/dist/brain/tool-call-id.d.ts +20 -0
- package/dist/brain/tool-call-repair.d.ts +13 -0
- package/dist/config/catalog.d.ts +47 -0
- package/dist/config/defaults.d.ts +33 -0
- package/dist/core/a2a-task-state.d.ts +53 -0
- package/dist/core/a2a.d.ts +51 -0
- package/dist/core/arg-summary.d.ts +62 -0
- package/dist/core/ask-question.d.ts +272 -2
- package/dist/core/auto-compaction.d.ts +467 -0
- package/dist/core/auto-compaction.js +20 -6
- package/dist/core/auto-mode-prompt-assets.d.ts +8 -0
- package/dist/core/auto-mode-prompt.d.ts +27 -0
- package/dist/core/auto-mode.d.ts +54 -3
- package/dist/core/auto-promote.d.ts +100 -0
- package/dist/core/background-agent-store.d.ts +292 -0
- package/dist/core/background-shell.d.ts +110 -0
- package/dist/core/cache-break-detector.d.ts +34 -0
- package/dist/core/canonical-json.d.ts +57 -0
- package/dist/core/checkpoint-store.d.ts +1574 -16
- package/dist/core/compliance.d.ts +30 -0
- package/dist/core/consolidate-scope.d.ts +75 -0
- package/dist/core/context-edit.d.ts +99 -0
- package/dist/core/context-guard.d.ts +46 -0
- package/dist/core/exec-gate.d.ts +44 -0
- package/dist/core/exec-output-tail.d.ts +61 -0
- package/dist/core/file-snapshot-store.d.ts +104 -0
- package/dist/core/fs-write-gate-policy.d.ts +36 -0
- package/dist/core/git-worktree-env.d.ts +31 -0
- package/dist/core/governance-codes.d.ts +19 -0
- package/dist/core/hooks.d.ts +608 -1
- package/dist/core/human-input-projection.d.ts +37 -0
- package/dist/core/human-input-projection.js +13 -0
- package/dist/core/image-downsample.d.ts +74 -0
- package/dist/core/locked-config.d.ts +37 -0
- package/dist/core/lsp-diagnostics.d.ts +77 -0
- package/dist/core/lsp-protocol.d.ts +29 -0
- package/dist/core/lsp-session.d.ts +60 -1
- package/dist/core/lsp.d.ts +150 -1
- package/dist/core/mailbox-store.d.ts +57 -0
- package/dist/core/mcp.d.ts +381 -0
- package/dist/core/media-byte-cap.d.ts +21 -0
- package/dist/core/memory-admission.d.ts +71 -0
- package/dist/core/memory-engine/content-origin.d.ts +64 -0
- package/dist/core/memory-engine/data-plane.d.ts +43 -0
- package/dist/core/memory-engine/dual-root.d.ts +24 -0
- package/dist/core/memory-engine/engine.d.ts +230 -0
- package/dist/core/memory-engine/engine.js +103 -35
- package/dist/core/memory-engine/file-backend.d.ts +155 -0
- package/dist/core/memory-engine/frontmatter.d.ts +16 -0
- package/dist/core/memory-engine/layout.d.ts +217 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts +12 -0
- package/dist/core/memory-engine/migrate.d.ts +9 -0
- package/dist/core/memory-engine/scan.d.ts +12 -0
- package/dist/core/memory-engine/scope-contract.d.ts +61 -1
- package/dist/core/memory-engine/sync-client.d.ts +87 -0
- package/dist/core/memory-engine/sync.d.ts +60 -0
- package/dist/core/memory-engine/tools.d.ts +41 -0
- package/dist/core/memory-engine/types.d.ts +188 -0
- package/dist/core/memory-recall.d.ts +141 -0
- package/dist/core/memory-vector.d.ts +20 -0
- package/dist/core/memory.d.ts +458 -0
- package/dist/core/message-utils.d.ts +6 -0
- package/dist/core/oracle-isolation.d.ts +69 -0
- package/dist/core/permission-rule-consent.d.ts +138 -0
- package/dist/core/permission-rule-model.d.ts +122 -0
- package/dist/core/permission-rule-store.d.ts +119 -3
- package/dist/core/permission-rules.d.ts +87 -1
- package/dist/core/present-plan-tool.d.ts +20 -0
- package/dist/core/pricing.d.ts +26 -0
- package/dist/core/property-harness.d.ts +86 -0
- package/dist/core/protocol-naming.d.ts +38 -0
- package/dist/core/protocol-table.d.ts +61 -0
- package/dist/core/push-queue.d.ts +1 -0
- package/dist/core/remote-env.d.ts +383 -1
- package/dist/core/retention-policy.d.ts +33 -0
- package/dist/core/retention.d.ts +51 -0
- package/dist/core/roles.d.ts +59 -0
- package/dist/core/runner/active-skill-scope.d.ts +34 -0
- package/dist/core/runner/assemble-result.d.ts +134 -0
- package/dist/core/runner/compaction-call-options.d.ts +97 -1
- package/dist/core/runner/grounding-signal.d.ts +10 -0
- package/dist/core/runner/image.d.ts +17 -0
- package/dist/core/runner/image.js +29 -15
- package/dist/core/runner/memory-consolidation.d.ts +60 -0
- package/dist/core/runner/prepare-memory.d.ts +59 -0
- package/dist/core/runner/prepare-task.d.ts +1011 -2
- package/dist/core/runner/prepare-task.js +12 -11
- package/dist/core/runner/prompt-suggestions.d.ts +7 -0
- package/dist/core/runner/runtask.d.ts +304 -3
- package/dist/core/runner/session-file-state-replay.d.ts +49 -0
- package/dist/core/runner/session-rule-policy.d.ts +58 -0
- package/dist/core/runner/strict-output-schema.d.ts +18 -3
- package/dist/core/runner/synthetic-tools.d.ts +113 -0
- package/dist/core/runner/teardown-bounded.d.ts +34 -0
- package/dist/core/runner/tool-disclosure.d.ts +227 -0
- package/dist/core/runner/tool-output-projection.d.ts +6 -0
- package/dist/core/runner/turn-attachments.d.ts +634 -0
- package/dist/core/runner/usage-accounting.d.ts +32 -0
- package/dist/core/runtime.d.ts +9 -0
- package/dist/core/safe-notify.d.ts +64 -0
- package/dist/core/safety-axis-vocab.d.ts +23 -0
- package/dist/core/safety-merge-corpus.d.ts +37 -0
- package/dist/core/scheduler.d.ts +121 -0
- package/dist/core/secret-env.d.ts +32 -0
- package/dist/core/select-model.d.ts +15 -0
- package/dist/core/sensitive-path-policy.d.ts +42 -0
- package/dist/core/session-policy-store.d.ts +94 -0
- package/dist/core/session-reconcile.d.ts +80 -0
- package/dist/core/session-store.d.ts +85 -0
- package/dist/core/session.d.ts +153 -0
- package/dist/core/shared-memory/contract.d.ts +22 -0
- package/dist/core/shared-memory/normalize.d.ts +123 -2
- package/dist/core/shared-memory/tools.d.ts +14 -0
- package/dist/core/shared-memory/types.d.ts +105 -0
- package/dist/core/shutdown-debug.d.ts +6 -0
- package/dist/core/side-query.d.ts +38 -0
- package/dist/core/side-query.js +6 -1
- package/dist/core/skill-tool-specifier.d.ts +72 -0
- package/dist/core/skills-directory.d.ts +100 -1
- package/dist/core/spec-contract.d.ts +89 -0
- package/dist/core/store-contracts/background-agent-store-contract.d.ts +31 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +26 -0
- package/dist/core/store-contracts/contract-harness.d.ts +20 -0
- package/dist/core/store-contracts/contract-kit-version.d.ts +27 -0
- package/dist/core/store-contracts/file-snapshot-store-contract.d.ts +8 -0
- package/dist/core/store-contracts/mailbox-store-contract.d.ts +42 -0
- package/dist/core/store-contracts/tool-result-store-contract.d.ts +13 -0
- package/dist/core/strategy-store.d.ts +37 -0
- package/dist/core/stub-env.d.ts +7 -0
- package/dist/core/surrogate-safe-slice.d.ts +35 -0
- package/dist/core/task-notification.d.ts +202 -0
- package/dist/core/task-outcome.d.ts +53 -0
- package/dist/core/task-registry-agent.d.ts +337 -1
- package/dist/core/task-registry-monitor.d.ts +12 -0
- package/dist/core/task-registry-shared.d.ts +540 -0
- package/dist/core/task-registry.d.ts +343 -0
- package/dist/core/task-registry.js +13 -2
- package/dist/core/task-tool-shape.d.ts +44 -0
- package/dist/core/tighten-task-spec.d.ts +21 -0
- package/dist/core/tool-detach.d.ts +21 -0
- package/dist/core/tool-errors.d.ts +131 -0
- package/dist/core/tool-errors.js +4 -0
- package/dist/core/tool-name-aliases.d.ts +27 -0
- package/dist/core/tool-policy.d.ts +555 -0
- package/dist/core/tool-result-budget.d.ts +32 -0
- package/dist/core/tool-result-store.d.ts +174 -1
- package/dist/core/tools.d.ts +45 -0
- package/dist/core/trace.d.ts +323 -0
- package/dist/core/types.d.ts +3859 -2
- package/dist/core/untrusted-egress.d.ts +8 -0
- package/dist/core/untrusted-text.d.ts +156 -0
- package/dist/core/usage-window-store.d.ts +95 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/warm-resume.d.ts +17 -0
- package/dist/core/wiring-manifest.d.ts +169 -0
- package/dist/core/with-retry.d.ts +24 -0
- package/dist/core/workflow-journal-store.d.ts +160 -0
- package/dist/core/workflow-run-store-contract.d.ts +25 -0
- package/dist/core/workflow-run-store.d.ts +119 -0
- package/dist/engine/compaction/compaction.d.ts +256 -1
- package/dist/engine/compaction/utils.d.ts +94 -0
- package/dist/engine/execution-env/kill-tree.d.ts +29 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +94 -0
- package/dist/engine/harness/agent-harness.d.ts +116 -0
- package/dist/engine/harness/agent-harness.js +3 -14
- package/dist/engine/harness/messages.d.ts +15 -0
- package/dist/engine/harness/types.d.ts +464 -2
- package/dist/engine/llm/diagnostics.d.ts +4 -0
- package/dist/engine/llm/event-stream.d.ts +3 -0
- package/dist/engine/llm/index.d.ts +7 -0
- package/dist/engine/llm/types.d.ts +500 -3
- package/dist/engine/llm/validation.d.ts +3 -0
- package/dist/engine/loop/agent-loop.d.ts +87 -2
- package/dist/engine/loop/runtime-deps.d.ts +7 -0
- package/dist/engine/loop/types.d.ts +424 -0
- package/dist/engine/lsp/frame-decoder.d.ts +13 -0
- package/dist/engine/lsp/node-lsp-manager.d.ts +107 -0
- package/dist/engine/lsp/stdio-lsp-transport.d.ts +7 -0
- package/dist/engine/session/import-validate.d.ts +27 -0
- package/dist/engine/session/log-digest.d.ts +93 -0
- package/dist/engine/session/memory-repo.d.ts +6 -0
- package/dist/engine/session/memory-storage.d.ts +2 -0
- package/dist/engine/session/session.d.ts +75 -0
- package/dist/engine/session/storage-base.d.ts +8 -0
- package/dist/fixtures/index.d.ts +36 -0
- package/dist/index.d.ts +16 -1
- package/dist/index.js +0 -1
- package/dist/internal/harness-types.d.ts +6 -0
- package/dist/internal/harness.d.ts +11 -0
- package/dist/internal/llm.d.ts +6 -0
- package/dist/orchestration/builtin-workflows.d.ts +53 -0
- package/dist/orchestration/dev-vm-script-runner.d.ts +19 -0
- package/dist/orchestration/goal.d.ts +57 -0
- package/dist/orchestration/goal.js +3 -0
- package/dist/orchestration/run-spec.d.ts +42 -0
- package/dist/orchestration/run-workflow-tool.d.ts +169 -0
- package/dist/orchestration/workflow-governance.d.ts +61 -0
- package/dist/orchestration/workflow-meta.d.ts +28 -0
- package/dist/orchestration/workflow-observe.d.ts +60 -0
- package/dist/orchestration/workflow-primitives.d.ts +23 -1
- package/dist/orchestration/workflow-sandbox-conformance.d.ts +38 -0
- package/dist/orchestration/workflow-script-runner.d.ts +88 -0
- package/dist/orchestration/workflow-script-store.d.ts +98 -0
- package/dist/orchestration/workflow-size-guideline.d.ts +67 -0
- package/dist/orchestration/workflow-types.d.ts +169 -2
- package/dist/orchestration/workflow.d.ts +358 -0
- package/dist/prompt-assembly/artifact-store.d.ts +33 -0
- package/dist/prompt-assembly/artifact.d.ts +25 -0
- package/dist/prompt-assembly/assemble.d.ts +20 -0
- package/dist/prompt-assembly/composer.d.ts +29 -0
- package/dist/prompt-assembly/epoch.d.ts +55 -1
- package/dist/prompt-assembly/event-registry.d.ts +35 -0
- package/dist/prompt-assembly/explain.d.ts +12 -0
- package/dist/prompt-assembly/tool-catalog.d.ts +38 -0
- package/dist/prompt-assembly/turn-snapshot.d.ts +40 -0
- package/dist/prompt-assembly/types.d.ts +115 -0
- package/dist/prompts/coordinator.d.ts +27 -0
- package/dist/prompts/default.d.ts +539 -0
- package/dist/prompts/simple-sections.d.ts +45 -0
- package/dist/prompts/supervisor.d.ts +66 -0
- package/dist/scenarios/env.d.ts +28 -0
- package/dist/scenarios/full-body.d.ts +50 -0
- package/dist/scenarios/scenario-registry.d.ts +60 -0
- package/dist/scenarios/teacher-quickstart.d.ts +27 -0
- package/dist/server/http.d.ts +17 -0
- package/dist/stores/cc/lockfile.d.ts +6 -0
- package/dist/stores/cc/mailbox-store.d.ts +8 -0
- package/dist/stores/cc/roster-adapter.d.ts +4 -0
- package/dist/stores/cc/sidecar-transcript.d.ts +66 -0
- package/dist/stores/file/background-agent-store.d.ts +24 -0
- package/dist/stores/file/checkpoint-store.d.ts +38 -0
- package/dist/stores/file/file-snapshot-store.d.ts +25 -0
- package/dist/stores/file/fs-atomic.d.ts +155 -0
- package/dist/stores/file/index.d.ts +89 -0
- package/dist/stores/file/mailbox-store.d.ts +36 -0
- package/dist/stores/file/memory-store.d.ts +82 -0
- package/dist/stores/file/permission-rule-store.d.ts +79 -0
- package/dist/stores/file/session-policy-store.d.ts +28 -0
- package/dist/stores/file/session-store.d.ts +40 -0
- package/dist/stores/file/shared-ledger.d.ts +83 -0
- package/dist/stores/file/tool-result-store.d.ts +11 -0
- package/dist/stores/file/usage-window-store.d.ts +18 -0
- package/dist/stores/file/workflow-journal-store.d.ts +100 -0
- package/dist/stores/file/workflow-run-store.d.ts +11 -0
- package/dist/tools/fs/bash-readonly-classifier.d.ts +282 -0
- package/dist/tools/fs/encoding.d.ts +60 -0
- package/dist/tools/fs/fs-bash.d.ts +133 -0
- package/dist/tools/fs/fs-pdf.d.ts +28 -0
- package/dist/tools/fs/fs-search-tools.d.ts +5 -0
- package/dist/tools/fs/fs-search-tools.js +0 -1
- package/dist/tools/fs/fs-shared.d.ts +360 -0
- package/dist/tools/fs/fs-write.d.ts +16 -0
- package/dist/tools/fs/gh-rate-limit.d.ts +22 -0
- package/dist/tools/fs/index.d.ts +79 -0
- package/dist/tools/fs/notebook.d.ts +56 -0
- package/dist/tools/fs/pdf.d.ts +70 -0
- package/dist/tools/fs/pdf.js +8 -2
- package/dist/tools/fs/repo-map.d.ts +10 -0
- package/dist/tools/fs/safety.d.ts +376 -0
- package/dist/tools/fs/search.d.ts +131 -0
- package/dist/tools/loop-tick.d.ts +24 -0
- package/dist/tools/monitor.d.ts +55 -0
- package/dist/tools/scheduler-tools.d.ts +51 -0
- package/dist/tools/sql-adapters.d.ts +18 -0
- package/dist/tools/sql.d.ts +25 -0
- package/dist/tools/task-list.d.ts +77 -0
- package/dist/tools/todo.d.ts +8 -0
- package/dist/tools/web.d.ts +184 -0
- package/dist/tools/worktree.d.ts +81 -0
- package/package.json +2 -2
- package/dist/tools/gitea-issue.d.ts +0 -13
- package/dist/tools/gitea-issue.js +0 -75
package/dist/core/mcp.d.ts
CHANGED
|
@@ -1,26 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP client integration. Protocol revision `2025-11-25`, supplied by `@modelcontextprotocol/sdk` 1.29.x
|
|
3
|
+
* (core pins the SDK and does not negotiate the revision itself). Client side only — core never implements
|
|
4
|
+
* an MCP server.
|
|
5
|
+
*
|
|
6
|
+
* ── DEPRECATION-IMMUNITY REGISTRY (MCP revision `2026-07-28`) ────────────────────────────────────────
|
|
7
|
+
* The `2026-07-28` revision deprecates four surfaces this module has NEVER implemented. That is not an
|
|
8
|
+
* accident and not an unfinished edge: each one was declined on its own merits, and the revision has now
|
|
9
|
+
* put all four on a deprecation clock. So there is no migration debt here — and, symmetrically, none of
|
|
10
|
+
* the four may be "completed" later on the grounds that the client looks incomplete next to the older
|
|
11
|
+
* revision's feature list:
|
|
12
|
+
*
|
|
13
|
+
* 1. **roots** (`roots/list`, `notifications/roots/list_changed`) — never implemented. The replacement the
|
|
14
|
+
* revision itself names is what this module already does: directory/file scope travels as ordinary tool
|
|
15
|
+
* arguments or resource URIs, never as a client-hosted root list a server can enumerate.
|
|
16
|
+
* 2. **sampling** (`sampling/createMessage`) — never implemented. A server that wants model inference uses
|
|
17
|
+
* its own provider; core never lends the caller's model channel (or budget) to a connected server.
|
|
18
|
+
* 3. **logging** (`logging/setLevel`, `notifications/message`) — never implemented. Server diagnostics
|
|
19
|
+
* arrive as stdio stderr, or as ordinary tool/resource content, or not at all.
|
|
20
|
+
* 4. **HTTP+SSE transport** — never implemented. `buildTransport` builds stdio and Streamable HTTP only;
|
|
21
|
+
* the SDK's `SSEClientTransport` is not imported anywhere. The revision's SSE off-ramp is therefore a
|
|
22
|
+
* no-op here.
|
|
23
|
+
*
|
|
24
|
+
* Consequence for future edits: adding any of the four is a REGRESSION, not a gap being closed. The bar for
|
|
25
|
+
* reopening one is a LATER protocol revision that revives the surface, or a concrete consumer requirement
|
|
26
|
+
* recorded under its own ticket — not the absence of the feature.
|
|
27
|
+
*
|
|
28
|
+
* Two more revision-relevant absences, same reasoning, different cause:
|
|
29
|
+
* - `resources/subscribe` / `resources/unsubscribe` — the revision REMOVES the methods. Tool-list freshness
|
|
30
|
+
* here is served by the explicit `RefreshMcpTools` tool over the existing connection, which is also the
|
|
31
|
+
* only thing this module's connect-per-task connection lifetime can honestly support.
|
|
32
|
+
* - `ping` — likewise removed by the revision. Liveness here is the idle watchdog plus per-call timeouts.
|
|
33
|
+
*/
|
|
1
34
|
import { type ProtocolId } from "./protocol-table.js";
|
|
2
35
|
import type { AgentTool } from "../internal/harness-types.js";
|
|
3
36
|
import type { ImageContent, TextContent } from "../internal/llm.js";
|
|
4
37
|
import { type McpImageResizer } from "./image-downsample.js";
|
|
5
38
|
import type { McpServerSpec, OnElicit, ToolEffect } from "./types.js";
|
|
39
|
+
/**
|
|
40
|
+
* The safety axes (design/77 §4 irreversibility, design/70 egress) derived from one materialized MCP
|
|
41
|
+
* tool's server-advertised `annotations`. These ride alongside the {@link AgentTool} (which is vendored
|
|
42
|
+
* and carries no axis fields) so `prepare-task` can fold them into the SAME irreversibleTools/egressTools
|
|
43
|
+
* collection that `spec.tools` feeds — otherwise a destructive MCP tool would register no gate and a
|
|
44
|
+
* no-policy deployment would silently AUTO-ALLOW it (MAJOR-1). The `name` is the namespaced tool name
|
|
45
|
+
* (`<server>__<tool>`), matching the keys the gate looks up.
|
|
46
|
+
*
|
|
47
|
+
* Trust note (design F): a server's `annotations` are SERVER-controlled and "not guaranteed faithful" (MCP
|
|
48
|
+
* spec), so they may only ever TIGHTEN — `destructiveHint` adds an `ask`/suspend, `openWorldHint` adds an
|
|
49
|
+
* egress tighten — never LOWER. A server's `readOnlyHint` does NOT lower `effect` (that would let a hostile
|
|
50
|
+
* server lie on a mutating tool to escape repeat-safety + path-confinement). The ONLY trusted way to LOWER an
|
|
51
|
+
* MCP tool below the fail-closed `write` default is the caller's {@link McpServerSpec.toolAxes} override
|
|
52
|
+
* (caller = trust root). The synthetic first-party resource tools are the one exception — core sets their
|
|
53
|
+
* `read` effect itself because it authored them.
|
|
54
|
+
*/
|
|
6
55
|
export interface McpToolAxis {
|
|
56
|
+
/** Namespaced tool name (`mcp__<server>__<tool>` — design/108 ① CC parity). */
|
|
7
57
|
name: string;
|
|
58
|
+
/** design/77 §4: `destructiveHint === true` → `"always"` (the gate always tightens allow→ask/suspend).
|
|
59
|
+
* `"never"` appears ONLY via an explicit caller override — enforcement ignores it (tighten-only),
|
|
60
|
+
* the ask's risk-axes report face consumes it (an explicit negative is a judgment, not silence). */
|
|
8
61
|
irreversibility?: "always" | "never";
|
|
62
|
+
/** design/70: a non-readOnly tool with `openWorldHint === true` → egress (external write — never
|
|
63
|
+
* auto-allowed). `false` appears ONLY via an explicit caller override — same posture as above:
|
|
64
|
+
* enforcement ignores it, the report face consumes it. */
|
|
9
65
|
egress?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* The repeat-safety / blast-radius class (NOT the data-trust axis — untrusted resource *content* is fenced
|
|
68
|
+
* separately by delimitUntrusted). `read`/`idempotent` here means "not write-capable", which keeps the tool
|
|
69
|
+
* off the LOUD ungated-write warning and out of path-confinement under a skill. Source is restricted by trust
|
|
70
|
+
* (design F): the SYNTHETIC first-party resource tools set `read` as a fact core controls, and the caller's
|
|
71
|
+
* {@link McpServerSpec.toolAxes} override may set any effect — a server's own `readOnlyHint` never sets it.
|
|
72
|
+
*/
|
|
10
73
|
effect?: ToolEffect;
|
|
11
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* REF-D17: one MCP tool dropped at intake (server/tool/reason) — the SINGLE shape {@link
|
|
77
|
+
* MaterializedMcp.droppedTools}, {@link McpRefreshResult.dropped}, and `turn-attachments.ts`'s
|
|
78
|
+
* disclosure rendering/batching all reference. MCP trust/disclosure is a security-relevant surface
|
|
79
|
+
* (the trust model was BREAKING-redone historically) — a drift between the connect-time and
|
|
80
|
+
* refresh-time shapes would make a real field change invisible at one of the two intake paths.
|
|
81
|
+
*/
|
|
12
82
|
export interface McpDroppedTool {
|
|
13
83
|
server: string;
|
|
14
84
|
tool: string;
|
|
15
85
|
reason: string;
|
|
16
86
|
}
|
|
87
|
+
/** Tools materialized from one or more MCP servers, plus a disposer to disconnect them. */
|
|
17
88
|
export interface MaterializedMcp {
|
|
18
89
|
tools: AgentTool[];
|
|
90
|
+
/**
|
|
91
|
+
* Per-tool safety axes derived from each tool's MCP `annotations` (design/77 §4 / design/70). One entry
|
|
92
|
+
* per materialized tool that carries a tightening hint; `prepare-task` folds these into its
|
|
93
|
+
* irreversibleTools/egressTools sets so a destructive/open-world MCP tool REGISTERS the gate + tightens
|
|
94
|
+
* even on a no-policy deployment. Empty when no server advertised a relevant annotation.
|
|
95
|
+
*/
|
|
19
96
|
toolAxes: McpToolAxis[];
|
|
97
|
+
/**
|
|
98
|
+
* MCP server `instructions` (design/64 §17.3, CC `# MCP Server Instructions`): the optional guidance a
|
|
99
|
+
* connected server returns from `initialize`. The Runner injects these into the (stable) system prompt so
|
|
100
|
+
* the model uses the server's tools correctly. One entry per server that provided non-empty instructions.
|
|
101
|
+
*/
|
|
20
102
|
serverInstructions: Array<{
|
|
21
103
|
server: string;
|
|
22
104
|
text: string;
|
|
23
105
|
}>;
|
|
106
|
+
/**
|
|
107
|
+
* G1 通告层续批 (CC `mcp_instructions_delta` parity) — the run-scoped instruction-delta ref the run
|
|
108
|
+
* loop drains at turn boundaries (`spec.attachments.mcpInstructions` opt-in; `newTools` consumption
|
|
109
|
+
* discipline: drained only when the announcement survived the byte cap intact).
|
|
110
|
+
* - `pendingRemovals`: an INSTRUCTION-BEARING server whose transport closed mid-task (the CC
|
|
111
|
+
* "servers have disconnected — their instructions above no longer apply" copy is instruction-scoped,
|
|
112
|
+
* so instruction-less servers are not tracked). `dispose()` disarms first: task teardown is not a
|
|
113
|
+
* disconnect.
|
|
114
|
+
* - `pendingAdds`: the CC add lane ("# MCP Server Instructions" reminder). Structurally present for a
|
|
115
|
+
* dynamic mid-task connect face; TODAY nothing populates it — sema connects all servers at prepare
|
|
116
|
+
* and carries their initial instructions in the stable system prompt (design/64 §17.3, deliberate
|
|
117
|
+
* CC deviation: prefix-cache-correct).
|
|
118
|
+
*/
|
|
24
119
|
instructionsDelta: {
|
|
25
120
|
pendingAdds: Array<{
|
|
26
121
|
server: string;
|
|
@@ -28,14 +123,74 @@ export interface MaterializedMcp {
|
|
|
28
123
|
}>;
|
|
29
124
|
pendingRemovals: string[];
|
|
30
125
|
};
|
|
126
|
+
/**
|
|
127
|
+
* One entry per server that failed to connect / list its tools and was SKIPPED (fail-open,
|
|
128
|
+
* design/29). The task proceeds with the healthy servers' tools — a single bad server (missing
|
|
129
|
+
* stdio command, unreachable URL) must never brick every task in the scenario. The Runner forwards
|
|
130
|
+
* these to `onError(phase:"mcp")`. Empty when every server connected.
|
|
131
|
+
*/
|
|
31
132
|
warnings: Error[];
|
|
133
|
+
/**
|
|
134
|
+
* [cc216] Tools DROPPED at intake because the server advertised a schema no provider accepts
|
|
135
|
+
* ({@link mcpToolSchemaProblem}) — without the drop, one malformed tool schema riding the wire
|
|
136
|
+
* fails the WHOLE model request (provider 400), bricking the task for every healthy tool
|
|
137
|
+
* (CC 2.1.216 ships the same intake prune, `tengu_mcp_drop_invalid_tool_schemas`).
|
|
138
|
+
*
|
|
139
|
+
* HONEST REACH (pinned in mcp-dropped-tools.test.ts): with the bundled TS MCP SDK, a string-root
|
|
140
|
+
* schema already fails the SDK client's OWN zod at `listTools` — the whole server is skipped
|
|
141
|
+
* (warnings face) and this gate never sees the listing, losing healthy sibling tools with it
|
|
142
|
+
* (SDK-upstream failure mode, recorded). This per-tool gate is DEFENSE IN DEPTH: it binds when a
|
|
143
|
+
* transport/SDK revision delivers schemas the client does not fully validate.
|
|
144
|
+
*
|
|
145
|
+
* The drop is NEVER silent, two faces (CC parity — its `mcp_dropped_tools_delta` system reminder):
|
|
146
|
+
* - operator: prepare-task forwards each entry to `onError(phase:"mcp")` alongside `warnings`;
|
|
147
|
+
* - model: the run loop announces the entries ONCE at a turn boundary (`mcp_dropped_tools`
|
|
148
|
+
* attachment, `mcpInstructions` opt-in lane) and DRAINS this array on intact delivery — same
|
|
149
|
+
* survival-gated consumption discipline as `instructionsDelta`.
|
|
150
|
+
* `tool` is the server-advertised name, neutralized at intake (`inlineUntrusted`); `reason` is
|
|
151
|
+
* core-TEMPLATED but its structural-error paths may embed server-controlled property names, so
|
|
152
|
+
* the whole string is likewise neutralized + bounded at intake (single-line, ≤240 cps, fences
|
|
153
|
+
* defused) — the bound also keeps one rendered announce entry inside a single frame.
|
|
154
|
+
*/
|
|
32
155
|
droppedTools: McpDroppedTool[];
|
|
156
|
+
/**
|
|
157
|
+
* design/99 §E9 — per-server status, a PURE PROJECTION of THIS materialization (no new connection logic).
|
|
158
|
+
* One entry per declared server. **Semantics = the moment of this task leg's materialize** — core never
|
|
159
|
+
* persists MCP connections, so it is "did this leg connect", NOT a live session-health signal between tasks.
|
|
160
|
+
* A consumer (service) surfacing it as session status must understand that. `toolNames` are the namespaced
|
|
161
|
+
* (`<server>__<tool>`) names exposed.
|
|
162
|
+
*
|
|
163
|
+
* RB-437-a — READ THIS AS A SNAPSHOT, NOT A HEARTBEAT. `status` is the connect-time verdict and is never
|
|
164
|
+
* rewritten: a server that dies mid-task still reads `connected` here, because that IS what happened at
|
|
165
|
+
* materialize. The one live bit is {@link McpServerStatus.transportClosed} (set if and when core observes
|
|
166
|
+
* the transport go away — see its own note for the reach). For an authoritative answer about a server's
|
|
167
|
+
* health RIGHT NOW, call {@link refresh} — it is the only face that touches the connection.
|
|
168
|
+
*/
|
|
33
169
|
statuses: McpServerStatus[];
|
|
170
|
+
/**
|
|
171
|
+
* [1605] RefreshMcpTools (CC 2.1.218 parity, cli-锚形) — re-read the tool list of one server (or
|
|
172
|
+
* every CONNECTED server when `server` is omitted) over the EXISTING connection. NEVER dials or
|
|
173
|
+
* re-dials: a dead/never-connected server reports `not_connected`; a live listTools failure
|
|
174
|
+
* reports `failed` (the connection is left as-is). A refreshed entry carries the NEW intake
|
|
175
|
+
* result (tools/axes/dropped — the same schema-gate/namespacing/axis pipeline as connect) plus
|
|
176
|
+
* the added/removed namespaced tool names relative to the previous listing; the caller (the
|
|
177
|
+
* RefreshMcpTools tool mount in prepare-task) swaps them into the harness toolset.
|
|
178
|
+
*
|
|
179
|
+
* LEG-LOCAL fact (review, documented): refresh results do NOT ride a checkpoint — a durable
|
|
180
|
+
* resume re-materializes and takes a FRESH first listing, so refreshed tools may be absent on the
|
|
181
|
+
* resumed leg until RefreshMcpTools is called again (an honest not-found, never a silent
|
|
182
|
+
* misroute).
|
|
183
|
+
*/
|
|
34
184
|
refresh: (server?: string) => Promise<McpRefreshResult[]>;
|
|
35
185
|
dispose: () => Promise<void>;
|
|
36
186
|
}
|
|
187
|
+
/** [1605] One per-server entry of {@link MaterializedMcp.refresh}. `added`/`removed` are namespaced
|
|
188
|
+
* (`mcp__<server>__<tool>`) names; `tools`/`axes`/`dropped` are present only on `"refreshed"`. */
|
|
37
189
|
export interface McpRefreshResult {
|
|
38
190
|
server: string;
|
|
191
|
+
/** The server's namespaced-name prefix (`mcp__<normalized-server>__`) — the consumer's SPLICE
|
|
192
|
+
* DOMAIN for the swap (review F4: a prefix domain is self-healing and decoupled from the diff
|
|
193
|
+
* baseline, which advances even when a consumer skips a swap). Present on every entry. */
|
|
39
194
|
prefix: string;
|
|
40
195
|
status: "refreshed" | "not_connected" | "failed";
|
|
41
196
|
toolCount: number;
|
|
@@ -46,8 +201,14 @@ export interface McpRefreshResult {
|
|
|
46
201
|
dropped?: McpDroppedTool[];
|
|
47
202
|
error?: string;
|
|
48
203
|
}
|
|
204
|
+
/** design/99 §E9 — projected per-server MCP status (see {@link MaterializedMcp.statuses}). NOTE: `serverInfo`
|
|
205
|
+
* and `error` are SERVER-controlled strings (verbatim from the remote) — UNTRUSTED; a consumer rendering them
|
|
206
|
+
* into a TUI/log must treat them as such (a hostile server could embed ANSI/break-out sequences). `toolNames`
|
|
207
|
+
* are namespaced with a core-controlled `mcp__<server>__` prefix (design/108 ①). */
|
|
49
208
|
export interface McpServerStatus {
|
|
50
209
|
name: string;
|
|
210
|
+
/** The CONNECT-TIME verdict for this leg — "did this server connect and list its tools". Deliberately
|
|
211
|
+
* frozen: a later death does not rewrite it (see {@link transportClosed} and `MaterializedMcp.refresh`). */
|
|
51
212
|
status: "connected" | "failed";
|
|
52
213
|
serverInfo?: {
|
|
53
214
|
name: string;
|
|
@@ -55,48 +216,194 @@ export interface McpServerStatus {
|
|
|
55
216
|
};
|
|
56
217
|
toolNames?: string[];
|
|
57
218
|
error?: string;
|
|
219
|
+
/**
|
|
220
|
+
* RB-437-a — set to `true` once core OBSERVES this server's transport close during the task; absent
|
|
221
|
+
* otherwise (never `false`: absence means "no close was observed", which is not the same as "alive").
|
|
222
|
+
* It mirrors exactly the flag core's own fail-fast path keys on, so `transportClosed === true` also
|
|
223
|
+
* means every further call to this server's tools/resources is refused without dialing.
|
|
224
|
+
*
|
|
225
|
+
* REACH (honest, and the reason `refresh()` stays the authority): this needs a transport-level close
|
|
226
|
+
* NOTIFICATION. A stdio server has one — the child process exiting closes the pipe. A streamable-HTTP
|
|
227
|
+
* endpoint does NOT: the SDK's HTTP transport raises `onclose` only when the client itself closes it,
|
|
228
|
+
* so an endpoint that dies is discovered per-REQUEST (as a translated transport failure carrying the
|
|
229
|
+
* server name and the outcome) and this field stays absent.
|
|
230
|
+
*/
|
|
58
231
|
transportClosed?: boolean;
|
|
59
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* design/108 ① (CC 2.1.187 parity) — the GLOBAL `mcp__` marker prefix. CC names every MCP tool
|
|
235
|
+
* `mcp__<server>__<tool>` so a consumer (permission allowlist, bypass-exempt, the flywheel's whitelist) can
|
|
236
|
+
* identify an MCP-originated tool by prefix ALONE, without knowing the per-deployment server names. Exported so
|
|
237
|
+
* downstream consumers share one source (the durable-resume canonicalizer is retired — RB-476-A).
|
|
238
|
+
* The value is OWNED by the protocol table (protocol-table.ts) — this export is the public face.
|
|
239
|
+
*
|
|
240
|
+
* The type is the LITERAL `"mcp__"`, not `string`: a downstream literal-typed position (a template-literal
|
|
241
|
+
* type, a keyed lookup) compiles against the literal and stops compiling the moment this widens — and the
|
|
242
|
+
* export-surface snapshot is name → kind, so it cannot see a widening at all. Annotated rather than
|
|
243
|
+
* asserted, so a table-side change to the prefix surfaces as a compile error here instead of being
|
|
244
|
+
* silently re-narrowed by a cast.
|
|
245
|
+
*/
|
|
60
246
|
export declare const MCP_PREFIX: "mcp__";
|
|
247
|
+
/**
|
|
248
|
+
* F4-② (CC :320015/:320061): resolve a server's self-declared per-tool result-size threshold from its
|
|
249
|
+
* `_meta`. Non-numeric/non-finite/non-positive → undefined (declaration ignored); valid → capped at
|
|
250
|
+
* {@link MCP_META_RESULT_SIZE_CAP}. Exported for tests.
|
|
251
|
+
*/
|
|
61
252
|
export declare function resolveMcpDeclaredResultSize(meta: Record<string, unknown> | undefined): number | undefined;
|
|
253
|
+
/**
|
|
254
|
+
* Apply the token gate to a mapped MCP content array (CC `$Mp`/`BMp` shape): text blocks consume a
|
|
255
|
+
* cumulative char budget of `tokens×4`; past the budget they are sliced/dropped head-keep, and the CC
|
|
256
|
+
* guidance note is appended as a final text block. Non-text blocks (images) pass through untouched —
|
|
257
|
+
* same convention as the offload wrapper. Exported for tests.
|
|
258
|
+
*/
|
|
62
259
|
export declare function gateMcpOutput(content: Array<TextContent | ImageContent>, limitTokens?: number): Array<TextContent | ImageContent>;
|
|
63
260
|
export declare function structuredContentErrorLine(structuredContent: unknown, collectedText: string): string | undefined;
|
|
261
|
+
/** Head+tail bound for MCP error text (exported for tests). */
|
|
64
262
|
export declare function truncateMcpErrorText(s: string): string;
|
|
263
|
+
/**
|
|
264
|
+
* Default per-call MCP tool timeout. The SDK's own default (60s) silently kills any long-running MCP tool
|
|
265
|
+
* with a -32001 and offers the deployment no knob; a very large default (matching the behavior of the
|
|
266
|
+
* reference agent client) lets the task-level budget/abort govern instead, while `MCP_TOOL_TIMEOUT` (ms)
|
|
267
|
+
* remains available to tighten it per deployment.
|
|
268
|
+
*/
|
|
65
269
|
export declare const MCP_TOOL_TIMEOUT_DEFAULT_MS = 100000000;
|
|
270
|
+
/**
|
|
271
|
+
* The bounds EVERY `MCP_*` millisecond knob resolves into — CC 223-same (`MNs` @354067 and the idle leg
|
|
272
|
+
* `Pyd` @354076 both clamp into `[1000, 2147483647]`; the constants were already ported here, the clamp
|
|
273
|
+
* was not).
|
|
274
|
+
*
|
|
275
|
+
* The ceiling is not cosmetic: `setTimeout` stores its delay in a signed 32-bit field, so a larger value
|
|
276
|
+
* is silently rewritten to `1` — an operator WIDENING a bound past 24.85 days (the shape of "basically
|
|
277
|
+
* turn this watchdog off") gets the exact opposite: a bound that fires ~immediately on every call. The
|
|
278
|
+
* floor closes the other end of the same unit trap — a bare `30` is what someone thinking in seconds
|
|
279
|
+
* types, and a 30ms MCP bound is never anyone's intent.
|
|
280
|
+
*/
|
|
66
281
|
export declare const MCP_ENV_MS_MIN = 1000;
|
|
67
282
|
export declare const MCP_ENV_MS_MAX = 2147483647;
|
|
283
|
+
/** Test seam: the announcement de-dupes per process, so a test asserting the line must be able to clear
|
|
284
|
+
* the ledger. Never called by production code. */
|
|
68
285
|
export declare function __resetMcpEnvAnnouncements(): void;
|
|
286
|
+
/** Resolve the per-call tool timeout in ms (env `MCP_TOOL_TIMEOUT`, else the large default). Exported for tests. */
|
|
69
287
|
export declare function mcpToolTimeoutMs(): number;
|
|
288
|
+
/**
|
|
289
|
+
* Resolve the TOTAL wall-clock ceiling for one tool call in ms (env `MCP_TOOL_TIMEOUT_TOTAL`, else the
|
|
290
|
+
* per-call timeout). The SDK's `resetTimeoutOnProgress` only re-arms the SDK's OWN per-call timer
|
|
291
|
+
* (`mcpToolTimeoutMs()` above — a different mechanism from {@link armMcpIdleWatchdog}'s idle watchdog
|
|
292
|
+
* below, despite the name-adjacent terms; disambiguated here on purpose, see that function's docstring
|
|
293
|
+
* for why sema needs both). It enforces a total bound ONLY when `maxTotalTimeout` is provided (protocol.js
|
|
294
|
+
* `_resetTimeout`), so without this a
|
|
295
|
+
* misbehaving/stuck server emitting periodic progress notifications could extend a call forever. Defaulting
|
|
296
|
+
* the ceiling to the per-call timeout means progress can keep an active call alive only within the same
|
|
297
|
+
* window the deployment already accepted; the resulting failure is the same -32001 timeout frame. Env
|
|
298
|
+
* parsing follows the `MCP_TOOL_TIMEOUT` discipline (unset/unparseable/non-positive → default). Exported
|
|
299
|
+
* for tests.
|
|
300
|
+
*/
|
|
70
301
|
export declare function mcpToolTotalTimeoutMs(perCallMs: number): number;
|
|
302
|
+
/**
|
|
303
|
+
* RB-199 FO-1 (form-one audit, CC 2.1.220): a server that goes SILENT — alive, transport open, no error,
|
|
304
|
+
* no close, just never responds and never emits progress — has no bound tighter than the (deliberately
|
|
305
|
+
* enormous, ~27.8h-default) total ceiling above. CC bounds this with a SEPARATE idle watchdog distinct
|
|
306
|
+
* from its total ceiling (`j7u` @345484: stdio 30min / http-sse 5min).
|
|
307
|
+
*
|
|
308
|
+
* Narrower than the audit's original framing: a CLOSED transport is already handled correctly by the SDK
|
|
309
|
+
* itself — `Protocol._onclose` (shared/protocol.js) rejects every in-flight response handler immediately
|
|
310
|
+
* with `ConnectionClosed` the moment `onclose` fires, so this watchdog exists for the SILENT-but-open case
|
|
311
|
+
* only, not as a substitute for connection-close handling.
|
|
312
|
+
*/
|
|
71
313
|
export declare const MCP_IDLE_TIMEOUT_STDIO_DEFAULT_MS: number;
|
|
72
314
|
export declare const MCP_IDLE_TIMEOUT_HTTP_DEFAULT_MS: number;
|
|
315
|
+
/** Resolve the idle-watchdog bound in ms for a transport kind (env `MCP_IDLE_TIMEOUT_STDIO` /
|
|
316
|
+
* `MCP_IDLE_TIMEOUT_HTTP`, else the CC-matched default). Exported for tests. */
|
|
73
317
|
export declare function mcpIdleTimeoutMs(kind: "stdio" | "http"): number;
|
|
318
|
+
/**
|
|
319
|
+
* Startup-phase (connect + initial listTools) timeout override in ms (env `MCP_TIMEOUT`); undefined keeps
|
|
320
|
+
* the SDK default. Startup deliberately stays bounded: a hung server at materialize time should fail open
|
|
321
|
+
* into a skipped-server warning quickly, not stall task preparation indefinitely.
|
|
322
|
+
*/
|
|
74
323
|
export declare function mcpStartupTimeoutMs(): number | undefined;
|
|
324
|
+
/** The protocol-range condition name for a JSON-RPC error code, or `undefined` for every other code
|
|
325
|
+
* (see {@link MCP_SPEC_ERROR_CODE_NAMES}). */
|
|
75
326
|
export declare function describeMcpSpecErrorCode(code: unknown): string | undefined;
|
|
327
|
+
/**
|
|
328
|
+
* RB-437-c — the SDK stamps `MCP error <code>: ` onto an McpError's message IN ITS CONSTRUCTOR, and it
|
|
329
|
+
* does so at BOTH ends of the wire: a server built on an MCP SDK throws an McpError, its already-stamped
|
|
330
|
+
* `.message` goes out as the JSON-RPC `error.message`, and the client constructs its own McpError over
|
|
331
|
+
* that string — so the failure reaches the model as `MCP error -32602: MCP error -32602: …`. Collapse a
|
|
332
|
+
* repeat of the SAME code (a leading stamp carrying a DIFFERENT code is server data, not a duplicate of
|
|
333
|
+
* ours, and is left alone). Exported for unit testing; not part of the package index.
|
|
334
|
+
*/
|
|
76
335
|
export declare function collapseMcpErrorPrefix(message: string): string;
|
|
336
|
+
/** The first errno-shaped `code` on an error's cause chain. `fetch` reports every network failure as a
|
|
337
|
+
* bare `TypeError: fetch failed` with the real cause nested underneath (and an AggregateError when a
|
|
338
|
+
* host resolved to several addresses), so the code is never on the thrown error itself.
|
|
339
|
+
* Exported for unit testing (RB-449 mcp-1); not part of the package index (src/index.ts re-exports are
|
|
340
|
+
* explicit and do not name it — see the sibling `collapseMcpErrorPrefix`/`classifyDirReadInvalidParams`
|
|
341
|
+
* comments for the same "exported for tests only" convention). */
|
|
77
342
|
export declare function networkErrorCode(err: unknown, depth?: number): string | undefined;
|
|
343
|
+
/** What {@link describeHttpTransportFailure} could establish about a transport-level HTTP failure:
|
|
344
|
+
* the condition to name in the model-facing copy, whether the request can be said NOT to have reached
|
|
345
|
+
* the remote, and the HTTP status when the endpoint answered with one. */
|
|
78
346
|
export interface HttpTransportFailure {
|
|
79
347
|
condition: string;
|
|
348
|
+
/** `"no"` = provably never delivered (a connect-phase errno); `"unknown"` = the request may have run. */
|
|
80
349
|
delivered: "no" | "unknown";
|
|
81
350
|
httpStatus?: number;
|
|
82
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* RB-437-b — a streamable-HTTP failure that never became an MCP exchange at all: the POST failed at the
|
|
354
|
+
* network layer (endpoint gone / unresolvable), or the endpoint answered with something that is not an
|
|
355
|
+
* MCP response. The SDK surfaces the first as `fetch`'s bare `TypeError: fetch failed` and the second as
|
|
356
|
+
* a `StreamableHTTPError`; NEITHER carries the server name, the MCP context or an outcome — while the
|
|
357
|
+
* stdio path for the same event (the server went away) has all three. Returns the condition to name and
|
|
358
|
+
* whether the request can be said not to have reached the server, or `undefined` when the failure is not
|
|
359
|
+
* of this class (an McpError is an answer FROM the server: the exchange happened, so it is never one).
|
|
360
|
+
*
|
|
361
|
+
* Exported (not on the package index) for the A2A client leg, which faces the SAME `fetch` layer and owes
|
|
362
|
+
* the same outcome contract — one classifier, so the two protocols cannot drift on what "the request never
|
|
363
|
+
* reached them" means.
|
|
364
|
+
*/
|
|
83
365
|
export declare function describeHttpTransportFailure(err: unknown): HttpTransportFailure | undefined;
|
|
84
366
|
export { normalizeNameSegment as normalizeMcpName, clampNameSegment } from "./protocol-naming.js";
|
|
85
367
|
export * from "./image-downsample.js";
|
|
368
|
+
/**
|
|
369
|
+
* design/116 W5-2 — compact, jq-friendly type signature for a `structuredContent` value, e.g.
|
|
370
|
+
* `{title: string, items: [{id: number}]}`. Port of CC 2.1.187 `inferCompactSchema` (services/mcp/client.ts,
|
|
371
|
+
* beside the structuredContent branch at client.ts:2676-2683): depth-2, first array element as the element
|
|
372
|
+
* type, ≤10 object entries then `, ...`.
|
|
373
|
+
*/
|
|
86
374
|
export declare function inferCompactSchema(value: unknown, depth?: number): string;
|
|
375
|
+
/** The per-peer HTTP auth declaration every protocol spec carries in the same two fields — the static
|
|
376
|
+
* headers the deployment configured, and the header name the per-task principal rides on (design/62).
|
|
377
|
+
* Named rather than inlined because it is a cross-module signature: {@link McpServerSpec}'s http
|
|
378
|
+
* transport and A2A's peer spec both satisfy it, and the resolver below serves both. */
|
|
87
379
|
export interface ProtocolHttpAuth {
|
|
88
380
|
headers?: Record<string, string>;
|
|
89
381
|
principalHeader?: string;
|
|
90
382
|
}
|
|
383
|
+
/**
|
|
384
|
+
* Resolve the HTTP request headers for one remote PEER of `protocol`, injecting the per-task end-user
|
|
385
|
+
* principal (design/62). The principal is added **only** when the spec declares a `principalHeader` AND a
|
|
386
|
+
* `principal` is present; it is injected **last** so it overrides any same-named static header; an absent
|
|
387
|
+
* principal sends no such header (the remote must then default to deny/public, never admin). Pure +
|
|
388
|
+
* exported for testing and so a consumer can verify what its config sends.
|
|
389
|
+
*
|
|
390
|
+
* Shared across protocols (A2A reuses it verbatim), which is why the failure names its protocol from the
|
|
391
|
+
* ARGUMENT rather than from a hard-coded literal: a copy of this guard per protocol is exactly the
|
|
392
|
+
* "second mint" shape whose copies stop tracking each other. Callers must invoke it INSIDE their per-peer
|
|
393
|
+
* boundary — the throw is one peer's configuration defect, and the surrounding per-peer catch is what
|
|
394
|
+
* turns it into a skipped peer instead of a failed task.
|
|
395
|
+
*/
|
|
91
396
|
export declare function resolveProtocolHttpHeaders(protocol: ProtocolId, t: ProtocolHttpAuth, principal?: string): Record<string, string> | undefined;
|
|
92
397
|
interface McpContentItem {
|
|
93
398
|
type: string;
|
|
94
399
|
text?: string;
|
|
95
400
|
data?: string;
|
|
96
401
|
mimeType?: string;
|
|
402
|
+
/** `resource_link` block: a pointer to a server resource. */
|
|
97
403
|
uri?: string;
|
|
98
404
|
name?: string;
|
|
99
405
|
description?: string;
|
|
406
|
+
/** `resource` block: an embedded resource (text or binary). */
|
|
100
407
|
resource?: {
|
|
101
408
|
uri?: string;
|
|
102
409
|
mimeType?: string;
|
|
@@ -105,6 +412,7 @@ interface McpContentItem {
|
|
|
105
412
|
};
|
|
106
413
|
}
|
|
107
414
|
export declare function mapContent(content: Array<McpContentItem>, serverName?: string, imageResizer?: McpImageResizer): Promise<Array<TextContent | ImageContent>>;
|
|
415
|
+
/** One tool's schema-normalization outcome (CC 220 `zyo` @336616-336654's return shape). */
|
|
108
416
|
export type McpSchemaNormalizeResult = {
|
|
109
417
|
outcome: "unchanged";
|
|
110
418
|
} | {
|
|
@@ -116,15 +424,88 @@ export type McpSchemaNormalizeResult = {
|
|
|
116
424
|
outcome: "drop";
|
|
117
425
|
reason: string;
|
|
118
426
|
};
|
|
427
|
+
/**
|
|
428
|
+
* RB-199 FO-2 (form-one audit, CC 2.1.220 `zyo` @336616-336654): flatten a root-level `anyOf`/`oneOf`/
|
|
429
|
+
* `allOf` combinator into a plain `{type:"object", properties, required}` shape a provider's tool-schema
|
|
430
|
+
* validator accepts, INSTEAD of leaving `mcpToolSchemaProblem` below to drop the whole tool. Without this,
|
|
431
|
+
* a server advertising the common "zod union" combinator shape (structurally VALID JSON Schema — the
|
|
432
|
+
* existing gate's root-type/structural checks both pass it) gets forwarded as-is and a strict provider
|
|
433
|
+
* (Anthropic) 400s the ENTIRE model request at the wire — the exact failure `mcpToolSchemaProblem`'s own
|
|
434
|
+
* docstring promises to contain ("a single misconfigured server never bricks the whole task"). A schema
|
|
435
|
+
* with no top-level combinator key is passed through `{outcome:"unchanged"}` — the vast majority of tools
|
|
436
|
+
* never reach the union-handling code below at all (fail-open by construction, matching CC's own early exit).
|
|
437
|
+
* Properties are collected from the top-level `properties` FIRST (so a sibling `properties` block — legal
|
|
438
|
+
* alongside a combinator, and semantically load-bearing — is never shadowed by a same-named combinator-
|
|
439
|
+
* branch property), then from every combinator branch present, in declaration order; the FIRST property of
|
|
440
|
+
* a given name wins (matches CC's own `!(d in r)` guard) — differing branches disagreeing on the SAME
|
|
441
|
+
* property's shape is a real ambiguity CC accepts too, not a sema gap. `required` is unioned from the
|
|
442
|
+
* top-level `required` PLUS `allOf` branches ONLY (never `anyOf`/`oneOf` branches — those are alternatives;
|
|
443
|
+
* unioning their `required` would demand fields the caller may legitimately omit by picking a different
|
|
444
|
+
* branch, exactly the correctness bug CC's own asymmetry avoids). Any exception during the walk (a $ref
|
|
445
|
+
* cycle degenerate enough to defeat the local-only resolver, e.g.) is caught and mapped to `outcome:"drop"`
|
|
446
|
+
* — a normalizer crash is evidence the schema is pathological, not a reason to propagate an exception out
|
|
447
|
+
* of the per-tool intake loop into the per-SERVER catch (same isolation principle `mcpToolSchemaProblem`'s
|
|
448
|
+
* own docstring already states for structural validation).
|
|
449
|
+
*/
|
|
119
450
|
export declare function normalizeMcpToolSchema(schema: unknown): McpSchemaNormalizeResult;
|
|
451
|
+
/**
|
|
452
|
+
* [cc216] Deterministic intake gate for a server-advertised tool `inputSchema` — returns a
|
|
453
|
+
* CORE-authored reason string when the schema would be rejected at the provider wire, else
|
|
454
|
+
* `undefined` (tool is kept). Deliberately CONSERVATIVE (fail-open): only shapes that are
|
|
455
|
+
* *structurally* unusable are dropped — anything a provider might accept rides through. An ABSENT
|
|
456
|
+
* schema is fine (intake defaults it to `{type:"object"}` below). CC 2.1.216 gates the same prune
|
|
457
|
+
* per-server via remote config (its rollout mechanism, not the mechanism itself); sema's gate is
|
|
458
|
+
* the deterministic predicate alone. RB-199 FO-2: run {@link normalizeMcpToolSchema} on the schema
|
|
459
|
+
* FIRST — a root-level anyOf/oneOf/allOf reaching this gate unflattened is exactly the shape this
|
|
460
|
+
* gate's own docstring promise ("a single misconfigured server never bricks the whole task") existed
|
|
461
|
+
* to catch, and this gate alone does not catch it (no type key ⇒ passes the root-type check; the
|
|
462
|
+
* combinator's own structure is legal JSON Schema ⇒ passes validateJsonSchemaShape too).
|
|
463
|
+
*/
|
|
120
464
|
export declare function mcpToolSchemaProblem(schema: unknown): string | undefined;
|
|
121
465
|
export declare function materializeMcpTools(specs: McpServerSpec[], principal?: string, onElicit?: OnElicit, imageResizer?: McpImageResizer): Promise<MaterializedMcp>;
|
|
466
|
+
/**
|
|
467
|
+
* Fold the caller's AUTHORITATIVE per-tool override (design F: caller = trust root) over the server-hint axis.
|
|
468
|
+
* Unlike server hints, the caller may RAISE or LOWER any axis: `effect` sets the repeat-safety class (lower to
|
|
469
|
+
* `read`/`idempotent` or raise to `write`); `egress: false` / `irreversibility: "never"` REMOVE a server-added
|
|
470
|
+
* tighten the caller knows is wrong. Returns `undefined` when nothing remains set.
|
|
471
|
+
*/
|
|
472
|
+
/** Exported for tests — the override algebra above is a contract face (negatives must survive). */
|
|
122
473
|
export declare function applyCallerAxisOverride(name: string, hint: McpToolAxis | undefined, override: {
|
|
123
474
|
effect?: ToolEffect;
|
|
124
475
|
egress?: boolean;
|
|
125
476
|
irreversibility?: "always" | "never";
|
|
126
477
|
} | undefined): McpToolAxis | undefined;
|
|
478
|
+
/** Read a first-page `-32602` message as either meaning (see {@link DIR_READ_NOT_A_DIRECTORY_RE}). Exported
|
|
479
|
+
* for the discrimination nails; the message is SERVER-authored and is only ever classified here, never
|
|
480
|
+
* trusted as instructions. */
|
|
127
481
|
export declare function classifyDirReadInvalidParams(message: string): "not_found" | "not_directory";
|
|
482
|
+
/**
|
|
483
|
+
* RB-408 G12 — `tools/call` result parse that accepts the MCP `2026-07-28` widening of
|
|
484
|
+
* `structuredContent` from "a JSON object" to ANY JSON value (the same revision that relaxes
|
|
485
|
+
* `inputSchema`/`outputSchema` to the full JSON Schema 2020-12 keyword set).
|
|
486
|
+
*
|
|
487
|
+
* SDK 1.29's `CallToolResultSchema` still types the field as a record, so a spec-legal array / string /
|
|
488
|
+
* number / boolean / null fails validation for the WHOLE result — and the failure takes the `content`
|
|
489
|
+
* blocks down with it: a server returning perfectly usable text plus a scalar `structuredContent`
|
|
490
|
+
* produced nothing but `Invalid tools/call result: expected record, received number`. That is a silent
|
|
491
|
+
* capability loss dressed as a protocol error, and it gets WORSE as servers adopt the revision.
|
|
492
|
+
*
|
|
493
|
+
* The widening is deliberately surgical: `structuredContent` is lifted out, the SDK's own strict schema
|
|
494
|
+
* runs over the remainder (so content-block validation, the `content` default and the loose passthrough
|
|
495
|
+
* of unknown top-level keys are byte-for-byte what they were), and the lifted value is re-attached
|
|
496
|
+
* VERBATIM — same reference, no rebuild. An object-valued `structuredContent` therefore behaves exactly
|
|
497
|
+
* as before, and a malformed `content` array is still rejected: this must not become a validation bypass.
|
|
498
|
+
* Same duck-typing posture as {@link LenientListToolsResultSchema} (no direct `zod` dependency — the SDK's
|
|
499
|
+
* `zod-compat` shim calls `.safeParse(data)` on any object lacking a Zod-4 `_zod` marker).
|
|
500
|
+
*
|
|
501
|
+
* RESIDUAL, SDK-side and deliberately not widened here: `Client.callTool` guards its `outputSchema`
|
|
502
|
+
* validation with a TRUTHINESS test on `result.structuredContent`, so a tool that declares an
|
|
503
|
+
* `outputSchema` and returns a falsy scalar (`0`, `""`, `false`, `null`) is still rejected by the SDK with
|
|
504
|
+
* "has an output schema but did not return structured content". That path is LOUD (never a silent drop),
|
|
505
|
+
* is bounded to outputSchema-declaring tools, and widening it means replacing `callTool` itself — which
|
|
506
|
+
* would mean re-implementing the two guards it exists for (the output validator and the
|
|
507
|
+
* `taskSupport:"required"` refusal, both keyed off SDK-private caches).
|
|
508
|
+
*/
|
|
128
509
|
export declare function parseCallToolResultLenient(data: unknown): {
|
|
129
510
|
success: true;
|
|
130
511
|
data: unknown;
|
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
import type { AgentMessage } from "../internal/harness-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Aggregate MEDIA (image) byte budget — the multimodal sibling of {@link AGGREGATE_TOOL_RESULT_BUDGET_CHARS}
|
|
4
|
+
* (which only counts TEXT, design/64 §17.2). batch-C added image reads (`Read` → `ImageContent`); each is bounded
|
|
5
|
+
* per-image (`MAX_IMAGE_READ_BYTES`), but N images accumulate ACROSS turns in the context and would otherwise grow
|
|
6
|
+
* the request unboundedly (a real gap — CC 2.1.196 added the same cap, `tengu_media_byte_cap`, validating it).
|
|
7
|
+
*
|
|
8
|
+
* This caps the SUM of inline image bytes across the whole message list: while over budget, the OLDEST images are
|
|
9
|
+
* stripped (replaced with a short text marker) until it fits — recent media (most relevant) is kept. Like the text
|
|
10
|
+
* budget it is a REQUEST-ONLY, NON-DESTRUCTIVE transform (returns a new array; the durable session keeps the full
|
|
11
|
+
* image, and the model can re-`Read` the file if it still needs it) applied in the `harness.on("context")` hook,
|
|
12
|
+
* and DETERMINISTIC (same messages + limit → same strip set → byte-identical request → prompt-cache safe).
|
|
13
|
+
*/
|
|
14
|
+
/** Default aggregate inline-media budget (bytes). Generous — only the pathological "N parallel huge image reads"
|
|
15
|
+
* case strips. Bounds the request while leaving normal multimodal use untouched. Overridable per-deployment. */
|
|
2
16
|
export declare const AGGREGATE_MEDIA_BUDGET_BYTES: number;
|
|
17
|
+
/** Telemetry for one strip pass (mirrors CC's `tengu_media_byte_cap_stripped` fields). */
|
|
3
18
|
export interface MediaStripInfo {
|
|
4
19
|
totalBytes: number;
|
|
5
20
|
limitBytes: number;
|
|
6
21
|
removedCount: number;
|
|
7
22
|
removedBytes: number;
|
|
8
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Cap the aggregate inline-image bytes across `messages` to `limitBytes`, stripping OLDEST images first. Returns the
|
|
26
|
+
* SAME array when already within budget or the limit is non-positive/non-finite (no allocation, no-op). Otherwise a
|
|
27
|
+
* shallow-cloned array with the stripped messages replaced (originals untouched). `onStripped` fires once if anything
|
|
28
|
+
* was removed.
|
|
29
|
+
*/
|
|
9
30
|
export declare function capAggregateMediaBytes(messages: AgentMessage[], opts: {
|
|
10
31
|
limitBytes: number;
|
|
11
32
|
onStripped?: (info: MediaStripInfo) => void;
|