Skip to main content
Glama

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
NameRequiredDescriptionDefault
apiIdYesAPI ID
bodyNoRequest body
headersNoRequest headers
pathParamsNoPath parameters
projectIdYesProject ID
queryParamsNoQuery parameters

Implementation Reference

  • 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) }] }; } );
  • 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; } }
  • 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; }
  • 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") },

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/scarqin/mcp-apikit'

If you have feedback or need assistance with the MCP directory API, please join our Discord server