create_network
Create a new network on Civo by specifying a label and optional region.
Instructions
Create a new network on Civo
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| label | Yes | Network label | |
| region | No | Region identifier |
Implementation Reference
- src/index.ts:379-400 (handler)Handler case for 'create_network' tool: validates args (label required), calls createNetwork API function, returns result with network label and ID.
case 'create_network': { if ( typeof args !== 'object' || args === null || typeof args.label !== 'string' ) { throw new Error('Invalid arguments for create_network'); } const network = await createNetwork( args as { label: string; region?: string } ); return { content: [ { type: 'text', text: `Created network ${network.label} (ID: ${network.id})`, }, ], isError: false, }; } - src/api/networks.ts:27-46 (helper)API helper function that POSTs to Civo API /v2/networks to create a new network, using CIVO_API_KEY and CIVO_API_URL from civo.ts.
export async function createNetwork(params: { label: string; region?: string; }): Promise<any> { const url = `${CIVO_API_URL}/networks`; const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${CIVO_API_KEY}`, }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(`Failed to create network: ${response.statusText}`); } return await response.json(); } - src/tools/networks.ts:12-29 (schema)Tool schema definition for 'create_network': expects object with required 'label' (string) and optional 'region' (string).
export const CREATE_NETWORK_TOOL: Tool = { name: 'create_network', description: 'Create a new network on Civo', inputSchema: { type: 'object', properties: { label: { type: 'string', description: 'Network label', }, region: { type: 'string', description: 'Region identifier', }, }, required: ['label'], }, }; - src/index.ts:62-93 (registration)Tool registration: CREATE_NETWORK_TOOL is registered in the server capabilities under the key CREATE_NETWORK_TOOL.name ('create_network').
// Server implementation const server = new Server( { name: 'example-servers/civo', version: '0.1.0', }, { capabilities: { tools: { [CREATE_INSTANCE_TOOL.name]: CREATE_INSTANCE_TOOL, [LIST_INSTANCES_TOOL.name]: LIST_INSTANCES_TOOL, [REBOOT_INSTANCE_TOOL.name]: REBOOT_INSTANCE_TOOL, [SHUTDOWN_INSTANCE_TOOL.name]: SHUTDOWN_INSTANCE_TOOL, [START_INSTANCE_TOOL.name]: START_INSTANCE_TOOL, [RESIZE_INSTANCE_TOOL.name]: RESIZE_INSTANCE_TOOL, [DELETE_INSTANCE_TOOL.name]: DELETE_INSTANCE_TOOL, [LIST_DISK_IMAGES_TOOL.name]: LIST_DISK_IMAGES_TOOL, [GET_DISK_IMAGE_TOOL.name]: GET_DISK_IMAGE_TOOL, [LIST_SIZES_TOOL.name]: LIST_SIZES_TOOL, [LIST_REGIONS_TOOL.name]: LIST_REGIONS_TOOL, [LIST_NETWORKS_TOOL.name]: LIST_NETWORKS_TOOL, [CREATE_NETWORK_TOOL.name]: CREATE_NETWORK_TOOL, [RENAME_NETWORK_TOOL.name]: RENAME_NETWORK_TOOL, [DELETE_NETWORK_TOOL.name]: DELETE_NETWORK_TOOL, [LIST_KUBERNETES_CLUSTERS_TOOL.name]: LIST_KUBERNETES_CLUSTERS_TOOL, [CREATE_KUBERNETES_CLUSTER_TOOL.name]: CREATE_KUBERNETES_CLUSTER_TOOL, [DELETE_KUBERNETES_CLUSTER_TOOL.name]: DELETE_KUBERNETES_CLUSTER_TOOL, [LIST_KUBERNETES_VERSIONS_TOOL.name]: LIST_KUBERNETES_VERSIONS_TOOL, }, }, } ); - src/index.ts:96-118 (registration)Tool registration in ListToolsRequestSchema handler: CREATE_NETWORK_TOOL is included in the list of available tools returned to the client.
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ CREATE_INSTANCE_TOOL, LIST_INSTANCES_TOOL, REBOOT_INSTANCE_TOOL, SHUTDOWN_INSTANCE_TOOL, START_INSTANCE_TOOL, RESIZE_INSTANCE_TOOL, DELETE_INSTANCE_TOOL, LIST_DISK_IMAGES_TOOL, GET_DISK_IMAGE_TOOL, LIST_SIZES_TOOL, LIST_REGIONS_TOOL, LIST_NETWORKS_TOOL, CREATE_NETWORK_TOOL, RENAME_NETWORK_TOOL, DELETE_NETWORK_TOOL, LIST_KUBERNETES_CLUSTERS_TOOL, CREATE_KUBERNETES_CLUSTER_TOOL, DELETE_KUBERNETES_CLUSTER_TOOL, LIST_KUBERNETES_VERSIONS_TOOL, ], }));