curl_put
Send HTTP PUT requests using curl to update or replace resources on a server. Supports JSON data, custom headers, redirects, and timeouts for seamless API interactions. Ideal for modifying remote data.
Instructions
Make an HTTP PUT request using curl
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content_type | No | Content-Type header (will be added automatically for JSON data) | |
| data | No | Data to send in the PUT request body | |
| follow_redirects | No | Whether to follow redirects | |
| headers | No | Optional HTTP headers in the format 'Header: Value' | |
| json_data | No | JSON object to send as PUT data | |
| timeout | No | Request timeout in seconds | |
| url | Yes | The URL to make the PUT request to |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"content_type": {
"description": "Content-Type header (will be added automatically for JSON data)",
"type": "string"
},
"data": {
"description": "Data to send in the PUT request body",
"type": "string"
},
"follow_redirects": {
"default": false,
"description": "Whether to follow redirects",
"type": "boolean"
},
"headers": {
"description": "Optional HTTP headers in the format 'Header: Value'",
"items": {
"type": "string"
},
"type": "array"
},
"json_data": {
"additionalProperties": {},
"description": "JSON object to send as PUT data",
"type": "object"
},
"timeout": {
"description": "Request timeout in seconds",
"type": "number"
},
"url": {
"description": "The URL to make the PUT request to",
"type": "string"
}
},
"required": [
"url"
],
"type": "object"
}
Implementation Reference
- src/index.ts:224-289 (handler)The main handler function for the 'curl_put' tool. Constructs curl command arguments for an HTTP PUT request, handles JSON/data payloads, headers, redirects, and timeout options, executes the command using the shared executeCurl helper, and formats the response.async ({ url, data, json_data, headers, content_type, follow_redirects, timeout }) => { const args = ['curl']; // Add the URL args.push(url); // Add PUT method args.push('-X', 'PUT'); // Handle data if (json_data) { args.push('-d', JSON.stringify(json_data)); if (!content_type) { content_type = 'application/json'; } } else if (data) { args.push('-d', data); } // Add content type header if (content_type) { args.push('-H', `Content-Type: ${content_type}`); } // Add additional headers if provided if (headers && headers.length > 0) { headers.forEach(header => { args.push('-H', header); }); } // Add follow redirects option if (follow_redirects) { args.push('-L'); } // Add timeout if provided if (timeout) { args.push('--max-time', timeout.toString()); } // Include response headers in output args.push('-i'); try { const result = await executeCurl(args); return { content: [ { type: "text", text: `Exit Code: ${result.exitCode}\n\nResponse:\n${result.stdout}${result.stderr ? `\n\nErrors:\n${result.stderr}` : ''}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error executing curl: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
- src/index.ts:215-223 (schema)Input schema validation using Zod for the curl_put tool parameters: URL (required), optional data/JSON payload, headers, content-type, follow redirects, and timeout.{ url: z.string().describe("The URL to make the PUT request to"), data: z.string().optional().describe("Data to send in the PUT request body"), json_data: z.record(z.any()).optional().describe("JSON object to send as PUT data"), headers: z.array(z.string()).optional().describe("Optional HTTP headers in the format 'Header: Value'"), content_type: z.string().optional().describe("Content-Type header (will be added automatically for JSON data)"), follow_redirects: z.boolean().optional().default(false).describe("Whether to follow redirects"), timeout: z.number().optional().describe("Request timeout in seconds"), },
- src/index.ts:212-214 (registration)Registration of the 'curl_put' tool on the MCP server, specifying name and description.server.tool( "curl_put", "Make an HTTP PUT request using curl",
- src/index.ts:23-62 (helper)Shared helper function to safely spawn and execute curl subprocess, capturing stdout/stderr/exit code. Used by all curl tools including curl_put.async function executeCurl(args: string[]): Promise<{ stdout: string; stderr: string; exitCode: number }> { return new Promise((resolve) => { // Ensure we're only calling curl with safe arguments if (!args.includes('curl')) { args.unshift('curl'); } const child = spawn('curl', args.slice(1), { stdio: ['pipe', 'pipe', 'pipe'], shell: false, }); let stdout = ''; let stderr = ''; child.stdout.on('data', (data) => { stdout += data.toString(); }); child.stderr.on('data', (data) => { stderr += data.toString(); }); child.on('close', (code) => { resolve({ stdout, stderr, exitCode: code || 0, }); }); child.on('error', (error) => { resolve({ stdout: '', stderr: error.message, exitCode: 1, }); }); }); }