vpc_list_subnets
List all subnets in an IBM Cloud VPC region. Filter by VPC ID and limit results for efficient network management.
Instructions
List all subnets
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": "vpc_list_subnets"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| vpc_id | No | ||
| region | No |
Implementation Reference
- src/tools/vpc/index.ts:32-34 (registration)Registration of the 'vpc_list_subnets' MCP tool via server.tool(). Defines the tool name, description, schema (limit, vpc_id, region as optional params), and handler.
server.tool("vpc_list_subnets", "List all subnets", { limit: z.number().optional(), vpc_id: z.string().optional(), region: z.string().optional(), }, async (p) => safeTool(() => client.get(vpcUrl(p.region||r, "/subnets"), {limit:p.limit,"vpc.id":p.vpc_id}))); - src/tools/vpc/index.ts:32-34 (handler)Handler implementation for vpc_list_subnets. Calls client.get() with the VPC API URL for /subnets, passing limit and vpc.id query params, wrapped in safeTool() for error handling.
server.tool("vpc_list_subnets", "List all subnets", { limit: z.number().optional(), vpc_id: z.string().optional(), region: z.string().optional(), }, async (p) => safeTool(() => client.get(vpcUrl(p.region||r, "/subnets"), {limit:p.limit,"vpc.id":p.vpc_id}))); - src/tools/vpc/index.ts:33-33 (schema)Input schema for vpc_list_subnets: limit (number, optional), vpc_id (string, optional), region (string, optional) — all defined using Zod.
limit: z.number().optional(), vpc_id: z.string().optional(), region: z.string().optional(), - src/lib/utils.ts:23-27 (helper)Helper function vpcUrl() builds the VPC API URL with required version and generation query params.
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)Helper function safeTool() wraps handler execution with try/catch, returning successContent or errorContent.
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); } }