haproxy_frontend_create
Create and configure a new HAProxy frontend on OPNSense MCP Server by specifying bind address, SSL settings, mode, backend, and access control lists for efficient traffic management.
Instructions
Create a new HAProxy frontend
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| acls | No | Access control lists | |
| backend | Yes | Default backend name | |
| bind | Yes | Bind address (e.g., 0.0.0.0:443) | |
| certificates | No | Certificate UUIDs or names | |
| description | No | ||
| mode | Yes | Frontend mode | |
| name | Yes | Frontend name | |
| ssl | No | Enable SSL |
Implementation Reference
- Main handler function that implements the logic to create a HAProxy frontend. Posts configuration to OPNsense API, handles associated ACLs and actions, and triggers reconfiguration.async createFrontend(frontend: Omit<HAProxyFrontend, 'uuid'>): Promise<{ uuid: string }> { try { const payload = this.buildFrontendPayload(frontend); const response = await this.client.post('/haproxy/settings/addFrontend', payload); if (!response.uuid) { throw new Error('No UUID returned from create frontend'); } // Add ACLs if provided if (frontend.acls && frontend.acls.length > 0) { for (const acl of frontend.acls) { await this.addACLToFrontend(response.uuid, acl); } } // Add actions if provided if (frontend.actions && frontend.actions.length > 0) { for (const action of frontend.actions) { await this.addActionToFrontend(response.uuid, action); } } await this.reconfigure(); return { uuid: response.uuid }; } catch (error) { throw new Error(`Failed to create HAProxy frontend: ${error}`); }
- Input schema/interface defining the structure for HAProxy frontend configuration, used by the createFrontend handler.export interface HAProxyFrontend { uuid?: string; name: string; bind: string; bindOptions?: { ssl?: boolean; certificates?: string[]; }; mode: 'http' | 'tcp'; backend: string; acls?: HAProxyACL[]; actions?: HAProxyAction[]; description?: string; enabled?: boolean; }
- Helper function to build the API payload from frontend configuration object.private buildFrontendPayload(frontend: HAProxyFrontend): any { const payload: any = { frontend: { name: frontend.name, bind: frontend.bind, mode: frontend.mode, defaultBackend: frontend.backend, description: frontend.description || '', enabled: frontend.enabled !== false ? '1' : '0' } }; if (frontend.bindOptions?.ssl) { payload.frontend.ssl = '1'; if (frontend.bindOptions.certificates && frontend.bindOptions.certificates.length > 0) { payload.frontend.certificates = frontend.bindOptions.certificates.join(','); } } return payload;
- Helper function to parse API response data into HAProxyFrontend object.private parseFrontend(data: any): HAProxyFrontend { return { uuid: data.uuid, name: data.name, bind: data.bind || '', mode: data.mode || 'http', backend: data.defaultBackend || '', description: data.description, enabled: data.enabled === '1', acls: [], actions: [], bindOptions: { ssl: data.ssl === '1', certificates: data.certificates ? data.certificates.split(',') : [] } };