JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10
  • Score
    100M100P100Q53665F
  • License GPL-3.0

MCP Server for PacketFence API integration - dynamically adapts to PacketFence versions

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

npm version Node.js Version License: GPL-3.0

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@latest

Install 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_pass file 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 start

3. Configure Your AI Assistant

Method 1: Install from npm (Recommended):

# Install from npm
npm install -g @packetfence/mcp-server

# Add to Claude Code
claude mcp add packetfence packetfence-mcp

Method 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-mcp

Claude 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

  1. PacketFence Detector: Detects version and deployment stage
  2. OAS Manager: Fetches and caches OpenAPI specifications
  3. OAS Parser: Parses endpoints with comprehensive audit logging
  4. Auth Manager: Handles PacketFence API authentication
  5. MCP Generator: Dynamically creates MCP resources and tools with coverage validation
  6. Schema Validator: Validates requests/responses against schemas
  7. 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 install

Run 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:integration

Build and Test

# Check project status
make status

# Run full build pipeline
make build

# Run tests with coverage
make test-coverage

Available 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_pass file 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-release file 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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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.

๐Ÿ“ž Support


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.