Ansible Automation Platform MCP server

Integrates with Ansible Automation Platform, OpenShift, and Event-Driven Ansible to enable advanced automation workflows, inventory management, and job template execution for DevOps teams.
Back to servers
Provider
Ricardo Lopez
Release date
Feb 27, 2025
Language
Python
Stats
7 stars

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.

Installation

Prerequisites

  • Ansible Automation Platform (AAP) environment
  • OpenShift Cluster with OpenShift Virtualization
  • Claude Desktop installed (Pro Plan recommended)
  • Python 3.10 or higher
  • Authentication with your OpenShift cluster

Step 1: Set Up Your Environment

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.

Step 2: Create Your Project

# 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

Step 3: Configure the Ansible MCP Server

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.

Step 4: Configure Claude Desktop

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:

  • Replace /absolute/path/to/uv with the full path to your uv binary (find with which uv)
  • Replace /absolute/path/to/ansible_mcp with your project directory
  • Replace <aap-token> with your AAP token
  • Replace <aap-url> with your AAP URL

To create an AAP token:

  1. Go to AAP Dashboard → Access Management → Users
  2. Select your user → Tokens → Create token
  3. Set Scope to 'Write' and click Create token

Usage

Step 5: Start Claude Desktop

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.

Step 6: Interact with Your Infrastructure

You can now ask Claude questions about your Ansible Automation Platform and OpenShift environments, such as:

  • "How many Job Templates are available?"
  • "How many VMs are on my OpenShift cluster?"
  • "Create a new inventory in AAP"
  • "Launch a specific job template"

Additional Capabilities

Click the hammer icon to see all available tools. These include:

  • Listing and creating inventories
  • Running job templates
  • Checking job statuses and logs
  • Managing projects
  • Working with OpenShift resources through the Kubernetes MCP server

Optional: Event-Driven Ansible Integration

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.

How to add this MCP server to Cursor

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.

Adding an MCP server to Cursor globally

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"
            ]
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later