MCP全栈框架

mcp-use是一个全栈MCP框架,提供构建MCP服务器、客户端和AI代理所需的一切,支持Python和TypeScript。

  • by syw2014
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 syw2014/mcp-use

使用说明

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 Agent

Create intelligent agents that can use tools, browse the web, manage files, and more.

Quick Start ↓ | Python Docs | TypeScript Docs

🔌 Use MCP Client

Connect directly to MCP servers and call tools programmatically without an agent.

Quick Start ↓ | Python Docs | TypeScript Docs

🛠️ Create an MCP Server

Build your own MCP servers with tools, resources, and prompts.

Quick Start ↓ | TypeScript Docs

🔍 Debug with Inspector

Test, debug, and explore your MCP servers interactively.

Quick Start ↓ | Inspector Docs | MCP Inspector online

🎨 Build ChatGPT Apps

Create interactive UIs with mcp-ui, react and live reload.

Quick Start | Templates

☁️ Deploy to MCP Cloud

Deploy and manage your MCP agents and servers in the cloud.

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

→ 完整的Python代理文档

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

→ 完整的TypeScript代理文档


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

→ Python客户端文档

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

→ TypeScript客户端文档


创建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

→ 完整的TypeScript服务器文档

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流
  • 💾 与本地存储的持续会话

→ 完整的检查员文件


📚 更多示例和文档

示例用例

完整的文件


✨ 主要特点

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类型安全、内置检查器和全面的文档。

开源

麻省理工学院授权和社区驱动。根据需要进行贡献、分叉或扩展。


🤝 社区与支持


📜 许可证

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}
}

贡献者

感谢我们所有出色的贡献者!

核心贡献者

  1. 彼得罗 (@皮埃特罗祖洛)
  2. 路易 (@函数=随机(浮点)@描述=随机(浮点数)@描述=RAND(浮点))
  3. 恩里科 (@tonxxd)


Built with ❤️ by the MCP-Use community
San Francisco | Zürich