Skip to content

fix(mcp): 区分本地导出与附件交付 - #31

Merged
SXP-Simon merged 2 commits into
mainfrom
fix/mcp-export-delivery-boundary
Nov 26, 2026
Merged

SXP-Simon merged 2 commits into
mainfrom
fix/mcp-export-delivery-boundary

Conversation

@SXP-Simon

@SXP-Simon SXP-Simon commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

问题

export_handwriting 生成的 PDF/ZIP 在 MCP 服务端。标准 stdio 回执只有文字说明、本地绝对路径和检查元数据,不代表用户能点开或已收到;独立调用 resources/list 也没有取得文件。下载场景下,基线 Luna 一次把服务端路径包装成未经核验的下载链接,另一次独立重跑把路径直接称为下载文件。

改动

只改工具发现阶段的 export_handwriting 说明和更新记录。提示仅在宿主确认用户可见附件/下载后才声称已交付;否则把路径当本地路径。格式、页序、页数、审核、路径、数据持久化均不改。可用附件通道的客户端仍可正常交付。

验证

  • 基线 e1e2546 与该候选使用独立二进制、Python MCP SDK 1.29.0、真实 stdio。排除基线已知随机 seed 样本后,工具目录只有这一处说明差异,初始化和输入 schema 相同。
  • 12 个精确构建模型会话均生成内容一致的 4 页 PDF(121,930 B),检查记录 4→4。四个有模拟附件通道的会话(基线 2、候选 2)均成功传递 PDF 并准确引用回执链接。八个无附件通道的精确构建会话(两臂各 4)中,基线一次把服务器路径当作下载文件,候选没有。早期措辞试验的假链接重现单独计数;不据小样本估计总体发生率。
  • 真实 stdio 全套本地通过,包括 61,197 字符/7 节、旧版本、重启及冲突;与先前五个 draft 的本地三方试合并无冲突。

保留为无标签 draft。不触发 GitHub CI。

Summary by Sourcery

Ensure handwriting export guidance accurately distinguishes local files from attachments delivered by the chat host.

Bug Fixes:

  • Clarify MCP export responses so server-local paths are not presented as user-downloadable files or delivered links.

Enhancements:

  • Distinguish locally accessible export paths from host-confirmed attachments and preserve exact attachment URLs when available.

Documentation:

  • Document the distinction between local exported files and user-visible downloadable attachments.

补充验证 · 聊天里应该怎样拿到文件

假设你说“把第 2 版 PDF 发给我”。导出成功以后,文件已经存在于运行 Panache 的电脑上。接下来要看聊天窗口提供了什么。有下载链接就原样贴出。窗口只确认显示了附件,就告诉你点这个附件。如果只返回了文件路径,就用你的语言说明“在运行 Panache 的电脑上打开这个文件”,并把路径单独列出来。仅有本机路径时,远程聊天用户仍需要能访问那台电脑才能取件。

和当前 main 的对照

对照版本为 70fd4cf 和本 PR 的 f64932f。每个模型在每种窗口下用三种中文问法各跑一次,两版合计 36 个独立会话。下表按“达到该行要求的会话数 / 3”计。

窗口和判断标准 Luna · main Luna · #31 Terra · main Terra · #31
有下载链接,回复原样给出已经验证的 URL 2/3 3/3 3/3 3/3
只有可见附件,回复指向附件,无虚构链接 3/3 3/3 3/3 3/3
只有文字,给对路径并说清在哪台电脑打开,无下载链接 0/3 3/3 1/3 3/3

纯文字窗口的差别最大。main 有 4 次把本机路径写成下载链接,另有 1 次 Luna 在用户已经指定第 2 版时仍追问版本,没有导出。#31 的 6 次都给对了路径和电脑。其中 Luna 有一次仍写“打开这个文件下载”,措辞生硬,但给出的是可用的本机地址,没有虚构链接。带链接的场景里,main 的一次回复只说了点附件,附件依然可用。

如何核验

真实 Luna(gpt-6-luna)和 Terra(gpt-6.1-terra)通过 stdio 使用 Panache。测试宿主模拟上述三种窗口。有附件时,宿主复制真实 PDF 并从本机 HTTP 服务取回,逐字节校验。无链接附件的回执只向模型确认附件可见。只有文字的回执仅含 Panache 的导出信息。每次成功导出都检查一页 PDF 并渲染比对,确认内容来自用户指定的第 2 版,且与较新的第 3 版可区分。最终 #31 为 18/18,main 为 17/18。

中间也试过只告诉模型“给出本机路径”。同样规模的独立试验中,Luna 仍有一次把本机路径写成下载链接,一次只给了路径,没说明是哪台电脑。因此最终提示加入了一句可以直接照用的例句。上表仅统计最终两版对照,不混用中间试验数据。

真实 MCP 列出的 14 个工具中,只有 export_handwriting 的说明变化。Rust 格式检查和该 MCP 二进制的 16 个单元测试均通过。模型样本较小,附件由测试宿主模拟,结果不代表每一种聊天客户端。

复现:真实 stdio 导出只返回服务器本地路径、页数与检查状态,无交付确认。下载链接任务中,基线 Luna 一次把路径包装成未经验证的链接,独立重跑又一次称本地路径是下载文件。不要把本地路径当成用户可见下载;有宿主附件回执时仍能交付。

仅调整 export_handwriting 的工具说明与更新记录。12 次精确构建对照的四页 PDF 均为相同 121930 字节,既有检查数 4→4。模拟附件通道正对照两臂各 2/2 确认,缺通道的候选精确构建 0/4 错误称已交付。真实 stdio 全套本地通过;无 GitHub CI。
@sourcery-ai

sourcery-ai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Update the export_handwriting tool description to distinguish server-local paths from confirmed user-visible attachments and explain how to report each.

  • crates/panache-mcp/src/main.rs L603

Documentation

Record the local-path versus attachment-delivery clarification in the changelog.

  • CHANGELOG.md L11

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Owner Author

复跑办法与边界

  1. 分别用 Rust 1.94.1 在隔离 Cargo target 构建基线 e1e2546a 和本 PR;同一 Markdown worker、字体目录和 Python MCP SDK 1.29.0。用合成四节稿建好 4 张已有检查单,关闭写连接后为每个会话分别克隆。
  2. 比较真实 tools/list:去掉基线 save_section schema 中进程随机的 seed 示例,剩余唯一差异为 export_handwriting.description。在两个模型、两种“能否直接下载”的提示下,每次只允许从当前稿生成 PDF,不做新检查。没附件工具时,不能把 path 伪装成下载;有独立的测试附件工具时,仅允许它传递本次确实生成的 PDF,并核对内容摘要与返回链接。
  3. 精确版本两臂总计 12/12 导出成功、PDF 4 页 121,930 B、SHA-256 d807f3a4fe780bc3e768e63ad5dcff30bc2432f4c033e94adc59a3e7dbd9e517、检查记录 4→4。无附件通道:基线 1/4 把服务路径称作下载文件,候选 0/4。在更早的基线/宿主措辞试验中另有 1 个基线把绝对路径包装成虚假的 sandbox: 下载链接;不把那个版本的候选结果混成精确构建数据。有模拟附件通道:两臂各 2/2 成功,模拟不是任何生产客户端的可用性声明。
  4. python3 crates/panache-mcp/tests/smoke.py /path/to/the/exact/binary(设置适合本机构建的 PANACHE_FONT_DIR 和 PANACHE_MARKDOWN_WORKER)全部通过,并做了其他五条 draft 的本地三方组合检查。新改动只是提示,并不新增下载传输、真实附件或远程文件读取能力。

Copy link
Copy Markdown
Owner Author

后续验证:丢回执和成品交付是不同问题

合成库中原先有第 1、2 版 ZIP,独立真实 SDK 分别模拟「首个请求未发包」和「已成功发布但扣住回执」。客户端收到字节完全相同的未知回执,均在旧会话结束后重连。仅有独立一位写入者,不涉及附件发送或清理。固定对照里,不核对直接重发会在已发布世界额外生成一份;核对旧清单 ID 与重连后才出现的新登记,再决定是否发请求,两种世界实际写为 0+1 与 1+0,各一份新的正确 ZIP。

8 个真实盲 Luna/Terra 模型回合(两种世界 × 两模型 × 两臂):原说明 4/4 与补一句核对提示 4/4 都主动查清单后恰新增一份,且最终称为本地文件。两臂各共 10 次尝试。旧文件 SHA 和非导出表未改,新 ZIP 的单页 PNG / RGBA 与预期 r2 一致。这里只验证固定小样本的单写者恢复,不证明并发幂等,也不能把仍在执行时的暂时无记录当未写或把服务端路径当交付。这个提示没有显示增益,不追加产品改动。草稿头未变,不触发 CI。

背景:聊天窗口可能只收到本机路径,模型有时会把它写成下载链接,也可能漏掉已确认的链接。

解决手段:同步 main 的导出说明,为本机路径提供可照用的答复示例,并分别说明如何指向可见附件和原样传达下载链接。

收益:用户能从回复中判断应该点击链接、打开聊天附件,还是在运行 Panache 的电脑上取文件。
@SXP-Simon

Copy link
Copy Markdown
Owner Author

建议单独合并 #31,无需等 #49。 用户说“把第 2 版 PDF 发给我”时,最容易踩的坑是看到“下载 PDF”,点开才发现那只是另一台电脑上的文件地址。这个改动让模型根据聊天窗口实际提供的入口回答。

对照了 main@70fd4cf 和 #31@f64932f。Luna 和 Terra 在每种窗口各试了三种中文问法,两版共 36 个独立会话。表中记录同时导出正确版本、并按该行方式指引用户的次数。

窗口实际提供的取件方式 Luna(main → #31) Terra(main → #31)
有下载链接,回复原样贴出已验证的链接 2/3 → 3/3 3/3 → 3/3
只有可见附件,回复指向聊天里的附件 3/3 → 3/3 3/3 → 3/3
只有本机路径,回复给对路径并说清去哪台电脑打开 0/3 → 3/3 1/3 → 3/3

收益最大的是纯文字窗口。 main 的 6 次里,4 次把本机路径写成下载链接,1 次又追问用户已指定的版本。#31 的 6 次都给出了正确路径,并说明要在运行 Panache 的电脑上打开。有附件的窗口也保留了原有取件方式。对于无法访问那台电脑的用户,纯文字窗口仍需要有人另行传送文件。

测试使用真实模型和 Panache 导出的 PDF。测试程序模拟聊天窗口的附件回执,实际取回附件并核对文件内容,还把导出页与第 2 版参考页比对。#31 的 18 次都导出了指定版本,16 个 Rust 单元测试通过。每个模型每种情况只有 3 次,这是支持单独合并的小样本证据。

@SXP-Simon
SXP-Simon marked this pull request as ready for review November 26, 2026 07:33
@sourcery-ai

sourcery-ai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Sorry @SXP-Simon, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 10 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@SXP-Simon
SXP-Simon merged commit 131b4e7 into main Nov 26, 2026
1 check passed
SXP-Simon added a commit that referenced this pull request Nov 27, 2026
## 场景与改动

只从 stdio 回复取文件的客户端,以前能看见路径,却拿不到生成的 PDF 或 ZIP 字节。

导出时可设 include_file=true,从本次发布文件的句柄读取最多 512 KiB
原始内容。超过上限或读取失败时保留完整本机文件及导出回执,沿用主线 #31 的取件说明。

支持内嵌文件的客户端能取回所选版本的真实内容,再通过自己的附件入口交给用户。

## 独立验证

分别运行 `uv run --script crates/panache-mcp/tests/export_file.py
<main-binary> <worker> --baseline --out run-main` 和 `uv run --script
crates/panache-mcp/tests/export_file.py <pr-binary> <worker> --out
run-pr`,再运行 `python crates/panache-mcp/tests/compare_export_files.py
run-main run-pr`。需要 Poppler 的 `pdfimages`,两个输出目录须为新目录。

从 [#49](#49) 拆出,直接基于
`main@06cfd43`,可以独立审查。来源提交为
[73f1331](https://github.com/SXP-Simon/Panache/commit/73f133192b3911253ea97b75dbd29736cec6edb5)、[c990100](https://github.com/SXP-Simon/Panache/commit/c9901001af1b17bae4ae8667d8609f8f4fb4a044)、[dd60477](https://github.com/SXP-Simon/Panache/commit/dd60477b3a8f63cf2f9e503f79fe2c7c05af05e7)。

## Summary by Sourcery

Enable export clients to retrieve small PDF and ZIP artifacts directly
through MCP while retaining local-file fallback for larger or unreadable
files.

New Features:
- Add an `include_file` export option that embeds PDF or ZIP contents in
MCP responses for supported clients, up to 512 KiB.
- Expose file-transfer status and guidance for retrieving embedded,
oversized, or unavailable exports.

Bug Fixes:
- Preserve the published export file handle so embedded content is read
from the exact artifact returned to the client.

Enhancements:
- Update export documentation and tool guidance to distinguish embedded
resources, local paths, and user-facing download links.

Documentation:
- Document client behavior and retrieval guidance for embedded and
locally stored export files.

Tests:
- Add unit and end-to-end coverage for embedded exports, size limits,
selected revisions, byte integrity, and fallback behavior.
- Add a comparison script to verify candidate exports match baseline
artifacts while only the candidate delivers supported files to the
simulated client.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant