OpenShift MCP Server
# OpenShift MCP Server
A Model Context Protocol (MCP) server for OpenShift diagnostics and troubleshooting.
## Features
### Storage Tools
- **Storage Analysis**: `get_cluster_storage_report` - comprehensive report of ephemeral storage usage on nodes, including top pod consumers.
- **Deep Forensics**: `inspect_node_storage_forensics` - deep analysis of disk usage on a specific node, checking for unused images and container writable layers.
- **PV Capacity**: `check_persistent_volume_capacity` - monitor persistent volume usage across namespaces with configurable thresholds.
### Monitoring Tools
- **Resource Balance**: `get_cluster_resource_balance` - analyze CPU and memory resource distribution across nodes.
- **Pod Restarts**: `detect_pod_restarts_anomalies` - identify pods with excessive restart counts within a time window.
- **GPU Utilization**: `get_gpu_utilization` - track GPU usage and identify idle GPU resources.
- **Inspect GPU Pod**: `inspect_gpu_pod` - run `nvidia-smi` inside a GPU-enabled pod to view real-time process and memory details.
- **Check GPU Health**: `check_gpu_health` - check for GPU hardware errors (XID) and throttling events across the cluster.
- **vLLM Metrics**: `get_vllm_metrics` - monitor vLLM inference server performance metrics (throughput, queue size, cache usage).
*All monitoring tools use Prometheus metrics via OpenShift route for real-time cluster observability.*
### Pod Diagnostics Tools
- **Pod Logs**: `get_pod_logs` - retrieve and analyze logs from a specific pod, with support for previous container logs, tail limits, and time-based filtering.
- **Pod Diagnostics**: `get_pod_diagnostics` - comprehensive health check of a pod including status, conditions, container states, restart counts, and issue detection.
## Installation
```bash
# Using uv (recommended)
uv tool install .
# Or pip
pip install .
```
## Configuration
This server relies on the `oc` command line tool.
1. Ensure `oc` is installed and in your PATH.
2. Ensure you are authenticated (`oc login ...`) to your target cluster before running the server.
### MCP Client Configuration
Configure the MCP server in your Claude Desktop or Gemini CLI settings:
```json
{
"mcpServers": {
"openshift-tools": {
"command": "uv",
"args": ["run", "openshift-mcp-server"]
}
}
}
```
## Example Usage
Once configured, you can ask questions like:
> "Give me a summary of storage usage for all nodes"
>
> "Check GPU utilization in the cluster"
>
> "Diagnose pod health for my-app-pod in production namespace"
**Simulated Tool Output (`get_cluster_storage_report`):**
```markdown
# Storage Usage Report (3 nodes)
### Node: master0.example.com
- **Filesystem**: Used: 36.70 Gi | Capacity: 99.44 Gi | Available: 62.74 Gi
- **Image FS**: Used: 34.17 Gi
- **Total Pod Ephemeral Storage**: 5.19 Gi
**Top Pod Consumers:**
- 2.60 Gi: `openshift-marketplace/redhat-operators-gb8ff`
- 974.96 Mi: `openshift-marketplace/community-operators-fq744`
```
**Simulated Tool Output (`get_gpu_utilization`):**
```markdown
### GPU Utilization Report
**Total GPUs Found:** 4
| Node | GPU | Utilization | Memory Used | Status |
|------|-----|-------------|-------------|--------|
| `host-a:9400` | 0 | **0.0%** | 0.0% | ⚠️ Idle |
| `host-a:9400` | 1 | **85.2%** | 92.3% | ✅ Active |
```
**Simulated Tool Output (`detect_pod_restarts_anomalies`):**
```markdown
### Pod Restart Anomalies (>5 in last 1h)
| Namespace | Pod | Restarts |
|-----------|-----|----------|
| `ns-1` | `pod-a-7b666bd598-cvrlk` | **34** |
| `ns-2` | `pod-b-6dcf7d7bb8-dw8sg` | **16** |
#### 📋 Recommendations
1. **Check Logs**: `oc logs <pod> -n <namespace> --previous`
2. **Check Events**: `oc get events -n <namespace>`
```
## Development
```bash
# Run locally
uv run openshift-mcp-server
```
### Testing the server directly
When run directly, the server expects JSON-RPC messages on standard input. You can verify the registered tools by simulating a full client handshake (Initialize -> Initialized -> Tools/List):
```bash
(echo '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test-client", "version": "1.0"}}}'; sleep 0.5; echo '{"jsonrpc": "2.0", "method": "notifications/initialized"}'; sleep 0.5; echo '{"jsonrpc": "2.0", "id": 2, "method": "tools/list"}') | uv run openshift-mcp-server
```
Expected output (truncated for brevity):
```json
{"jsonrpc":"2.0","id":1,"result":{...}}
{"jsonrpc":"2.0","id":2,"result":{"tools":[{"name":"get_cluster_storage_report",...},{"name":"inspect_node_storage_forensics",...},...]}}
```
TDQS
Scored across 11 tools
Each tool has a clearly distinct purpose with no significant overlap. For example, check_gpu_health focuses on hardware errors, get_gpu_utilization monitors usage metrics, and inspect_gpu_pod runs diagnostics inside pods. The descriptions clearly differentiate between cluster-wide monitoring, pod-level diagnostics, storage analysis, and GPU-specific operations.
The naming follows a consistent verb_noun pattern throughout (e.g., check_gpu_health, get_cluster_resource_balance, inspect_node_storage_forensics). All tools use snake_case, and verbs like 'check', 'get', 'detect', and 'inspect' are appropriately matched to their actions. The only minor deviation is 'get_vllm_metrics' which uses an acronym, but it still fits the pattern.
With 11 tools, the count is well-scoped for an OpenShift monitoring and diagnostics server. Each tool serves a specific, non-redundant function in areas like GPU health, storage analysis, pod diagnostics, and cluster resource monitoring. The set covers essential operations without being overwhelming or too sparse.
The toolset provides comprehensive coverage for monitoring and diagnostics in an OpenShift cluster, including GPU health, storage, pod stability, and resource balance. Minor gaps exist, such as no tools for node-level CPU/memory diagnostics beyond resource balance or for managing resources (e.g., scaling pods), but agents can work around these with the available tools for core troubleshooting workflows.