Skip to content

feat: /mcp 状态与手动重连;定价表外置 ~/.corecoder/pricing.json - #37

Merged
he-yufeng merged 3 commits into
mainfrom
feat/mcp-command-pricing
Oct 7, 2026
Merged

he-yufeng merged 3 commits into
mainfrom
feat/mcp-command-pricing

Conversation

@he-yufeng

@he-yufeng he-yufeng commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Roadmap #35 的第六、七项,两个 commit 各绿一套测试。

/mcp 状态与手动重连。 server 进程死了以前是静死的:tool 还在列表里,调用才报错。现在 /mcp 列出每个 server 的存活状态和死因,/mcp reconnect <name> 关掉旧进程重跑握手;agent 持有的 mcp__ 工具路由走 client 不走近程,重连成功即恢复,agent 侧零改动。实现上把 spawn 从 __init__ 拆成 _start(),读线程按进程实例把守(proc is self._proc),旧读线程不会在重连后把新进程误标 dead。不做自动重连:手动触发不会风暴,自动重连要回答的退避问题这轮不想答。

定价表外置。 estimated_cost 每次调用时读 ~/.corecoder/pricing.json 覆盖内置表,新模型调价不用等发版。整个文件有任何坏条目即静默回落内置表,不做逐条目容错:半坏的覆盖表比没有更危险。无缓存无刷新,12 行。

测试:224 passed(基线 215 + 9 新)。MCP 侧用 stdin/stdout 念 JSON-RPC 的假 server,crash 工具 os._exit(1) 模拟死亡,覆盖 crash 重连后旧 tool 对象直接可用、重连失败保持 dead 等 5 例;pricing 侧覆盖优先、扩新模型、三种损坏形态回落。conftest 加了 autouse 隔离,PRICING_FILE 指向 tmp,真机文件进不了测试。

文档按 doc-pin 测试要求同步:README 双语、article 00/03/06/08 双语的行数钉和功能句。

顺带修了一个 main 上的存量红:doc 行数钉的 sweep 用 str(relative_to) 当键,Windows 上是反斜杠,所有正斜杠引用全部解析失败,Windows 四条腿从 c941e87 起一直红。改为 as_posix(),一行。

A dead MCP server used to stay dead until the whole session restarted.
The client now keeps its spawn spec, so reconnect() can close the old
process, start a fresh one and redo initialize + tools/list; the mcp__
tools the agent already holds route through the client, so they work
again the moment the new handshake lands. The reader thread guards on
its own process, so a reader left over from before a reconnect cannot
mark the new process dead.

The REPL grows /mcp: list each server with its state and tool count,
or /mcp reconnect <name> to revive one by hand. No auto-reconnect: a
manual trigger keeps the client free of retry policy.
estimated_cost used to read only the hardcoded _PRICING table, so a new
model or a moved price meant waiting for a release. _load_pricing() now
overlays the user's pricing.json (same shape) on the built-ins, and a
missing or broken file quietly means the built-ins.
The sweep keys were str(relative_to) which is backslash-formed on
Windows, so every forward-slash doc reference failed to resolve there.
as_posix() keeps the keys slash-formed on all platforms. Windows legs
on main have been red on this since c941e87.
@he-yufeng
he-yufeng merged commit 10b67f1 into main Oct 7, 2026
14 checks passed
@he-yufeng
he-yufeng deleted the feat/mcp-command-pricing branch October 7, 2026 04:59
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