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
| Name | Required | Description | Default |
|---|---|---|---|
| consumerGroup | Yes | consumer group configuration object | |
| id | No | consumer group ID |
Implementation Reference
- src/tools/consumer-group.ts:6-13 (handler)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); } });
- src/schemas/consumer-group.ts:22-25 (schema)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, });
- src/tools/consumer-group.ts:6-13 (registration)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); } });
- src/utils/adminAPI.ts:11-80 (helper)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);