test_api
Validate API integration by sending structured requests with specified project ID, API ID, headers, query, path parameters, and body using MCP-APIKit.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiId | Yes | API ID | |
| body | No | Request body | |
| headers | No | Request headers | |
| pathParams | No | Path parameters | |
| projectId | Yes | Project ID | |
| queryParams | No | Query parameters |
Implementation Reference
- src/services/mcpServer.ts:121-140 (registration)Registers the 'test_api' tool with Zod input schema, thin wrapper handler that delegates to eolinkService.testApi, and formats response as MCP content.this.server.tool( "test_api", { projectId: z.string().describe("Project ID"), apiId: z.string().describe("API ID"), headers: z.record(z.string()).optional().describe("Request headers"), queryParams: z.record(z.string()).optional().describe("Query parameters"), pathParams: z.record(z.string()).optional().describe("Path parameters"), body: z.any().optional().describe("Request body") }, async (params) => { const response = await eolinkService.testApi(params); return { content: [{ type: "text", text: JSON.stringify({ response }, null, 2) }] }; } );
- src/services/eolinkService.ts:113-167 (handler)Main handler function that executes the API test: fetches API details, substitutes path params, performs HTTP request via axios, handles errors, measures response time, and returns structured response.async testApi(request: ApiTestRequest): Promise<ApiTestResponse> { try { // First, get the API details to construct the proper request const api = await this.getApi(request.projectId, request.apiId); if (!api) { throw new Error(`API ${request.apiId} not found in project ${request.projectId}`); } // Construct the URL with path parameters let url = api.path; if (request.pathParams) { Object.entries(request.pathParams).forEach(([key, value]) => { url = url.replace(`{${key}}`, encodeURIComponent(value)); }); } // Start timing the request const startTime = Date.now(); // Make the request const response = await axios({ method: api.method, url: url, headers: { ...this.getHeaders(), ...request.headers }, params: request.queryParams, data: request.body, }); // Calculate response time const responseTime = Date.now() - startTime; // Return formatted response return { statusCode: response.status, headers: response.headers as Record<string, string>, body: response.data, responseTime, }; } catch (error: any) { console.error(`Error testing API ${request.apiId}:`, error); // Handle Axios error response if (error.response) { return { statusCode: error.response.status, headers: error.response.headers as Record<string, string>, body: error.response.data, responseTime: 0, }; } // Handle other errors throw error; } }
- src/models/api.ts:70-86 (schema)TypeScript interfaces defining the input (ApiTestRequest) and output (ApiTestResponse) schemas used by the testApi handler.// API test request model export interface ApiTestRequest { projectId: string; apiId: string; headers?: Record<string, string>; queryParams?: Record<string, string>; pathParams?: Record<string, string>; body?: any; } // API test response model export interface ApiTestResponse { statusCode: number; headers: Record<string, string>; body: any; responseTime: number; }
- src/services/mcpServer.ts:123-130 (schema)Zod schema for validating tool inputs, matching the ApiTestRequest structure.{ projectId: z.string().describe("Project ID"), apiId: z.string().describe("API ID"), headers: z.record(z.string()).optional().describe("Request headers"), queryParams: z.record(z.string()).optional().describe("Query parameters"), pathParams: z.record(z.string()).optional().describe("Path parameters"), body: z.any().optional().describe("Request body") },