Skip to main content
Glama

create_upstream

Configure and deploy an upstream service with load balancing, health checks, and timeout settings using customizable algorithms for efficient traffic management.

Instructions

Create an upstream service with load balancing settings

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idNoupstream id
upstreamYesupstream service configuration object

Implementation Reference

  • Executes the create_upstream tool by calling the Admin API with POST to /upstreams if no id, or PUT to /upstreams/{id} if id provided.
    server.tool("create_upstream", "Create an upstream service with load balancing settings", CreateUpstreamSchema.shape, async (args) => {
      const upstreamId = args.id;
      if (!upstreamId) {
        return await makeAdminAPIRequest(`/upstreams`, "POST", args.upstream);
      } else {
        return await makeAdminAPIRequest(`/upstreams/${upstreamId}`, "PUT", args.upstream);
      }
    });
  • Zod schema for validating input to the create_upstream tool, consisting of optional id and upstream configuration object.
    export const CreateUpstreamSchema = z.object({ id: z.string().optional().describe("upstream id"), upstream: UpstreamSchema });
  • Registers the create_upstream tool on the MCP server with description, input schema, and handler function.
    server.tool("create_upstream", "Create an upstream service with load balancing settings", CreateUpstreamSchema.shape, async (args) => {
      const upstreamId = args.id;
      if (!upstreamId) {
        return await makeAdminAPIRequest(`/upstreams`, "POST", args.upstream);
      } else {
        return await makeAdminAPIRequest(`/upstreams/${upstreamId}`, "PUT", args.upstream);
      }
    });
  • Helper function that performs HTTP requests to the APISIX Admin API endpoint, handling success and error responses as MCP CallToolResult. Used by the create_upstream handler.
    export async function makeAdminAPIRequest(
      path: string,
      method: string = "GET",
      data?: object
    ): Promise<CallToolResult> {
      const baseUrl = `${APISIX_SERVER_HOST}:${APISIX_ADMIN_API_PORT}${APISIX_ADMIN_API_PREFIX}`;
      const url = `${baseUrl}${path}`;
    
      try {
        const response = await axios({
          method,
          url,
          data,
          headers: {
            "X-API-KEY": APISIX_ADMIN_KEY,
            "Content-Type": "application/json",
          },
        });
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(response.data, null, 2),
            },
          ],
        };
      } catch (error) {
        if (axios.isAxiosError(error)) {
          console.error(`Request failed: ${method} ${url}`);
          console.error(
            `Status: ${error.response?.status}, Error: ${error.message}`
          );
    
          if (error.response?.data) {
            try {
              const stringifiedData = JSON.stringify(error.response.data);
              console.error(`Response data: ${stringifiedData}`);
            } catch {
              console.error(`Response data: [Cannot parse as JSON]`);
            }
          }
    
          return {
            isError: true,
            content: [
              {
                type: "text",
                text: JSON.stringify(
                  `Status: ${error.response?.status}\nMessage: ${error.message}
    Data:\n${JSON.stringify(error.response?.data || {}, null, 2)}`,
                  null,
                  2
                ),
              },
            ],
          };
        } else {
          return {
            isError: true,
            content: [
              {
                type: "text",
                text: JSON.stringify(error, null, 2),
              },
            ],
          };
        }
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the action ('create') without disclosing behavioral traits. It doesn't mention required permissions, whether creation is idempotent, rate limits, error conditions, or what happens on success (e.g., returns the created upstream object). This leaves significant gaps for a mutation tool.

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 directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded with the core action, 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?

For a complex creation tool with 2 parameters (one being a highly nested object), no annotations, and no output schema, the description is inadequate. It doesn't explain the expected input structure, required fields beyond 'nodes', or what the tool returns upon success, leaving the agent to rely solely on the schema without contextual guidance.

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 parameters are well-documented in the schema. The description adds minimal value by hinting at 'load balancing settings', which relates to some parameters like 'type' and 'nodes', but doesn't explain parameter relationships or provide examples beyond what the schema already specifies.

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 ('create') and resource ('upstream service') with a specific feature ('load balancing settings'). It distinguishes from sibling tools like 'update_upstream' by specifying creation rather than modification, though it doesn't explicitly contrast with other creation tools like 'create_service' or 'create_route'.

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?

No guidance is provided on when to use this tool versus alternatives like 'create_service' or 'update_upstream'. The description mentions 'load balancing settings' but doesn't clarify if this is the primary tool for load balancing configuration or if there are prerequisites (e.g., needing nodes defined first).

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