Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/panache-mcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ cargo build --locked --release -p panache-mcp

使用自己的纸张时,在第一次调用 `save_section` 时传入 `paper_path`,例如 `{"markdown":"第一题","paper_path":"C:/作业/南昌大学横线纸.jpg"}`。路径指向运行 MCP 的电脑上的图片。默认保留原照片,按识别到的横线投影字迹和插图。`paper` 返回排版尺寸、边距、行距、识线结果,投影时另有原照尺寸。可用 `preview_handwriting(view="paper")` 单独看底纸,或在导入时通过 `paper_guides` 指定参考线。需要校平底纸时传 `paper_mode="flatten"`。无可靠横线时保留底图,使用普通行距。纸张随稿件保存一次,后续追加、回查、预览和导出可在原图移动后继续使用。

如果照片是聊天附件,请先确认客户端能提供 MCP 进程可读的本机文件路径,必要时先把图片存到这台电脑。带视觉能力的模型可以查看客户端转交的预览图。客户端或模型只能处理文字时,可读取版面和像素测量,并请用户打开导出文件确认外观,再按反馈修改。
如果照片是聊天附件,先用客户端支持的文件传送功能,把照片交给 Panache。云端没有这项功能时,可在照片所在电脑连接桌面版再使用。复制手机或另一台电脑上的路径不能传照片。带视觉能力的模型可以查看客户端转交的预览图。客户端或模型只能处理文字时,可读取版面和像素测量,并请用户打开导出文件确认外观,再按反馈修改。

| 工具 | 用法 |
| --- | --- |
Expand Down
3 changes: 2 additions & 1 deletion crates/panache-mcp/src/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ pub struct Guide {
#[derive(Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct Save {
/// Optional absolute local image path for a new draft. Imports and aligns the paper once.
/// Optional absolute path to an image file readable on the computer running Panache. Imports and aligns the paper once.
/// A chat attachment or URL alone is not a file path. If the client cannot transfer the photo to that computer, explain this instead of guessing a path.
/// Use with the default plain preset. All revisions share the saved image.
pub paper_path: Option<std::path::PathBuf>,
/// With paper_path: photo (default) preserves camera perspective; flatten aligns the background.
Expand Down
2 changes: 1 addition & 1 deletion crates/panache-mcp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl ServerHandler for Panache {
"Ask for a photo clearly showing it or permission to fill only visible areas; wait before saving or trial placement. If partial work was requested, proceed there. ",
"For looser, less uniform homework or lab handwriting (字稍微草一点), inspect describe_controls(group=variation). For requested crossed-out mistakes (涂改痕迹), inspect group=strike. ",
"Use save_section(markdown), then its draft_id and revision for preview_handwriting or export_handwriting. ",
"English letters and digits follow the main font by default. Leave Latin controls unset unless the user requests a different look for them or dislikes how they appear. For an undecided homework or lab-report style, see list_fonts for sample guidance. Use list_drafts to resume. A paper_path must be readable on the server computer. ",
"English letters and digits follow the main font by default. Leave Latin controls unset unless the user requests a different look for them or dislikes how they appear. For an undecided homework or lab-report style, see list_fonts for sample guidance. Use list_drafts to resume. A paper_path must be readable on the server computer. For a chat photo, use client transfer or run Panache on the computer with the photo. Ask for the missing file only if needed. ",
"For print-and-report, export once and report review.unreviewed_pages. Look up existing receipts with read_section(view=review); full-page preview_handwriting(view=review) files a check. Last-page lookups use current pagination and cannot confirm the historical last page. Follow photo_appearance.preview_arguments for a native detail crop. ",
"If images cannot reach the model, use the reported measurements and ask the user to inspect the page before judging its appearance. ",
"Forms, unruled paper and artwork are supported. Follow specified or delegated placement, matching field orientation and preserving printed labels. ",
Expand Down
2 changes: 1 addition & 1 deletion crates/panache-mcp/src/paper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl ImportedPaper {
) -> Result<Self> {
ensure!(
path.is_absolute() && path.is_file(),
"paper_path must be an absolute path to a local image file"
"paper_path must be an absolute path to an image file readable on the computer running Panache. A chat attachment or URL alone is not a file path. If the client cannot transfer the photo to that computer, explain this instead of guessing a path."
);
let limits = Limits::default();
let file = File::open(path).context("Cannot open paper image")?;
Expand Down
53 changes: 53 additions & 0 deletions crates/panache-mcp/tests/paper_path_retry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# /// script
# dependencies = ["mcp>=1.12,<2", "Pillow"]
# ///
"""Retry an unavailable worksheet after a local transfer."""

import base64
import io
import shutil

from PIL import Image, ImageChops
import argparse
import asyncio
from pathlib import Path
from tempfile import TemporaryDirectory

from mcp_client import call, isolated_session, open_db


async def run(binary, home):
async with isolated_session(binary, home) as (client, info):
path = home / "作业 纸.png"
args = dict(markdown="观察记录", style={"seed": 31}, paper_path=str(path))
with open_db(home) as db:
original = list(db.iterdump())
for unavailable in (str(path), "https://example.invalid/worksheet.png"):
failure = await client.call_tool("save_section", {**args, "paper_path": unavailable})
assert failure.isError and "computer running Panache" in failure.content[0].text
with open_db(home) as db:
assert list(db.iterdump()) == original
shutil.copyfile(Path(__file__).parent / "fixtures/ruled.png", path)
result = (await call(client, "save_section", **args)).structuredContent
assert result["revision"] == 1
preview = await call(
client, "preview_handwriting", draft_id=result["draft_id"], view="image"
)
png = base64.b64decode(next(b.data for b in preview.content if b.type == "image"))
with Image.open(io.BytesIO(png)) as page, Image.open(path) as sheet:
assert page.size == sheet.size
delta = ImageChops.difference(page.convert("RGB"), sheet.convert("RGB"))
area = sheet.width * sheet.height
unchanged = sum(n for n, rgb in delta.getcolors(area) if rgb == (0, 0, 0))
assert area * 0.95 < unchanged < area
print(
f"Two unavailable inputs left the draft store unchanged; {unchanged}/{area} original pixels retained."
)


if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("binary", type=Path)
args = parser.parse_args()
with TemporaryDirectory() as temp:
asyncio.run(run(args.binary.resolve(), Path(temp)))