MCP工具集成服务

Easy MCP 是一个简化MCP服务集成的工具,提供自动资源管理和零侵入集成功能,支持多种MCP服务,如高德地图、天气API等,适用于需要快速集成MCP服务的开发场景。

  • by Annyfee
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Annyfee/easy-mcp-langchain

使用说明

🚀 Easy MCP - Make MCP Tools as Simple as Local Functions

Integrate any MCP service with one line of code Automatic management of sub process lifecycle · Zero configuration access to LangChain/LangGraph Agent

✨ feature

  • ✅ Automatic Resource ManagementNo need to manually start/stop MCP service
  • ✅ Zero intrusion integration: Return to the standard LangChain Tool list
  • ✅ Multi service supportHigh tech map, weather, and database MCP one-time access
  • ✅ Production availableException safe, child process isolation, asynchronous non blocking

🚀 Quick Start

1. Installation

pip install easy-mcp

two 🧪 Call Gaode Map MCP with "5-line code"

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())

Output Example

{
  "pois": [
    {"name": "杭州西湖", "location": "120.1551,30.2741", ...}
  ]
}

🤖 Building 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", "西湖附近有什么酒店?")]})

👉 View complete example:examples/full_agent_demo.py

🔧 Supported MCP services

Service Installation Command Required Environment Variables
Gaode Map npx @amap/amap-maps-mcp-server AMAP_MAPS_API_KEY
Weather API npx @weather/mcp-server WEATHER_API_KEY
Custom MCP Any process that complies with the MCP protocol -

📂 project structure

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

❓ Frequently Asked Questions (FAQ)

Q: How to add a new MCP service?

Just add a new configuration to the list of MCPToolLoader ([...]):

{
    "command": "python",
    "args": ["my_mcp_server.py"],
    "env": {"API_KEY": "..."}
}

Q: Will child processes remain?

can't. MCPToolLoader ensures:

  • MCP subprocess automatically exits 100%
  • Do not leave zombie processes behind
  • Can still be safely cleaned under abnormal conditions