aliyun_invoke_api
Invoke any Alibaba Cloud OpenAPI endpoint dynamically to manage all cloud resources and services.
Instructions
Invoke ANY Alibaba Cloud OpenAPI endpoint dynamically. This tool allows you to manage ALL of Alibaba Cloud. Use the OpenAPI documentation to find the correct endpoint, apiVersion, and action. Note: RPC requests are most common.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| endpoint | Yes | The API endpoint (e.g., 'https://ecs.aliyuncs.com' or 'https://vpc.aliyuncs.com') | |
| apiVersion | Yes | The API version (e.g., '2014-05-26') | |
| action | Yes | The action name (e.g., 'DescribeInstances', 'CreateVpc') | |
| parameters | No | The parameters for the action, as a JSON object. | |
| method | No | HTTP Method (POST/GET). Defaults to POST. |
Implementation Reference
- src/tools/universal/index.ts:41-77 (handler)The handler function `handleUniversalTool` that executes the tool logic. It validates input with zod, creates an Alibaba Cloud API client, and makes the request to the specified endpoint/action.
export async function handleUniversalTool(args: any) { const schema = z.object({ endpoint: z.string(), apiVersion: z.string(), action: z.string(), parameters: z.record(z.string(), z.any()).default({}), method: z.enum(["GET", "POST"]).default("POST"), }); const parsed = schema.parse(args); // @ts-ignore const client = new Core.default({ accessKeyId: config.ALIBABA_CLOUD_ACCESS_KEY_ID, accessKeySecret: config.ALIBABA_CLOUD_ACCESS_KEY_SECRET, endpoint: parsed.endpoint, apiVersion: parsed.apiVersion, }); const requestOption = { method: parsed.method }; try { const result = await client.request(parsed.action, parsed.parameters, requestOption); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; } catch (error: any) { throw new Error(`Alibaba Cloud API Error: ${error.message}\nDetails: ${JSON.stringify(error.data || {})}`); } } - src/tools/universal/index.ts:5-39 (schema)The registration function `registerUniversalTool` which includes the input schema definition for the tool: endpoint, apiVersion, action, parameters (optional), method (optional).
export function registerUniversalTool() { return [ { name: "aliyun_invoke_api", description: "Invoke ANY Alibaba Cloud OpenAPI endpoint dynamically. This tool allows you to manage ALL of Alibaba Cloud. Use the OpenAPI documentation to find the correct endpoint, apiVersion, and action. Note: RPC requests are most common.", inputSchema: { type: "object", properties: { endpoint: { type: "string", description: "The API endpoint (e.g., 'https://ecs.aliyuncs.com' or 'https://vpc.aliyuncs.com')" }, apiVersion: { type: "string", description: "The API version (e.g., '2014-05-26')" }, action: { type: "string", description: "The action name (e.g., 'DescribeInstances', 'CreateVpc')" }, parameters: { type: "object", description: "The parameters for the action, as a JSON object." }, method: { type: "string", description: "HTTP Method (POST/GET). Defaults to POST.", enum: ["GET", "POST"] } }, required: ["endpoint", "apiVersion", "action"] } } ]; } - src/index.ts:31-43 (registration)The tool registration in the ListToolsRequestSchema handler. `registerUniversalTool()` is called to return the tool definition including the 'aliyun_invoke_api' tool.
server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ ...registerUniversalTool(), ...registerEcsTools(), ...registerVpcTools(), ...registerRdsTools(), ...registerRamTools(), ...registerAckTools(), ...registerSlbTools() ], }; }); - src/index.ts:46-53 (registration)The tool dispatch in the CallToolRequestSchema handler. When tool name is 'aliyun_invoke_api', it calls `handleUniversalTool(args)`.
server.setRequestHandler(CallToolRequestSchema, async (request) => { try { const name = request.params.name; const args = request.params.arguments; if (name === "aliyun_invoke_api") { return await handleUniversalTool(args); } - src/auth/config.ts:1-12 (helper)Auth configuration helper: loads ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET from environment, used by the universal tool handler to authenticate API calls.
import dotenv from 'dotenv'; import { z } from 'zod'; dotenv.config(); const configSchema = z.object({ ALIBABA_CLOUD_ACCESS_KEY_ID: z.string().min(1, "Access Key ID is required"), ALIBABA_CLOUD_ACCESS_KEY_SECRET: z.string().min(1, "Access Key Secret is required"), ALIBABA_CLOUD_REGION_ID: z.string().default("cn-hangzhou"), }); export const config = configSchema.parse(process.env);