$git clone https://github.com/ip2a/mcpstore<table align="center"> <tr> <td> <pre> ███ ███ ██████ ███████ ██████ ████████ ██████ ██████ ███████ ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ███████ ██████ ██ ██ ██ ██████ █████ ██ ██ ██ ██ ██
| 1 | <div align="center"> |
| 2 | |
| 3 | <table align="center"> |
| 4 | <tr> |
| 5 | <td> |
| 6 | <pre> |
| 7 | ███ ███ ██████ ███████ ██████ ████████ ██████ ██████ ███████ |
| 8 | ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ |
| 9 | ██ ████ ██ ██ ███████ ██████ ██ ██ ██ ██████ █████ |
| 10 | ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ |
| 11 | ██ ██ ██████ ██ ██████ ██ ██████ ██ ██ ███████ |
| 12 | </pre> |
| 13 | </td> |
| 14 | </tr> |
| 15 | </table> |
| 16 | |
| 17 | --- |
| 18 | |
| 19 |     |
| 20 | |
| 21 | |
| 22 | |
| 23 | [English](README_en.md) | [简体中文](README_zh.md) |
| 24 | |
| 25 | |
| 26 | [文档](https://ip2a.github.io/mcpstore/) | [快速使用](###简单示例) |
| 27 | |
| 28 | </div> |
| 29 | |
| 30 | ### mcpstore 是什么? |
| 31 | |
| 32 | 开发者最佳的mcp管理包 快速维护mcp服务并应用 |
| 33 | |
| 34 | ### 快速开始 |
| 35 | |
| 36 | ```bash |
| 37 | pip install mcpstore |
| 38 | ``` |
| 39 | |
| 40 | ### Rust-first 架构 |
| 41 | |
| 42 | 当前 `mcpstore` 以 Rust 作为唯一真实运行时: |
| 43 | |
| 44 | - `mcpstore api` 由 Rust 二进制直接启动完整 HTTP API 服务 |
| 45 | - `mcpstore mcp-server` 由 Rust 二进制直接暴露 MCP Server,支持 `stdio` 和 `streamable-http` |
| 46 | - Python 包主要提供 PyO3 store facade、稳定的 Python SDK 入口,以及 Python 生态 adapter |
| 47 | |
| 48 | 如果你只想把 `mcpstore` 当成独立服务使用,优先直接调用 Rust CLI: |
| 49 | |
| 50 | ```bash |
| 51 | mcpstore api --config-path ./mcp.json --port 18200 |
| 52 | mcpstore mcp-server --config-path ./mcp.json |
| 53 | mcpstore mcp-server --config-path ./mcp.json --transport streamable-http --port 18300 --path /mcp |
| 54 | ``` |
| 55 | |
| 56 | ### 简单示例 |
| 57 | |
| 58 | 一切的开始:初始化一个store |
| 59 | |
| 60 | ```python |
| 61 | from mcpstore import MCPStore |
| 62 | store = MCPStore.setup_store() |
| 63 | ``` |
| 64 | |
| 65 | 现在你获得了一个 `store`,利用`store`去使用你的MCP服务,`store` 会维护和管理这些 MCP 服务。 |
| 66 | |
| 67 | #### 给store添加第一个服务 |
| 68 | |
| 69 | ```python |
| 70 | #在上面的代码下面加入 |
| 71 | store.for_store().add_service({"mcpServers": {"mcpstore_wiki": {"url": "https://example.com/mcp"}}}) |
| 72 | store.for_store().wait_service("mcpstore_wiki") |
| 73 | ``` |
| 74 | |
| 75 | `add_service`方法支持多种mcp服务配置格式,。`wait_service`用来等待服务就绪。 |
| 76 | |
| 77 | #### 将mcp适配转为langchain需要的对象 |
| 78 | |
| 79 | ```python |
| 80 | #在上面的代码下面加入 |
| 81 | tools = store.for_store().for_langchain().list_tools() |
| 82 | print("loaded langchain tools:", len(tools)) |
| 83 | ``` |
| 84 | |
| 85 | 轻松将mcp服务转为langchain可以直接使用的tools列表 |
| 86 | |
| 87 | ##### 框架适配 |
| 88 | |
| 89 | 积极支持更多的框架 |
| 90 | |
| 91 | | 已支持框架 | 获取工具 | |
| 92 | | --- | --- | |
| 93 | | LangChain | `tools = store.for_store().for_langchain().list_tools()` | |
| 94 | | LangGraph | `tools = store.for_store().for_langgraph().list_tools()` | |
| 95 | | AutoGen | `tools = store.for_store().for_autogen().list_tools()` | |
| 96 | | CrewAI | `tools = store.for_store().for_crewai().list_tools()` | |
| 97 | | LlamaIndex | `tools = store.for_store().for_llamaindex().list_tools()` | |
| 98 | |
| 99 | #### 代码中使用 以langchain为例 |
| 100 | |
| 101 | ```python |
| 102 | #添加上面的代码 |
| 103 | from langchain.agents import create_agent |
| 104 | from langchain_openai import ChatOpenAI |
| 105 | llm = ChatOpenAI( |
| 106 | temperature=0, |
| 107 | model="your-model", |
| 108 | api_key="sk-*****", |
| 109 | base_url="https://api.xxx.com" |
| 110 | ) |
| 111 | agent = create_agent(model=llm, tools=tools, system_prompt="你是一个助手,回答的时候带上表情") |
| 112 | events = agent.invoke({"messages": [{"role": "user", "content": "mcpstore怎么添加服务?"}]}) |
| 113 | print(events) |
| 114 | ``` |
| 115 | 如你所见。这里的langchain的agent可以正常的调用你通过`sotre`管理的mcp服务了。 |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | #### 为 Agent 分组 |
| 121 | |
| 122 | 使用 `for_agent(agent_id)` 实现分组 |
| 123 | |
| 124 | ```python |
| 125 | #不同的agent需要不同的mcp的集合 |
| 126 | |
| 127 | agent_id1 = "agent1" |
| 128 | store.for_agent(agent_id1).add_service({"name": "mcpstore_wiki", "url": "https://example.com/mcp"}) |
| 129 | |
| 130 | agent_id2 = "agent2" |
| 131 | store.for_agent(agent_id2).add_service({"name": "gitodo", "command": "uvx", "args": ["gitodo"]}) |
| 132 | |
| 133 | agent1_tools = store.for_agent(agent_id1).list_tools() |
| 134 | |
| 135 | agent2_tools = store.for_agent(agent_id2).list_tools() |
| 136 | ``` |
| 137 | |
| 138 | `store.for_agent(agent_id)` 与 `store.for_store()` 镜像大部分函数接口, `agent` 的分组是 `store` 的逻辑子集。 |
| 139 | |
| 140 | 通过为不同 `agent` 隔离mcp服务,避免上下文过长,并由 `sotre` 统一维护。 |
| 141 | |
| 142 | #### Rust API 与 MCP Server |
| 143 | |
| 144 | 当前推荐直接使用 Rust CLI 暴露服务,而不是再依赖历史 Python hub 接口: |
| 145 | |
| 146 | ```bash |
| 147 | # 启动 Rust HTTP API |
| 148 | mcpstore api --config-path ./mcp.json --host 127.0.0.1 --port 18200 |
| 149 | |
| 150 | # 以 stdio 启动 Rust MCP Server |
| 151 | mcpstore mcp-server --config-path ./mcp.json |
| 152 | |
| 153 | # 以 streamable-http 启动 Rust MCP Server |
| 154 | mcpstore mcp-server --config-path ./mcp.json --transport streamable-http --host 127.0.0.1 --port 18300 --path /mcp |
| 155 | ``` |
| 156 | |
| 157 | Python 侧已不再提供嵌入式 API server;请直接使用 Rust CLI 启动服务。 |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | #### 常用接口 |
| 163 | |
| 164 | | 动作 |