curl_request
Send HTTP requests to external APIs by specifying URL, method, headers, and data. Integrate with external services effectively using this tool within the MCP Filesystem Server.
Instructions
Execute a curl request to an external HTTP API. Allows specifying URL, method, headers, and data. Useful for integrating with external services via HTTP.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | No | Data to send in the request body | |
| followRedirects | No | Whether to follow redirects | |
| headers | No | HTTP headers to include in the request | |
| insecure | No | Whether to skip SSL certificate verification (use with caution) | |
| method | No | HTTP method | GET |
| timeout | No | Request timeout in seconds | |
| url | Yes | Full URL to send the request to |
Implementation Reference
- src/utils/curl/index.ts:42-89 (handler)The main handler function that constructs a curl command from the provided arguments and executes it using the bash_execute tool.export async function handleCurlRequest(args: CurlRequestArgs, config: Config) { try { const { url, method, headers, data, timeout, followRedirects, insecure } = args // Build curl command with appropriate options let command = `curl -X ${method} ` // Add headers Object.entries(headers).forEach(([key, value]) => { command += `-H "${key}: ${value}" ` }) // Add data if present if (data) { command += `-d '${data}' ` } // Add additional options command += `-s ` // Silent mode but show error messages command += `--connect-timeout ${timeout} ` if (followRedirects) { command += `-L ` } if (insecure) { command += `-k ` } // Add URL (should be last) command += `"${url}"` // Log the command (without sensitive headers like Authorization) const logCommand = command.replace( /-H "Authorization: [^"]*"/, '-H "Authorization: [REDACTED]"' ) await logger.debug(`Executing curl request: ${logCommand}`) // Execute the command using bash_execute const result = await handleBashExecute({ command, timeout: timeout * 1000 }, config) return result } catch (error) { await logger.error('Error executing curl request', { error }) throw error } }
- src/utils/curl/index.ts:16-35 (schema)Zod schema defining the input parameters for the curl_request tool, including URL, method, headers, body data, and various curl options.export const CurlRequestArgsSchema = z.object({ url: z.string().describe('Full URL to send the request to'), method: z .enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']) .default('GET') .describe('HTTP method'), headers: z .record(z.string(), z.string()) .optional() .default({}) .describe('HTTP headers to include in the request'), data: z.string().optional().describe('Data to send in the request body'), timeout: z.number().positive().optional().default(30).describe('Request timeout in seconds'), followRedirects: z.boolean().optional().default(true).describe('Whether to follow redirects'), insecure: z .boolean() .optional() .default(false) .describe('Whether to skip SSL certificate verification (use with caution)'), })
- src/index.ts:372-378 (registration)Tool registration in the listTools response, defining the name, description, and input schema for curl_request.name: 'curl_request', description: 'Execute a curl request to an external HTTP API. ' + 'Allows specifying URL, method, headers, and data. ' + 'Useful for integrating with external services via HTTP.', inputSchema: zodToJsonSchema(CurlRequestArgsSchema) as ToolInput, },
- src/index.ts:765-774 (registration)Dispatcher case in the main CallToolRequest handler that validates arguments using the schema and delegates to the handleCurlRequest function.case 'curl_request': { const parsed = CurlRequestArgsSchema.safeParse(a) if (!parsed.success) { throw new FileSystemError(`Invalid arguments for ${name}`, 'INVALID_ARGS', undefined, { errors: parsed.error.format(), }) } return await handleCurlRequest(parsed.data, config) }