opnsense_route_apply
Applies pending static route configuration changes to reconfigure routing on the OPNsense firewall.
Instructions
Apply static route configuration changes (reconfigure routing)
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": "opnsense_route_apply"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/routing.ts:241-244 (handler)Handler for opnsense_route_apply: sends POST to /routes/routes/reconfigure to apply static route configuration changes.
case "opnsense_route_apply": { const result = await client.post("/routes/routes/reconfigure"); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } - src/tools/routing.ts:137-141 (schema)Schema definition for opnsense_route_apply: no input parameters required (empty object schema).
{ name: "opnsense_route_apply", description: "Apply static route configuration changes (reconfigure routing)", inputSchema: { type: "object" as const, properties: {} }, }, - src/index.ts:67-67 (registration)Registers the routing tool handler (including opnsense_route_apply) in the toolHandlers map with the OPNsense MCP server.
for (const def of routingToolDefinitions) toolHandlers.set(def.name, handleRoutingTool); - src/tools/routing.ts:188-325 (helper)The handleRoutingTool function dispatches all routing tool calls, including opnsense_route_apply which calls the reconfigure endpoint.
export async function handleRoutingTool( name: string, args: Record<string, unknown>, client: OPNsenseClient, ): Promise<{ content: Array<{ type: "text"; text: string }> }> { try { switch (name) { case "opnsense_route_list": { const result = await client.get("/routes/routes/searchroute"); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } case "opnsense_route_add": { const parsed = AddRouteSchema.parse(args); const result = await client.post("/routes/routes/addroute", { route: { network: parsed.network, gateway: parsed.gateway, disabled: parsed.disabled ? "1" : "0", description: parsed.description ?? "", }, }); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } case "opnsense_route_update": { const parsed = UpdateRouteSchema.parse(args); const existing = await client.get<{ route: Record<string, unknown> }>( `/routes/routes/getroute/${parsed.uuid}`, ); const route = existing.route; const result = await client.post(`/routes/routes/setroute/${parsed.uuid}`, { route: { network: parsed.network ?? route["network"], gateway: parsed.gateway ?? route["gateway"], disabled: parsed.disabled !== undefined ? parsed.disabled ? "1" : "0" : route["disabled"], description: parsed.description ?? route["description"], }, }); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } case "opnsense_route_delete": { const { uuid } = DeleteRouteSchema.parse(args); const result = await client.post(`/routes/routes/delroute/${uuid}`); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } case "opnsense_route_apply": { const result = await client.post("/routes/routes/reconfigure"); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } case "opnsense_route_gateway_list": { const result = await client.get("/routing/settings/searchGateway"); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } case "opnsense_route_gateway_status": { const result = await client.get("/routes/gateway/status"); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } case "opnsense_route_gateway_update": { const parsed = GatewayUpdateSchema.parse(args); // Round-trip: get current state, flatten multi-selects, override only provided fields const current = (await client.get<{ gateway_item?: Record<string, unknown> }>( `/routing/settings/getGateway/${encodeURIComponent(parsed.uuid)}`, ))?.gateway_item ?? {}; const flat: Record<string, unknown> = { name: extractSelected(current["name"]) ?? current["name"], descr: parsed.description ?? (extractSelected(current["descr"]) ?? current["descr"] ?? ""), interface: extractSelected(current["interface"]) ?? "", ipprotocol: extractSelected(current["ipprotocol"]) ?? "inet", gateway: extractSelected(current["gateway"]) ?? current["gateway"] ?? "", defaultgw: boolToFlag(parsed.defaultgw) ?? (extractSelected(current["defaultgw"]) ?? current["defaultgw"] ?? "0"), fargw: extractSelected(current["fargw"]) ?? current["fargw"] ?? "", monitor_disable: boolToFlag(parsed.monitor_disable) ?? (extractSelected(current["monitor_disable"]) ?? current["monitor_disable"] ?? "0"), monitor_noroute: extractSelected(current["monitor_noroute"]) ?? current["monitor_noroute"] ?? "", monitor: parsed.monitor !== undefined ? parsed.monitor : (extractSelected(current["monitor"]) ?? current["monitor"] ?? ""), force_down: extractSelected(current["force_down"]) ?? current["force_down"] ?? "", priority: parsed.priority !== undefined ? String(parsed.priority) : (extractSelected(current["priority"]) ?? current["priority"] ?? "255"), weight: parsed.weight !== undefined ? String(parsed.weight) : (extractSelected(current["weight"]) ?? current["weight"] ?? "1"), latencylow: extractSelected(current["latencylow"]) ?? current["latencylow"] ?? "", latencyhigh: extractSelected(current["latencyhigh"]) ?? current["latencyhigh"] ?? "", losslow: extractSelected(current["losslow"]) ?? current["losslow"] ?? "", losshigh: extractSelected(current["losshigh"]) ?? current["losshigh"] ?? "", interval: extractSelected(current["interval"]) ?? current["interval"] ?? "", time_period: extractSelected(current["time_period"]) ?? current["time_period"] ?? "", loss_interval: extractSelected(current["loss_interval"]) ?? current["loss_interval"] ?? "", data_length: extractSelected(current["data_length"]) ?? current["data_length"] ?? "", disabled: boolToFlag(parsed.disabled) ?? (extractSelected(current["disabled"]) ?? current["disabled"] ?? "0"), }; const result = await client.post( `/routing/settings/setGateway/${encodeURIComponent(parsed.uuid)}`, { gateway_item: flat }, ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } case "opnsense_route_gateway_apply": { GatewayApplySchema.parse(args); const result = await client.post("/routing/settings/reconfigure", {}); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } default: return { content: [{ type: "text", text: `Unknown routing tool: ${name}` }] }; } } catch (error: unknown) { const message = error instanceof Error ? error.message : "Unknown error"; return { content: [{ type: "text", text: `Error executing ${name}: ${message}` }] }; } }