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) 
          }]
        };
      }
    );
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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