🚀 Easy MCP — 让 MCP 工具像本地函数一样简单
一行代码集成任意 MCP 服务 自动管理子进程生命周期 · 零配置接入 LangChain / LangGraph Agent
✨ 特性
- ✅ 自动资源管理:无需手动启动/关闭 MCP 服务
- ✅ 零侵入集成:返回标准 LangChain Tool 列表
- ✅ 多服务支持:高德地图、天气、数据库 MCP 一次性接入
- ✅ 生产可用:异常安全、子进程隔离、异步非阻塞
🚀 快速开始
1. 安装
pip install easy-mcp
2. 🧪「5 行代码」调用高德地图 MCP
from src.easy_mcp import MCPToolLoader
import asyncio
async def main():
async with MCPToolLoader([{
"command": "npx",
"args": ["-y", "@amap/amap-maps-mcp-server"],
"env": {"AMAP_MAPS_API_KEY": "你的密钥"}
}]) as tools:
search = next(t for t in tools if t.name == "maps_text_search")
print(await search.ainvoke({"keywords": "西湖", "city": "杭州"}))
asyncio.run(main())
输出示例
{
"pois": [
{"name": "杭州西湖", "location": "120.1551,30.2741", ...}
]
}
🤖 构建 MCP-Powered Agent
from langgraph.graph import StateGraph
from src.easy_mcp import MCPToolLoader
async with MCPToolLoader([高德配置]) as tools:
graph = StateGraph(MessagesState)
graph.add_node("agent", create_agent_node(tools))
# ... 添加更多工具结点 ...
app = graph.compile()
await app.ainvoke({"messages": [("user", "西湖附近有什么酒店?")]})
👉 查看完整示例:examples/full_agent_demo.py
🔧 支持的 MCP 服务
| 服务 | 安装命令 | 必需环境变量 |
|---|---|---|
| 高德地图 | npx @amap/amap-maps-mcp-server |
AMAP_MAPS_API_KEY |
| 天气 API | npx @weather/mcp-server |
WEATHER_API_KEY |
| 自定义 MCP | 任意符合 MCP 协议的进程 | - |
📂 项目结构
easy-mcp/
├── examples/
│ ├── quickstart.py # 5 行上手示例
│ └── full_agent_demo.py # 完整 LangGraph Agent 示例
├── src/easy_mcp/
│ ├── __init__.py # 导出 MCPToolLoader
│ ├── bridge.py # MCP ↔ LangChain 适配器
│ └── client.py # MCP 客户端封装
└── README.md
❓ 常见问题(FAQ)
Q: 如何添加新的 MCP 服务?
只需在 MCPToolLoader([...]) 的列表中添加一个新的配置:
{
"command": "python",
"args": ["my_mcp_server.py"],
"env": {"API_KEY": "..."}
}
Q: 子进程会残留吗?
不会。 MCPToolLoader 使用 AsyncExitStack 和自动回收机制保证:
- MCP 子进程 100% 自动退出
- 不留下僵尸进程
- 异常情况下仍可安全清理
Metadata
Release files for easy-mcp-langchain 0.1.2
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 | |
|---|---|---|---|---|
| easy_mcp_langchain-0.1.2.tar.gz | 10.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| easy_mcp_langchain-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.7 kB
Release files / easy_mcp_langchain-0.1.2.tar.gz
| Download URL | easy_mcp_langchain-0.1.2.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d27a38be8e191b8afbbfbfdea59dc8a6b8dd0aeb44ebe73a83d3a9e561980210
|
|
BLAKE2b-256 checksum How to use checksums |
3703128f0751c5d7dcf6da511574d52d180e17cbb89610c3df362596e42099cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / easy_mcp_langchain-0.1.2-py3-none-any.whl
| Download URL | easy_mcp_langchain-0.1.2-py3-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cb74268c04d151837edf5cc96c6730bcdbb0ac5a6a66b46e8cced5504a5ce52d
|
|
BLAKE2b-256 checksum How to use checksums |
59e7bf3f8b5dca803f1f4d381ec9851aa9e565676a0918260e7e5056bc7d50d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Security for easy-mcp-langchain 0.1.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.