mcp测试mcp
](https://www.python.org/downloads/) 
帮助AI助手测试其他MCP服务器的MCP服务器。它提供了连接到目标MCP服务器、发现其功能、执行工具、读取资源和测试提示的工具,所有这些都是通过适当的MCP协议通信实现的。
特性
- 连接管理:连接到任何MCP服务器(STDIO或HTTP传输),自动检测协议,跟踪连接状态
- 工具测试:列出所有具有完整输入模式的工具,使用任意参数调用工具,获取详细的执行结果
- 资源测试:列出所有包含元数据、读取文本和二进制内容的资源
- 快速测试:列出所有带有参数模式的提示,获取带有自定义参数的呈现提示
- LLM集成:使用实际的LLM推理端到端执行提示,支持模板变量和JSON提取
安装
先决条件: Node.js 16+和Python 3.11+
选择您的AI编码工具:
Claude Desktop / Claude Code
配置文件位置:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - 视窗:
%APPDATA%/Claude/claude_desktop_config.json
配置:
{
"mcpServers": {
"mcp-test-mcp": {
"command": "npx",
"args": ["-y", "mcp-test-mcp"]
}
}
}或者使用Claude Code CLI:
claude mcp add mcp-test-mcp -- npx -y mcp-test-mcpCursor
配置文件位置:
- 全球:
~/.cursor/mcp.json - 项目:
.cursor/mcp.json
或通过以下方式访问: File → 偏好→ 光标设置→ MCP
配置:
{
"mcpServers": {
"mcp-test-mcp": {
"command": "npx",
"args": ["-y", "mcp-test-mcp"]
}
}
}Windsurf
配置文件位置: ~/.codeium/windsurf/mcp_config.json
或通过以下方式访问: 风帆设置→ 级联→ 插件
配置:
{
"mcpServers": {
"mcp-test-mcp": {
"command": "npx",
"args": ["-y", "mcp-test-mcp"]
}
}
}VS Code (GitHub Copilot)
需要VS代码1.99+ chat.agent.enabled 设置已启用。
配置文件位置:
- 工作区:
.vscode/mcp.json - 全球:运行
MCP: Open User Configuration从命令选项板
配置:
{
"servers": {
"mcpTestMcp": {
"command": "npx",
"args": ["-y", "mcp-test-mcp"]
}
}
}注:VS代码使用 servers 而不是 mcpServers 并推荐camelCase命名。
OpenAI Codex CLI
配置文件位置: ~/.codex/config.toml
通过CLI添加:
codex mcp add mcp-test-mcp -- npx -y mcp-test-mcp或者手动添加到config.toml:
[mcp_servers.mcp-test-mcp]
command = "npx"
args = ["-y", "mcp-test-mcp"]With LLM Integration (Optional)
要使用 execute_prompt_with_llm 工具,将环境变量添加到您的配置中:
JSON格式(Claude、Cursor、Windsurf、VS Code):
{
"mcpServers": {
"mcp-test-mcp": {
"command": "npx",
"args": ["-y", "mcp-test-mcp"],
"env": {
"LLM_URL": "https://your-llm-endpoint.com/v1",
"LLM_MODEL_NAME": "your-model-name",
"LLM_API_KEY": "your-api-key"
}
}
}
}TOML格式(Codex):
[mcp_servers.mcp-test-mcp]
command = "npx"
args = ["-y", "mcp-test-mcp"]
[mcp_servers.mcp-test-mcp.env]
LLM_URL = "https://your-llm-endpoint.com/v1"
LLM_MODEL_NAME = "your-model-name"
LLM_API_KEY = "your-api-key"Local Development
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install from PyPI
pip install mcp-test-mcp
# Or install from source
git clone https://github.com/example/mcp-test-mcp
cd mcp-test-mcp
pip install -e ".[dev]"命令行选项
服务器支持不同部署场景的多种传输方式:
# Default: stdio transport (for Claude Desktop/Code)
mcp-test-mcp
# Explicit stdio
mcp-test-mcp --transport stdio
# HTTP transport for web deployments
mcp-test-mcp --transport streamable-http
mcp-test-mcp --transport streamable-http --host 0.0.0.0 --port 8080
# Legacy SSE transport (for backward compatibility)
mcp-test-mcp --transport sse --port 9000选项:
| 标志 | 简短 | 描述 | 默认 |
|---|---|---|---|
--transport | -t | 运输类型: stdio, streamable-http, sse | stdio |
--host | -H | 要绑定的主机(仅限HTTP传输) | 127.0.0.1 |
--port | -p | 要绑定的端口(仅限HTTP传输) | 8000 |
与npx一起使用:
# HTTP server via npx
npx -y mcp-test-mcp --transport streamable-http --port 8080快速开始
配置后,通过自然对话测试MCP服务器:
- 连接: “连接到我的MCP服务器/path/to/server”
- 使用身份验证连接: “连接到https://api.example.com/mcp使用身份验证令牌sk-。.."
- 通过npx连接: “使用带有args-y@modelcontextprotocol/server-everything的npx命令连接到服务器”
- 发现: “它有什么工具?”
- 测试: “用消息‘Hello’调用回显工具”
- 状态: “连接状态如何?”
- 断开连接: “断开与服务器的连接”
可用工具
连接管理
- connect_to_server:连接到目标MCP服务器。支持多种传输模式和身份验证:
- 自动检测:传递HTTP的URL或stdio的文件路径 - 显式stdio:使用 command/args 对于npm/pip包(例如。, command="npx", args=["-y", "some-package"]) - 认证:通过以下方式持有代币 auth="your-token" 或通过OAuth auth="oauth" - 标头:通过自定义HTTP标头 headers 参数
- 断开:关闭活动连接
- get_connection_status:检查连接状态和统计信息
工具测试
- list_tools:获取具有完整模式的所有工具
- call_tool:使用参数执行工具
资源测试
- 列表_资源:获取所有包含元数据的资源
- read_resource:按URI读取资源内容
快速测试
- list_prompts:获取所有带有参数模式的提示
- get_prompt:使用参数获取渲染提示
- execute_prompt_with_llm:使用实际LLM推理执行提示
效用
- 健康检查:验证服务器是否正在运行
- 拼:测试连接性(返回“pong”)
- 回声:回复一条消息
- 添加:添加两个数字
环境变量
运输配置
这些环境变量配置服务器传输。CLI参数优先。
| 变量 | 描述 | 默认值 |
|---|---|---|
MCP_TEST_TRANSPORT | 运输类型: stdio, streamable-http, sse | stdio |
MCP_TEST_HOST | 要绑定的主机(仅限HTTP传输) | 127.0.0.1 |
MCP_TEST_PORT | 要绑定的端口(仅限HTTP传输) | 8000 |
优先: CLI参数>环境变量>默认值
核心
- MCP_TEST_LOG_LEVEL:日志记录级别(调试、信息、警告、错误)。默认值:信息
- MCP_TEST_CONNECT_TIMEOUT:连接超时(秒)。默认值:30.0
LLM集成(用于execute_prompt_with_LLM)
- LLM网址:LLM API终结点URL
- LLM_MODEL_NAME:型号名称
- LLM_API_KEY(LLM_API_密钥):API密钥
发展
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run with coverage
pytest --cov=mcp_test_mcp --cov-report=html
# Format and lint
black src/ tests/
ruff check src/ tests/
mypy src/容器部署
对于在容器(例如OpenShift、Kubernetes)中部署mcp-test-mcp:
FROM registry.redhat.io/ubi9/python-311:latest
WORKDIR /app
# Install mcp-test-mcp
RUN pip install --no-cache-dir mcp-test-mcp
# Expose HTTP port
EXPOSE 8000
# Run with streamable-http transport
CMD ["mcp-test-mcp", "--transport", "streamable-http", "--host", "0.0.0.0", "--port", "8000"]或者使用环境变量:
# kubernetes deployment snippet
env:
- name: MCP_TEST_TRANSPORT
value: "streamable-http"
- name: MCP_TEST_HOST
value: "0.0.0.0"
- name: MCP_TEST_PORT
value: "8000"文档
- 测试指导 -完整的LLM集成示例指南
许可证
MIT许可证-请参阅 许可证 了解详情。
