update_upstream
Modify specific upstream attributes in APISIX-MCP, such as load balancing, timeout, health checks, and TLS settings, to optimize API gateway performance and configuration.
Instructions
Update specific attributes of an existing upstream
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "update_upstream"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | upstream id | |
| upstream | No | upstream service configuration object |
Implementation Reference
- src/tools/upstream.ts:15-28 (handler)The handler implementation for the 'update_upstream' tool. It is registered inline with server.tool(). It checks if an ID is provided and if so, makes a PATCH request to the /upstreams/{id} endpoint using the helper makeAdminAPIRequest.
server.tool("update_upstream", "Update specific attributes of an existing upstream", UpdateUpstreamSchema.shape, async (args) => { if (!args.id) { return { content: [ { type: "text", text: JSON.stringify({ error: "Upstream ID is required for updates" }, null, 2), }, ], }; } return await makeAdminAPIRequest(`/upstreams/${args.id}`, "PATCH", args.upstream); }); - src/schemas/upstream.ts:68-68 (schema)Zod schema definition for validating the input parameters of the update_upstream tool, including ID and partial upstream configuration.
export const UpdateUpstreamSchema = createNullablePatchSchema(z.object({ id: z.string().describe("upstream id"), upstream: UpstreamSchema.partial() })); - src/utils/adminAPI.ts:11-80 (helper)Supporting utility function that performs the actual HTTP request to the APISIX Admin API and formats the response as MCP CallToolResult. Used by the update_upstream 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), }, ], }; } } }