vpc_stop_instance
Stop a running VPC virtual server instance by providing its ID. Optionally force the stop or specify a region.
Instructions
Stop a running VSI
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| instance_id | Yes | ||
| force | No | ||
| region | No |
Implementation Reference
- src/tools/vpc/index.ts:74-76 (handler)The handler for the vpc_stop_instance tool. It accepts an instance_id (string, required), force (boolean, optional), and region (string, optional). It calls the VPC API POST /instances/{instance_id}/actions with action type 'stop'. If force is true, the instance is force-stopped. Wrapped in safeTool for error handling, and calls assertWriteAllowed via the w() helper to enforce read-only mode.
server.tool("vpc_stop_instance", "Stop a running VSI", { instance_id: z.string(), force: z.boolean().optional(), region: z.string().optional(), }, async (p) => safeTool(async () => { w(); return client.post(vpcUrl(p.region||r, `/instances/${p.instance_id}/actions`),{type:"stop",force:p.force}); })); - src/tools/vpc/index.ts:74-76 (schema)The schema/input validation for vpc_stop_instance defined inline via zod: instance_id (z.string()), force (z.boolean().optional()), region (z.string().optional()).
server.tool("vpc_stop_instance", "Stop a running VSI", { instance_id: z.string(), force: z.boolean().optional(), region: z.string().optional(), }, async (p) => safeTool(async () => { w(); return client.post(vpcUrl(p.region||r, `/instances/${p.instance_id}/actions`),{type:"stop",force:p.force}); })); - src/server.ts:53-53 (registration)Registration call: registerVPCTools(server, client, config) which registers all VPC tools including vpc_stop_instance on the MCP server.
registerVPCTools(server, client, config); - src/lib/utils.ts:23-27 (helper)The vpcUrl helper builds the full VPC API URL with version and generation parameters. Used by the handler to construct the URL for the stop instance API call.
export function vpcUrl(region: string, path: string, version: string = "2024-11-19"): string { const base = `https://${region}.iaas.cloud.ibm.com/v1${path}`; const sep = base.includes("?") ? "&" : "?"; return `${base}${sep}version=${version}&generation=2`; } - src/lib/utils.ts:70-77 (helper)The safeTool helper wraps async tool handlers with try/catch, returning MCP-compatible success or error content blocks.
export async function safeTool<T>(fn: () => Promise<T>): Promise<ReturnType<typeof successContent> | ReturnType<typeof errorContent>> { try { const result = await fn(); return successContent(result); } catch (error) { return errorContent(error); } }