REST API测试工具

一个基于TypeScript的MCP服务器,用于通过Claude、Cline等MCP客户端测试REST API端点,支持多种HTTP方法和认证方式。

  • by dkmaker
  • JavaScript
  • 本地部署
  • 103 星标
  • 更新于
在 GitHub 查看 dkmaker/mcp-rest-api

使用说明

MCP REST API测试仪

一个基于TypeScript的MCP服务器,可以通过Claude、Cline和其他MCP客户端测试REST API。该工具允许您直接从开发环境中测试任何REST API端点并与之交互。

安装

全局安装软件包:

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, PATCH 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路径解析的已知问题(问题#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"
      }
    }
  }
}

注意:将环境变量替换为实际值。一次只能配置一种身份验证方法:

  1. 基本身份验证(用户名/密码)
  2. 承载令牌(如果未配置基本身份验证)
  3. API密钥(如果既没有配置基本认证也没有配置承载令牌)

特性

  • 使用不同的HTTP方法测试REST API端点

  • 支持GET、POST、PUT、DELETE和PATCH请求

  • 详细的响应信息,包括状态、标头和正文

  • 自定义标题:

    • 通过HEADER_*环境变量发送全局标头
    • 不区分大小写的前缀(HEADER_、HEADER__、HEADER_)
    • 标题名称的大小写保留
    • 基于优先级的应用程序(按请求>身份验证>自定义)
  • 请求POST/PUT方法的正文处理

  • 响应大小管理:

    • 自动响应大小限制(默认值:10KB/10000字节)
    • 通过REST_RESPONSE_size_limit环境变量配置大小限制
    • 当响应超过限制时清除截断元数据
    • 保留响应结构,同时仅截断正文内容
  • SSL证书验证:

    • 默认情况下启用安全操作
    • 可以对自签名证书或开发环境禁用
    • 通过REST_ENABLE-SSL_VERIFY环境变量进行控制
  • 多种身份验证方法:

    • 基本身份验证(用户名/密码)
    • 承载令牌身份验证
    • API密钥验证(自定义标头)

使用示例

安装并配置后,您可以通过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"
  }
});

发展

  1. 克隆存储库:
git clone https://github.com/zenturacp/mcp-rest-api.git
cd mcp-rest-api
  1. 安装依赖项:
npm install
  1. 构建项目:
npm run build

对于自动重建的开发:

npm run watch

许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。