From 3e3aa697ca7cb3a9bf723c4e38f0c780f715e3b1 Mon Sep 17 00:00:00 2001 From: Turtle Date: Sat, 14 Nov 2026 17:13:11 +0800 Subject: [PATCH] fix(ptc): fall back safely when program image substitution fails Contain any substitution failure, including deep values, in the ordered commit lane, state the all-or-nothing contract and text delivery in the docs, and describe the raw-block fallback in the MCP declaration. Refs #8468 --- .../ptc-mcp-image-values/guide.i18n.yaml | 8 +++---- .../v0.2.2-rc.3/ptc-mcp-image-values/guide.md | 6 +++--- .../ptc-mcp-image-values/guide.zh.md | 6 +++--- .../core/tool-executor-ptc/README.i18n.yaml | 8 +++---- packages/core/tool-executor-ptc/README.md | 4 ++-- packages/core/tool-executor-ptc/README.zh.md | 4 ++-- packages/core/tool-executor-ptc/src/ptc.ts | 21 +++++++++---------- .../core/tool-executor-ptc/tests/ptc.spec.ts | 21 +++++++++++++------ packages/mcp/mcp-client/README.i18n.yaml | 8 +++---- packages/mcp/mcp-client/README.md | 4 ++-- packages/mcp/mcp-client/README.zh.md | 4 ++-- packages/mcp/mcp-client/src/tools.ts | 2 +- .../system-prompt.expected.md | 4 ++-- 13 files changed, 54 insertions(+), 46 deletions(-) diff --git a/docs/upgrade-guide/v0.2.2-rc.3/ptc-mcp-image-values/guide.i18n.yaml b/docs/upgrade-guide/v0.2.2-rc.3/ptc-mcp-image-values/guide.i18n.yaml index 6587409e10..65f82997f3 100644 --- a/docs/upgrade-guide/v0.2.2-rc.3/ptc-mcp-image-values/guide.i18n.yaml +++ b/docs/upgrade-guide/v0.2.2-rc.3/ptc-mcp-image-values/guide.i18n.yaml @@ -9,8 +9,8 @@ en: d6de4dbd1d9e5b97 zh: abfc0e17251123b4 /admitted-mcp-image-blocks-become-ptc-image-values/change: - en: 80fe10337d792bc9 - zh: 0afb3f889ff171bb + en: 49c1de6568812254 + zh: e33b028fb5369be3 /admitted-mcp-image-blocks-become-ptc-image-values/migration: - en: 4f114f246170f87c - zh: b831bbdf9bbc9e7d + en: 7015ecfe11765993 + zh: 677267091fa5458a diff --git a/docs/upgrade-guide/v0.2.2-rc.3/ptc-mcp-image-values/guide.md b/docs/upgrade-guide/v0.2.2-rc.3/ptc-mcp-image-values/guide.md index 6250d92c0d..92b53610c3 100644 --- a/docs/upgrade-guide/v0.2.2-rc.3/ptc-mcp-image-values/guide.md +++ b/docs/upgrade-guide/v0.2.2-rc.3/ptc-mcp-image-values/guide.md @@ -11,13 +11,13 @@ English | [中文](guide.zh.md) An MCP tool result keeps its canonical `{ content, structuredContent? }` value. Each image block admitted to durable model context now also carries an `attachment` reference beside its original `type`, `mimeType`, and `data` fields. Refused images keep their original fields only. -In PTC mode, each value entry of the form `{ type: 'image', attachment }` whose attachment appears in the finalized tool result becomes an `Image`, the same value that `read_image` and CUA screenshots return. Previously, the program received the base64 image block, so `inspect(result)` printed the base64 data, and the picture was attached automatically as additional model context. Now `inspect` shows the picture, and the picture enters the conversation only when the program inspects it. When the value does not reference every image of the final result, or the program cannot read an image file, the program receives the raw blocks and the pictures are still attached automatically, as before. Image blocks that an output policy removed keep their `attachment` field but stay JSON. +In PTC mode, each value entry of the form `{ type: 'image', attachment }` whose attachment appears in the finalized tool result becomes an `Image`, the same value that `read_image` and CUA screenshots return. Previously, the program received the base64 image block, so `inspect(result)` printed the base64 data, and the complete result content, text and pictures, was attached automatically as additional model context. Now `inspect` shows the picture, and the result's text and pictures enter the conversation only when the program inspects them, as for native CUA screenshots. When the value does not reference every image of the final result, or the program cannot read an image file, the program receives the raw blocks and the complete result content is still attached automatically, as before. Image blocks that an output policy removed keep their `attachment` field but stay JSON. -This affects PTC programs that read `data` or `mimeType` from an admitted MCP image block, and code that compares MCP tool values with the raw server result. +This affects PTC programs that read `data` or `mimeType` from an admitted MCP image block or rely on the automatic attachment of its result text, and code that compares MCP tool values with the raw server result. ## Migration -1. In PTC programs, inspect the `Image` to show it, or read its file through `path`: +1. In PTC programs, inspect the `Image` and any result text the model needs, or read the image file through `path`: ```js const result = await tools.mcp__server__screenshot({}); diff --git a/docs/upgrade-guide/v0.2.2-rc.3/ptc-mcp-image-values/guide.zh.md b/docs/upgrade-guide/v0.2.2-rc.3/ptc-mcp-image-values/guide.zh.md index 8c4186ed64..ba7964fd34 100644 --- a/docs/upgrade-guide/v0.2.2-rc.3/ptc-mcp-image-values/guide.zh.md +++ b/docs/upgrade-guide/v0.2.2-rc.3/ptc-mcp-image-values/guide.zh.md @@ -11,13 +11,13 @@ description: "已接受的 MCP 图片块携带附件引用,并以 Image 值而 MCP 工具结果保留其规范值 `{ content, structuredContent? }`。每个进入持久模型上下文的图片块现在除原有的 `type`、`mimeType` 和 `data` 字段外,还携带 `attachment` 引用。被拒绝的图片仅保留原有字段。 -在 PTC 模式下,形如 `{ type: 'image', attachment }` 且其附件出现在最终工具结果中的每个值条目都会变为 `Image`,与 `read_image` 和 CUA 截图返回的值相同。此前,程序收到的是 base64 图片块,因此 `inspect(result)` 输出 base64 数据,图片则自动作为额外模型上下文附加。现在 `inspect` 展示图片,且图片仅在程序 inspect 时进入对话。返回值未引用最终结果中的每张图片,或程序无法读取某个图片文件时,程序接收原始块,图片仍与此前一样自动附加。被输出策略移除的图片块保留 `attachment` 字段,但仍为 JSON。 +在 PTC 模式下,形如 `{ type: 'image', attachment }` 且其附件出现在最终工具结果中的每个值条目都会变为 `Image`,与 `read_image` 和 CUA 截图返回的值相同。此前,程序收到的是 base64 图片块,因此 `inspect(result)` 输出 base64 数据,包括文本与图片在内的完整结果内容则自动作为额外模型上下文附加。现在 `inspect` 展示图片,且结果的文本与图片仅在程序 inspect 时进入对话,与原生 CUA 截图相同。返回值未引用最终结果中的每张图片,或程序无法读取某个图片文件时,程序接收原始块,完整的结果内容仍与此前一样自动附加。被输出策略移除的图片块保留 `attachment` 字段,但仍为 JSON。 -从已接受的 MCP 图片块读取 `data` 或 `mimeType` 的 PTC 程序,以及将 MCP 工具值与服务器原始结果比较的代码会受到影响。 +从已接受的 MCP 图片块读取 `data` 或 `mimeType`、或依赖其结果文本自动附加的 PTC 程序,以及将 MCP 工具值与服务器原始结果比较的代码会受到影响。 ## 迁移 -1. 在 PTC 程序中,inspect `Image` 以展示图片,或通过 `path` 读取其文件: +1. 在 PTC 程序中,inspect `Image` 以及模型需要的结果文本,或通过 `path` 读取图片文件: ```js const result = await tools.mcp__server__screenshot({}); diff --git a/packages/core/tool-executor-ptc/README.i18n.yaml b/packages/core/tool-executor-ptc/README.i18n.yaml index f155e062ac..009b299646 100644 --- a/packages/core/tool-executor-ptc/README.i18n.yaml +++ b/packages/core/tool-executor-ptc/README.i18n.yaml @@ -21,8 +21,8 @@ en: 78708b3779d999a9 zh: ad6173f9f01630de /deepseek-ai-dsh-tool-executor-ptc/understand-the-implementation/ptc-mode: - en: 265927786eb7bac9 - zh: d2d94cb74911c8f9 + en: 4da0f9293816b976 + zh: c5f77ea403d30ff5 /deepseek-ai-dsh-tool-executor-ptc/further-exploration: en: ee69078c38c655a9 zh: fb0873407f23c8c5 @@ -60,8 +60,8 @@ en: f4703836365dc3d4 zh: a09ff48a6550fd69 /deepseek-ai-dsh-tool-executor-ptc/known-limitations-and-deferred-work: - en: e4482e6f077cc814 - zh: 42c60bf70128383b + en: 0159ba9c4dda070f + zh: 9be2f81d398868a1 /deepseek-ai-dsh-tool-executor-ptc/known-limitations-and-deferred-work/dev-note: en: e67f633dc6fe7773 zh: 3bb0c20c93f16f98 diff --git a/packages/core/tool-executor-ptc/README.md b/packages/core/tool-executor-ptc/README.md index 9caf5f8a8f..6adeaa3400 100644 --- a/packages/core/tool-executor-ptc/README.md +++ b/packages/core/tool-executor-ptc/README.md @@ -70,7 +70,7 @@ Text inspection reuses the completed pipeline's `output.render` result after con New sub-calls use `:ptc:` ids. Consumers treat these ids as opaque and correlate events by exact equality; restored historical ids retain their original bytes. The [PTC mode decision](../../../.agents/notes/implemented/feature/2026-06-15-ptc.md) owns durable naming and restoration rules. -TypeScript bindings for `read_image` and CUA screenshot operations return an `Image` with a readable `path`, `width`, and `height`. In other tool values, each `{ type: 'image', attachment }` entry whose attachment appears in the finalized result becomes an `Image`, as admitted MCP image blocks do; images the value does not reference still reach the model as additional context. Passing it to `inspect` places its durable attachment among the captured text in the `run_code` result. Images nested in arrays and objects are displayed with their containing value. On program failure, inspected output accompanies the original diagnostic; outer result replacements remain authoritative. If an output policy removes a screenshot or read_image image, the binding rejects with ToolCallError and includes the retained text notice. Additional contexts retain their producing tool’s attribution. +TypeScript bindings for `read_image` and CUA screenshot operations return an `Image` with a readable `path`, `width`, and `height`. Other tool values are substituted all or nothing: when `{ type: 'image', attachment }` entries reference every image of the finalized result and the program can read each one, those entries become `Image`s, as admitted MCP image blocks do, and the result's text and images reach the model only through `inspect`; otherwise the value stays raw and the complete result content reaches the model as additional context. Passing it to `inspect` places its durable attachment among the captured text in the `run_code` result. Images nested in arrays and objects are displayed with their containing value. On program failure, inspected output accompanies the original diagnostic; outer result replacements remain authoritative. If an output policy removes a screenshot or read_image image, the binding rejects with ToolCallError and includes the retained text notice. Additional contexts retain their producing tool’s attribution. When the caller cancels and the runtime reports `abort`, `run_code` waits for cleanup and returns the native tool cancellation result: `AbortError` / `ABORTED`, with `Error: tool call aborted` as its content. Retained runtimes append their cancellation diagnostic, including whether variables were preserved or cleared. The Agent records the specific cancellation cause in `turn/end`, including a hook's reason. Other runtime failures retain `CODE_RUN_FAILED` and their diagnostics, even if the caller also cancels. A runtime rejection keeps a `PtcRuntimeError` code and otherwise becomes `CODE_RUN_FAILED` with the rejection as `cause`. A blank `description`, an invalid `timeoutMs`, or `timeoutMs` or `sandbox_permissions` on a runtime that does not support it fails as `ToolArgsError` with `INVALID_ARGS`; a call after executor disposal fails with `CODE_RUN_UNAVAILABLE`; and a missing runtime, `workingDirectory`, or `sandboxPolicy` fails as `ToolContextUnavailableError`. Cancellation can discard retained runtime state and does not undo completed tool effects. @@ -156,7 +156,7 @@ The schema remains stable while the caller's description and runtime settings re These constraints apply to the host integration and accepted calls. -- **Program Images need a value reference** — read_image, CUA screenshots, and values with `{ type: 'image', attachment }` entries yield `Image`s; other image-producing tools keep their declared values and automatically attach their pictures as additional model context. +- **Program Images need a value reference** — read_image, CUA screenshots, and values whose `{ type: 'image', attachment }` entries reference every result image yield `Image`s; other image-producing tools keep their declared values and automatically attach their pictures as additional model context. - **Program Images require attachment path mapping** — the filesystem must map stored host attachments to readable program paths. `fs-ssh` has no such mapping, so read_image and CUA image adaptation rejects in that composition, while value-referenced images stay raw JSON and reach the model as additional context. - **No built-in reset control** — the shipped Loader plugin does not expose its executor instance through a service, GUI control or SDK endpoint. Hosts needing reset must mount and retain `PtcExecutor` in their own composition; that integration owns retries after a failed reset. - **PTC mode uses TypeScript, and presentation is per agent rather than per tool** — PTC execution requires `ctx.ptcRuntime.language === 'typescript'`; within one agent no tool can be native-only while another is ptc-only. diff --git a/packages/core/tool-executor-ptc/README.zh.md b/packages/core/tool-executor-ptc/README.zh.md index 430dbe8dfd..5662d9f5b5 100644 --- a/packages/core/tool-executor-ptc/README.zh.md +++ b/packages/core/tool-executor-ptc/README.zh.md @@ -70,7 +70,7 @@ PTC 执行器公开保留的 `run_code` 传输,以及确定性的 TypeScript S 新子调用使用 `:ptc:` 标识。消费方将这些标识视为不透明值,并通过精确相等关联事件;恢复的历史标识保留原始字节。[PTC mode 决策](../../../.agents/notes/implemented/feature/2026-06-15-ptc.zh.md) 负责持久化命名与恢复规则。 -TypeScript 中的 `read_image` 与 CUA 截图操作返回 `Image`,其中包含可读取的 `path`、`width` 和 `height`。其他工具的返回值中,若 `{ type: 'image', attachment }` 条目的附件出现在最终结果里,该条目会变为 `Image`,与已接受的 MCP 图片块相同;返回值未引用的图片仍作为额外上下文进入模型。将其传给 `inspect` 后,持久附件会按顺序与文本一起进入 `run_code` 结果。数组和对象内嵌的图片会随所在值一起展示。程序失败时,已 inspect 的输出随原始诊断一起呈现;外层替换的结果保持生效。输出策略移除截图或 read_image 图片时,绑定以 ToolCallError 拒绝,并包含保留的文本提示。额外上下文保留生成工具的归属。 +TypeScript 中的 `read_image` 与 CUA 截图操作返回 `Image`,其中包含可读取的 `path`、`width` 和 `height`。其他工具的返回值按全有或全无的方式替换:当 `{ type: 'image', attachment }` 条目引用了最终结果中的每张图片且程序能读取每张图片时,这些条目会变为 `Image`,与已接受的 MCP 图片块相同,结果的文本与图片仅通过 `inspect` 进入模型;否则返回值保持原样,完整的结果内容作为额外上下文进入模型。将其传给 `inspect` 后,持久附件会按顺序与文本一起进入 `run_code` 结果。数组和对象内嵌的图片会随所在值一起展示。程序失败时,已 inspect 的输出随原始诊断一起呈现;外层替换的结果保持生效。输出策略移除截图或 read_image 图片时,绑定以 ToolCallError 拒绝,并包含保留的文本提示。额外上下文保留生成工具的归属。 调用方取消且运行时报告 `abort` 时,`run_code` 等待清理完成,并返回原生工具的取消结果:`AbortError` / `ABORTED`,内容为 `Error: tool call aborted`。保留状态的运行时会附加取消诊断,包括变量被保留还是清空。Agent 在 `turn/end` 中记录具体取消原因,包括 hook 的理由。其他运行时失败保留 `CODE_RUN_FAILED` 及其诊断,即使调用方同时取消。运行时拒绝保留 `PtcRuntimeError` 的 code,否则变为 `CODE_RUN_FAILED` 并以该拒绝为 `cause`。`description` 为空白、`timeoutMs` 无效,或运行时不支持却传入 `timeoutMs` 或 `sandbox_permissions` 时,以带 `INVALID_ARGS` 的 `ToolArgsError` 失败;执行器释放后的调用以 `CODE_RUN_UNAVAILABLE` 失败;缺少运行时、`workingDirectory` 或 `sandboxPolicy` 时以 `ToolContextUnavailableError` 失败。取消可能丢弃保留的运行时状态,也不会撤销已完成的工具操作。 @@ -156,7 +156,7 @@ Error: code run failed (abort): run_code exceeded its limit of 2048 tool calls ( 以下约束适用于宿主集成及已开始的调用。 -- **程序 Image 需要返回值引用**:read_image、CUA 截图以及含 `{ type: 'image', attachment }` 条目的返回值会产生 `Image`;其他图片工具保留其声明的返回值,并将图片自动附加到模型的额外上下文。 +- **程序 Image 需要返回值引用**:read_image、CUA 截图以及其 `{ type: 'image', attachment }` 条目引用了每张结果图片的返回值会产生 `Image`;其他图片工具保留其声明的返回值,并将图片自动附加到模型的额外上下文。 - **程序 Image 要求附件路径映射**:文件系统必须将宿主存储的附件映射为程序可读的路径。`fs-ssh` 没有这项映射,因此该组合中的 read_image 与 CUA 图片适配会拒绝,而返回值引用的图片保持原始 JSON,并作为额外上下文进入模型。 - **没有内置重置控件**:自带的 Loader 插件不通过服务、GUI 控件或 SDK 端点暴露执行器实例。需要重置的宿主必须在自己的组合中挂载并保留 `PtcExecutor`,该集成负责失败后的重试。 - **PTC mode 使用 TypeScript,且呈现方式按 agent 而非按工具**:PTC 执行要求 `ctx.ptcRuntime.language === 'typescript'`;同一个 agent 内不能让一个工具仅使用 Native,而另一个仅使用 PTC。 diff --git a/packages/core/tool-executor-ptc/src/ptc.ts b/packages/core/tool-executor-ptc/src/ptc.ts index db080c9476..9cffc34185 100644 --- a/packages/core/tool-executor-ptc/src/ptc.ts +++ b/packages/core/tool-executor-ptc/src/ptc.ts @@ -567,17 +567,16 @@ export function createRunCodeTransport( if (parked === undefined) return const result = await executor.complete(parked.exec, parked) const images = result.content.filter(block => block.type === 'image') - // A value that carries every result image hands them to the program; otherwise they reach the model directly. - const programValue = usesProgramImage || result.isError || images.length === 0 ? undefined - : substituteProgramImages(result.value, images, (ref) => { - // The ordered lane must not reject: an unresolvable reference keeps the images in model context. - try { - return readableImage(ref) - } catch (error: unknown) { - logger.warn(`tools: ${name} image ${String(ref.attachmentId)} has no program path: ${toolErrorMessage(error)}`) - return undefined - } - }) + // A value carrying every result image goes to the program; otherwise the content reaches the model directly. + let programValue: PtcJsonValue | undefined + if (!usesProgramImage && !result.isError && images.length > 0) { + // The ordered lane must not reject: a failed substitution keeps the content in model context. + try { + programValue = substituteProgramImages(result.value, images, readableImage) + } catch (error: unknown) { + logger.warn(`tools: ${name} result images stay in model context: ${toolErrorMessage(error)}`) + } + } if (!usesProgramImage && !result.isError && images.length > 0 && programValue === undefined) { exec.deferContext(createUserMessage({ content: result.content, diff --git a/packages/core/tool-executor-ptc/tests/ptc.spec.ts b/packages/core/tool-executor-ptc/tests/ptc.spec.ts index bb69c64717..e0383fcb6d 100644 --- a/packages/core/tool-executor-ptc/tests/ptc.spec.ts +++ b/packages/core/tool-executor-ptc/tests/ptc.spec.ts @@ -1788,16 +1788,21 @@ describe('the run_code dispatch bridge', () => { expect(content[2]).toEqual({ type: 'image', data: 'Ag==', attachment: removed }) }) - it.each(['missing', 'throwing'] as const)('delivers referenced result images as deferred context with %s image storage paths', async (storage) => { + it.each(['missing', 'throwing', 'deep'] as const)('delivers referenced result images as deferred context with %s substitution input', async (storage) => { const { ctx, runtime } = await setup({ mode: 'ptc' }) onTestFinished(() => ctx.fiber.dispose()) - if (storage === 'throwing') { - ctx.provide('attachments', { imageHostPath: () => { throw new Error('invalid reference') } } as never) + if (storage !== 'missing') { + ctx.provide('attachments', { imageHostPath: () => { + if (storage === 'throwing') throw new Error('invalid reference') + return '/host/image.png' + } } as never) ctx.provide('fs', { processPathFromHostPath: (path: string) => path } as never) } const warn = vi.spyOn(ctx.logger, 'warn').mockImplementation(() => {}) const shown = { attachmentId: brandString(`sha256:${'a'.repeat(64)}`), mediaType: 'image/png' as const, bytes: 1, width: 1, height: 1 } - const raw = { content: [{ type: 'image', data: 'AQ==', attachment: shown }] } + let deep: JsonValue = [] + for (let depth = 0; depth < (storage === 'deep' ? 5_000 : 0); depth++) deep = [deep] + const raw = { content: [{ type: 'image', data: 'AQ==', attachment: shown }], deep } ctx.tools.register(defineTool({ name: 'screenshot', description: 'Return an image without a program path.', parameters: {}, output: { schema: { type: 'json' }, render: () => [{ type: 'image', attachment: shown }] }, @@ -1811,9 +1816,13 @@ describe('the run_code dispatch bridge', () => { const result = await runCode(ctx, 'program') - expect(value).toEqual(raw) + // Recursive equality would exceed the stack on the deep fixture; the deep member is checked by depth. + expect((value as typeof raw).content).toEqual(raw.content) + let depth = 0 + for (let level: JsonValue = (value as typeof raw).deep; Array.isArray(level) && level.length > 0; level = level[0]!) depth++ + expect(depth).toBe(storage === 'deep' ? 5_000 : 0) expect(result.additionalContexts).toMatchObject([{ source: { kind: 'ptc-mode' }, content: [{ type: 'image', attachment: shown }] }]) - expect(warn).toHaveBeenCalledTimes(storage === 'throwing' ? 1 : 0) + expect(warn).toHaveBeenCalledTimes(storage === 'missing' ? 0 : 1) }) it.each([ diff --git a/packages/mcp/mcp-client/README.i18n.yaml b/packages/mcp/mcp-client/README.i18n.yaml index 0e243ca42b..0cca3bb433 100644 --- a/packages/mcp/mcp-client/README.i18n.yaml +++ b/packages/mcp/mcp-client/README.i18n.yaml @@ -60,8 +60,8 @@ en: 9f6397197d9a607d zh: 79cf93aaf2e25a39 /deepseek-ai-dsh-mcp-client/model-experience/discovered-mcp-tools/what-the-model-sees: - en: 1fea5fb6f70eedff - zh: 8964a52a2a6ee3c8 + en: 083306cb90dc2eed + zh: 87460e0628d4e61c /deepseek-ai-dsh-mcp-client/model-experience/discovered-mcp-tools/token-effect: en: ca10fdaa3b33d694 zh: 7a26d39b88d09f1d @@ -72,8 +72,8 @@ en: a8503137ad03720c zh: 611a2dadf7c0c706 /deepseek-ai-dsh-mcp-client/model-experience/tool-call-history-and-results/what-the-model-sees: - en: 996378d59c5fcd31 - zh: 4653c4c6d3b6751e + en: a48e4c17efb2f6ff + zh: 924900ab7c288b96 /deepseek-ai-dsh-mcp-client/model-experience/tool-call-history-and-results/token-effect: en: cc030374eca00e1c zh: d4b19b9db621b367 diff --git a/packages/mcp/mcp-client/README.md b/packages/mcp/mcp-client/README.md index 010cd222ab..635c1b01c2 100644 --- a/packages/mcp/mcp-client/README.md +++ b/packages/mcp/mcp-client/README.md @@ -184,7 +184,7 @@ Read these pages when the package-level contract is not enough. They move from t #### What the model sees -After discovery succeeds, SDK-admitted MCP tools appear as native tools named `mcp____` (or their deterministic normalized form), with the server description and input schema. A re-sync replaces the generation; disposal or an exhausted reconnect budget removes it. A server without the tools capability connects with an empty tool set. In PTC mode, each tool's SDK output declaration documents its `content` array: `MCP content blocks in order. A viewable image block is an Image; inspect it to see the image.` +After discovery succeeds, SDK-admitted MCP tools appear as native tools named `mcp____` (or their deterministic normalized form), with the server description and input schema. A re-sync replaces the generation; disposal or an exhausted reconnect budget removes it. A server without the tools capability connects with an empty tool set. In PTC mode, each tool's SDK output declaration documents its `content` array: `MCP content blocks in order. An image block is an Image when the program can read it; otherwise it is the raw MCP block.` #### Token effect @@ -198,7 +198,7 @@ The tool-definition prefix stays stable while the discovered set and schemas are #### What the model sees -The public tool name and JSON arguments remain in assistant history. The canonical value retains the complete MCP JSON blocks and optional structured content for programmatic and PTC mode callers; supported image blocks project beside text in their original order after exact route-capability proof. When the program can read every image the final result keeps, a PTC program receives those image blocks as `Image`s that `inspect` shows as pictures, not base64, and the pictures enter the conversation only when inspected; otherwise the program receives the raw blocks and the pictures are attached as additional context. Refused images, audio, embedded resources, resource links, and unknown blocks remain visible as bounded text diagnostics, and MCP `isError` rejects the call before image persistence. +The public tool name and JSON arguments remain in assistant history. The canonical value retains the complete MCP JSON blocks and optional structured content for programmatic and PTC mode callers; supported image blocks project beside text in their original order after exact route-capability proof. When the program can read every image the final result keeps, a PTC program receives those image blocks as `Image`s that `inspect` shows as pictures, not base64, and the result's text and pictures enter the conversation only when inspected; otherwise the program receives the raw blocks and the complete result content is attached as additional context. Refused images, audio, embedded resources, resource links, and unknown blocks remain visible as bounded text diagnostics, and MCP `isError` rejects the call before image persistence. #### Token effect diff --git a/packages/mcp/mcp-client/README.zh.md b/packages/mcp/mcp-client/README.zh.md index d22388d7a1..ca0e56ffdd 100644 --- a/packages/mcp/mcp-client/README.zh.md +++ b/packages/mcp/mcp-client/README.zh.md @@ -184,7 +184,7 @@ SDK 通过旧版通知或现代协议订阅接收工具列表变化。监督器 #### 模型看到什么 -发现成功后,SDK 接受的 MCP 工具以原生工具名称 `mcp____`(或其确定性规范化形式)出现,携带服务器描述和输入 schema。重新同步会替换注册代;释放或重连预算耗尽会移除工具。未声明 tools 能力的服务器以空工具集连接。在 PTC 模式下,每个工具的 SDK 输出声明会为其 `content` 数组附上说明:`MCP content blocks in order. A viewable image block is an Image; inspect it to see the image.` +发现成功后,SDK 接受的 MCP 工具以原生工具名称 `mcp____`(或其确定性规范化形式)出现,携带服务器描述和输入 schema。重新同步会替换注册代;释放或重连预算耗尽会移除工具。未声明 tools 能力的服务器以空工具集连接。在 PTC 模式下,每个工具的 SDK 输出声明会为其 `content` 数组附上说明:`MCP content blocks in order. An image block is an Image when the program can read it; otherwise it is the raw MCP block.` #### Token 影响 @@ -198,7 +198,7 @@ SDK 通过旧版通知或现代协议订阅接收工具列表变化。监督器 #### 模型看到什么 -公开工具名称和 JSON 参数保留在 assistant 历史中。规范值始终为程序化调用方与 PTC 模式调用方保留完整的 MCP JSON 块与可选结构化内容;受支持的图片块在确切路由能力得到证明后,按原始顺序与文本一起投影。程序能读取最终结果保留的每张图片时,PTC 程序将这些图片块作为 `Image` 接收,`inspect` 将其显示为图片而非 base64,且图片仅在被 inspect 时进入对话;否则程序接收原始块,图片作为额外上下文附加。被拒绝的图片、音频、嵌入资源、资源链接与未知块继续以有界文本诊断可见;MCP `isError` 会在图片持久化之前拒绝调用。 +公开工具名称和 JSON 参数保留在 assistant 历史中。规范值始终为程序化调用方与 PTC 模式调用方保留完整的 MCP JSON 块与可选结构化内容;受支持的图片块在确切路由能力得到证明后,按原始顺序与文本一起投影。程序能读取最终结果保留的每张图片时,PTC 程序将这些图片块作为 `Image` 接收,`inspect` 将其显示为图片而非 base64,且结果的文本与图片仅在被 inspect 时进入对话;否则程序接收原始块,完整的结果内容作为额外上下文附加。被拒绝的图片、音频、嵌入资源、资源链接与未知块继续以有界文本诊断可见;MCP `isError` 会在图片持久化之前拒绝调用。 #### Token 影响 diff --git a/packages/mcp/mcp-client/src/tools.ts b/packages/mcp/mcp-client/src/tools.ts index 6aa284e43b..3ecab88264 100644 --- a/packages/mcp/mcp-client/src/tools.ts +++ b/packages/mcp/mcp-client/src/tools.ts @@ -352,7 +352,7 @@ function createOutput(rawName: string, structuredSchema: JsonSchemaNode | undefi schema: { type: 'object', properties: { - content: { type: 'array', items: {}, description: 'MCP content blocks in order. A viewable image block is an Image; inspect it to see the image.' }, + content: { type: 'array', items: {}, description: 'MCP content blocks in order. An image block is an Image when the program can read it; otherwise it is the raw MCP block.' }, structuredContent: structuredSchema ?? {}, }, required: structuredSchema === undefined ? ['content'] : ['content', 'structuredContent'], diff --git a/snapshots/session/computer-use-cua-driver-mcp-ptc/system-prompt.expected.md b/snapshots/session/computer-use-cua-driver-mcp-ptc/system-prompt.expected.md index dd063d2bd1..d94e1a0cc6 100644 --- a/snapshots/session/computer-use-cua-driver-mcp-ptc/system-prompt.expected.md +++ b/snapshots/session/computer-use-cua-driver-mcp-ptc/system-prompt.expected.md @@ -458,12 +458,12 @@ interface ToolOutputMap { list_mcp_resource_templates: JsonValue; list_mcp_resources: JsonValue; "mcp__cua-driver-mcp__disconnect": { - /** MCP content blocks in order. A viewable image block is an Image; inspect it to see the image. */ + /** MCP content blocks in order. An image block is an Image when the program can read it; otherwise it is the raw MCP block. */ content: JsonValue[]; structuredContent?: JsonValue; }; "mcp__cua-driver-mcp__screenshot": { - /** MCP content blocks in order. A viewable image block is an Image; inspect it to see the image. */ + /** MCP content blocks in order. An image block is an Image when the program can read it; otherwise it is the raw MCP block. */ content: JsonValue[]; structuredContent?: JsonValue; };