update_service
Modify service attributes like name, description, labels, upstream configuration, and plugins using the APISIX-MCP server to maintain and enhance API gateway services.
Instructions
Update specific attributes of an existing service
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | service id | |
| service | No | service configuration object |
Implementation Reference
- src/tools/service.ts:15-17 (handler)The inline handler function for the 'update_service' tool. It calls makeAdminAPIRequest to perform a PATCH request on `/services/${args.id}` with the provided service attributes. This constitutes the core logic of the tool.server.tool("update_service", "Update specific attributes of an existing service", UpdateServiceSchema.shape, async (args) => { return await makeAdminAPIRequest(`/services/${args.id}`, "PATCH", args.service); });
- src/tools/service.ts:15-17 (registration)Registration of the 'update_service' tool using server.tool(), including description, input schema (UpdateServiceSchema.shape), and the handler function.server.tool("update_service", "Update specific attributes of an existing service", UpdateServiceSchema.shape, async (args) => { return await makeAdminAPIRequest(`/services/${args.id}`, "PATCH", args.service); });
- src/utils/adminAPI.ts:11-80 (helper)Supporting utility function `makeAdminAPIRequest` that performs HTTP requests to the APISIX Admin API, handling both success and error responses in MCP format. Used by the update_service 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), }, ], }; } } }