Skip to main content

mainspring-mcp

MCP client 外挂(T4-1):装了就把 MCP 工具注册进 core 的 ToolRegistry,core 对 MCP 零感知。

设计小节

  1. 传输只负责一收一发,协议握手 / 超时 / 重连全在 client.py;stdio 与 HTTP 共用一套 client。
  2. MCP session 绑定 transport:传输断开才重建并重新握手(只重试一次);超时不重放——慢调用可能已有副作用。
  3. stdio 用换行分隔 JSON(MCP 规范),stderr 异步排空并保留尾部,崩溃原因随异常带出。
  4. Streamable HTTP 同时接受 application/json 与 text/event-stream,Mcp-Session-Id 自动续带。
  5. 工具名 {prefix}__{name} 消歧,provider 安全字符清洗 + 64 字符截断(短哈希后缀)。
  6. schema 只清洗不重建(补 type: object、剔除幽灵 required),参数模型宽松透传,MCP server 是 schema 权威。
  7. 结果 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)

Source distribution for mainspring-mcp 0.1.0
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)

Table of built distributions (wheels) for mainspring-mcp 0.1.0
File Interpreter ABI Platform Actions
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 log

Release 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 log

Security 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.

Select from 2 files

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 log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page