This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Python-based MCP (Model Context Protocol) server that provides tools for interacting with Juniper Apstra Fabric Manager APIs. The server exposes datacenter network management capabilities through MCP tools.
The project consists of two main Python files:
- FastMCP Server: Built using the
fastmcpframework with native transport support - Transport Modes: Supports stdio (secure) and streamable-http (with native FastMCP streaming)
- MCP Tool Definitions: 21 MCP tools organized into logical groups
- Native FastMCP Transport: Uses FastMCP's built-in HTTP and SSE capabilities
- Authentication Layer: Handles config-based authentication with Apstra server
- API Wrappers: Core functions that wrap Apstra REST API endpoints
- Error Handling: Comprehensive error handling with proper exception propagation
- JSON Response Formatting: Consistent JSON formatting for all responses
Health & Status Tools (2 tools):
- Health check: Server status (
health()) - Formatting: Formatting guidelines (
formatting_guidelines())
Query Tools (12 tools):
- Blueprint management: Get blueprint information (
get_bp()) - Infrastructure queries: Get racks (
get_racks()), routing zones (get_rz()) - Network queries: Get virtual networks (
get_vn()), remote gateways (get_remote_gw()) - Connectivity templates: Get connectivity templates (
get_ct()), application endpoints (get_app_ep()) - System queries: Get systems/devices (
get_system_info()) - Monitoring: Get anomalies (
get_anomalies()), protocol sessions (get_protocol_sessions()) - Configuration queries: Check diff status (
get_diff_status()), get templates (get_templates())
Management Tools (3 tools):
- Configuration management: Deploy configurations (
deploy()), delete blueprints (delete_blueprint()) - Policy management: Apply connectivity template policies (
apply_ct_policies())
Create Tools (4 tools):
- Network provisioning: Create virtual networks with advanced options (
create_vn()), remote gateways (create_remote_gw()) - Blueprint creation: Create datacenter (
create_datacenter_blueprint()) and freeform blueprints (create_freeform_blueprint())
- Native FastMCP Transport: Uses FastMCP's built-in streamable-http with automatic SSE upgrades
- Config-based Authentication: Simple authentication using configuration file credentials
- Enhanced Virtual Network Creation: Advanced VN creation with VXLAN/VLAN support, SVI IPs, and leaf expansion
- Connectivity Template Management: Query connectivity templates and manage application endpoint policy assignments
- Policy Batch Operations: Apply/remove connectivity template policies across multiple interfaces
- Remote Gateway Management: Comprehensive EVPN remote gateway creation with optional parameters
- Flexible Configuration: Support for various server:port configurations with 443 as default
- Consistent Error Handling: All functions use
response.raise_for_status()and proper exception handling
# For Claude Desktop - uses config file authentication
python3 apstra_mcp.py -t stdio -f apstra_config.json# Start streamable HTTP server with native FastMCP streaming
python3 apstra_mcp.py -t streamable-http -H 0.0.0.0 -p 8080 -f apstra_config.json# Start HTTP streaming server
docker-compose up -dBefore running, create a configuration file (see apstra_config_sample.json for reference):
server: IP address or hostname of the Apstra serverport: Port number for the Apstra server (optional, defaults to 443)username: Apstra username for authenticationpassword: Apstra password for authentication
Flexible Port Configuration Options:
- Separate server and port:
"server": "hostname", "port": "8443" - Combined format:
"server": "hostname:8443" - Default HTTPS:
"server": "hostname"(uses port 443)
Legacy Support: The configuration also supports legacy field names (aos_server, aos_port) for backward compatibility.
{
"mcpServers": {
"apstra": {
"command": "python3",
"args": ["/path/to/apstra_mcp.py", "-t", "stdio", "-f", "/path/to/apstra_config.json"]
}
}
}Security Note:
- stdio transport (default): Secure by default, no network exposure
- streamable-http transport: Network-accessible, use reverse proxy with authentication for production
fastmcp: MCP server frameworkhttpx: HTTP client for API requestssys: Standard library for system operations
- Server uses
verify=Falsefor HTTPS requests (bypasses SSL verification) - Credentials are stored in JSON configuration files
- Consider using encrypted credential storage for production use
- stdio Transport: Secure local communication for Claude Desktop integration
- streamable-http Transport: Network-accessible transport with native FastMCP streaming capabilities
- Configuration-based: Uses credentials from JSON configuration file
- Stateless Operation: No session management or token persistence required
- Apstra Integration: Direct authentication against Apstra Fabric Manager
- Native FastMCP Integration: Leverages FastMCP framework's built-in transport capabilities
- Automatic SSE Support: Streaming responses with Server-Sent Events for real-time updates
- Simplified Architecture: Single server process with minimal dependencies
- Container Support: Docker deployment with configurable transport modes
- GET functions first: All query operations grouped together
- Management functions: Deploy and delete operations
- CREATE functions last: All creation operations grouped at the end
- Use
response.raise_for_status()for HTTP error detection - Print errors to
sys.stderrbefore returning error messages - Return formatted error messages instead of raising exceptions to MCP clients
stdio mode:
python3 apstra_mcp.py -t stdio -f apstra_config.jsonstreamable-http mode:
python3 apstra_mcp.py -t streamable-http -H 0.0.0.0 -p 8080 -f apstra_config.jsonDocker deployment:
docker-compose up -d- Always use
json.dumps(response.json(), indent=2)for consistent formatting - Handle different API response structures (some use 'items', others use specific keys like 'nodes')
- For single object endpoints, return the object directly without array wrapping
- Required parameters first in function signature
- Optional parameters with sensible defaults last
- Use None for truly optional parameters that should be excluded from payload
- Use default values for parameters that should always be included