MCP应用框架

mcp-use是一个全栈MCP框架,用于为ChatGPT/Claude构建MCP应用和为AI代理构建MCP服务器。

  • by Mallikarjun63
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 Mallikarjun63/Zen-citizen-mcp

使用说明



 




关于

mcp使用 是全栈MCP框架 为ChatGPT/Claude构建MCP应用程序,为AI代理构建MCP服务器。

文档

访问我们的 文档 或者跳到快速入门(TypeScript | python)

编码代理的技能

使用Claude Code、Codex、Cursor或其他AI编码代理?

安装mcp应用程序的mcp使用技巧

快速入门:MCP服务器和MCP应用程序

TypeScript

构建您的第一个MCP服务器或MPC应用程序:

npx create-mcp-use-app@latest

或者手动创建服务器:

import { MCPServer, text } from "mcp-use/server";
import { z } from "zod";

const server = new MCPServer({
  name: "my-server",
  version: "1.0.0",
});

server.tool({
  name: "get_weather",
  description: "Get weather for a city",
  schema: z.object({ city: z.string() }),
}, async ({ city }) => {
  return text(`Temperature: 72°F, Condition: sunny, City: ${city}`);
});

await server.listen(3000);
// Inspector at http://localhost:3000/inspector

→ 完整的TypeScript服务器文档

MCP应用程序

MCP应用程序允许您构建跨Claude、ChatGPT和其他MCP客户端工作的交互式小部件——一次编写,随处运行。

服务器:定义一个工具并将其指向一个小部件:

import { MCPServer, widget } from "mcp-use/server";
import { z } from "zod";

const server = new MCPServer({
  name: "weather-app",
  version: "1.0.0",
});

server.tool({
  name: "get-weather",
  description: "Get weather for a city",
  schema: z.object({ city: z.string() }),
  widget: "weather-display", // references resources/weather-display/widget.tsx
}, async ({ city }) => {
  return widget({
    props: { city, temperature: 22, conditions: "Sunny" },
    message: `Weather in ${city}: Sunny, 22°C`,
  });
});

await server.listen(3000);

小部件:在中创建一个React组件 resources/weather-display/widget.tsx:

import { useWidget, type WidgetMetadata } from "mcp-use/react";
import { z } from "zod";

const propSchema = z.object({
  city: z.string(),
  temperature: z.number(),
  conditions: z.string(),
});

export const widgetMetadata: WidgetMetadata = {
  description: "Display weather information",
  props: propSchema,
};

const WeatherDisplay: React.FC = () => {
  const { props, isPending, theme } = useWidget<z.infer<typeof propSchema>>();
  const isDark = theme === "dark";

  if (isPending) return <div>Loading...</div>;

  return (
    <div style={{
      background: isDark ? "#1a1a2e" : "#f0f4ff",
      borderRadius: 16, padding: 24,
    }}>
      <h2>{props.city}</h2>
      <p>{props.temperature}° — {props.conditions}</p>
    </div>
  );
};

export default WeatherDisplay;

小工具在 resources/ 是 自动发现 --无需手动注册。

访问 MCP应用程序文档


python

pip install mcp-use
from typing import Annotated

from mcp.types import ToolAnnotations
from pydantic import Field

from mcp_use import MCPServer

server = MCPServer(name="Weather Server", version="1.0.0")

@server.tool(
    name="get_weather",
    description="Get current weather information for a location",
    annotations=ToolAnnotations(readOnlyHint=True, openWorldHint=True),
)
async def get_weather(
    city: Annotated[str, Field(description="City name")],
) -> str:
    return f"Temperature: 72°F, Condition: sunny, City: {city}"

# Start server with auto-inspector
server.run(transport="streamable-http", port=8000)
# 🎉 Inspector at http://localhost:8000/inspector

→ 完整的Python服务器文档


检查员

mcp-use Inspector允许您交互式地测试和调试mcp服务器。

包括汽车 使用时 server.listen():

server.listen(3000);
// Inspector at http://localhost:3000/inspector

在线的 连接到托管的MCP服务器时:

访问https://inspector.mcp-use.com

独立:检查任何MCP服务器:

npx @mcp-use/inspector --url http://localhost:3000/mcp

访问 检查员文件


部署

将MCP服务器部署到生产环境:

npx @mcp-use/cli login
npx @mcp-use/cli deploy

或者将您的GitHub仓库连接到 manufact.com --生产就绪,具有可观察性、度量、日志和分支部署。


包装概述

这个monorepo包含Python和TypeScript的多个包:

Python 包

包 描述 版本
mcp使用 完整的MCP服务器和MCP代理SDK

TypeScript软件包

包 描述 版本
mcp使用 MCP服务器、MCP应用程序和MCP代理的核心框架
@mcp使用/cli 带有热装和自动检查器的构建工具
@mcp使用/检查员 用于MCP服务器的基于Web的预览器和调试器
创建mcp使用应用程序 项目脚手架工具

另外:MCP代理和客户

mcp的使用还提供了完整的mcp代理和客户端实现。

Build an AI Agent

python

pip install mcp-use langchain-openai
import asyncio
from langchain_openai import ChatOpenAI
from mcp_use import MCPAgent, MCPClient

async def main():
    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() {
  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代理文档

Use MCP Client

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客户端文档


符合模型上下文协议


社区与支持


星迹


贡献者

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

核心贡献者

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


Built with ❤️ by Manufact team and the mcp-use community
San Francisco | Zürich