Package Exports
- @packetfence/mcp-server
- @packetfence/mcp-server/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@packetfence/mcp-server) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
PacketFence MCP Server
A dynamic Model Context Protocol (MCP) server that provides AI assistants with secure access to PacketFence network access control system APIs. This server automatically adapts to different PacketFence versions and deployment stages without requiring code changes.
๐ Features
- ๐ Dynamic API Discovery: Automatically loads and parses PacketFence OpenAPI specifications from GitHub
- ๐ฆ Version Adaptive: Supports PacketFence 14.0+ with automatic version detection
- ๐ Secure Authentication: Session-based authentication with automatic token refresh
- โ๏ธ Deployment Stage Aware: Adapts interface based on pre-configured vs post-configured deployments
- ๐ ๏ธ Complete CRUD Operations: Exposes GET, POST, PUT, DELETE operations as MCP resources and tools
- โ Schema Validation: Dynamic request/response validation using OpenAPI schemas
- ๐๏ธ Zero Maintenance: No hardcoded version-specific logic - adapts automatically to PacketFence changes
- ๐ Comprehensive Logging: Structured logging with performance metrics and audit trails
- ๐งช Dynamic Testing: OAS-based test coverage ensuring ALL endpoints are validated
- ๐ Endpoint Coverage: Real-time validation that all API endpoints are properly exposed
๐ Prerequisites
- Node.js: Version 18.0.0 or higher
- PacketFence: Version 14.0 or higher
- Network Access: Access to GitHub (for OpenAPI spec fetching) and PacketFence API endpoint
๐ฆ Installation
Install from npm
npm install -g @packetfence/mcp-server@latestInstall from Source (Current Method)
git clone https://github.com/inverse-inc/packetfence-mcp.git
cd packetfence-mcp
npm install
npm link # Makes packetfence-mcp command available globallyโก Quick Start
1. Verify PacketFence Setup
Ensure your PacketFence installation has:
- System API user configured
conf/unified_api_system_passfile with system password- API accessible at
https://localhost:1443(default)
2. Run the MCP Server
# Using global installation
packetfence-mcp
# Using npx
npx @packetfence/mcp-server
# From source
npm start3. Configure Your AI Assistant
Claude Code (Recommended)
Method 1: Install from npm (Recommended):
# Install from npm
npm install -g @packetfence/mcp-server
# Add to Claude Code
claude mcp add packetfence packetfence-mcpMethod 2: Install from source:
# Install from source and link globally
git clone https://github.com/inverse-inc/packetfence-mcp.git
cd packetfence-mcp
npm install
npm link
# Add to Claude Code
claude mcp add packetfence packetfence-mcpClaude Desktop
Add the MCP server to your Claude Desktop configuration (claude_desktop_config.json):
{
"mcpServers": {
"packetfence": {
"command": "packetfence-mcp",
"args": []
}
}
}Other MCP Clients
# Connect via stdio
packetfence-mcp๐ง Configuration
The server automatically detects configuration from your PacketFence installation:
- Version: Read from
conf/pf-release - Deployment Stage: Detected from
conf/pf.conf - System Password: Read from
conf/unified_api_system_pass - API Endpoint: Defaults to
https://localhost:1443
Environment Variables
| Variable | Default | Description |
|---|---|---|
PACKETFENCE_ROOT |
/usr/local/pf |
PacketFence installation directory |
PACKETFENCE_API_URL |
https://localhost:1443 |
PacketFence API base URL |
MCP_NO_PROMPT |
false |
Disable user prompts for API endpoint access (true/1 to enable) |
LOG_LEVEL |
info |
Logging level (debug, info, warn, error) |
LOG_FORMAT |
console |
Log output format (console, json) |
LOG_FILE |
- | Optional log file path for persistent logging |
๐ ๏ธ Usage Examples
Once connected to an AI assistant, you can perform PacketFence operations:
Node Management
"Show me all network nodes"
"Create a new node with MAC 00:11:22:33:44:55"
"Update node 00:11:22:33:44:55 status to registered"
"Delete node with MAC 00:11:22:33:44:55"User Management
"List all PacketFence users"
"Create a new user with username 'john.doe'"
"Show user details for 'john.doe'"Security Events
"Show recent security events"
"Close security event ID 12345"System Information
"Show PacketFence system status"
"Display current configuration"๐๏ธ Architecture
Dynamic Components
- PacketFence Detector: Detects version and deployment stage
- OAS Manager: Fetches and caches OpenAPI specifications
- OAS Parser: Parses endpoints with comprehensive audit logging
- Auth Manager: Handles PacketFence API authentication
- MCP Generator: Dynamically creates MCP resources and tools with coverage validation
- Schema Validator: Validates requests/responses against schemas
- Logger: Structured logging with performance metrics and correlation IDs
Supported Operations
- Resources (GET operations): Read-only access to PacketFence data
- Tools (POST/PUT/DELETE operations): Modify PacketFence configuration
- Bulk Operations: Automatically split into individual operations
- Error Handling: Comprehensive error reporting with context
๐งช Development
Setup Development Environment
git clone https://github.com/inverse-inc/packetfence-mcp.git
cd packetfence-mcp
npm installRun Tests
# Run all tests (excludes integration tests)
npm test
# Run all tests including integration tests
npm run test:all
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watch
# Run specific test file
npm test -- auth-manager.test.js
# Run integration tests only
npm run test:integrationBuild and Test
# Check project status
make status
# Run full build pipeline
make build
# Run tests with coverage
make test-coverageAvailable Make Targets
make help # Show all available targets
make install # Install dependencies
make test # Run test suite
make build # Full build pipeline (install + lint + test)
make lint # Run ESLint code quality checks
make version-check # Check version synchronization
make status # Show comprehensive project status
make clean # Clean build artifacts and caches๐ Security
- No Credentials Stored: System password read from PacketFence configuration
- Session Management: Automatic token refresh and session validation
- HTTPS Only: Secure communication with PacketFence API
- Input Validation: All inputs validated against OpenAPI schemas
- Error Sanitization: Sensitive information filtered from error messages
๐ Troubleshooting
Common Issues
Connection Refused
Error: connect ECONNREFUSED 127.0.0.1:1443- Verify PacketFence API is running
- Check firewall settings
- Ensure correct API URL configuration
Authentication Failed
Error: Invalid credentials for system user- Verify
conf/unified_api_system_passfile exists and is readable - Check system user configuration in PacketFence
Version Detection Failed
Error: Could not parse version from pf-release file- Ensure PacketFence is properly installed
- Check
conf/pf-releasefile exists
OpenAPI Fetch Failed
Error: Failed to fetch OAS for version X.Y- Verify internet connectivity
- Check if PacketFence version has maintenance branch on GitHub
Debug Mode
Enable verbose logging:
# Enable debug logging
LOG_LEVEL=debug packetfence-mcp
# Enable JSON structured logging
LOG_FORMAT=json packetfence-mcp
# Log to file
LOG_FILE=/tmp/packetfence-mcp.log packetfence-mcp
# Combined debugging
LOG_LEVEL=debug LOG_FORMAT=json LOG_FILE=/tmp/debug.log packetfence-mcp๐ค Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Guidelines
- Follow existing code style (ESLint configuration provided)
- Add tests for new features (prefer dynamic OAS-based tests)
- Update documentation as needed
- Ensure all tests pass before submitting PR
- Use structured logging instead of console statements
- Follow the guidelines in CLAUDE.md for LLM development practices
๐ License
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.
๐ Links
๐ Support
- Documentation: PacketFence Docs
- Community: PacketFence Discourse
- Issues: GitHub Issues
- Commercial Support: Inverse Inc.
Note: This MCP server is designed to run on the same machine as PacketFence for security and performance reasons. Remote deployments may require additional configuration and security considerations.