HTTP请求服务器

一个提供curl功能的MCP服务器,允许AI助手直接从其环境发起HTTP请求。

  • by 247arjun
  • JavaScript
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 247arjun/mcp-curl

使用说明

用于Curl的MCP服务器

提供curl功能的模型上下文协议(MCP)服务器,允许AI助手直接从其环境中发出HTTP请求。

特性

  • HTTP方法:支持GET、POST、PUT、DELETE请求
  • 文件下载:使用curl下载文件
  • 高级选项:自定义标头、超时、重定向等
  • JSON支持:用于POST/PUT请求的内置JSON数据处理
  • 用户代理:自定义用户代理字符串支持
  • 安全:通过输入验证安全执行子流程

安装

方法1:NPM安装(推荐)

# Install globally
npm install -g @247arjun/mcp-curl

# Or install locally in your project
npm install @247arjun/mcp-curl

方法2:来源

# Clone the repository
git clone https://github.com/247arjun/mcp-curl.git
cd mcp-curl

# Install dependencies
npm install

# Build the project
npm run build

# Optional: Link globally
npm link

方法3:直接从GitHub

# Install directly from GitHub
npm install -g git+https://github.com/247arjun/mcp-curl.git

配置

Claude桌面设置

添加到您的Claude Desktop配置文件中:

地点:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • 窗户: %APPDATA%/Claude/claude_desktop_config.json

配置:

{
  "mcpServers": {
    "mcp-curl": {
      "command": "mcp-curl",
      "args": []
    }
  }
}

替代方案:使用npx(无需全局安装)

{
  "mcpServers": {
    "mcp-curl": {
      "command": "npx",
      "args": ["@247arjun/mcp-curl"]
    }
  }
}

地方发展设置

{
  "mcpServers": {
    "mcp-curl": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-curl/build/index.js"]
    }
  }
}

添加配置后,重新启动Claude Desktop以加载MCP服务器。

可用工具

1. curl_get

发出HTTP GET请求。

参数:

  • url (string):向其发出GET请求的URL
  • headers (数组,可选):HTTP标头格式为“Header:Value”
  • timeout (数字,可选):请求超时(秒)
  • follow_redirects (布尔值,可选):是否遵循重定向
  • user_agent (string,可选):自定义用户代理字符串

例子:

{
  "url": "https://api.example.com/data",
  "headers": ["Authorization: Bearer token"],
  "timeout": 30,
  "follow_redirects": true,
  "user_agent": "MyApp/1.0"
}

2. curl_post

使用数据发出HTTP POST请求。

参数:

  • url (string):向其发出POST请求的URL
  • json_data (object,可选):作为POST数据发送的JSON对象
  • data (string,可选):POST请求正文中要发送的数据
  • headers (数组,可选):HTTP标头
  • content_type (字符串,可选):Content-Type标头
  • timeout (数字,可选):请求超时(秒)
  • follow_redirects (布尔值,可选):是否遵循重定向

例子:

{
  "url": "https://api.example.com/data",
  "json_data": {"key": "value"},
  "headers": ["Content-Type: application/json"]
}

3. curl_put

发出HTTP PUT请求。

参数:

  • url (string):向其发出PUT请求的URL
  • json_data (object,可选):作为PUT数据发送的JSON对象
  • data (string,可选):在PUT请求体中发送的数据
  • headers (数组,可选):HTTP标头
  • content_type (字符串,可选):Content-Type标头
  • timeout (数字,可选):请求超时(秒)
  • follow_redirects (布尔值,可选):是否遵循重定向

例子:

{
  "url": "https://api.example.com/data/123",
  "data": "raw data",
  "content_type": "text/plain"
}

4. curl_delete

发出HTTP DELETE请求。

参数:

  • url (string):向其发出DELETE请求的URL
  • headers (数组,可选):HTTP标头
  • timeout (数字,可选):请求超时(秒)
  • follow_redirects (布尔值,可选):是否遵循重定向

例子:

{
  "url": "https://api.example.com/data/123",
  "headers": ["Authorization: Bearer token"]
}

5. curl_download

下载文件。

参数:

  • url (string):要下载的文件的URL
  • output_filename (字符串,可选):输出文件名
  • resume (布尔值,可选):如果文件存在,则恢复部分下载
  • timeout (数字,可选):请求超时(秒)
  • follow_redirects (布尔值,可选):是否遵循重定向

例子:

{
  "url": "https://example.com/file.zip",
  "output_filename": "downloaded_file.zip",
  "resume": true
}

6. curl_advanced

使用自定义参数执行curl(高级用户)。

参数:

  • args (array):curl参数数组(不包括'curl'本身)

例子:

{
  "args": ["-X", "PATCH", "-H", "Content-Type: application/json", "-d", "{\"status\":\"updated\"}", "https://api.example.com/items/1"]
}

使用示例

发出GET请求

{
  "tool": "curl_get",
  "url": "https://api.example.com/users",
  "headers": ["Authorization: Bearer your-token"]
}

POST JSON数据

{
  "tool": "curl_post",
  "url": "https://api.example.com/users",
  "json_data": {
    "name": "John Doe",
    "email": "john@example.com"
  }
}

下载文件

{
  "tool": "curl_download",
  "url": "https://example.com/file.zip",
  "output_filename": "download.zip"
}

发展

先决条件

  • Node.js 18.0.0或更高版本
  • npm包管理器
  • curl命令行工具

建筑

npm run build

测试

手动测试服务器:

echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | node build/index.js

运行测试:

npm test

代码检查

npm run lint
npm run lint:fix

项目结构

mcp-curl/
├── src/
│   └── index.ts          # Main server implementation
├── build/
│   └── index.js          # Compiled JavaScript
├── test/
│   └── basic.test.js     # Basic functionality tests
├── examples/
│   └── test-server.js    # Example usage
├── .github/
│   └── workflows/
│       └── ci.yml        # CI/CD pipeline
├── package.json          # Project configuration
├── tsconfig.json         # TypeScript configuration
├── .eslintrc.json        # ESLint configuration
├── LICENSE               # MIT License
├── DEPLOYMENT.md         # Deployment guide
├── CONTRIBUTING.md       # Contribution guidelines
├── CHANGELOG.md          # Version history
└── README.md             # This file

验证

测试服务器是否正常工作:

# Test the built server
node build/index.js

# Should show: "Curl MCP Server running on stdio"
# Press Ctrl+C to exit

故障排除

常见问题

  1. “找不到命令”错误

    • 确保mcp-curl已全局安装: npm install -g @247arjun/mcp-curl
    • 或者使用npx: "command": "npx", "args": ["@247arjun/mcp-curl"]
  2. “权限被拒绝”错误

    • 检查文件权限: chmod +x build/index.js
    • 重建项目: npm run build
  3. MCP服务器未出现在Claude中

    • 验证配置文件中的JSON语法
    • 完全重新启动克劳德桌面
    • 检查命令路径是否正确
  4. “找不到curl命令”

    • 在您的系统上安装curl(通常预装在macOS/Linux上)
    • Windows用户:通过软件包管理器安装或从curl网站下载

调试

通过设置环境变量启用详细日志记录:

# For development
DEBUG=1 node build/index.js

# Test with sample input
echo '{"jsonrpc": "2.0", "method": "initialize", "params": {}}' | node build/index.js

安全说明

  • 对所有curl参数进行输入验证和清理
  • 高级模式下的受限文件操作
  • 使用spawn而不是shell安全执行子流程
  • 不执行任意shell命令
  • 使用Zod模式进行输入验证