MCP REST API测试器
一个基于 TypeScript 的 MCP 服务器,通过 Cline 实现对 REST API 的测试。此工具允许您直接从开发环境中测试和与任何 REST API 端点进行交互。
服务介绍
MCP REST API 测试器
这是一个基于 TypeScript 的 MCP 服务器,它可以通过 Cline 来测试 REST API。该工具允许你直接从开发环境中测试和与任何 REST API 端点交互。
安装
通过 Smithery 安装
要通过 Smithery 自动为 Claude Desktop 安装 REST API 测试器:
npx -y @smithery/cli install dkmaker-mcp-rest-api --client claude
手动安装
- 全局安装包:
npm install -g dkmaker-mcp-rest-api
- 配置 Cline 自定义指令:
为了确保 Cline 能够有效地使用此工具,请将以下内容添加到你的 Cline 自定义指令中(设置 > 自定义指令):
# REST API Testing Instructions
The `test_request` tool enables testing, debugging, and interacting with REST API endpoints. The tool provides comprehensive request/response information and handles authentication automatically.
## When to Use
- Testing specific API endpoints
- Debugging API responses
- Verifying API functionality
- Checking response times
- Validating request/response formats
- Testing local development servers
- Testing API sequences
- Verifying error handling
## Key Features
- Supports GET, POST, PUT, DELETE methods
- Handles authentication (Basic, Bearer, API Key)
- Normalizes endpoints automatically
- Provides detailed response information
- Configurable SSL verification and response limits
## Resources
The following resources provide detailed documentation:
- examples: Usage examples and common patterns
- response-format: Response structure and fields
- config: Configuration options and setup guide
Access these resources to understand usage, response formats, and configuration options.
## Important Notes
- Review API implementation for expected behavior
- Handle sensitive data appropriately
- Consider rate limits and API constraints
- Restart server after configuration changes
- 将服务器添加到你的 MCP 配置中:
虽然这些说明是针对 Cline 的,但该服务器应该可以与任何 MCP 实现一起工作。根据您的操作系统进行配置:
Windows
⚠️ 重要:由于已知的 Windows 路径解析问题(问题 #40),您必须使用完整路径而不是 %APPDATA%。
添加到 C:\Users\<YourUsername>\AppData\Roaming\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json:
{
"mcpServers": {
"rest-api": {
"command": "node",
"args": [
"C:/Users/<YourUsername>/AppData/Roaming/npm/node_modules/dkmaker-mcp-rest-api/build/index.js"
],
"env": {
"REST_BASE_URL": "https://api.example.com",
// Basic Auth
"AUTH_BASIC_USERNAME": "your-username",
"AUTH_BASIC_PASSWORD": "your-password",
// OR Bearer Token
"AUTH_BEARER": "your-token",
// OR API Key
"AUTH_APIKEY_HEADER_NAME": "X-API-Key",
"AUTH_APIKEY_VALUE": "your-api-key",
// SSL Verification (enabled by default)
"REST_ENABLE_SSL_VERIFY": "false", // Set to false to disable SSL verification for self-signed certificates
// Response Size Limit (optional, defaults to 10000 bytes)
"REST_RESPONSE_SIZE_LIMIT": "10000", // Maximum response size in bytes
// Custom Headers (optional)
"HEADER_X-API-Version": "2.0",
"HEADER_Custom-Client": "my-client",
"HEADER_Accept": "application/json"
}
}
}
}
macOS
添加到 ~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json:
{
"mcpServers": {
"rest-api": {
"command": "npx",
"args": [
"-y",
"dkmaker-mcp-rest-api"
],
"env": {
"REST_BASE_URL": "https://api.example.com",
// Basic Auth
"AUTH_BASIC_USERNAME": "your-username",
"AUTH_BASIC_PASSWORD": "your-password",
// OR Bearer Token
"AUTH_BEARER": "your-token",
// OR API Key
"AUTH_APIKEY_HEADER_NAME": "X-API-Key",
"AUTH_APIKEY_VALUE": "your-api-key",
// SSL Verification (enabled by default)
"REST_ENABLE_SSL_VERIFY": "false", // Set to false to disable SSL verification for self-signed certificates
// Custom Headers (optional)
"HEADER_X-API-Version": "2.0",
"HEADER_Custom-Client": "my-client",
"HEADER_Accept": "application/json"
}
}
}
}
注意:请用实际值替换环境变量。一次只配置一种身份验证方法:
- 基本身份验证(用户名/密码)
- Bearer Token(如果未配置基本身份验证)
- API 密钥(如果既未配置基本身份验证也未配置 Bearer Token)
功能
-
测试 REST API 端点,支持不同的 HTTP 方法
-
支持 GET、POST、PUT 和 DELETE 请求
-
详细的响应信息,包括状态、头部和正文
-
自定义头部:
- 通过 HEADER_* 环境变量设置全局头部
- 大小写不敏感的前缀 (HEADER_, header_, HeAdEr_)
- 保持头部名称的大小写
- 基于优先级的应用(每请求 > 认证 > 自定义)
-
对 POST/PUT 方法的支持请求体处理
-
响应大小管理:
- 自动限制响应大小(默认:10KB/10000 字节)
- 通过 REST_RESPONSE_SIZE_LIMIT 环境变量配置大小限制
- 当响应超出限制时提供清晰的截断元数据
- 在仅截断正文内容的同时保留响应结构
-
SSL 证书验证:
- 默认启用以确保安全操作
- 可为自签名证书或开发环境禁用
- 通过 REST_ENABLE_SSL_VERIFY 环境变量控制
-
多种认证方法:
- 基本认证(用户名/密码)
- Bearer Token 认证
- API Key 认证(自定义头部)
使用示例
安装并配置完成后,您可以使用 Cline 中的 REST API 测试器来测试您的 API 端点:
// Test a GET endpoint
use_mcp_tool('rest-api', 'test_request', {
"method": "GET",
"endpoint": "/users"
});
// Test a POST endpoint with body
use_mcp_tool('rest-api', 'test_request', {
"method": "POST",
"endpoint": "/users",
"body": {
"name": "John Doe",
"email": "john@example.com"
}
});
// Test with custom headers
use_mcp_tool('rest-api', 'test_request', {
"method": "GET",
"endpoint": "/products",
"headers": {
"Accept-Language": "en-US",
"X-Custom-Header": "custom-value"
}
});
开发
- 克隆仓库:
git clone https://github.com/zenturacp/mcp-rest-api.git
cd mcp-rest-api
- 安装依赖项:
npm install
- 构建项目:
npm run build
对于带有自动重建的开发:
npm run watch
许可证
本项目根据 MIT 许可证发布 - 详情请参阅 LICENSE 文件。