mainspring-mcp
MCP client 外挂(T4-1):装了就把 MCP 工具注册进 core 的 ToolRegistry,core 对 MCP 零感知。
设计小节
- 传输只负责一收一发,协议握手 / 超时 / 重连全在
client.py;stdio 与 HTTP 共用一套 client。 - MCP session 绑定 transport:传输断开才重建并重新握手(只重试一次);超时不重放——慢调用可能已有副作用。
- stdio 用换行分隔 JSON(MCP 规范),stderr 异步排空并保留尾部,崩溃原因随异常带出。
- Streamable HTTP 同时接受
application/json与text/event-stream,Mcp-Session-Id自动续带。 - 工具名
{prefix}__{name}消歧,provider 安全字符清洗 + 64 字符截断(短哈希后缀)。 - schema 只清洗不重建(补
type: object、剔除幽灵required),参数模型宽松透传,MCP server 是 schema 权威。 - 结果 content 拼文本,
isError=true抛MCPToolCallError→ core Tool 管道转is_error,run 不炸。
用法
from mainspring.tool import ToolRegistry
from mainspring_mcp import register_mcp_tools, stdio_client
client = stdio_client(
["npx", "-y", "@modelcontextprotocol/server-filesystem", "."],
name="filesystem",
)
await client.connect()
registry = ToolRegistry()
await register_mcp_tools(registry, client) # 工具名: filesystem__read_file ...
HTTP(Streamable)同理:http_client("https://server/mcp", name="fetch")。
验收与边界
- 本机用例跑 stdio 真子进程(filesystem / fetch 这类社区 server 需本机有
npx与网络,未纳入 CI); server 崩溃 → is_error、崩溃后自动重连、慢调用超时均为自动化用例;- core 零 MCP import 由 import-linter「core 不 import 任何外挂」契约守护。
Metadata
Release files for mainspring-mcp 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mainspring_mcp-0.1.0.tar.gz | 15.5 kB | With provenance | Details for mainspring_mcp-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mainspring_mcp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for mainspring_mcp-0.1.0-py3-none-any.whl |
Total release size: 34.5 kB
Release files / mainspring_mcp-0.1.0.tar.gz
| Download URL | mainspring_mcp-0.1.0.tar.gz |
|---|---|
| Size | 15.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e10e9af062689eebd5df561a0bf56ce40446c66e1a97d73fd27f3c76d3a0b309
|
|
BLAKE2b-256 checksum How to use checksums |
4e8cb848531f798edce0b939ec598f96d7ca8a511f009c36ceee79a8c1a7a533
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logRelease files / mainspring_mcp-0.1.0-py3-none-any.whl
| Download URL | mainspring_mcp-0.1.0-py3-none-any.whl |
|---|---|
| Size | 19.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
167d05f506d5c96b03bbfb0502023bb00451c44cab92a3d7669bec1542179284
|
|
BLAKE2b-256 checksum How to use checksums |
531a2d45d10d0a6b557aa650f1c70f99e1ccc7eddd06ee2dd8bda125961732c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logSecurity for mainspring-mcp 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mainspring_mcp-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.