A comprehensive Model Context Protocol (MCP) server for Apache Ambari cluster management, enabling LLMs to interact with Ambari clusters through standardized tools, resources, and prompts.
- π οΈ Comprehensive Tools: Service management, host monitoring, configuration updates, health checks
- π Rich Resources: Cluster status, operational modes, documentation
- π¬ Context-Aware Prompts: Maintenance workflows, scaling guides, configuration management
- π Mode-Based Operations: Different behavioral contexts for various operational scenarios
- Normal: Full access with safety confirmations
- Cluster Maintenance: Restricted to monitoring and safe shutdown operations
- Scale Up: Optimized for capacity expansion (prevents accidental shutdowns)
- Config Edit: Focused on configuration management (service operations disabled)
- Development: Enhanced logging with no confirmations for rapid development
- MCP Server: Standard MCP protocol support (stdio, SSE, streamable HTTP)
- FastAPI REST Interface: Web API for demonstrations and integrations
- CLI Interface: Command-line tools for server management and testing
- Docker Support: Containerized deployment with docker-compose
- Installation
- Quick Start
- Configuration
- Usage Examples
- Architecture
- API Reference
- Development
- Docker Deployment
- Contributing
- Python 3.11 or higher
- Apache Ambari server (accessible via REST API)
- Optional: Docker for containerized deployment
# Clone the repository
git clone <repository-url>
cd ambari_mcp
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Install in development mode
pip install -e .# Build and run with docker-compose
docker-compose up -d
# Or build manually
docker build -t ambari-mcp .
docker run -p 8000:8000 -p 8001:8001 ambari-mcpCreate a .env file (copy from env.example):
# Ambari Configuration
AMBARI_HOST=your-ambari-server
AMBARI_PORT=8080
AMBARI_USERNAME=admin
AMBARI_PASSWORD=admin
AMBARI_CLUSTER_NAME=YourClusterpython -m ambari_mcp.main test-connection# Run MCP server with stdio transport
python -m ambari_mcp.main run-mcp
# Run with HTTP transport
python -m ambari_mcp.main run-mcp --transport streamable-http --port 8001
# Run FastAPI interface
python -m ambari_mcp.main run-fastapi --port 8000
# Run both concurrently
python -m ambari_mcp.main run-both# Run MCP client example
python examples/mcp_client_example.py
# Run FastAPI demo
python examples/fastapi_demo.py| Variable | Default | Description |
|---|---|---|
AMBARI_HOST |
localhost | Ambari server hostname |
AMBARI_PORT |
8080 | Ambari server port |
AMBARI_USERNAME |
admin | Ambari username |
AMBARI_PASSWORD |
admin | Ambari password |
AMBARI_CLUSTER_NAME |
- | Default cluster name (auto-detect if empty) |
AMBARI_USE_SSL |
false | Use HTTPS for Ambari connections |
MCP_SERVER_NAME |
ambari-mcp | MCP server name |
MCP_MODE |
normal | Initial operational mode |
LOG_LEVEL |
INFO | Logging level |
Each mode has specific restrictions and behaviors:
# Normal Mode - Full access with confirmations
mode_manager.switch_mode("normal")
# Maintenance Mode - Read-only with safe shutdown only
mode_manager.switch_mode("cluster_maintenance")
# Scale Up Mode - Prevents service shutdowns
mode_manager.switch_mode("scale_up")
# Config Edit Mode - Configuration management only
mode_manager.switch_mode("config_edit")
# Development Mode - All operations without confirmations
mode_manager.switch_mode("development")from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
# Connect to Ambari MCP Server
server_params = StdioServerParameters(
command="python",
args=["-m", "ambari_mcp.main", "run-mcp", "--transport", "stdio"]
)
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
# Switch to maintenance mode
result = await session.call_tool("switch_mode", {
"mode": "cluster_maintenance",
"reason": "Scheduled maintenance"
})
# Get cluster status
status = await session.call_tool("get_cluster_status", {})
# Stop a service safely
result = await session.call_tool("stop_service", {
"service_name": "YARN"
})import httpx
async with httpx.AsyncClient() as client:
# Get cluster health
health = await client.get("http://localhost:8000/cluster/health")
# Switch operational mode
mode_switch = await client.post("http://localhost:8000/modes/switch",
json={"mode": "scale_up", "reason": "Adding new nodes"})
# Start a service
start_result = await client.post("http://localhost:8000/services/HDFS/start")# Server information
python -m ambari_mcp.main info
# Test Ambari connection
python -m ambari_mcp.main test-connection MyCluster
# Run with specific configuration
python -m ambari_mcp.main run-mcp --host 0.0.0.0 --port 8001 --transport sse
# Run FastAPI with auto-reload
python -m ambari_mcp.main run-fastapi --reloadUse the cluster_overview prompt to get a comprehensive view:
- Overall cluster health status
- Service states and any issues
- Host health and capacity
- Recent operations or changes
- Recommendations for any issues found
1. Switch to appropriate mode for the operation
2. Check current service status
3. Verify service dependencies
4. Execute operation with proper confirmations
5. Monitor operation progress
6. Verify successful completion
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β LLM Client β β FastAPI Web β β CLI Tools β
β β β Interface β β β
βββββββββββ¬ββββββββ ββββββββββ¬ββββββββββ βββββββββββ¬ββββββββ
β β β
βββββββββββββββββββββββΌβββββββββββββββββββββββββ
β
βββββββββββββΌββββββββββββ
β Ambari MCP Server β
β β
β βββββββββββββββββββ β
β β Mode Manager β β
β β - Normal β β
β β - Maintenance β β
β β - Scale Up β β
β β - Config Edit β β
β β - Development β β
β βββββββββββββββββββ β
β β
β βββββββββββββββββββ β
β β MCP Components β β
β β - Tools β β
β β - Resources β β
β β - Prompts β β
β βββββββββββββββββββ β
βββββββββββββ¬ββββββββββββ
β
βββββββββββββΌββββββββββββ
β Ambari Client β
β - REST API β
β - Authentication β
β - Error Handling β
β - Retry Logic β
βββββββββββββ¬ββββββββββββ
β
βββββββββββββΌββββββββββββ
β Apache Ambari β
β Cluster Management β
βββββββββββββββββββββββββββ
| Tool | Description | Modes |
|---|---|---|
switch_mode |
Change operational mode | All |
get_cluster_status |
Get comprehensive cluster status | All |
list_services |
List all cluster services | All |
start_service |
Start a stopped service | Normal, Scale Up, Development |
stop_service |
Stop a running service | Normal, Maintenance, Development |
restart_service |
Restart a service | Normal, Scale Up, Development |
get_service_info |
Get detailed service information | All |
list_hosts |
List all cluster hosts | All |
get_host_info |
Get detailed host information | All |
get_configurations |
Retrieve configuration settings | All |
update_configuration |
Update configuration properties | Normal, Scale Up, Config Edit, Development |
health_check |
Perform cluster health check | All |
get_request_status |
Check operation status | All |
| Resource | Description |
|---|---|
ambari://cluster/{name}/status |
Real-time cluster status |
ambari://mode/current |
Current operational mode info |
ambari://documentation/modes |
Mode documentation |
ambari://documentation/api |
API operation documentation |
| Prompt | Description | Use Case |
|---|---|---|
cluster_overview |
Comprehensive cluster analysis | Health monitoring |
service_management |
Service operation guidance | Service lifecycle |
maintenance_checklist |
Maintenance workflow | Planned maintenance |
scale_up_planning |
Capacity expansion guide | Cluster scaling |
configuration_management |
Config change workflow | Configuration updates |
GET /health- Server health checkGET /status- Comprehensive server status
GET /modes- List available modesGET /modes/current- Get current modePOST /modes/switch- Switch operational mode
GET /cluster/status- Get cluster statusGET /cluster/health- Cluster health check
GET /services- List servicesGET /services/{name}- Get service detailsPOST /services/{name}/start- Start servicePOST /services/{name}/stop- Stop servicePOST /services/{name}/restart- Restart service
GET /hosts- List hostsGET /hosts/{name}- Get host details
GET /configurations/{type}- Get configurationPUT /configurations/{type}- Update configuration
GET /requests- List recent requestsGET /requests/{id}- Get request status
GET /mcp/tools- List available MCP toolsGET /mcp/resources- List available MCP resourcesGET /mcp/prompts- List available MCP prompts
# Clone and setup
git clone <repository-url>
cd ambari_mcp
python -m venv venv
source venv/bin/activate
# Install with development dependencies
pip install -r requirements.txt
pip install -e .
# Run tests
pytest
# Code formatting
black ambari_mcp/
isort ambari_mcp/
# Type checking
mypy ambari_mcp/# Run with auto-reload and debug logging
python -m ambari_mcp.main run-both --mcp-transport streamable-http
# Run FastAPI with reload
python -m ambari_mcp.main run-fastapi --reload
# Run in development mode (no confirmations)
MCP_MODE=development python -m ambari_mcp.main run-mcp# Unit tests
pytest tests/
# Integration tests (requires Ambari)
pytest tests/integration/
# Test with example scripts
python examples/mcp_client_example.py
python examples/fastapi_demo.py# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Scale for high availability
docker-compose up -d --scale ambari-mcp=3
# Stop services
docker-compose down# Build image
docker build -t ambari-mcp .
# Run MCP server
docker run -d \
--name ambari-mcp-server \
-p 8001:8001 \
-e AMBARI_HOST=your-ambari-server \
-e AMBARI_USERNAME=admin \
-e AMBARI_PASSWORD=admin \
ambari-mcp
# Run FastAPI interface
docker run -d \
--name ambari-mcp-api \
-p 8000:8000 \
-e AMBARI_HOST=your-ambari-server \
ambari-mcp \
python -m ambari_mcp.main run-fastapi# docker-compose.override.yml
version: '3.8'
services:
ambari-mcp:
environment:
- AMBARI_HOST=production-ambari.example.com
- AMBARI_USERNAME=mcp-user
- AMBARI_PASSWORD=secure-password
- AMBARI_CLUSTER_NAME=ProductionCluster
- LOG_LEVEL=INFO
- MCP_MODE=normalWe welcome contributions! Please see our contributing guidelines:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes with proper tests and documentation
- Run the test suite:
pytest - Format your code:
black . && isort . - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow PEP 8 style guidelines
- Add type hints for all functions
- Include docstrings for public APIs
- Write tests for new functionality
- Update documentation for new features
This project is licensed under the MIT License - see the LICENSE file for details.
- Model Context Protocol for the MCP specification
- Apache Ambari for cluster management capabilities
- FastAPI for the REST interface framework
- Anthropic for MCP development and support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: See the
/docsdirectory for detailed documentation
Built with β€οΈ for the Apache Ambari and MCP communities