post_data
Send HTTP POST requests with data payloads to specified URLs for API integration and data transmission.
Instructions
Send data via HTTP POST request
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL to send POST request to | |
| data | Yes | Data to send in POST body |
Implementation Reference
- Handler function for the 'post_data' tool that performs an HTTP POST request with the provided data to the specified URL, returns response status, headers, and body, or error details if failed.case "post_data": { const url = request.params.arguments?.url as string; const data = request.params.arguments?.data; if (!url || !data) { throw new Error("URL and data are required"); } try { const response = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(data), }); const responseText = await response.text(); const headers = Object.fromEntries(response.headers.entries()); return { content: [ { type: "text", text: `HTTP ${response.status} ${response.statusText}\n\nHeaders:\n${JSON.stringify(headers, null, 2)}\n\nResponse:\n${responseText}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error posting data: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }
- Schema definition for the 'post_data' tool including name, description, and input schema requiring 'url' (string) and 'data' (object).{ name: "post_data", description: "Send data via HTTP POST request", inputSchema: { type: "object", properties: { url: { type: "string", description: "URL to send POST request to", }, data: { type: "object", description: "Data to send in POST body", }, }, required: ["url", "data"], }, },
- src/examples/single-node-server.ts:26-63 (registration)Registration of available tools list including 'post_data' in the ListToolsRequestHandler.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "fetch_url", description: "Fetch content from a URL via HTTP GET request", inputSchema: { type: "object", properties: { url: { type: "string", description: "URL to fetch", }, }, required: ["url"], }, }, { name: "post_data", description: "Send data via HTTP POST request", inputSchema: { type: "object", properties: { url: { type: "string", description: "URL to send POST request to", }, data: { type: "object", description: "Data to send in POST body", }, }, required: ["url", "data"], }, }, ], }; });