A Very basic and simple Model Context Protocol (MCP) server that provides integration with Ansible Automation Platform (AAP) via API. This server allows Large Language Models to interact with AAP to extract available templates and launch Ansible job templates with custom parameters. This is just a demo, and not a full MCP Server capabiliy, feel free to use this code as you want.
- Template Discovery: Extract available job templates from configured AAP projects
- Job Launching: Launch Ansible job templates with custom extra variables and parameters
- Job Monitoring: Check job status and retrieve job outputs/logs
- Connection Testing: Verify AAP connectivity and authentication
- Error Handling: Robust error handling with retry logic and detailed error messages
- Python 3.8+
- Access to an Ansible Automation Platform instance
- AAP API access token with appropriate permissions
-
Clone this repository
-
Install dependencies:
uv pip install -r requirements.txt
-
Configure environment variables:
cp env_example .env # Edit .env with your AAP configuration
Create a .env
file in the project root with the following variables:
# Ansible Automation Platform Configuration
AAP_URL=https://your-aap-instance.com
AAP_TOKEN=your-access-token-here
AAP_PROJECT_ID=your-project-id
AAP_VERIFY_SSL=True
# Optional settings
AAP_TIMEOUT=30
AAP_MAX_RETRIES=3
AAP_URL
: Base URL of your AAP instance (e.g.,https://controller.example.com
)AAP_TOKEN
: Bearer token for API authenticationAAP_PROJECT_ID
: Default project ID to extract templates fromAAP_VERIFY_SSL
: Whether to verify SSL certificates (True/False)AAP_TIMEOUT
: Request timeout in seconds (default: 30)AAP_MAX_RETRIES
: Number of retry attempts for failed requests (default: 3)
Before integrating with Claude Desktop, test your server setup:
uv run python tools/test_mcp_server.py
This will validate:
- Environment configuration
- AAP connection
- Template extraction
- MCP server functionality
Start the MCP server:
uv run python server.py
The server will start and listen for MCP protocol messages on stdin/stdout.
-
Locate your Claude Desktop configuration file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
- Linux:
~/.config/claude/claude_desktop_config.json
- macOS:
-
Edit the configuration file and add the MCP server:
{
"mcpServers": {
"ansible-aap": {
"command": "uv",
"args": ["run", "python", "server.py"],
"cwd": "<PATH TO THE PROJECT>",
"env": {
"AAP_URL": "https://your-aap-instance.com",
"AAP_TOKEN": "your-access-token-here",
"AAP_PROJECT_ID": "your-project-id",
"AAP_VERIFY_SSL": "True",
"AAP_TIMEOUT": "30",
"AAP_MAX_RETRIES": "3"
}
}
}
}
Important: Replace the placeholder values with your actual AAP configuration:
cwd
: Use the absolute path to your MCP server directoryAAP_URL
: Your AAP instance URLAAP_TOKEN
: Your API access tokenAAP_PROJECT_ID
: Your project ID
After saving the configuration, restart Claude Desktop completely.
Once restarted, you can test the integration by asking Claude questions like:
- "What Ansible templates are available?"
- "Show me the job templates from my AAP project"
- "Show nodes with with low disk space"
- "Check the status of job 123"
You should see Claude respond with information about your Ansible templates and be able to launch jobs. If there are issues, check:
- Claude Desktop logs for error messages
- Your AAP credentials and permissions
- Network connectivity to your AAP instance
Instead of embedding credentials in the Claude Desktop config, you can create a .env
file:
{
"mcpServers": {
"ansible-aap": {
"command": "uv",
"args": ["run", "python", "server.py"],
"cwd": "<PATH TO THE PROJECT>"
}
}
}
Then create a .env
file in your project directory with the AAP configuration.
The server provides the following tools:
Extract available job templates from the configured AAP project.
Parameters:
project_id
(optional): Override the configured project ID
Example:
{
"name": "get_job_templates",
"arguments": {
"project_id": "5"
}
}
Launch an Ansible job template with optional parameters.
Parameters:
template_id
(required): ID of the job template to launchextra_vars
(optional): Extra variables to pass to the job templateinventory
(optional): Inventory ID to usecredentials
(optional): List of credential IDs to use
Example:
{
"name": "launch_job_template",
"arguments": {
"template_id": 10,
"extra_vars": {
"target_host": "web-server-01",
"service_name": "nginx",
"restart_service": true
},
"inventory": 2
}
}
Get the status and details of a running or completed job.
Parameters:
job_id
(required): ID of the job to check
Example:
{
"name": "get_job_status",
"arguments": {
"job_id": 123
}
}
Get the output/logs of a job.
Parameters:
job_id
(required): ID of the job to get output from
Example:
{
"name": "get_job_output",
"arguments": {
"job_id": 123
}
}
Test the connection to Ansible Automation Platform.
Parameters: None
Example:
{
"name": "test_aap_connection",
"arguments": {}
}
This server can be integrated with various MCP-compatible LLM clients. The server provides a standardized interface for LLMs to:
- Discover Infrastructure: Query available Ansible templates to understand what automation is available
- Execute Operations: Launch specific templates with custom parameters based on the conversation context
- Monitor Progress: Check job status and retrieve outputs to provide feedback to users
- Discovery: LLM calls
get_job_templates
to see what automation is available - Planning: Based on user request, LLM identifies the appropriate template and parameters
- Execution: LLM calls
launch_job_template
with the required parameters - Monitoring: LLM uses
get_job_status
andget_job_output
to track progress and provide updates
The server includes comprehensive error handling:
- Connection Errors: Automatic retry with exponential backoff
- Authentication Errors: Clear error messages for token/permission issues
- Validation Errors: Parameter validation with helpful error messages
- Rate Limiting: Respectful API usage with configurable timeouts
- Store AAP tokens securely in environment variables
- Use HTTPS for AAP connections
- Validate SSL certificates in production (
AAP_VERIFY_SSL=True
) - Limit template access through AAP project configuration
- Monitor job launches and outputs for security compliance