UNPKG

@edjl/rest-mcp

Version:

REST API tools for MCP (Model Context Protocol)

54 lines 2.09 kB
import { z } from 'zod'; import { makeRequest } from '../utils/request.js'; export const putTool = { name: 'rest_put', description: 'Make a PUT request to an API endpoint', inputSchema: z.object({ url: z.string().describe('The URL to send the PUT request to'), body: z.any().optional().describe('The request body (will be JSON stringified)'), headers: z.record(z.string()).optional().describe('Additional headers to include'), withoutAuthorization: z.boolean().optional().describe('Skip authorization header'), contentType: z.string().optional().describe('Content-Type header (default: application/json)'), queryParams: z.record(z.any()).optional().describe('Query parameters to append to URL'), }), handler: async (params, authToken) => { try { const result = await makeRequest({ url: params.url, method: 'PUT', body: params.body, headers: params.headers, withoutAuthorization: params.withoutAuthorization, contentType: params.contentType, queryParams: params.queryParams, }, authToken); // Return in MCP format return { content: [ { type: 'text', text: JSON.stringify({ response: result.data, status: result.status, statusText: result.statusText, headers: result.headers, }, null, 2) } ] }; } catch (error) { console.error(`[PUT Tool Error]`, error); return { content: [ { type: 'text', text: `Error: ${error.message}` } ], isError: true }; } }, }; //# sourceMappingURL=put.js.map