返回市场
MCP美国东部服务器

MCP美国东部服务器

作者:mcp-use161 星标更新:2025-10-27

项目介绍

<div align="center" style="margin: 0 auto; max-width: 80%;"> <picture> <source media="(prefers-color-scheme: dark)" srcset="./packages/mcp-use/static/logo_white.svg"> <source media="(prefers-color-scheme: light)" srcset="./packages/mcp-use/static/logo_black.svg"> <img alt="mcp use logo" src="./packages/mcp-use/static/logo_white.svg" width="80%" style="margin: 20px auto;"> </picture> </div> <h1 align="center">MCP-Use:完整的用于模型上下文协议的TypeScript框架</h1> <p align="center"> <a href="https://github.com/mcp-use/mcp-use-ts/stargazers" alt="GitHub stars"> <img src="https://img.shields.io/github/stars/mcp-use/mcp-use-ts?style=social" /></a> <a href="https://github.com/mcp-use/mcp-use-ts/blob/main/LICENSE" alt="License"> <img src="https://img.shields.io/github/license/mcp-use/mcp-use-ts" /></a> <a href="https://discord.gg/XkNkSkMz3V" alt="Discord"> <img src="https://dcbadge.limes.pink/api/server/XkNkSkMz3V?style=flat" /></a> </p> <p align="center"> <strong>构建强大的AI代理,创建带有UI组件的MCP服务器,并使用内置检查器进行调试——全部基于TypeScript</strong> </p>

🎯 MCP-Use是什么?

MCP-Use是一个全面的TypeScript框架,用于构建和使用模型上下文协议(MCP)应用程序。它提供了你需要的一切来创建可以使用工具的AI代理,构建具有丰富UI界面的MCP服务器,并使用强大的开发者工具调试你的应用程序。

📦 包概述

描述版本下载量
mcp-useMCP客户端和服务器的核心框架npmnpm
@mcp-use/cli具有热重载和自动检查器的构建工具npmnpm
@mcp-use/inspector针对MCP服务器的基于Web的调试器npmnpm
create-mcp-use-app项目脚手架工具npmnpm

🚀 快速开始

在不到一分钟的时间内开始使用MCP-Use:

# 创建一个新的MCP应用
npx create-mcp-use-app my-mcp-app

# 导航到你的项目
cd my-mcp-app

# 使用热重载和自动检查器启动开发
npm run dev

你的MCP服务器现在正在http://localhost:3000运行,并且检查器会自动在浏览器中打开!


📚 包文档

mcp-use:核心框架

MCP-Use生态系统的核心——一个强大框架,用于构建MCP客户端和服务器。

作为MCP客户端

连接任何LLM到任何MCP服务器并构建智能代理:

import { MCPClient, MCPAgent } from 'mcp-use'
import { ChatOpenAI } from '@langchain/openai'

// 配置MCP服务器
const client = MCPClient.fromDict({
  mcpServers: {
    filesystem: {
      command: 'npx',
      args: ['@modelcontextprotocol/server-filesystem']
    },
    github: {
      command: 'npx',
      args: ['@modelcontextprotocol/server-github'],
      env: { GITHUB_TOKEN: process.env.GITHUB_TOKEN }
    }
  }
})

// 创建一个AI代理
const agent = new MCPAgent({
  llm: new ChatOpenAI({ model: 'gpt-4' }),
  client,
  maxSteps: 10
})

// 使用自然语言运行代理
const result = await agent.run(
  '搜索项目中的TypeScript文件并创建总结'
)

关键客户端特性:

  • 🤖 LLM无关性:支持OpenAI、Anthropic、Google或任何LangChain支持的LLM
  • 🔄 流式支持:实时流式传输,通过stream()streamEvents()方法
  • 🌐 多服务器:同时连接多个MCP服务器
  • 🔒 工具控制:限制对特定工具的访问以确保安全
  • 📊 可观测性:内置Langfuse集成用于监控
  • 🎯 服务器管理器:根据可用工具自动选择服务器

作为MCP服务器框架

构建自己的MCP服务器,具有自动检查器和UI能力:

import { createMCPServer } from 'mcp-use/server'
import { z } from 'zod'

// 创建你的MCP服务器
const server = createMCPServer('weather-server', {
  version: '1.0.0',
  description: '天气信息MCP服务器'
})

// 定义工具,使用Zod模式
server.tool('get_weather', {
  description: '获取城市的当前天气',
  parameters: z.object({
    city: z.string().describe('城市名称'),
    units: z.enum(['celsius', 'fahrenheit']).optional()
  }),
  execute: async ({ city, units = 'celsius' }) => {
    const weather = await fetchWeather(city, units)
    return {
      temperature: weather.temp,
      condition: weather.condition,
      humidity: weather.humidity
    }
  }
})

// 定义资源
server.resource('weather_map', {
  description: '交互式天气地图',
  uri: 'weather://map',
  mimeType: 'text/html',
  fetch: async () => {
    return generateWeatherMapHTML()
  }
})

// 启动服务器
server.listen(3000)
// 🎉 检查器自动可用于 http://localhost:3000/inspector
// 🚀 MCP端点位于 http://localhost:3000/mcp

关键服务器特性:

  • 🔍 自动检查器:调试UI自动挂载在/inspector
  • 🎨 UI组件:构建与MCP工具一起提供的React组件
  • 🔐 OAuth支持:内置身份验证流程处理
  • 📡 多种传输方式:支持HTTP/SSE和WebSocket
  • 🛠️ TypeScript优先:完全类型安全和推断
  • ♻️ 热重载:开发模式下自动重启

高级特性

AI SDK集成流式传输:

import { streamEventsToAISDKWithTools } from 'mcp-use'
import { LangChainAdapter } from 'ai'

// 在你的Next.js API路由中
export async function POST(req: Request) {
  const { prompt } = await req.json()

  const streamEvents = agent.streamEvents(prompt)
  const enhancedStream = streamEventsToAISDKWithTools(streamEvents)
  const readableStream = createReadableStreamFromGenerator(enhancedStream)

  return LangChainAdapter.toDataStreamResponse(readableStream)
}

自定义UI组件:

// resources/analytics-dashboard.tsx
import { useMcp } from 'mcp-use/react'

export default function AnalyticsDashboard() {
  const { callTool, status } = useMcp()
  const [data, setData] = useState(null)

  useEffect(() => {
    callTool('get_analytics', { period: '7d' })
      .then(setData)
  }, [])

  return (
    <div>
      <h1>分析仪表板</h1>
      {/* 你的仪表板UI */}
    </div>
  )
}

完整的mcp-use文档 →


@mcp-use/cli

针对MCP应用的强大构建和开发工具,集成了检查器。

# 开发模式下的热重载
mcp-use dev

# 生产构建
mcp-use build

# 启动生产服务器
mcp-use start

它做了什么:

  • 🚀 开发模式下自动打开检查器
  • ♻️ 服务器和UI组件的热重载
  • 📦 将React组件捆绑成独立的HTML页面
  • 🏗️ 优化生产构建,包括资产哈希
  • 🛠️ TypeScript编译,监视模式

示例工作流程:

# 开始开发
mcp-use dev
# 服务器运行在 http://localhost:3000
# 检查器在 http://localhost:3000/inspector 打开
# 监视更改...

# 修改代码
# 服务器自动重启
# UI组件热重载
# 检查器实时更新

完整的CLI文档 →


@mcp-use/inspector

针对MCP服务器的基于Web的调试工具——类似于Swagger UI但针对MCP。

特性:

  • 🔍 交互式测试工具,实时执行
  • 📊 监控连接状态和服务器健康状况
  • 🔐 自动处理OAuth流程
  • 💾 使用localStorage持久化会话
  • 🎨 美观且响应式的UI

三种使用方式:

  1. 自动(与mcp-use服务器):
server.listen(3000)
// 检查器在 http://localhost:3000/inspector
  1. 独立CLI
npx mcp-inspect --url https://mcp.example.com/sse
  1. 自定义挂载
import { mountInspector } from '@mcp-use/inspector'
mountInspector(app, '/debug')

完整的检查器文档 →


create-mcp-use-app

零配置的MCP应用项目脚手架。

# 交互模式
npx create-mcp-use-app

# 直接模式
npx create-mcp-use-app my-app --template advanced

你会得到什么:

  • ✅ 完整的TypeScript设置
  • ✅ 预配置的构建脚本
  • ✅ 示例工具和组件
  • ✅ 准备好的开发环境
  • ✅ Docker和CI/CD配置(高级模板)

完整的create-mcp-use-app文档 →


💡 实际案例

示例1:AI驱动的文件管理器

// 创建一个可以管理文件的代理
const agent = new MCPAgent({
  llm: new ChatOpenAI(),
  client: MCPClient.fromDict({
    mcpServers: {
      filesystem: {
        command: 'npx',
        args: ['@modelcontextprotocol/server-filesystem', '/Users/me/documents']
      }
    }
  })
})

// 使用自然语言操作文件
await agent.run('整理所有PDF文件到一个按日期排序的“PDFs”文件夹')
await agent.run('查找所有TypeScript文件并创建项目总结')
await agent.run('删除所有超过30天的临时文件')

示例2:多工具研究助手

// 连接到多个MCP服务器
const client = MCPClient.fromDict({
  mcpServers: {
    browser: { command: 'npx', args: ['@playwright/mcp'] },
    search: { command: 'npx', args: ['@mcp/server-search'] },
    memory: { command: 'npx', args: ['@mcp/server-memory'] }
  }
})

const researcher = new MCPAgent({
  llm: new ChatAnthropic(),
  client,
  useServerManager: true // 根据可用工具自动选择适当的服务器
})

// 复杂的研究任务
const report = await researcher.run(`
  研究量子计算的最新发展。
  查找最近的论文,访问官方网站,
  并创建一个包含来源的综合总结。
`)

示例3:数据库管理员助手

const server = createMCPServer('db-admin', {
  version: '1.0.0'
})

server.tool('execute_query', {
  description: '安全地执行SQL查询',
  parameters: z.object({
    query: z.string(),
    database: z.string()
  }),
  execute: async ({ query, database }) => {
    // 验证并执行查询
    const results = await db.query(query, { database })
    return { rows: results, count: results.length }
  }
})

// 创建一个AI驱动的DBA
const dba = new MCPAgent({
  llm: new ChatOpenAI({ model: 'gpt-4' }),
  client: new MCPClient({ url: 'http://localhost:3000/mcp' })
})

await dba.run('显示本周注册的所有用户')
await dba.run('优化性能日志中的慢查询')

🏗️ 项目结构

典型的MCP-Use项目结构:

my-mcp-app/
├── src/
│   └── index.ts          # MCP服务器定义
├── resources/            # UI组件(React组件)
│   ├── dashboard.tsx     # 主仪表板组件
│   └── settings.tsx      # 设置面板组件
├── package.json         # 依赖项和脚本
├── tsconfig.json        # TypeScript配置
├── .env                 # 环境变量
└── dist/               # 构建输出
    ├── index.js        # 编译后的服务器
    └── resources/      # 编译后的组件

🛠️ 开发工作流程

本地开发

# 1. 创建你的项目
npx create-mcp-use-app my-project

# 2. 开始开发
cd my-project
npm run dev

# 3. 修改代码 - 热重载处理其余部分
# 4. 使用自动打开的检查器进行测试

生产部署

# 构建生产版本
npm run build

# 使用Docker部署
docker build -t my-mcp-server .
docker run -p 3000:3000 my-mcp-server

# 或者部署到任何Node.js主机
npm run start

🤝 社区和支持


📊 发布与版本管理

此单仓库使用现代工具进行包管理:

使用Changesets(推荐)

# 为你的更改创建changeset
pnpm changeset

# 根据changesets版本化包
pnpm changeset version

# 发布所有更改过的包
pnpm changeset publish

手动发布

# 发布单独的包
pnpm --filter mcp-use publish --access public
pnpm --filter @mcp-use/cli publish --access public
pnpm --filter @mcp-use/inspector publish --access public
pnpm --filter create-mcp-use-app publish --access public

# 或一次性发布所有包
pnpm -r publish --access public

🧑‍💻 贡献

我们欢迎贡献!查看我们的贡献指南以开始。

开发设置

# 克隆仓库
git clone https://github.com/mcp-use/mcp-use-ts.git
cd mcp-use-ts

# 安装依赖项
pnpm install

# 构建所有包
pnpm build

# 运行测试
pnpm test

# 开始开发
pnpm dev

📜 许可证

MIT © MCP-Use


<p align="center"> <strong>由MCP-Use团队用心打造</strong> </p>