Skip to main content
Glama

test_api

Execute API tests by sending requests with configurable parameters, headers, and body content to validate endpoints in development environments.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectIdYesProject ID
apiIdYesAPI ID
headersNoRequest headers
queryParamsNoQuery parameters
pathParamsNoPath parameters
bodyNoRequest body

Implementation Reference

  • Core handler function that implements the API testing logic: fetches API details, constructs URL with path params, executes axios request, measures response time, and handles errors.
    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 type definitions for ApiTestRequest (input) and ApiTestResponse (output) used by the testApi handler.
    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 runtime schema for validating inputs to the test_api MCP tool.
    { 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") },
  • Registration of the "test_api" MCP tool, including schema, description, and thin wrapper handler that delegates to eolinkService.testApi.
    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) }] }; } );

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