Skip to main content
Glama

create_upstream

Configure and deploy an upstream service with load balancing, health checks, and timeout settings using customizable algorithms for efficient traffic management.

Instructions

Create an upstream service with load balancing settings

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idNoupstream id
upstreamYesupstream service configuration object

Implementation Reference

  • Executes the create_upstream tool by calling the Admin API with POST to /upstreams if no id, or PUT to /upstreams/{id} if id provided.
    server.tool("create_upstream", "Create an upstream service with load balancing settings", CreateUpstreamSchema.shape, async (args) => { const upstreamId = args.id; if (!upstreamId) { return await makeAdminAPIRequest(`/upstreams`, "POST", args.upstream); } else { return await makeAdminAPIRequest(`/upstreams/${upstreamId}`, "PUT", args.upstream); } });
  • Zod schema for validating input to the create_upstream tool, consisting of optional id and upstream configuration object.
    export const CreateUpstreamSchema = z.object({ id: z.string().optional().describe("upstream id"), upstream: UpstreamSchema });
  • Registers the create_upstream tool on the MCP server with description, input schema, and handler function.
    server.tool("create_upstream", "Create an upstream service with load balancing settings", CreateUpstreamSchema.shape, async (args) => { const upstreamId = args.id; if (!upstreamId) { return await makeAdminAPIRequest(`/upstreams`, "POST", args.upstream); } else { return await makeAdminAPIRequest(`/upstreams/${upstreamId}`, "PUT", args.upstream); } });
  • Helper function that performs HTTP requests to the APISIX Admin API endpoint, handling success and error responses as MCP CallToolResult. Used by the create_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), }, ], }; } } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/api7/apisix-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server