Skip to main content
Glama

create_or_update_consumer

Create or update a consumer in APISIX with username, description, labels, and plugins via the APISIX-MCP server, ensuring accurate consumer management.

Instructions

Create a consumer, if the consumer already exists, it will be updated

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descNoconsumer description
group_idNoconsumer group id
labelsNoconsumer labels
pluginsNoconsumer plugins
usernameYesconsumer username

Implementation Reference

  • Defines the ConsumerSchema (Zod schema) which is aliased as CreateOrUpdateConsumerSchema and used for input validation of the tool.
    export const ConsumerSchema = z
      .object({
        username: z.string().describe("consumer username"),
        desc: z.string().optional().describe("consumer description"),
        labels: z.record(z.string(), z.string()).optional().describe("consumer labels"),
        plugins: PluginSchema.optional().describe("consumer plugins"),
        group_id: z.string().optional().describe("consumer group id"),
      })
      .passthrough()
      .describe("consumer configuration object");
  • Registers the "create_or_update_consumer" tool on the MCP server with description, input schema, and inline async handler function.
    server.tool(
      "create_or_update_consumer",
      "Create a consumer, if the consumer already exists, it will be updated",
      CreateOrUpdateConsumerSchema.shape,
      async (args) => {
        return await makeAdminAPIRequest(`/consumers`, "PUT", args);
      }
    );
  • The server.tool call includes the handler lambda that executes the tool logic by calling makeAdminAPIRequest.
    server.tool(
      "create_or_update_consumer",
      "Create a consumer, if the consumer already exists, it will be updated",
      CreateOrUpdateConsumerSchema.shape,
      async (args) => {
        return await makeAdminAPIRequest(`/consumers`, "PUT", args);
      }
    );
  • Supporting utility function makeAdminAPIRequest that performs the HTTP request to the APISIX Admin API using axios and formats the response as CallToolResult.
    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 for behavioral disclosure. It states the create-or-update logic but lacks critical information: what 'updated' means (full replacement vs partial merge), whether this is idempotent, what permissions are required, error conditions, or what happens on success. For a mutation tool with zero annotation coverage, this leaves significant gaps.

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 communicates the core functionality without waste. It's front-loaded with the essential information and contains no redundant or unnecessary elements. Every word earns its place.

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 mutation tool with 5 parameters (including nested objects), no annotations, and no output schema, the description is inadequate. It doesn't explain the update semantics, error handling, authentication needs, or what the tool returns. The agent lacks sufficient context to use this tool confidently beyond basic parameter passing.

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 all parameters are documented in the schema. The description adds no parameter-specific information beyond what the schema provides. It doesn't explain how parameters like 'plugins' or 'labels' affect the create/update behavior, or which fields are required for updates versus creation. Baseline 3 is appropriate when the schema does the heavy lifting.

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 verb ('create or update') and resource ('consumer'), making the purpose immediately understandable. It distinguishes from pure creation tools like 'create_consumer_group' by specifying the update behavior when the consumer already exists. However, it doesn't explicitly differentiate from other consumer-related tools like 'update_consumer_group' or 'delete_resource'.

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. It doesn't mention prerequisites, when to choose this over separate create/update tools (though none exist for consumers), or any constraints like authentication requirements. The agent must infer usage from the name and description alone.

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