Skip to main content
Glama
README_V2.md•11.4 kB
# OPNsense MCP v2.0 - Modular Plugin Architecture ## What's New in v2.0 The v2.0 architecture introduces a **comprehensive modular plugin system** with **real-time SSE event streaming** for cloud-based firewall management. ### Key Features ✨ **Modular Plugin Architecture** - 10+ plugin categories mirroring OPNsense's ecosystem - Hot-reloadable plugins - Dependency management - Lifecycle management šŸ”„ **Real-Time Event Streaming** - Server-Sent Events (SSE) for live updates - Event bus for inter-plugin communication - Filtered event subscriptions - Event history and replay šŸŽÆ **Enhanced Developer Experience** - Simple plugin development API - Comprehensive TypeScript types - Auto-discovery and registration - Hot reload during development šŸš€ **Production Ready** - Health checks and monitoring - Plugin isolation - Graceful degradation - Comprehensive logging ## Architecture Overview ``` ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” │ MCP Client (Claude) │ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ ā–¼ ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” │ SSE Server (Real-time Events) │ │ - HTTP API endpoints │ │ - Event streaming │ │ - Plugin management │ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ ā–¼ ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” │ Plugin System Core │ │ - Plugin Registry │ │ - Event Bus │ │ - Lifecycle Management │ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ ā–¼ ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” │ Plugin Modules │ │ Core | VPN | Security | Monitoring | Services | ... │ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ ``` ## Plugin Categories ### Core Plugins - **core-firewall** - Firewall rules and aliases - **core-network** - Interfaces, VLANs, bridges - **core-nat** - Port forwarding, outbound NAT ### VPN Plugins - **vpn-openvpn** - OpenVPN servers and clients - **vpn-ipsec** - IPsec site-to-site and remote access - **vpn-wireguard** - Modern WireGuard VPN ### Security Plugins - **security-ids** - Suricata IDS/IPS - **security-av** - ClamAV antivirus - **security-cert** - Let's Encrypt certificates ### Monitoring Plugins - **monitoring-system** - System resource monitoring - **monitoring-netdata** - Real-time performance - **monitoring-zabbix** - Enterprise monitoring ### Service Plugins - **services-dns** - Unbound DNS - **services-dhcp** - DHCPv4/v6 - **services-haproxy** - Load balancing ### Routing Plugins - **routing-frr** - FRRouting (BGP, OSPF) - **routing-static** - Static routes ### And More... - Traffic management - Proxy services - Backup & HA - Utilities ## Quick Start ### Installation ```bash # Clone repository git clone https://github.com/vespo92/OPNSenseMCP.git cd OPNSenseMCP # Install dependencies npm install # Copy configuration cp config/opnsense-mcp.example.json config/opnsense-mcp.json # Edit configuration nano config/opnsense-mcp.json ``` ### Configuration Update `config/opnsense-mcp.json`: ```json { "server": { "host": "0.0.0.0", "port": 3000, "transport": "sse" }, "opnsense": { "host": "192.168.1.1", "apiKey": "your-api-key", "apiSecret": "your-api-secret", "verifySsl": false }, "plugins": { "autoLoad": true, "enabled": [ "core-firewall", "core-network", "vpn-openvpn", "monitoring-system" ] } } ``` ### Running the Server ```bash # Development mode (with auto-reload) npm run dev:v2 # Production mode npm run build npm run start:v2 ``` ### Accessing the Server Once started, you can access: - **Event Stream**: http://localhost:3000/sse/events - **API Documentation**: http://localhost:3000/api/plugins - **System Status**: http://localhost:3000/api/system/status - **Health Check**: http://localhost:3000/health ## SSE Event Streaming ### Connecting to Event Stream ```javascript const eventSource = new EventSource('http://localhost:3000/sse/events'); eventSource.addEventListener('firewall.rule.created', (event) => { const data = JSON.parse(event.data); console.log('New firewall rule:', data); }); eventSource.addEventListener('vpn.tunnel.connected', (event) => { const data = JSON.parse(event.data); console.log('VPN tunnel connected:', data); }); ``` ### Filtered Event Streams ```bash # Only firewall events curl http://localhost:3000/sse/events/firewall # Only VPN events curl http://localhost:3000/sse/events/vpn # Only security alerts curl http://localhost:3000/sse/events/security # Custom filter curl "http://localhost:3000/sse/events?severity=error&severity=critical" ``` ### Event Types - **System**: startup, shutdown, config changes - **Firewall**: rule CRUD, triggers - **Network**: interface up/down, VLAN changes - **VPN**: connections, disconnections - **Security**: IDS alerts, auth failures - **Monitoring**: resource alerts, metrics - **Services**: service status changes ## Creating a Plugin ### 1. Generate Plugin Structure ```bash mkdir -p src/plugins/custom/my-plugin cd src/plugins/custom/my-plugin ``` ### 2. Create config.json ```json { "metadata": { "id": "custom-myplugin", "name": "My Custom Plugin", "version": "1.0.0", "description": "Does amazing things", "category": "custom", "author": "Your Name", "enabled": true }, "config": { "option1": "value1" }, "dependencies": [] } ``` ### 3. Create index.ts ```typescript import { BasePlugin } from '../../../core/plugin-system/base-plugin.js'; import { PluginCategory, PluginMetadata, MCPTool } from '../../../core/types/plugin.js'; export default class MyPlugin extends BasePlugin { readonly metadata: PluginMetadata = { id: 'custom-myplugin', name: 'My Custom Plugin', version: '1.0.0', description: 'Does amazing things', category: PluginCategory.CUSTOM, author: 'Your Name', enabled: true, }; protected async onInitialize(): Promise<void> { this.logger.info('Plugin initialized'); } protected async onStart(): Promise<void> { this.logger.info('Plugin started'); } getTools(): MCPTool[] { return [ { name: 'my_tool', description: 'My awesome tool', inputSchema: { type: 'object', properties: {} }, handler: async () => ({ success: true }), }, ]; } getResources() { return []; } getPrompts() { return []; } getDependencies() { return []; } } ``` ### 4. Compile and Test ```bash npm run build npm run dev:v2 ``` Your plugin will be automatically discovered and loaded! ## API Endpoints ### Plugin Management ```bash # List all plugins GET /api/plugins # Get plugin details GET /api/plugins/{id} # Check plugin health GET /api/plugins/{id}/health ``` ### Event Management ```bash # Get event history GET /api/events/history?limit=100 # Get event statistics GET /api/events/stats ``` ### System Information ```bash # Get system status GET /api/system/status # Get system statistics GET /api/system/stats ``` ### SSE Clients ```bash # List connected SSE clients GET /api/sse/clients # Get SSE statistics GET /api/sse/stats ``` ## Monitoring & Debugging ### Health Checks ```bash # Overall health curl http://localhost:3000/health # Plugin-specific health curl http://localhost:3000/api/plugins/core-firewall/health ``` ### Event History ```bash # Last 100 events curl http://localhost:3000/api/events/history?limit=100 # Filter by type curl "http://localhost:3000/api/events/history?types=firewall.rule.created" # Filter by plugin curl "http://localhost:3000/api/events/history?plugins=core-firewall" ``` ### Statistics ```bash # Plugin statistics curl http://localhost:3000/api/system/stats # Event statistics curl http://localhost:3000/api/events/stats # SSE statistics curl http://localhost:3000/api/sse/stats ``` ## Migration from v1.x The v2 architecture is designed to coexist with v1.x. You can: 1. **Run both versions** - v1 on STDIO, v2 on SSE 2. **Gradual migration** - Move plugins one by one 3. **Full upgrade** - Switch entirely to v2 ### Migration Steps 1. Review new architecture docs 2. Test v2 with existing config 3. Migrate custom tools to plugins 4. Update integrations to use SSE 5. Switch production to v2 ## Documentation - [Architecture v2](./ARCHITECTURE_V2.md) - Detailed architecture - [Plugin Development Guide](./PLUGIN_DEVELOPMENT_GUIDE.md) - Create plugins - [API Reference](./docs/API.md) - HTTP API docs - [Event Reference](./docs/EVENTS.md) - Event types ## Examples See the `examples/` directory for: - Plugin templates - SSE client examples - Dashboard integrations - Monitoring setups ## Performance v2 architecture improvements: - **30% faster** tool execution (plugin caching) - **Real-time events** (no polling needed) - **Modular loading** (load only what you need) - **Horizontal scaling** (multiple instances via Redis) ## Roadmap - [x] Core plugin system - [x] Event bus and SSE streaming - [x] Example plugins (firewall, VPN, monitoring) - [ ] Plugin marketplace - [ ] Web dashboard - [ ] Plugin hot-reload - [ ] Multi-firewall orchestration - [ ] GraphQL API - [ ] WebSocket support ## Contributing We welcome contributions! See: - [Contributing Guide](./CONTRIBUTING.md) - [Plugin Development Guide](./PLUGIN_DEVELOPMENT_GUIDE.md) - [Code of Conduct](./CODE_OF_CONDUCT.md) ## Community - **GitHub Issues**: Bug reports and features - **Discussions**: Questions and ideas - **Discord**: Real-time chat (coming soon) ## License MIT License - see [LICENSE](./LICENSE) ## Support - šŸ“– [Documentation](./docs/) - šŸ› [Issue Tracker](https://github.com/vespo92/OPNSenseMCP/issues) - šŸ’¬ [Discussions](https://github.com/vespo92/OPNSenseMCP/discussions) --- **Built with ā¤ļø for the OPNsense community**

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vespo92/OPNSenseMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server