UNPKG

@edjl/rest-mcp

Version:

REST API tools for MCP (Model Context Protocol)

50 lines 1.81 kB
import { z } from 'zod'; import { makeRequest } from '../utils/request.js'; export const getTool = { name: 'rest_get', description: 'Make a GET request to an API endpoint', inputSchema: z.object({ url: z.string().describe('The URL to send the GET request to'), headers: z.record(z.string()).optional().describe('Additional headers to include'), withoutAuthorization: z.boolean().optional().describe('Skip authorization header'), 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: 'GET', headers: params.headers, withoutAuthorization: params.withoutAuthorization, 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(`[GET Tool Error]`, error); return { content: [ { type: 'text', text: `Error: ${error.message}` } ], isError: true }; } }, }; //# sourceMappingURL=get.js.map