使用说明
Full-Stack MCP Framework
mcp-use provides everything you need to build with Model Context Protocol
MCP servers, MCP clients and AI agents in 6 lines of code, in both Python and TypeScript.
堆栈
- 🤖 MCP代理 -可以跨步骤使用工具和推理的AI代理
- 🔌 MCP客户端 -将任何LLM连接到任何MCP服务器
- 🛠️ MCP服务器 -构建自己的MCP服务器
- 🔍 MCP检查员 -基于Web的MCP服务器调试器
- 🎨 MCP-UI资源 -使用交互式小部件构建ChatGPT应用程序
🚀 What Do You Want to Build?
🤖 Build an AI AgentCreate intelligent agents that can use tools, browse the web, manage files, and more. |
🔌 Use MCP ClientConnect directly to MCP servers and call tools programmatically without an agent. |
🛠️ Create an MCP ServerBuild your own MCP servers with tools, resources, and prompts. |
🔍 Debug with InspectorTest, debug, and explore your MCP servers interactively. |
🎨 Build ChatGPT AppsCreate interactive UIs with mcp-ui, react and live reload. |
☁️ Deploy to MCP CloudDeploy and manage your MCP agents and servers in the cloud. |
📦 Quick Start
构建AI代理
创建一个可以使用MCP工具完成复杂任务的AI代理。
python
pip install mcp-use langchain-openai
import asyncio
from langchain_openai import ChatOpenAI
from mcp_use import MCPAgent, MCPClient
async def main():
# Configure MCP server
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("List all files in the directory")
print(result)
asyncio.run(main())
TypeScript
npm install mcp-use @langchain/openai
import { ChatOpenAI } from "@langchain/openai";
import { MCPAgent, MCPClient } from "mcp-use";
async function main() {
// Configure MCP server
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("List all files in the directory");
console.log(result);
}
main();
使用MCP客户端
直接连接到MCP服务器,无需AI代理即可访问编程工具。
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: {result.content[0].text}")
await client.close_all_sessions()
asyncio.run(main())
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: ${result.content[0].text}`);
await client.closeAllSessions();
}
main();
创建MCP服务器
使用自定义工具、资源和提示构建自己的MCP服务器。
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: "My custom MCP server",
});
// Define a tool
server.tool("get_weather", {
description: "Get weather for a city",
parameters: z.object({
city: z.string().describe("City name"),
}),
execute: async ({ city }) => {
return { temperature: 72, condition: "sunny", city };
},
});
// Start server with auto-inspector
server.listen(3000);
// 🎉 Inspector at http://localhost:3000/inspector
python
马上就来! 现在,请使用TypeScript实现来创建MCP服务器。
使用检查器
使用交互式基于web的检查器调试和测试您的MCP服务器。
自动(带mcp使用服务器)
当您使用创建服务器时 mcp-use,检查器自动可用:
server.listen(3000);
// Inspector automatically at: http://localhost:3000/inspector
独立
通过CLI检查任何MCP服务器:
npx @mcp-use/inspector --url http://localhost:3000/sse
特征:
- 🔍 与实时执行交互的测试工具
- 📊 监控连接状态和服务器运行状况
- 🔐 自动处理OAuth流
- 💾 与本地存储的持续会话
📚 更多示例和文档
示例用例
- 用Playwright浏览网页 -自动化浏览器任务
- 多服务器设置 -同时使用多个MCP服务器
- 流媒体响应 -实时代理输出
- UI控件 -构建交互式React组件
- AI SDK集成 -用于Next.js应用程序的Vercel AI SDK
完整的文件
- 📘 Python文档 -完整的Python指南
- 📗 TypeScript文档 -完整的TypeScript指南
- 🔍 检查员文件 -检查员指南
- 🌐 在线文档 -完整的在线文档
✨ 主要特点
| Feature | Description | Python | TypeScript |
|---|---|---|---|
| 🤖 MCP Agents | AI agents with tool access and multi-step reasoning | ✅ | ✅ |
| 🔌 MCP Clients | Direct connection to any MCP server | ✅ | ✅ |
| 🛠️ MCP Servers | Build custom MCP servers | 🔜 | ✅ |
| 🔍 Inspector | Web-based debugging tool | ✅ | ✅ |
| 🎨 UI Widgets | Build interactive React UIs | ➖ | ✅ |
| 🌐 Multi-Server | Connect to multiple servers simultaneously | ✅ | ✅ |
| 📡 Streaming | Real-time streaming responses | ✅ | ✅ |
| 📊 Observability | Built-in Langfuse integration | ✅ | ✅ |
| 🔐 OAuth Support | Built-in OAuth flow handling | ✅ | ✅ |
| 🛡️ Tool Control | Restrict access to specific tools | ✅ | ✅ |
📦 包装概述
这个monorepo包含Python和TypeScript的多个包:
Python包
| 包 | 描述 | 版本 |
|---|---|---|
| mcp使用 | 完整的MCP客户端和代理库 |
TypeScript软件包
| 包 | 描述 | 版本 |
|---|---|---|
| mcp使用 | 客户端、代理和服务器的核心框架 | |
| @mcp使用/cli | 带有热装和自动检查器的构建工具 | |
| @mcp使用/检查员 | 基于Web的MCP服务器调试器 | |
| 创建mcp使用应用程序 | 项目脚手架工具 |
🏗️ 存储库结构
mcp-use/
├── libraries/
│ ├── python/ → Python implementation
│ │ ├── mcp_use/ → Core library
│ │ ├── examples/ → Python examples
│ │ └── docs/ → Python documentation
│ │
│ └── typescript/ → TypeScript implementation
│ └── packages/
│ ├── mcp-use/ → Core framework
│ ├── cli/ → Build tool
│ ├── inspector/ → Web inspector
│ └── create-mcp-use-app/ → Scaffolding
└── README.md → This file
🌟 为什么使用MCP?
完整的垂直堆叠
构建从人工智能代理到服务器的所有内容,而不仅仅是客户端。用您喜欢的语言创建完整的MCP生态系统。
语言灵活性
为ML/数据工作流选择Python,为web应用程序选择TypeScript。相同的功能,不同的语言。
生产就绪
包括可观察性、流媒体、多服务器支持、沙盒和开箱即用的工具访问控制。
开发者体验
热重载、TypeScript/Python类型安全、内置检查器和全面的文档。
开源
麻省理工学院授权和社区驱动。根据需要进行贡献、分叉或扩展。
🤝 社区与支持
- 💬 Discord 的中文翻译是“不和谐”或“纷争”。: 加入我们的社区
- 🐛 GitHub问题: 报告错误或请求功能
- 📖 文档: docs.mcp-use.com
- 🌐 网站: mcp-use.com
- 🐦 推特:关注 @皮埃特罗祖洛 和 @函数=随机(浮点)@描述=随机(浮点数)@描述=RAND(浮点)
📜 许可证
MIT© MCP使用贡献者
🙏 贡献
我们热爱贡献!查看我们的贡献指南:
⭐ 明星历史
📝 引用
此项目最初基于mcp使用/mcp使用 由Pietro Zullo和撰稿人撰写。 此后,它已经演变为由Jerry Shi维护的独立分叉(syw2014) , 具有附加模块和集成(例如LangGraph和RAG代理扩展)。
如果您在项目中使用此存储库或衍生工具,请引用:
@software{mcp_use2025,
author = {Zullo, Pietro and Contributors},
title = {MCP-Use: Complete MCP Ecosystem for Python and TypeScript},
year = {2025},
publisher = {GitHub},
url = {https://github.com/mcp-use/mcp-use}
}
贡献者
感谢我们所有出色的贡献者!
核心贡献者
- 彼得罗 (@皮埃特罗祖洛)
- 路易 (@函数=随机(浮点)@描述=随机(浮点数)@描述=RAND(浮点))
- 恩里科 (@tonxxd)
Built with ❤️ by the MCP-Use community
San Francisco | Zürich
