MCP客户端工具

一款全面的交互式CLI客户端,用于连接任何模型上下文协议(MCP)服务器,支持多种传输类型并提供用户友好的菜单系统。

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

使用说明

通用MCP客户端

一个全面的交互式CLI客户端,用于连接到任何模型上下文协议(MCP)服务器。支持多种传输类型,并提供用户友好的菜单系统,用于探索和与MCP服务器交互。

特性

  • 多种运输支持

    • stdio -连接到作为进程运行的本地MCP服务器
    • Streamable HTTP -使用HTTP POST+SSE流连接到基于HTTP的MCP服务器(建议用于HTTP服务器)
    • SSE -传统服务器仅发送事件传输(已弃用)
    • WebSocket -(即将推出)
  • 交互式菜单系统

    • 添加和管理多个MCP服务器配置
    • 浏览服务器功能、工具、提示和资源
    • 具有交互式参数输入的调用工具
    • 使用格式化输出读取资源
    • 使用带有参数支持的提示
  • MCP聚合器/代理服务器

    • 运行一个聚合多个配置服务器的MCP服务器
    • 通过一个端点从连接的服务器公开所有工具、资源和提示
    • 自动添加前缀以防止命名冲突
    • 支持所有传输类型(stdio、HTTP、SSE)
    • 非常适合Claude Desktop或其他需要统一访问的MCP客户端
  • OAuth2身份验证

    • 需要身份验证的服务器的自动OAuth2流
    • 动态客户端注册(RFC 7591)
    • 令牌刷新支持
    • 凭证持久性

先决条件

  • Node.js 17或更高版本
  • npm包管理器

安装

npm install
npm run build

用法

交互式客户端模式

启动交互式菜单以连接和浏览MCP服务器:

npm start

聚合器/代理服务器模式

启动聚合服务器,通过单个MCP端点公开所有配置的服务器:

npm run aggregator
# Or specify a custom port
npm run aggregator 3001

聚合服务器将:

  1. 从以下位置加载所有服务器 mcp-servers.json
  2. 自动连接到每台服务器
  3. 聚合所有工具、资源和提示
  4. 在以下位置启动HTTP服务器 http://localhost:3000/mcp (或您指定的端口)

然后,您可以从Claude Desktop或任何其他MCP客户端连接到此聚合器端点:

{
  "mcpServers": {
    "my-aggregated-servers": {
      "url": "http://localhost:3000/mcp"
    }
  }
}

优点:

  • 通过单一连接访问所有MCP服务器
  • 无需在MCP客户端中单独配置每个服务器
  • 工具、资源和提示会自动添加前缀以避免冲突
  • 支持具有OAuth2身份验证的服务器

添加服务器

stdio服务器(本地进程)

示例:本地文件系统MCP服务器

Server name: Filesystem
Description: Local filesystem access
Command: npx
Arguments: -y @modelcontextprotocol/server-filesystem /path/to/directory

流式HTTP服务器

示例:线性MCP服务器

Server name: Linear
Description: Linear project management
URL: https://mcp.linear.app/mcp
Requires authentication: Yes
Authentication type: OAuth2

示例:带有Bearer令牌的自定义服务器

Server name: My Custom Server
Description: Custom MCP server
URL: https://api.example.com/mcp
Requires authentication: Yes
Authentication type: Bearer Token
Bearer token: your-token-here

SSE服务器(已弃用)

SSE传输已弃用。将Streamable HTTP用于基于HTTP的服务器。

如果您需要连接到仅限SSE的旧服务器:

Server name: Legacy Server
Description: Old SSE server
URL: https://legacy.example.com/mcp
Requires authentication: No

服务器配置

服务器配置存储在 mcp-servers.json 在项目根中。如果需要,您还可以手动编辑此文件。

配置示例:

[
  {
    "id": "srv_1234567890_abc123",
    "name": "Filesystem",
    "description": "Local filesystem access",
    "transport": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/username/Documents"]
    },
    "createdAt": 1234567890000,
    "lastUsed": 1234567890000
  },
  {
    "id": "srv_0987654321_xyz789",
    "name": "Linear",
    "description": "Linear project management",
    "transport": {
      "type": "streamable-http",
      "url": "https://mcp.linear.app/mcp",
      "requiresAuth": true,
      "authType": "oauth2"
    },
    "createdAt": 1234567890000,
    "lastUsed": 1234567890000
  }
]

可用的MCP服务器

以下是您可以连接的一些MCP服务器:

官方服务器

  • 文件系统: npx -y @modelcontextprotocol/server-filesystem <directory>
  • GitHub: npx -y @modelcontextprotocol/server-github
  • GitLab公司: npx -y @modelcontextprotocol/server-gitlab
  • Google 云端硬盘: npx -y @modelcontextprotocol/server-gdrive
  • Slack: npx -y @modelcontextprotocol/server-slack
  • PostgreSQL: npx -y @modelcontextprotocol/server-postgres <connection-string>

第三方服务器

  • 线性: https://mcp.linear.app/mcp (使用OAuth2的流式HTTP)

功能详解

1.主菜单

启动应用程序时,您将看到主菜单:

╔═══════════════════════════════════════════╗
║   Universal MCP Client Manager           ║
╚═══════════════════════════════════════════╝

? What would you like to do?
  🔌 Connect to a server
  ➕ Add new server
  📝 Manage servers
  🚪 Exit

2.连接到服务器

选择要连接的已配置服务器。客户将:

  • 使用配置的传输建立连接
  • 如果需要,处理身份验证
  • 显示服务器功能
  • 打开服务器交互菜单

3.服务器交互菜单

连接后,您可以:

╔═══════════════════════════════════════════╗
║   Connected to: Server Name               ║
╚═══════════════════════════════════════════╝

📦 Server: server-name v1.0.0

✨ Capabilities:
  Tools: ✓
  Resources: ✓
  Prompts: ✓

? What would you like to do?
  🔧 Browse Tools
  📚 Browse Resources
  💬 Browse Prompts
  ℹ️  View Server Info
  ← Disconnect

4.浏览和使用工具

  • 查看带有描述的可用工具
  • 查看每个工具的输入模式
  • 具有交互式参数输入的调用工具
  • 查看格式化结果

5.浏览和阅读资源

  • 使用URI列出可用资源
  • 查看资源元数据(MIME类型、描述)
  • 读取资源内容
  • 查看格式化输出

6.浏览和使用提示

  • 查看带有描述的可用提示
  • 请参阅必需和可选参数
  • 使用带有交互式参数输入的提示
  • 查看提示结果

认证

对于需要OAuth2身份验证的服务器:

  1. 客户端将自动发现OAuth2元数据
  2. 注册动态客户端(如果需要)
  3. 打开浏览器进行授权
  4. 处理回调和代币交换
  5. 将凭据安全地存储在 auth-credentials.json
  6. 自动刷新过期的令牌

项目结构

src/
├── index.ts                  # Main entry point (interactive mode)
├── start-aggregator.ts       # Aggregator server entry point
├── aggregator-server.ts      # MCP aggregator/proxy implementation
├── menu-system.ts            # Interactive menu interface
├── universal-mcp-client.ts   # Universal MCP client implementation
├── server-config.ts          # Server configuration management
├── oauth2-client.ts          # OAuth2 authentication
└── credential-storage.ts     # Credential persistence

发展

# Build the project
npm run build

# Run in development mode (rebuilds and runs)
npm run dev

安全

  • 使用PKCE进行OAuth2授权代码流
  • 凭据存储在本地 auth-credentials.json
  • 访问令牌是短暂的,会自动刷新
  • 状态参数防止CSRF攻击
  • 所有通信都使用HTTPS

许可证

麻省理工学院