vpc_delete_subnet
Delete a subnet by providing its subnet ID. Optionally specify the region to target the correct VPC.
Instructions
Delete a subnet
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| subnet_id | Yes | ||
| region | No |
Implementation Reference
- src/tools/vpc/index.ts:44-46 (handler)The handler function for the 'vpc_delete_subnet' tool. It accepts 'subnet_id' (required) and optional 'region', validates write access via assertWriteAllowed(), then sends a DELETE request to the VPC API endpoint '/subnets/{subnet_id}'. Returns {message: 'Subnet deleted'} on success.
server.tool("vpc_delete_subnet", "Delete a subnet", { subnet_id: z.string(), region: z.string().optional(), }, async (p) => safeTool(async () => { w(); await client.delete(vpcUrl(p.region||r, `/subnets/${p.subnet_id}`)); return {message:"Subnet deleted"}; })); - src/tools/vpc/index.ts:44-46 (schema)Input schema for 'vpc_delete_subnet' defined inline: 'subnet_id' (z.string(), required) and 'region' (z.string(), optional). Zod is imported at line 2.
server.tool("vpc_delete_subnet", "Delete a subnet", { subnet_id: z.string(), region: z.string().optional(), }, async (p) => safeTool(async () => { w(); await client.delete(vpcUrl(p.region||r, `/subnets/${p.subnet_id}`)); return {message:"Subnet deleted"}; })); - src/tools/vpc/index.ts:7-9 (registration)The 'registerVPCTools' function (lines 7-9) is the registration function that calls server.tool(...) for all VPC tools, including 'vpc_delete_subnet' on line 44. It is invoked from src/server.ts line 53.
export function registerVPCTools(server: McpServer, client: IBMCloudAPIClient, config: ServerConfig) { const r = config.region; const w = () => assertWriteAllowed(config.allowWrite); - src/lib/utils.ts:14-18 (helper)assertWriteAllowed() helper used by the handler to throw if write operations are disabled in config.
export function assertWriteAllowed(allowWrite: boolean): void { if (!allowWrite) { throw new WriteNotAllowedError(); } } - src/lib/utils.ts:23-27 (helper)vpcUrl() helper used by the handler to build the full API URL with version and generation parameters.
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`; }