๐ Automate Apache Ambari operations with AI/LLM: Conversational control for Hadoop cluster management, service monitoring, configuration inspection, and precise Ambari Metrics queries via Model Context Protocol (MCP) tools.
MCP Ambari API is a powerful Model Context Protocol (MCP) server that enables seamless Apache Ambari cluster management through natural language commands. Built for DevOps engineers, data engineers, and system administrators who work with Hadoop ecosystems.
- โ Interactive Ambari Operations Hub โ Provides an MCP-based foundation for querying and managing services through natural language instead of console or UI interfaces.
- โ Real-time Cluster Visibility โ Comprehensive view of key metrics including service status, host details, alert history, and ongoing requests in a single interface.
- โ Metrics Intelligence Pipeline โ Dynamically discovers and filters AMS appIds and metric names, connecting directly to time-series analysis workflows.
- โ Automated Operations Workflow โ Consolidates repetitive start/stop operations, configuration checks, user queries, and request tracking into consistent scenarios.
- โ Built-in Operational Reports โ Instantly delivers dfsadmin-style HDFS reports, service summaries, and capacity metrics through LLM or CLI interfaces.
- โ Safety Guards and Guardrails โ Requires user confirmation before large-scale operations and provides clear guidance for risky commands through prompt templates.
- โ LLM Integration Optimization โ Includes natural language examples, parameter mapping, and usage guides to ensure stable AI agent operations.
- โ Flexible Deployment Models โ Supports stdio/streamable-http transport, Docker Compose, and token authentication for deployment across development and production environments.
- โ Performance-Oriented Caching Architecture โ Built-in AMS metadata cache and request logging ensure fast responses even in large-scale clusters.
- โ Scalable Code Architecture โ Asynchronous HTTP, structured logging, and modularized tool layers enable easy addition of new features.
- โ Production-Validated โ Based on tools validated in test Ambari clusters, ready for immediate use in production environments.
- โ Diversified Deployment Channels โ Available through PyPI packages, Docker images, and other preferred deployment methods.
apache-ambari
hadoop-cluster
mcp-server
cluster-automation
devops-tools
big-data
infrastructure-management
ai-automation
llm-tools
python-mcp
Note: The following instructions assume you are using the
streamable-http
mode for MCP Server.
To set up a Ambari Demo cluster, follow the guide at: Install Ambari 3.0 with Docker
Start the MCP-Server
, MCPO
(MCP-Proxy for OpenAPI), and OpenWebUI
.
- Ensure Docker and Docker Compose are installed on your system.
- Clone this repository and navigate to its root directory.
- Set up environment configuration:
# Copy environment template and configure your settings cp .env.example .env # Edit .env with your Ambari cluster information
- Configure your Ambari connection in
.env
file:# Ambari cluster connection AMBARI_HOST=host.docker.internal AMBARI_PORT=7070 AMBARI_USER=admin AMBARI_PASS=admin AMBARI_CLUSTER_NAME=TEST-AMBARI # Ambari Metrics (AMS) collector AMBARI_METRICS_HOST=host.docker.internal AMBARI_METRICS_PORT=16188 AMBARI_METRICS_PROTOCOL=http AMBARI_METRICS_TIMEOUT=15 # (Optional) Enable authentication for streamable-http mode # Recommended for production environments REMOTE_AUTH_ENABLE=false REMOTE_SECRET_KEY=your-secure-secret-key-here
- Run:
docker-compose up -d
- OpenWebUI will be available at:
http://localhost:${DOCKER_EXTERNAL_PORT_OPENWEBUI}
(default: 3001) - The MCPO-Proxy will be accessible at:
http://localhost:${DOCKER_EXTERNAL_PORT_MCPO_PROXY}
(default: 8001) - The MCPO API Docs:
http://localhost:${DOCKER_EXTERNAL_PORT_MCPO_PROXY}/mcp-ambari-api/docs
- logging in to OpenWebUI with an admin account
- go to "Settings" โ "Tools" from the top menu.
- Enter the
mcp-ambari-api
Tool address (e.g.,http://localhost:8000/mcp-ambari-api
) to connect MCP Tools with your Ambari cluster.
Below is an example screenshot showing how to query the Ambari cluster using MCP Tools in OpenWebUI:
-
Terminology quick reference
- appId: Ambari Metrics Service groups every metric under an application identifier (e.g.,
namenode
,datanode
,ambari_server
,HOST
). Think of it as the component or service emitting that timeseries. - metric name: The fully qualified string Ambari uses for each timeseries (e.g.,
jvm.JvmMetrics.MemHeapUsedM
,dfs.datanode.BytesWritten
). Exact names are required when querying AMS.
- appId: Ambari Metrics Service groups every metric under an application identifier (e.g.,
-
list_common_metrics_catalog
: keyword search against the live metadata-backed metric catalog (cached locally). Usesearch="heap"
or similar to narrow suggestions before running a time-series query.
Example: โShow the heap-related metrics available for the NameNode appId.โ -
list_ambari_metric_apps
: list discovered AMSappId
values, optionally including metric counts; passrefresh=true
orlimit
to control output.
Example: โList every appId currently exposed by AMS.โ -
The natural-language query โAMS์์ ์ฌ์ฉ ๊ฐ๋ฅํ appId ๋ชฉ๋ก๋ง ๋ณด์ฌ์คโ maps to
list_ambari_metric_apps
and returns the exact identifiers you can copy into other tools. -
list_ambari_metrics_metadata
: raw AMS metadata explorer (supportsapp_id
,metric_name_filter
,host_filter
,search
, adjustablelimit
, default 50).
Example: โGive me CPU-related metric metadata under HOST.โ -
query_ambari_metrics
: fetch time-series data; the tool auto-selects curated metric names, falls back to metadata search when needed, and honors Ambari's default precision unless you explicitly supplyprecision="SECONDS"
, etc.
Examples: โPlot the last 30 minutes ofjvm.JvmMetrics.MemHeapUsedM
for the NameNode.โ / โComparejvm.JvmMetrics.MemHeapUsedM
for DataNode hostsbigtop-hostname0.demo.local
andbigtop-hostname1.demo.local
over the past 30 minutes.โ -
hdfs_dfadmin_report
: produce a DFSAdmin-style capacity/DataNode summary (mirrorshdfs dfsadmin -report
).
Live Metric Catalog (via AMS metadata)
- Metric names are discovered on demand from
/ws/v1/timeline/metrics/metadata
and cached for quick reuse. - Use
list_common_metrics_catalog
or theambari-metrics://catalog/all
resource (append?refresh=true
to bypass the cache) to inspect the latestappId โ metric
mapping. Queryambari-metrics://catalog/apps
to list appIds orambari-metrics://catalog/<appId>
for a single app. - Typical appIds include
ambari_server
,namenode
,datanode
,nodemanager
,resourcemanager
, andHOST
, but the list adapts to whatever the Ambari Metrics service advertises in your cluster.
Recent updates removed natural-language metric guessing in favor of deterministic, catalog-driven lookups. Keep the following rules in mind when you (or an LLM agent) call query_ambari_metrics
:
- Always pass an explicit
app_id
. If it is missing or unsupported, the tool returns a list of valid appIds and aborts so you can choose one manually. - Specify exact metric names. Use
list_common_metrics_catalog(app_id="<target>", search="keyword")
,list_ambari_metric_apps
(to discover appIds), or theambari-metrics://catalog/<appId>
resource to browse the live per-app metric set and copy the identifier (e.g.,jvm.JvmMetrics.MemHeapUsedM
). - Host-scope behavior: When
hostnames
is omitted the API returns cluster-wide aggregates. Provide one or more hosts (comma-separated) to focus on specific nodes. - No fuzzy matches. The server now calls Ambari exactly as requested. If the metric is wrong or empty, Ambari will simply return no datapointsโdouble-check the identifier via
/ws/v1/timeline/metrics/metadata
.
Example invocation:
query_ambari_metrics(
metric_names="jvm.JvmMetrics.MemHeapUsedM",
app_id="nodemanager",
duration="1h",
group_by_host=true
)
For multi-metric lookups, pass a comma-separated list of exact names. Responses document any auto-applied host filters so you can copy/paste them into subsequent requests.
This MCP server supports two connection modes: stdio (traditional) and streamable-http (Docker-based). You can configure the transport mode using CLI arguments or environment variables.
Configuration Priority: CLI arguments > Environment variables > Default values
--type
(-t
): Transport type (stdio
orstreamable-http
) - Default:stdio
--host
: Host address for HTTP transport - Default:127.0.0.1
--port
(-p
): Port number for HTTP transport - Default:8000
--auth-enable
: Enable Bearer token authentication for streamable-http mode - Default:false
--secret-key
: Secret key for Bearer token authentication (required when auth enabled)
Variable | Description | Default | Project Default |
---|---|---|---|
PYTHONPATH |
Python module search path for MCP server imports | - | /app/src |
MCP_LOG_LEVEL |
Server logging verbosity (DEBUG, INFO, WARNING, ERROR) | INFO |
INFO |
FASTMCP_TYPE |
MCP transport protocol (stdio for CLI, streamable-http for web) | stdio |
streamable-http |
FASTMCP_HOST |
HTTP server bind address (0.0.0.0 for all interfaces) | 127.0.0.1 |
0.0.0.0 |
FASTMCP_PORT |
HTTP server port for MCP communication | 8000 |
8000 |
REMOTE_AUTH_ENABLE |
Enable Bearer token authentication for streamable-http mode Default: false (if undefined, empty, or null) |
false |
false |
REMOTE_SECRET_KEY |
Secret key for Bearer token authentication Required when REMOTE_AUTH_ENABLE=true |
- | your-secret-key-here |
AMBARI_HOST |
Ambari server hostname or IP address | 127.0.0.1 |
host.docker.internal |
AMBARI_PORT |
Ambari server port number | 8080 |
8080 |
AMBARI_USER |
Username for Ambari server authentication | admin |
admin |
AMBARI_PASS |
Password for Ambari server authentication | admin |
admin |
AMBARI_CLUSTER_NAME |
Name of the target Ambari cluster | TEST-AMBARI |
TEST-AMBARI |
DOCKER_EXTERNAL_PORT_OPENWEBUI |
Host port mapping for Open WebUI container | 8080 |
3001 |
DOCKER_EXTERNAL_PORT_MCP_SERVER |
Host port mapping for MCP server container | 8080 |
18001 |
DOCKER_EXTERNAL_PORT_MCPO_PROXY |
Host port mapping for MCPO proxy container | 8000 |
8001 |
Note: AMBARI_CLUSTER_NAME
serves as the default target cluster for operations when no specific cluster is specified. All environment variables can be configured via the .env
file.
Transport Selection Logic:
Configuration Priority: CLI arguments > Environment variables > Default values
Transport Selection Logic:
- CLI Priority:
--type streamable-http --host 0.0.0.0 --port 18001
- Environment Priority:
FASTMCP_TYPE=streamable-http FASTMCP_HOST=0.0.0.0 FASTMCP_PORT=18001
- Legacy Support:
FASTMCP_PORT=18001
(automatically enables streamable-http mode) - Default:
stdio
mode when no configuration is provided
# 1. Clone the repository
git clone https://github.com/call518/MCP-Ambari-API.git
cd MCP-Ambari-API
# 2. Set up environment configuration
cp .env.example .env
# 3. Configure your Ambari connection in .env file
AMBARI_HOST=your-ambari-host
AMBARI_PORT=your-ambari-port
AMBARI_USER=your-username
AMBARI_PASS=your-password
AMBARI_CLUSTER_NAME=your-cluster-name
For streamable-http
mode, this MCP server supports Bearer token authentication to secure remote access. This is especially important when running the server in production environments.
Enable Authentication:
# In .env file
REMOTE_AUTH_ENABLE=true
REMOTE_SECRET_KEY=your-secure-secret-key-here
Or via CLI:
python -m mcp_ambari_api --type streamable-http --auth-enable --secret-key your-secure-secret-key-here
- stdio mode (Default): Local-only access, no authentication needed
- streamable-http + REMOTE_AUTH_ENABLE=false/undefined: Remote access without authentication
โ ๏ธ NOT RECOMMENDED for production - streamable-http + REMOTE_AUTH_ENABLE=true: Remote access with Bearer token authentication โ RECOMMENDED for production
๐ Default Policy:
REMOTE_AUTH_ENABLE
defaults tofalse
if undefined, empty, or null. This ensures the server starts even without explicit authentication configuration.
When authentication is enabled, MCP clients must include the Bearer token in the Authorization header:
{
"mcpServers": {
"mcp-ambari-api": {
"type": "streamable-http",
"url": "http://your-server:8000/mcp",
"headers": {
"Authorization": "Bearer your-secure-secret-key-here"
}
}
}
}
- Always enable authentication when using streamable-http mode in production
- Use strong, randomly generated secret keys (32+ characters recommended)
- Use HTTPS when possible (configure reverse proxy with SSL/TLS)
- Restrict network access using firewalls or network policies
- Rotate secret keys regularly for enhanced security
- Monitor access logs for unauthorized access attempts
When authentication fails, the server returns:
- 401 Unauthorized for missing or invalid tokens
- Detailed error messages in JSON format for debugging
{
"mcpServers": {
"mcp-ambari-api": {
"command": "uvx",
"args": ["--python", "3.12", "mcp-ambari-api"],
"env": {
"AMBARI_HOST": "host.docker.internal",
"AMBARI_PORT": "8080",
"AMBARI_USER": "admin",
"AMBARI_PASS": "admin",
"AMBARI_CLUSTER_NAME": "TEST-AMBARI",
"MCP_LOG_LEVEL": "INFO"
}
}
}
}
On MCP-Client Host:
{
"mcpServers": {
"mcp-ambari-api": {
"type": "streamable-http",
"url": "http://localhost:18001/mcp"
}
}
}
With Bearer Token Authentication (Recommended for production):
{
"mcpServers": {
"mcp-ambari-api": {
"type": "streamable-http",
"url": "http://localhost:18001/mcp",
"headers": {
"Authorization": "Bearer your-secure-secret-key-here"
}
}
}
}
claude_desktop_config.json
{
"mcpServers": {
"mcp-ambari-api": {
"command": "uvx",
"args": ["--python", "3.12", "mcp-ambari-api"],
"env": {
"AMBARI_HOST": "localhost",
"AMBARI_PORT": "7070",
"AMBARI_USER": "admin",
"AMBARI_PASS": "admin",
"AMBARI_CLUSTER_NAME": "TEST-AMBARI",
"MCP_LOG_LEVEL": "INFO"
}
}
}
}
(Option) Configure Multiple Ambari Cluster
{
"mcpServers": {
"Ambari-Cluster-A": {
"command": "uvx",
"args": ["--python", "3.12", "mcp-ambari-api"],
"env": {
"AMBARI_HOST": "a.foo.com",
"AMBARI_PORT": "8080",
"AMBARI_USER": "admin-user",
"AMBARI_PASS": "admin-pass",
"AMBARI_CLUSTER_NAME": "AMBARI-A",
"MCP_LOG_LEVEL": "INFO"
}
},
"Ambari-Cluster-B": {
"command": "uvx",
"args": ["--python", "3.12", "mcp-ambari-api"],
"env": {
"AMBARI_HOST": "b.bar.com",
"AMBARI_PORT": "8080",
"AMBARI_USER": "admin-user",
"AMBARI_PASS": "admin-pass",
"AMBARI_CLUSTER_NAME
5C91
": "AMBARI-B",
"MCP_LOG_LEVEL": "INFO"
}
}
}
}
Remote Access with Authentication (Claude Desktop):
{
"mcpServers": {
"mcp-ambari-api-remote": {
"type": "streamable-http",
"url": "http://your-server-ip:18001/mcp",
"headers": {
"Authorization": "Bearer your-secure-secret-key-here"
}
}
}
}
- Hadoop Service Management: Start, stop, restart HDFS, YARN, Spark, HBase, and more
- Bulk Operations: Control all cluster services simultaneously
- Status Monitoring: Real-time service health and performance tracking
- Unified Config Tool: Single interface for all configuration types (yarn-site, hdfs-site, etc.)
- Bulk Configuration: Export and manage multiple configurations with filtering
- Configuration Validation: Syntax checking and validation before applying changes
- Real-time Alerts: Current and historical cluster alerts with filtering
- Request Tracking: Monitor long-running operations with detailed progress
- Host Monitoring: Hardware metrics, component states, and resource utilization
- User Management: Check cluster user administration
- Host Management: Node registration, component assignments, and health monitoring
This MCP server provides the following tools for Ambari cluster management:
get_cluster_info
- Retrieve basic cluster information and statusget_active_requests
- List currently active/running operationsget_request_status
- Check status and progress of specific requests
get_cluster_services
- List all services with their statusget_service_status
- Get detailed status of a specific serviceget_service_components
- List components and host assignments for a serviceget_service_details
- Get comprehensive service informationstart_service
- Start a specific servicestop_service
- Stop a specific servicerestart_service
- Restart a specific servicestart_all_services
- Start all services in the clusterstop_all_services
- Stop all services in the clusterrestart_all_services
- Restart all services in the cluster
dump_configurations
- Unified configuration tool (replacesget_configurations
,list_configurations
, and the former internaldump_all_configurations
). Supports:- Single type:
dump_configurations(config_type="yarn-site")
- Bulk summary:
dump_configurations(summarize=True)
- Filter by substring (type or key):
dump_configurations(filter="memory")
- Service filter (narrow types by substring):
dump_configurations(service_filter="yarn", summarize=True)
- Keys only (no values):
dump_configurations(include_values=False)
- Limit number of types:
dump_configurations(limit=10, summarize=True)
- Single type:
Breaking Change:
get_configurations
andlist_configurations
were removed in favor of this single, more capable tool.
list_hosts
- List all hosts in the clusterget_host_details
- Get detailed information for specific or all hosts (includes component states, hardware metrics, and service assignments)
list_users
- List all users in the Ambari system with their usernames and API linksget_user
- Get detailed information about a specific user including:- Basic profile (ID, username, display name, user type)
- Status information (admin privileges, active status, login failures)
- Authentication details (LDAP user status, authentication sources)
- Group memberships, privileges, and widget layouts
get_alerts_history
- Unified alert tool for both current and historical alerts:- Current mode (
mode="current"
): Retrieve current/active alerts with real-time status- Current alert states across cluster, services, or hosts
- Maintenance mode filtering (ON/OFF)
- Summary formats: basic summary and grouped by definition
- Detailed alert information including timestamps and descriptions
- History mode (
mode="history"
): Retrieve historical alert events from the cluster- Scope filtering: cluster-wide, service-specific, or host-specific alerts
- Time range filtering: from/to timestamp support
- Pagination support for large datasets
- Common features (both modes):
- State filtering: CRITICAL, WARNING, OK, UNKNOWN alerts
- Definition filtering: filter by specific alert definition names
- Multiple output formats: detailed, summary, compact
- Unified API for consistent alert querying experience
- Current mode (
- ๐ Report Bugs: GitHub Issues
- ๐ก Request Features: Feature Requests
- ๐ง Submit PRs: Contributing Guidelines
- ๐ Improve Docs: Help make documentation better
- Language: Python 3.12
- Framework: Model Context Protocol (MCP)
- API: Apache Ambari REST API
- Transport: stdio (local) and streamable-http (remote)
- Deployment: Docker, Docker Compose, PyPI
-
WSL2(networkingMode = bridged) + Docker-Desktop
.wslconfig
: tested withnetworkingMode = bridged
-
Python 3.12 venv
### Option-1: with uv uv venv --python 3.12 --seed ### Option-2: with pip python3.12 -m venv .venv source .venv/bin/activate pip install -U pip
After you've thoroughly explored the existing functionality, you might want to add your own custom tools for specific monitoring or management needs. This MCP server is designed for easy extensibility.
Add reusable data functions to src/mcp_ambari_api/functions.py
:
async def get_your_custom_data(target_resource: str = None) -> List[Dict[str, Any]]:
"""Your custom data retrieval function."""
# Example implementation - adapt to your Ambari service
endpoint = f"/clusters/{AMBARI_CLUSTER_NAME}/your_custom_endpoint"
if target_resource:
endpoint += f"/{target_resource}"
response_data = await make_ambari_request(endpoint)
if response_data is None or "items" not in response_data:
return []
return response_data["items"]
Add your tool function to src/mcp_ambari_api/mcp_main.py
:
@mcp.tool()
@log_tool
async def get_your_custom_analysis(limit: int = 50, target_name: Optional[str] = None) -> str:
"""
[Tool Purpose]: Brief description of what your tool does
[Core Functions]:
- Feature 1: Data aggregation and analysis
- Feature 2: Resource monitoring and insights
- Feature 3: Performance metrics and reporting
[Required Usage Scenarios]:
- When user asks "your specific analysis request"
- Your business-specific monitoring needs
Args:
limit: Maximum results (1-100)
target_name: Target resource/service name (optional)
Returns:
Formatted analysis results (success: formatted data, failure: English error message)
"""
try:
limit = max(1, min(limit, 100)) # Always validate input
results = await get_your_custom_data(target_resource=target_name)
if not results:
return f"No custom analysis data found{' for ' + target_name if target_name else ''}."
# Apply limit
limited_results = results[:limit]
# Format output
result_lines = [
f"Custom Analysis Results{' for ' + target_name if target_name else ''}",
"=" * 50,
f"Found: {len(limited_results)} items (total: {len(results)})",
""
]
for i, item in enumerate(limited_results, 1):
# Customize this formatting based on your data structure
name = item.get("name", "Unknown")
status = item.get("status", "N/A")
result_lines.append(f"[{i}] {name}: {status}")
return "\n".join(result_lines)
except Exception as e:
return f"Error: Exception occurred while retrieving custom analysis - {str(e)}"
Add your helper function to the imports section in src/mcp_ambari_api/mcp_main.py
:
from mcp_ambari_api.functions import (
format_timestamp,
format_single_host_details,
make_ambari_request,
# ... existing imports ...
get_your_custom_data, # Add your new function here
)
Add your tool description to src/mcp_ambari_api/prompt_template.md
for better AI recognition:
### Custom Analysis Tools
**get_your_custom_analysis**
- "Show me custom analysis results"
- "Get custom analysis for target_name"
- "Display custom monitoring data"
- ๐ **Features**: Custom data aggregation, resource monitoring, performance insights
# Local testing with MCP Inspector
./run-mcp-inspector-local.sh
# Or test with Docker environment
docker-compose up -d
docker-compose logs -f mcp-server
# Test with natural language queries:
# "Show me custom analysis results"
# "Get custom analysis for my_target"
- Always use
@mcp.tool()
and@log_tool
decorators for proper registration and logging - Follow the existing error handling patterns - return English error messages starting with "Error:"
- Use
make_ambari_request()
function for all Ambari API calls to ensure consistent authentication and error handling - Validate all input parameters before using them in API calls
- Test thoroughly with both valid and invalid inputs
- Custom service health checks beyond standard Ambari monitoring
- Specialized configuration validation for your organization's standards
- Custom alert aggregation and reporting formats
- Integration with external monitoring systems via Ambari data
- Automated compliance checking for cluster configurations
A: Ambari 2.7+ is recommended. Earlier versions may work but are not officially tested.
A: Yes, as long as Ambari API endpoints are accessible, it works with on-premise, cloud, and hybrid deployments.
A: Check your AMBARI_HOST
, AMBARI_PORT
, and network connectivity. Enable debug logging with MCP_LOG_LEVEL=DEBUG
.
A: This provides programmatic access via AI/LLM commands, perfect for automation, scripting, and integration with modern DevOps workflows.
๐ค Got ideas? Found bugs? Want to add cool features?
We're always excited to welcome new contributors! Whether you're fixing a typo, adding a new monitoring tool, or improving documentation - every contribution makes this project better.
Ways to contribute:
- ๐ Report issues or bugs
- ๐ก Suggest new Ambari monitoring features
- ๐ Improve documentation
- ๐ Submit pull requests
- โญ Star the repo if you find it useful!
Pro tip: The codebase is designed to be super friendly for adding new tools. Check out the existing @mcp.tool()
functions in mcp_main.py
and follow the Adding Custom Tools guide above.
This project is licensed under the MIT License.