get_secret_by_id
Retrieve a specific secret by its ID from supported secret managers like Vault, AWS, or GCP using the APISIX-MCP server integration.
Instructions
Get a secret by ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | secret id | |
| manager | Yes | secret manager type | |
| page | No | page number | |
| page_size | No | page size |
Implementation Reference
- src/tools/secret.ts:6-14 (handler)Inline handler function for the 'get_secret_by_id' tool, which calls the admin API to fetch a secret by ID or list secrets with pagination.server.tool("get_secret_by_id", "Get a secret by ID", GetSecretSchema.shape, async (args) => { if (args.id) { return await makeAdminAPIRequest(`/secrets/${args.manager}/${args.id}`); } else { const query = ""; return await makeAdminAPIRequest(`/secrets/${args.manager}?page=${args.page}&page_size=${args.page_size}${query}`); } });
- src/schemas/secret.ts:52-57 (schema)Zod schema defining the input parameters for the 'get_secret_by_id' tool: optional id, manager type, and pagination fields from PaginationSchema.export const GetSecretSchema = z .object({ id: z.string().optional().describe("secret id"), manager: SecretTypeSchema.describe("secret manager type"), }) .merge(PaginationSchema);
- src/tools/secret.ts:6-14 (registration)Registration of the 'get_secret_by_id' tool on the MCP server using server.tool with description, schema, and handler.server.tool("get_secret_by_id", "Get a secret by ID", GetSecretSchema.shape, async (args) => { if (args.id) { return await makeAdminAPIRequest(`/secrets/${args.manager}/${args.id}`); } else { const query = ""; return await makeAdminAPIRequest(`/secrets/${args.manager}?page=${args.page}&page_size=${args.page_size}${query}`); } });
- src/utils/adminAPI.ts:11-80 (helper)Utility function used by the tool handler to perform 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), }, ], }; } } }