This Model Context Protocol (MCP) server enables integration between Claude Desktop and your Ansible Automation Platform and OpenShift environments. The server provides a bridge that allows Claude to interact with your infrastructure through specialized tools.
First, install the uv
package manager and jbang:
curl -LsSf https://astral.sh/uv/install.sh | sh
Install jbang for the Kubernetes MCP Server:
Restart your terminal to ensure both commands are available.
# Create a new directory for our project
uv init ansible
cd ansible
# Create virtual environment and activate it
uv venv
source .venv/bin/activate
# Install dependencies
uv add "mcp[cli]" httpx
# Create our server file
touch ansible.py
Create the MCP Server by adding the following code to your ansible.py
file:
import os
import httpx
from mcp.server.fastmcp import FastMCP
from typing import Any
# Environment variables for authentication
AAP_URL = os.getenv("AAP_URL")
AAP_TOKEN = os.getenv("AAP_TOKEN")
if not AAP_TOKEN:
raise ValueError("AAP_TOKEN is required")
# Headers for API authentication
HEADERS = {
"Authorization": f"Bearer {AAP_TOKEN}",
"Content-Type": "application/json"
}
# Initialize FastMCP
mcp = FastMCP("ansible")
async def make_request(url: str, method: str = "GET", json: dict = None) -> Any:
"""Helper function to make authenticated API requests to AAP."""
async with httpx.AsyncClient() as client:
response = await client.request(method, url, headers=HEADERS, json=json)
if response.status_code not in [200, 201]:
return f"Error {response.status_code}: {response.text}"
return response.json() if "application/json" in response.headers.get("Content-Type", "") else response.text
@mcp.tool()
async def list_inventories() -> Any:
"""List all inventories in Ansible Automation Platform."""
return await make_request(f"{AAP_URL}/inventories/")
# Additional tool methods would be here - copy the complete code provided in the README
if __name__ == "__main__":
mcp.run(transport="stdio")
The complete code includes many more methods for interacting with AAP, including listing and creating inventories, job templates, and more.
Locate and edit the Claude Desktop configuration file:
# On MacOS
nano ~/Library/Application\ Support/Claude/claude_desktop_config.json
Add the following configuration:
{
"mcpServers": {
"ansible": {
"command": "/absolute/path/to/uv",
"args": [
"--directory",
"/absolute/path/to/ansible_mcp",
"run",
"ansible.py"
],
"env": {
"AAP_TOKEN": "<aap-token>",
"AAP_URL": "https://<aap-url>/api/controller/v2"
}
},
"kubernetes": {
"command": "jbang",
"args": [
"--quiet",
"https://github.com/quarkiverse/quarkus-mcp-servers/blob/main/kubernetes/src/main/java/io/quarkus/mcp/servers/kubernetes/MCPServerKubernetes.java"
]
}
}
}
Be sure to:
/absolute/path/to/uv
with the full path to your uv binary (find with which uv
)/absolute/path/to/ansible_mcp
with your project directory<aap-token>
with your AAP token<aap-url>
with your AAP URLTo create an AAP token:
Launch Claude Desktop after saving your configuration. Verify that the MCP servers are connected by looking for the hammer icon in the interface. The number next to the hammer indicates how many MCP tools are available.
You can now ask Claude questions about your Ansible Automation Platform and OpenShift environments, such as:
Click the hammer icon to see all available tools. These include:
You can extend your setup with Event-Driven Ansible by creating an additional MCP server. Create an eda.py
file in your project directory with the provided code, and update your Claude configuration to include the EDA server.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.