展示HN:PolyMCP – MCP工具、自治代理和编排
我构建了PolyMCP,这是一个框架和运行时,用于将Python函数作为MCP工具暴露,通过标准化的MCP服务器提供服务,并通过自主代理协调这些工具,这些代理能够规划和执行多步骤的工作流。
PolyMCP不仅仅是一个MCP服务器:它将现有的Python代码转变为适合代理使用的工具,并赋予代理发现、组合和跨多个服务进行协调的能力,同时支持自适应规划和现实世界的执行。
生态系统的关键部分:
1) 将Python函数暴露为MCP工具
可以直接将现有的Python函数作为MCP工具使用,而无需重写它们:
```python
from polymcp.polymcp_toolkit import expose_tools_http
def add(a: int, b: int) -> int:
return a + b
app = expose_tools_http([add], title="数学工具")
```
类型提示会自动生成结构化工具模式,并包含输入/输出验证和错误处理。可以在同一服务器上暴露多个函数。
2) 自主代理:PolyClaw
PolyClaw超越了简单的工具调用。它:
- 将复杂任务分解为可执行的步骤
- 动态选择和协调MCP工具
- 根据需求启动或连接到MCP服务器
- 在继续之前验证输出
- 在执行失败时调整计划
- 在隔离的Docker容器中运行所有内容
示例运行:
```bash
polymcp agent run \
--type polyclaw \
--query "构建一个销售报告管道并进行端到端测试" \
--model minimax-m2.5:cloud \
--verbose
```
在后台,系统根据需要进行规划,提供基础设施,顺序或并行执行步骤,并在出现故障时处理自适应重新规划。
为什么这很重要
目前大多数AI代理系统要么静态调用工具,要么假设基础设施已经存在。而PolyMCP则:
- 以最小的摩擦使现有的Python代码适合代理使用
- 通过MCP标准化工具,以便多个代理和服务可以与之交互
- 提供跨多个服务的自主协调
- 根据需要动态启动基础设施
- 验证步骤结果并从故障中恢复
- 使用Docker进行安全、隔离的执行
PolyMCP对企业自动化、DevOps工作流、数据管道、内部工具协调以及任何复杂的多工具推理任务(代理必须可靠地进行规划和执行)都非常有用。
代码库: [https://github.com/poly-mcp/PolyMCP](https://github.com/poly-mcp/PolyMCP)
欢迎提出问题。
查看原文
I built PolyMCP, a framework and runtime for exposing Python functions as MCP tools, serving them via standardized MCP servers, and orchestrating them with autonomous agents that can plan and execute multi‑step workflows.<p>PolyMCP is more than just an MCP server: it turns existing Python code into agent‑ready tools and gives agents the ability to discover, compose, and orchestrate across multiple services with adaptive planning and real‑world execution support.<p>Key parts of the ecosystem:<p>1) Expose Python functions as MCP tools
Use existing Python functions directly as MCP tools without rewriting them:<p>from polymcp.polymcp_toolkit import expose_tools_http<p>def add(a: int, b: int) -> int:
return a + b<p>app = expose_tools_http([add], title="Math Tools")<p>Type hints automatically generate structured tool schemas, and input/output validation and error handling are included. Multiple functions can be exposed on the same server.<p>2) Autonomous agent: PolyClaw
PolyClaw goes beyond tool calling. It:
• Decomposes complex tasks into executable steps
• Selects and orchestrates MCP tools dynamically
• Starts or connects to MCP servers on demand
• Validates outputs before proceeding
• Adapts plans when execution fails
• Runs everything in isolated Docker containers<p>Example run:<p>polymcp agent run \
--type polyclaw \
--query "Build a sales reporting pipeline and test it end‑to‑end" \
--model minimax‑m2.5:cloud \
--verbose<p>Under the hood, the system plans, provisions infrastructure as needed, executes steps sequentially or in parallel, and handles adaptive replanning when something fails.<p>Why this matters<p>Most AI agent systems today either call tools statically or assume the infrastructure already exists. PolyMCP instead:
• Makes existing Python code agent‑ready with minimal friction
• Standardizes tools via MCP so multiple agents and services can interact with them
• Provides autonomous orchestration across multiple services
• Spins up infrastructure dynamically when needed
• Validates step results and recovers from failures
• Uses Docker for safe, isolated execution<p>PolyMCP is useful for enterprise automation, DevOps workflows, data pipelines, internal tooling orchestration, and any complex multi‑tool reasoning tasks where agents must plan and execute reliably.<p>Repo: <a href="https://github.com/poly‑mcp/PolyMCP" rel="nofollow">https://github.com/poly‑mcp/PolyMCP</a><p>Happy to answer questions.