Curl命令执行服务器

一个提供安全Curl命令执行功能的模型上下文协议(MCP)服务器,支持GET/POST请求、文件下载和自定义命令,适用于终端集成和自动化场景。

  • by neeraj15022001
  • JavaScript
  • 本地部署
  • 3 星标
  • 更新于
在 GitHub 查看 neeraj15022001/curl-mcp-server

使用说明

卷曲MCP服务器

一种模型上下文协议(MCP)服务器,通过终端shell集成提供安全的curl命令执行功能。

特性

  • GET请求:使用自定义标头执行HTTP GET请求
  • POST请求:发送具有可配置内容类型的POST数据
  • 自定义命令:执行具有安全限制的自定义curl命令
  • 文件下载:下载文件并获取元数据
  • 安全:内置防止危险操作的保护措施
  • 超时:可配置的请求超时(最多30秒)
  • 输出限制:防止输出尺寸过大

安装

# Clone or create the project directory
mkdir curl-mcp-server
cd curl-mcp-server

# Install dependencies
npm install @modelcontextprotocol/sdk
npm install -D typescript @types/node tsx

# Create src directory and add the TypeScript code
mkdir src
# Place the server code in src/index.ts

# Build the project
npm run build

先决条件

  • Node.js 18+
  • curl PATH中可用的命令
  • TypeScript编译器

可用工具

1.curl_get

执行HTTP GET请求。

参数:

  • url (必填):请求的URL
  • headers (可选):“Key:Value”格式的标头数组
  • timeout (可选):超时秒数(默认值:10,最大值:30)
  • follow_redirects (可选):遵循HTTP重定向(默认:true)

例子:

{
  "url": "https://api.github.com/user",
  "headers": ["Authorization: token YOUR_TOKEN"],
  "timeout": 15
}

2.curl_post

执行HTTP POST请求。

参数:

  • url (必填):请求的URL
  • data (必填):要发送的POST数据
  • content_type (可选):Content-Type标头(默认:“application/json”)
  • headers (可选):附加标头数组
  • timeout (可选):超时秒数(默认值:10,最大值:30)

例子:

{
  "url": "https://api.example.com/data",
  "data": "{\"key\": \"value\"}",
  "content_type": "application/json",
  "headers": ["Authorization: Bearer TOKEN"]
}

3.curl_custom

完全控制执行自定义curl命令。

参数:

  • args (必需):curl参数数组(不带'curl'命令)
  • timeout (可选):超时秒数(默认值:10,最大值:30)

例子:

{
  "args": ["-X", "PUT", "-H", "Content-Type: application/json", "-d", "{\"status\": \"updated\"}", "https://api.example.com/resource/123"],
  "timeout": 20
}

4.curl_download

下载文件并获取元数据。

参数:

  • url (必填):下载网址
  • output_file (可选):输出文件路径
  • timeout (可选):超时秒数(默认值:30,最大值:30)

例子:

{
  "url": "https://example.com/file.pdf",
  "output_file": "/tmp/downloaded_file.pdf"
}

安全功能

  • URL验证:只允许使用HTTP和HTTPS URL
  • 参数筛选:危险卷曲标志被阻挡
  • 输出限制:最大1MB输出大小,以防止内存问题
  • 超时:所有请求都有可配置的超时
  • 安全默认值:所有参数的合理默认值

受阻操作

为了安全起见,以下curl操作受到限制:

  • 文件上传(--upload-file, --form)
  • 配置文件加载(--config)
  • 无限制的文件输出(通过特定工具控制)
  • 二进制数据上传
  • 跟踪文件生成

使用示例

基本GET请求

# Through MCP client
{
  "tool": "curl_get",
  "arguments": {
    "url": "https://httpbin.org/get"
  }
}

使用JSON数据进行POST

{
  "tool": "curl_post",
  "arguments": {
    "url": "https://httpbin.org/post",
    "data": "{\"message\": \"hello world\"}",
    "content_type": "application/json"
  }
}

自定义头

{
  "tool": "curl_get",
  "arguments": {
    "url": "https://api.github.com/user",
    "headers": [
      "Authorization: token ghp_xxxxxxxxxxxx",
      "User-Agent: MyApp/1.0"
    ]
  }
}

运行服务器

# Development mode
npm run dev

# Production mode
npm run build
npm start

与Claude Desktop集成

添加到您的Claude Desktop配置中:

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

错误处理

服务器为以下对象提供详细的错误消息:

  • URL无效
  • 超时错误
  • 卷曲执行失败
  • 超出输出大小限制
  • 违反安全规定

局限性

  • 最大请求超时:30秒
  • 最大输出大小:1MB
  • 仅支持HTTP/HTTPS协议
  • 为了安全起见,某些卷曲标志被阻止

贡献

请随时提交问题和增强请求。确保彻底测试任何更改,特别是与安全相关的修改。

许可证

MIT许可证-有关详细信息,请参阅许可证文件。