get_credential
Retrieve all credentials or a specific credential for a consumer linked to the APISIX-MCP server by providing the username and optional credential ID.
Instructions
Get all credentials or a specific credential for a consumer
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | credential id | |
| username | Yes | consumer username |
Implementation Reference
- src/tools/consumer.ts:15-20 (registration)Registers the 'get_credential' tool with inline handler function that retrieves consumer credentials (all or specific by id) using the makeAdminAPIRequest helper.server.tool("get_credential", "Get all credentials or a specific credential for a consumer", GetCredentialSchema.shape, async (args) => { if (args.id) { return await makeAdminAPIRequest(`/consumers/${args.username}/credentials/${args.id}`, "GET"); } return await makeAdminAPIRequest(`/consumers/${args.username}/credentials`, "GET"); });
- src/schemas/consumer.ts:34-37 (schema)Zod input schema for get_credential tool: requires username, optional id for specific credential.export const GetCredentialSchema = z.object({ username: ConsumerSchema.shape.username, id: z.string().optional().describe("credential id"), });
- src/utils/adminAPI.ts:11-80 (helper)Helper utility function that makes HTTP requests to the APISIX admin API using axios, with authentication via X-API-KEY, returns formatted CallToolResult; used by get_credential 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), }, ], }; } } }