Skip to main content
Glama

send_request_to_gateway

Send one or multiple requests to the APISIX gateway for processing, including path, method, data, and headers, with optional parallel execution.

Instructions

Send a request or multiple requests to the APISIX gateway

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
requestsYesarray of requests to send in parallel

Implementation Reference

  • Implementation of the 'send_request_to_gateway' tool handler. Sends one or multiple HTTP requests (with optional repeats) to the APISIX gateway, handles responses and errors, flattens results, and returns JSON with summary.
    server.tool("send_request_to_gateway", "Send a request or multiple requests to the APISIX gateway", SendRequestSchema.shape, async (args) => {
      const makeRequest = async (config: RequestConfig) => {
        try {
          const response = await axios.request({
            url: `${APISIX_SERVER_HOST}:${APISIX_SERVER_PORT}${config.path}`,
            method: config.method,
            data: config.data,
            headers: config.headers,
            timeout: 10000,
          });
    
          return {
            status: response.status,
            data: response.data,
            headers: response.headers,
          };
        } catch (error) {
          // handle error
          const axiosError = error as AxiosError;
          if (axiosError.response) {
            // The server responded with an error status code
            return {
              status: axiosError.response.status,
              data: axiosError.response.data || { error: 'Request failed' },
              headers: axiosError.response?.headers || {},
            };
          } else if (axiosError.request) {
            // The request was sent but no response was received
            return {
              status: 503, // Use 503 to indicate service is unavailable
              data: { error: 'Gateway is not responding' },
              headers: axiosError.request?.headers || {},
            };
          } else {
            // An error occurred while setting up the request
            return {
              status: 500,
              data: { error: axiosError.message || 'Request error' },
              headers: axiosError.request?.headers || {},
            };
          }
        }
      };
    
      const makeRepeatedRequests = async (config: RequestConfig) => {
        const repeatCount = config.repeatCount || 1;
        if (repeatCount > 1) {
          return Promise.all(Array(repeatCount).fill(null).map(() => makeRequest(config)));
        } else {
          return makeRequest(config);
        }
      };
    
      let results = [];
      results = await Promise.all(args.requests.map(req => makeRepeatedRequests(req)));
    
    
      // Flatten results if needed and count
      const flatResults = results.flat();
      const singleResults = flatResults.filter(r => !Array.isArray(r));
      const multiResults = flatResults.filter(r => Array.isArray(r)).flat();
      const allResults = [...singleResults, ...multiResults];
    
      return {
        content: [{
          type: "text" as const,
          text: JSON.stringify({
            results: allResults,
            summary: {
              total: allResults.length,
              successful: allResults.filter(r => r.status >= 200 && r.status < 300).length,
              failed: allResults.filter(r => r.status >= 400).length
            }
          }, null, 2)
        }]
      };
    });
  • Zod schema defining the input for 'send_request_to_gateway': array of requests with path, method, optional data, headers, repeatCount.
    export const SendRequestSchema = z.object({
      requests: z.array(z.object({
        path: z.string().describe("request path"),
        method: z.string().describe("request method"),
        data: z.any().optional().describe("request data"),
        headers: z.record(z.string(), z.string()).optional().describe("request headers"),
        repeatCount: z.number().optional().describe("number of requests to send in parallel").default(1),
      })).describe("array of requests to send in parallel"),
    });
  • src/index.ts:22-22 (registration)
    Call to setupCommonTools which registers the 'send_request_to_gateway' tool among others on the MCP server.
    setupCommonTools(server);
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions sending requests 'in parallel' (implied from the schema), but doesn't disclose critical behavioral traits: whether this is read-only or mutating, authentication requirements, rate limits, error handling, or what the response looks like. For a tool that sends requests to a gateway, this leaves significant gaps in understanding its behavior.

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

Conciseness5/5

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

The description is a single, efficient sentence that states the core purpose without unnecessary words. It's appropriately sized and front-loaded with the essential information, making it easy to parse quickly.

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

Completeness2/5

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

Given the complexity of sending requests to a gateway (potentially mutating operations, authentication needs, response formats) and the absence of both annotations and output schema, the description is insufficient. It doesn't explain what happens after sending requests, what kind of responses to expect, or any operational constraints, leaving significant gaps for an agent to use this tool effectively.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already fully documents the 'requests' parameter and its nested properties. The description adds no additional meaning beyond what's in the schema (like explaining what types of requests are appropriate or format examples). With complete schema coverage, the baseline score of 3 is appropriate.

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

Purpose4/5

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

The description clearly states the action ('send a request or multiple requests') and target ('to the APISIX gateway'), providing a specific verb+resource combination. However, it doesn't distinguish this from sibling tools that might also interact with the gateway (like create_route or update_service), which would require explicit differentiation for a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With many sibling tools for managing APISIX resources (create_route, update_service, etc.), there's no indication whether this is for testing, debugging, or operational requests, nor any prerequisites or exclusions mentioned.

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

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/api7/apisix-mcp'

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