Skip to main content
Glama

create_consumer_group

Define and configure consumer groups in the APISIX-MCP server by specifying an ID, labels, plugins, and a description to manage API traffic effectively.

Instructions

Create a consumer group

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
consumerGroupYesconsumer group configuration object
idNoconsumer group ID

Implementation Reference

  • Inline handler function for the 'create_consumer_group' tool. It checks if an ID is provided to decide between creating a new consumer group (POST) or updating an existing one (PUT) via the admin API.
    server.tool("create_consumer_group", "Create a consumer group", CreateConsumerGroupSchema.shape, async (args) => {
      const groupId = args.id;
      if (!groupId) {
        return await makeAdminAPIRequest("/consumer_groups", "POST", args.consumerGroup);
      } else {
        return await makeAdminAPIRequest(`/consumer_groups/${groupId}`, "PUT", args.consumerGroup);
      }
    });
  • Zod schema defining the input parameters for the 'create_consumer_group' tool: optional id and required consumerGroup config.
    export const CreateConsumerGroupSchema = z.object({
      id: z.string().optional().describe("consumer group ID"),
      consumerGroup: ConsumerGroupSchema,
    });
  • The server.tool call that registers the 'create_consumer_group' tool with its description, schema, and handler.
    server.tool("create_consumer_group", "Create a consumer group", CreateConsumerGroupSchema.shape, async (args) => {
      const groupId = args.id;
      if (!groupId) {
        return await makeAdminAPIRequest("/consumer_groups", "POST", args.consumerGroup);
      } else {
        return await makeAdminAPIRequest(`/consumer_groups/${groupId}`, "PUT", args.consumerGroup);
      }
    });
  • Utility function used by the tool handler to make authenticated HTTP requests to the APISIX Admin API and format the response as MCP 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),
              },
            ],
          };
        }
      }
    }
  • src/index.ts:29-29 (registration)
    Invocation of the setup function that registers the consumer group tools, including 'create_consumer_group', on the MCP server.
    setupConsumerGroupTools(server);
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 but only states the action without explaining what 'create' entails. It doesn't mention permissions required, whether this is idempotent, what happens on conflicts, or what the response contains. The description adds minimal value beyond the obvious action.

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 extremely concise at just three words with zero wasted language. It's front-loaded with the core action, though this conciseness comes at the cost of completeness.

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 creation tool with no annotations and no output schema, the description is inadequate. It doesn't explain what a consumer group is, what happens after creation, potential side effects, or error conditions. Given the complexity implied by nested parameters and sibling tools, more context is needed.

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%, providing good documentation for both parameters (id and consumerGroup object with desc, labels, plugins). The description adds no parameter information beyond what's in the schema, so it meets the baseline of 3 where schema does the heavy lifting.

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

Purpose2/5

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

The description 'Create a consumer group' is a tautology that merely restates the tool name without adding meaningful context. It specifies the verb 'create' and resource 'consumer group' but provides no differentiation from sibling tools like 'create_service' or 'create_route', nor does it explain what a consumer group is in this system.

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?

No guidance is provided on when to use this tool versus alternatives. The description lacks context about prerequisites, when this operation is appropriate, or how it relates to sibling tools like 'update_consumer_group' or 'create_or_update_consumer'. This leaves the agent with no usage context.

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