opnsense_fw_toggle_rule
Toggle a firewall rule's enabled state by UUID. Apply after changing to activate the rule.
Instructions
Enable or disable a firewall rule by UUID. Run opnsense_fw_apply afterwards to activate.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uuid | Yes | UUID of the rule to toggle | |
| enabled | Yes | 1 to enable, 0 to disable |
Implementation Reference
- src/tools/firewall.ts:164-180 (registration)Tool definition registration for opnsense_fw_toggle_rule, defining the name, description, and input schema (uuid + enabled enum).
{ name: "opnsense_fw_toggle_rule", description: "Enable or disable a firewall rule by UUID. Run opnsense_fw_apply afterwards to activate.", inputSchema: { type: "object" as const, properties: { uuid: { type: "string", description: "UUID of the rule to toggle" }, enabled: { type: "string", enum: ["0", "1"], description: "1 to enable, 0 to disable", }, }, required: ["uuid", "enabled"], }, }, - src/tools/firewall.ts:33-36 (schema)Zod validation schema for the toggle rule tool — validates uuid and enabled ("0" or "1").
const ToggleRuleSchema = z.object({ uuid: UuidSchema, enabled: z.enum(["0", "1"]), }); - src/tools/firewall.ts:360-366 (handler)Handler function: parses args with ToggleRuleSchema, then POSTs to /firewall/filter/toggleRule/{uuid}/{enabled} via the OPNsenseClient.
case "opnsense_fw_toggle_rule": { const parsed = ToggleRuleSchema.parse(args); const result = await client.post( `/firewall/filter/toggleRule/${parsed.uuid}/${parsed.enabled}`, ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } - src/index.ts:60-70 (registration)Server registration: maps opnsense_fw_toggle_rule to the handleFirewallTool handler in the MCP server tool registry.
for (const def of firewallToolDefinitions) toolHandlers.set(def.name, handleFirewallTool); for (const def of diagnosticsToolDefinitions) toolHandlers.set(def.name, handleDiagnosticsTool); for (const def of interfacesToolDefinitions) toolHandlers.set(def.name, handleInterfacesTool); for (const def of dhcpToolDefinitions) toolHandlers.set(def.name, handleDhcpTool); for (const def of systemToolDefinitions) toolHandlers.set(def.name, handleSystemTool); for (const def of acmeToolDefinitions) toolHandlers.set(def.name, handleAcmeTool); for (const def of firmwareToolDefinitions) toolHandlers.set(def.name, handleFirmwareTool); for (const def of routingToolDefinitions) toolHandlers.set(def.name, handleRoutingTool); for (const def of vlanToolDefinitions) toolHandlers.set(def.name, handleVlanTool); for (const def of tailscaleToolDefinitions) toolHandlers.set(def.name, handleTailscaleTool); for (const def of natToolDefinitions) toolHandlers.set(def.name, handleNatTool); - src/utils/validation.ts:3-55 (helper)UUID validation schema used by ToggleRuleSchema to validate the uuid field.
export const UuidSchema = z .string() .uuid("Invalid UUID format"); export const IpAddressSchema = z .string() .regex( /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/, "Invalid IPv4 address", ); export const CidrSchema = z .string() .regex( /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\/(?:3[0-2]|[12]?\d)$/, "Invalid CIDR notation", ); export const HostnameSchema = z .string() .regex( /^(?!-)[a-zA-Z0-9-]{1,63}(?<!-)(?:\.(?!-)[a-zA-Z0-9-]{1,63}(?<!-))*$/, "Invalid hostname", ); export const PortSchema = z .number() .int() .min(1, "Port must be at least 1") .max(65535, "Port must be at most 65535"); export const MacAddressSchema = z .string() .regex( /^[0-9a-fA-F]{2}(?::[0-9a-fA-F]{2}){5}$/, "Invalid MAC address (expected format: AA:BB:CC:DD:EE:FF)", ); export const DomainSchema = z .string() .regex( /^(?!-)[a-zA-Z0-9-]{1,63}(?<!-)(?:\.(?!-)[a-zA-Z0-9-]{1,63}(?<!-))*\.[a-zA-Z]{2,}$/, "Invalid domain name", ); export const ProtocolSchema = z.enum(["TCP", "UDP", "ICMP", "any"]); export const FirewallActionSchema = z.enum(["pass", "block", "reject"]); export const DirectionSchema = z.enum(["in", "out"]); export const ServiceActionSchema = z.enum(["start", "stop", "restart"]);