MCP服务器检查工具

一个用于检查和优化MCP(Model Context Protocol)服务器上下文令牌消耗的CLI工具。

  • by dabit3
  • JavaScript
  • 本地部署
  • 4 星标
  • 更新于
在 GitHub 查看 dabit3/mcp-inspector

使用说明

mcp检查员

一个CLI工具,用于检查MCP(模型上下文协议)服务器并分析其上下文令牌成本。

MCP服务器为您的AI助手添加工具,但每个工具定义都会消耗上下文令牌。此工具可帮助您了解MCP服务器的“权重”,以便您优化设置并避免上下文膨胀。

安装

npm install -g mcp-inspector

或者直接使用npx运行:

npx mcp-inspector

用法

检查单个服务器

通过提供以下命令检查任何MCP服务器:

# Inspect the filesystem server
mcp-inspector inspect npx -y @modelcontextprotocol/server-filesystem /tmp

# Inspect a local server
mcp-inspector inspect node ./my-server.js

# Inspect with custom timeout
mcp-inspector inspect --timeout 60000 npx -y @modelcontextprotocol/server-postgres

# Get JSON output
mcp-inspector inspect --json npx -y @modelcontextprotocol/server-filesystem /tmp

扫描您的MCP配置

扫描Claude Desktop或Cline配置中配置的所有服务器:

# Auto-detect config file
mcp-inspector scan

# Specify config file
mcp-inspector scan --config ~/.config/claude/claude_desktop_config.json

# JSON output
mcp-inspector scan --json

帮助

mcp-inspector --help
mcp-inspector help-config

输出

该工具显示:

  • 服务器信息:名称和版本
  • 摘要:工具、资源和提示的数量
  • 上下文成本:每个组件的估计令牌
  • 工具故障:每个工具及其代币成本,按重量排序
  • 建议:上下文成本高时的建议

输出示例

Server Info
--------------------------------------------------
  Name:    filesystem
  Version: 1.0.0

Summary
--------------------------------------------------
  Tools:     5
  Resources: 0
  Prompts:   0

Context Cost (estimated tokens)
--------------------------------------------------
  Tools:     842
  Resources: 0
  Prompts:   0
  --------------------
  Total:     842

Tools
--------------------------------------------------
  read_file - 215 tokens
    Read the complete contents of a file from the file system
  write_file - 198 tokens
    Create a new file or overwrite an existing file with new content
  list_directory - 156 tokens
    Get a detailed listing of all files and directories in a specified path
  create_directory - 142 tokens
    Create a new directory or ensure a directory exists
  delete_file - 131 tokens
    Remove a file from the file system

配置扫描输出

Found 3 MCP server(s)

[filesystem]
Command: npx -y @modelcontextprotocol/server-filesystem /tmp
  Tools: 5, Resources: 0, Tokens: 842

[postgres]
Command: npx -y @modelcontextprotocol/server-postgres
  Tools: 3, Resources: 0, Tokens: 1.2k

[github]
Command: npx -y @modelcontextprotocol/server-github
  Tools: 12, Resources: 0, Tokens: 2.4k


Total Context Cost
--------------------------------------------------
  github                     2.4k (54%) ████████████
  postgres                   1.2k (27%) ██████
  filesystem                  842 (19%) ████
  ---------------------------------------------
  TOTAL                      4.4k

  Warning: High total context cost!
  Consider disabling unused servers or using ENABLE_TOOL_SEARCH=true

为何这很重要

您添加到Claude或其他AI助手的每个MCP工具都会消耗上下文令牌。这发生在你的谈话开始之前。如果你有多个服务器和许多工具,你可能会在工具定义上燃烧数千个令牌。

上下文膨胀的常见症状:

  • 简短有效的对话
  • API成本更高
  • 模型遗忘早期上下文

使用 mcp-inspector 致:

  1. 确定哪些服务器最重
  2. 确定您实际需要哪些工具
  3. 优化您的MCP配置

降低上下文成本的技巧

  1. 禁用未使用的服务器:如果您不经常使用服务器,请将其禁用
  2. 使用ENABLE_TOOL_SEARCH=true:Claude可以搜索工具,而不是预先加载所有定义
  3. 选择轻量级服务器:一些服务器提供更少、更集中的工具
  4. 构建自定义服务器:仅使用您需要的工具创建服务器

配置文件位置

  • 克劳德桌面(macOS): ~/Library/Application Support/Claude/claude_desktop_config.json
  • 克劳德桌面(Linux): ~/.config/claude/claude_desktop_config.json
  • Cline(VS代码): ~/.cline/mcp_settings.json

许可证

麻省理工学院