Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
content_typeNoContent-Type header (will be added automatically for JSON data)
dataNoData to send in the PUT request body
follow_redirectsNoWhether to follow redirects
headersNoOptional HTTP headers in the format 'Header: Value'
json_dataNoJSON object to send as PUT data
timeoutNoRequest timeout in seconds
urlYesThe URL to make the PUT request to

Implementation Reference

  • 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)}`, }, ], }; } }
  • 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",
  • 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, }); }); }); }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/247arjun/mcp-curl'

If you have feedback or need assistance with the MCP directory API, please join our Discord server