<div align="center">
<div align="center" style="margin: 0 auto; max-width: 80%;">
<a href="https://mcp-use.com">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="./static/logo_white.svg">
<source media="(prefers-color-scheme: light)" srcset="./static/logo_black.svg">
<img alt="mcp use logo" src="./static/logo_black.svg" width="80%" style="margin: 20px auto;">
</picture>
</a>
</div>
<h1 align="center" style="border:0; font-style:italic; font-weight:300;">全栈MCP框架</h1>
<p align="center" style="max-width:600px; margin-bottom:40px">
<b>mcp-use</b> 提供了构建所需的一切,使用 <a href="https://modelcontextprotocol.io">模型上下文协议</a> <br/> MCP服务器、MCP客户端和AI代理,仅需6行代码,支持<b>Python</b> 和 <b>TypeScript</b>。</p>
<p align="center">
<a href="https://github.com/mcp-use/mcp-use/stargazers" alt="GitHub stars">
<img src="https://img.shields.io/github/stars/mcp-use/mcp-use?style=social" /></a>
<a href="https://github.com/mcp-use/mcp-use/blob/main/LICENSE" alt="License">
<img src="https://img.shields.io/github/license/mcp-use/mcp-use" /></a>
<a href="https://docs.mcp-use.com" alt="Documentation">
<img src="https://img.shields.io/badge/mcp--use-docs-red" /></a>
<a href="https://mcp-use.com" alt="Website">
<img src="https://img.shields.io/badge/cloud-mcp--use.com-blue" /></a>
<a href="https://x.com/mcpuse" alt="X follow mcp-use">
<img src="https://img.shields.io/twitter/follow/mcp-use?style=social" /></a>
<a href="https://discord.gg/XkNkSkMz3V" alt="Discord">
<img src="https://dcbadge.limes.pink/api/server/XkNkSkMz3V?style=flat" /></a>
<br/>
<a href="https://github.com/mcp-use/mcp-use/tree/main/libraries/python" alt="Python repository">
<img src="https://img.shields.io/badge/pyhton-repo-grey?labelColor=white&logo=python" alt="Badge"></a>
<a href="https://pypi.org/project/mcp_use/" alt="PyPI Version">
<img src="https://img.shields.io/pypi/v/mcp_use.svg"/></a>
<a href="https://pypi.org/project/mcp_use/" alt="PyPI Downloads">
<img src="https://static.pepy.tech/badge/mcp-use" /></a>
<a href="https://docs.mcp-use.com/python" alt="Python Documentation">
<img src="https://img.shields.io/badge/python-docs-red" /></a>
<br/>
<a href="https://github.com/mcp-use/mcp-use/tree/main/libraries/typescript" alt="Typescript Documentation">
<img src="https://img.shields.io/badge/typescript-repo-grey?labelColor=white&logo=typescript" alt="Badge"></a>
<a href="https://www.npmjs.com/package/mcp-use" alt="NPM Version">
<img src="https://img.shields.io/npm/v/mcp-use.svg"/></a>
<a href="https://www.npmjs.com/package/mcp-use" alt="NPM Downloads">
<img src="https://img.shields.io/npm/dw/mcp-use.svg"/></a>
<a href="https://docs.mcp-use.com/typescript" alt="Typescript Documentation">
<img src="https://img.shields.io/badge/typescript-docs-red" /></a>
<br/>
<a href="https://inspector.mcp-use.com" alt="MCP Inspector Online">
<img src="https://img.shields.io/badge/MCP%20Inspector-black" /></a>
<a href="https://mcp-use.com" alt="MCP Deploy">
<img src="https://img.shields.io/badge/Deploy%20MCP-black" /></a>
</p>
</div>
技术栈
- 🤖 MCP代理 - 能够使用工具并进行多步推理的AI代理
- 🔌 MCP客户端 - 将任何LLM连接到任何MCP服务器
- 🛠️ MCP服务器 - 构建自己的MCP服务器
- 🔍 MCP检查器 - 基于Web的MCP服务器调试器
- 🎨 MCP-UI资源 - 使用交互式小部件构建ChatGPT应用程序
<h2 align="left" style="border:0; margin-top:50px">🚀 想要构建什么?</h2>
<table>
<tr>
<td width="50%" valign="top">
<h3>🤖 构建一个AI代理</h3>
<p>创建能够使用工具、浏览网络、管理文件等的智能代理。</p>
<p>
<a href="#build-an-ai-agent">快速开始 ↓</a> |
<a href="https://docs.mcp-use.com/python/agent/agent-configuration">Python文档</a> |
<a href="https://docs.mcp-use.com/typescript/agent/agent-configuration">TypeScript文档</a>
</p>
</td>
<td width="50%" valign="top">
<h3>🔌 使用MCP客户端</h3>
<p>直接连接到MCP服务器,并通过编程方式调用工具,无需代理。</p>
<p>
<a href="#use-mcp-client">快速开始 ↓</a> |
<a href="https://docs.mcp-use.com/python/client/client-configuration">Python文档</a> |
<a href="https://docs.mcp-use.com/typescript/client/client-configuration">TypeScript文档</a>
</p>
</td>
</tr>
<tr>
<td width="50%" valign="top">
<h3>🛠️ 创建一个MCP服务器</h3>
<p>使用工具、资源和提示构建自己的MCP服务器。</p>
<p>
<a href="#create-an-mcp-server">快速开始 ↓</a> |
<a href="https://docs.mcp-use.com/typescript/server/getting-started">TypeScript文档</a>
</p>
</td>
<td width="50%" valign="top">
<h3>🔍 使用检查器调试</h3>
<p>测试、调试和探索您的MCP服务器。</p>
<p>
<a href="#use-the-inspector">快速开始 ↓</a> |
<a href="https://docs.mcp-use.com/inspector/index">检查器文档</a> |
<a href="https://inspector.mcp-use.com">在线MCP检查器</a>
</p>
</td>
</tr>
<tr>
<td width="50%" valign="top">
<h3>🎨 构建ChatGPT应用程序</h3>
<p>使用mcp-ui、React和实时重载创建交互式UI。</p>
<p>
<a href="https://docs.mcp-use.com/typescript/server/mcp-ui-resources">快速开始</a> |
<a href="https://docs.mcp-use.com/typescript/server/templates">模板</a>
</p>
</td>
<td width="50%" valign="top">
<h3>☁️ 部署到MCP云</h3>
<p>在云端部署和管理您的MCP代理和服务器。</p>
<p>
<a href="https://docs.mcp-use.com/home/mcp101">快速开始</a> |
<a href="https://mcp-use.com">云 ↗</a>
</p>
</td>
</tr>
</table>
<h2 style="border:0; margin-top:30px;">📦 快速开始</h2>
构建一个AI代理
创建一个可以使用MCP工具完成复杂任务的AI代理。
<img src="./static/python.svg" height="14" style="margin-right:4px; top:-1px; position:relative;" align="center" /> Python
pip install mcp-use langchain-openai
import asyncio
from langchain_openai import ChatOpenAI
from mcp_use import MCPAgent, MCPClient
async def main():
# 配置MCP服务器
config = {
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
}
}
}
client = MCPClient.from_dict(config)
llm = ChatOpenAI(model="gpt-4o")
agent = MCPAgent(llm=llm, client=client)
result = await agent.run("列出目录中的所有文件")
print(result)
asyncio.run(main())
→ 完整Python代理文档
<img src="./static/typescript.svg" height="14" style="margin-right:4px; top:-1px; position:relative;" align="center" /> Typescript
npm install mcp-use @langchain/openai
import { ChatOpenAI } from "@langchain/openai";
import { MCPAgent, MCPClient } from "mcp-use";
async function main() {
// 配置MCP服务器
const config = {
mcpServers: {
filesystem: {
command: "npx",
args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
},
},
};
const client = MCPClient.fromDict(config);
const llm = new ChatOpenAI({ modelName: "gpt-4o" });
const agent = new MCPAgent({ llm, client });
const result = await agent.run("列出目录中的所有文件");
console.log(result);
}
main();
→ 完整TypeScript代理文档
使用MCP客户端
直接连接到MCP服务器,无需AI代理即可访问程序化工具。
<img src="./static/python.svg" height="14" style="margin-right:4px; top:-1px; position:relative;" align="center" /> Python
import asyncio
from mcp_use import MCPClient
async def main():
config = {
"mcpServers": {
"calculator": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-everything"]
}
}
}
client = MCPClient.from_dict(config)
await client.create_all_sessions()
session = client.get_session("calculator")
result = await session.call_tool(name="add", arguments={"a": 5, "b": 3})
print(f"结果: {result.content[0].text}")
await client.close_all_sessions()
asyncio.run(main())
→ Python客户端文档
<img src="./static/typescript.svg" height="14" style="margin-right:4px; top:-1px; position:relative;" align="center" /> Typescript
import { MCPClient } from "mcp-use";
async function main() {
const config = {
mcpServers: {
calculator: {
command: "npx",
args: ["-y", "@modelcontextprotocol/server-everything"],
},
},
};
const client = new MCPClient(config);
await client.createAllSessions();
const session = client.getSession("calculator");
const result = await session.callTool("add", { a: 5, b: 3 });
console.log(`结果: ${result.content[0].text}`);
await client.closeAllSessions();
}
main();
→ TypeScript客户端文档
创建一个MCP服务器
使用自定义工具、资源和提示构建自己的MCP服务器。
<img src="./static/typescript.svg" height="14" style="margin-right:4px; top:-1px; position:relative;" align="center" /> Typescript
npx create-mcp-use-app my-server
cd my-server
npm install
import { createMCPServer } from "mcp-use/server";
import { z } from "zod";
const server = createMCPServer("my-server", {
version: "1.0.0",
description: "我的自定义MCP服务器",
});
// 定义一个工具
server.tool("get_weather", {
description: "获取城市的天气",
parameters: z.object({
city: z.string().describe("城市名称"),
}),
execute: async ({ city }) => {
return { temperature: 72, condition: "晴朗", city };
},
});
// 启动服务器并自动打开检查器
server.listen(3000);
// 🎉 检查器位于 http://localhost:3000/inspector
→ 完整TypeScript服务器文档
<img src="./static/python.svg" height="14" style="margin-right:4px; top:-1px; position:relative;" align="center" /> Python
即将推出! 目前,请使用TypeScript实现来创建MCP服务器。
使用检查器
使用基于Web的交互式检查器调试和测试您的MCP服务器。
自动(与mcp-use服务器一起)
当您使用mcp-use创建服务器时,检查器会自动可用:
server.listen(3000);
// 检查器自动位于:http://localhost:3000/inspector
独立
通过CLI检查任何MCP服务器:
npx @mcp-use/inspector --url http://localhost:3000/sse
功能:
- 🔍 通过实时执行测试工具
- 📊 监控连接状态和服务器健康状况
- 🔐 自动处理OAuth流程
- 💾 使用localStorage持久化会话
→ 完整检查器文档
📚 更多示例及文档
示例用例
完整文档
✨ 关键特性
<table>
<tr>
<th width="200">特性</th>
<th>描述</th>
<th>Python</th>
<th>TypeScript</th>
</tr>
<tr>
<td><strong>🤖 MCP代理</strong></td>
<td>具有工具访问和多步推理能力的AI代理</td>
<td align="center">✅</td>
<td align="center">✅</td>
</tr>
<tr>
<td><strong>🔌 MCP客户端</strong></td>
<td>直接连接到任何MCP服务器</td>
<td align="center">✅</td>
<td align="center">✅</td>
</tr>
<tr>
<td><strong>🛠️ MCP服务器</strong></td>
<td>构建自定义MCP服务器</td>
<td align="center">🔜</td>
<td align="center">✅</td>
</tr>
<tr>
<td><strong>🔍 检查器</strong></td>
<td>基于Web的调试工具</td>
<td align="center">✅</td>
<td align="center">✅</td>
</tr>
<tr>
<td><strong>🎨 UI小部件</strong></td>
<td>构建交互式React UI</td>
<td align="center">➖</td>
<td align="center">✅</td>
</tr>
<tr>
<td><strong>🌐 多服务器</strong></td>
<td>同时连接到多个服务器</td>
<td align="center">✅</td>
<td align="center">✅</td>
</tr>
<tr>
<td><strong>📡 流式传输</strong></td>
<td>实时流式传输响应</td>
<td align="center">✅</td>
<td align="center">✅</td>
</tr>
<tr>
<td><strong>📊