MCP Ansible Server
Enables comprehensive Ansible automation management through natural language, including playbook creation and execution, inventory management, role scaffolding, and project workflows. Supports both local inventories and full project lifecycle management with syntax validation and idempotency testing.
README
MCP Ansible Server
Advanced Ansible Model Context Protocol (MCP) server in Python exposing Ansible utilities for inventories, playbooks, roles, and project workflows.
Quick start
git clone https://github.com/bsahane/mcp-ansible.git
cd mcp-ansible
# Create and activate Python virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Install dependencies via requirements.txt
python -m pip install -U pip
pip install -r requirements.txt
# (Optional) install the project package locally
pip install -e .
# Run the MCP server
python src/ansible_mcp/server.py
Requirements
- Python 3.10+
- macOS/Linux
Setup
cd /Users/bsahane/Developer/cursor/mcp-ansible
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -U pip
pip install "mcp[cli]>=1.2.0" "PyYAML>=6.0.1" "ansible-core>=2.16.0"
pip install -e .
Run the server
python src/ansible_mcp/server.py
Cursor config (/Users/bsahane/.cursor/mcp.json)
{
"mcpServers": {
"ansible-mcp": {
"command": "python",
"args": [
"/Users/bsahane/Developer/cursor/mcp-ansible/src/ansible_mcp/server.py"
],
"env": {
"MCP_ANSIBLE_PROJECT_ROOT": "/Users/bsahane/GitLab/projectAIOPS/mcp-ansible-server",
"MCP_ANSIBLE_INVENTORY": "/Users/bsahane/GitLab/projectAIOPS/mcp-ansible-server/inventory/hosts.ini",
"MCP_ANSIBLE_PROJECT_NAME": "projectAIOPS"
}
}
}
}
Claude for Desktop config
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"ansible-mcp": {
"command": "python",
"args": [
"/Users/bsahane/Developer/cursor/mcp-ansible/src/ansible_mcp/server.py"
],
"env": {
"MCP_ANSIBLE_PROJECT_ROOT": "/Users/bsahane/GitLab/projectAIOPS/mcp-ansible-server",
"MCP_ANSIBLE_INVENTORY": "/Users/bsahane/GitLab/projectAIOPS/mcp-ansible-server/inventory/hosts.ini",
"MCP_ANSIBLE_PROJECT_NAME": "projectAIOPS"
}
}
}
}
Tools (names)
- create-playbook: Create playbooks from YAML strings or dicts
- validate-playbook: Validate playbook syntax (ansible-playbook --syntax-check)
- ansible-playbook: Execute playbooks
- ansible-task: Run ad-hoc tasks (defaults to connection=local for localhost)
- ansible-role: Execute roles via generated temporary playbook
- create-role-structure: Scaffold role directory tree
- ansible-inventory: List inventory hosts and groups
- register-project: Register an Ansible project for easy reuse
- list-projects: Show registered projects and default
- project-playbooks: Discover playbooks under a project root
- project-run-playbook: Run a playbook using a registered project’s inventory/env
Local inventory suite (no AAP/AWX)
- inventory-parse: Parse inventories (ansible.cfg-aware), return hosts/groups/hostvars
- inventory-graph: Show group/host graph
- inventory-find-host: Show a host’s groups and merged vars
- ansible-ping: Ad-hoc ping module
- ansible-gather-facts: Run setup and return parsed facts
- validate-yaml: Validate YAML files with error locations
- galaxy-install: Install roles/collections from requirements
- project-bootstrap: Galaxy install + env inspection
Environment variables (optional)
- MCP_ANSIBLE_PROJECT_ROOT: absolute project root
- MCP_ANSIBLE_INVENTORY: inventory path or directory
- MCP_ANSIBLE_PROJECT_NAME: label for env project
- MCP_ANSIBLE_ROLES_PATH: colon-separated roles paths
- MCP_ANSIBLE_COLLECTIONS_PATHS: colon-separated collections paths
- MCP_ANSIBLE_ENV_<KEY>: forwarded to process env (e.g., MCP_ANSIBLE_ENV_ANSIBLE_CONFIG)
Examples (Claude Tools)
-
List hosts from inventory:
- Tool: ansible-inventory
- Args: inventory = "/Users/bsahane/GitLab/projectAIOPS/mcp-ansible-server/inventory/hosts.ini"
-
Run a simple playbook:
- Tool: ansible-playbook
- Args:
- playbook_path: absolute path to playbook.yml
- inventory: "/Users/bsahane/GitLab/projectAIOPS/mcp-ansible-server/inventory/hosts.ini"
-
Ad-hoc ping localhost:
- Tool: ansible-task
- Args:
- host_pattern: "localhost"
- module: "ping"
- inventory: "localhost,"
-
Scaffold a role:
- Tool: create-role-structure
- Args:
- base_path: "/tmp"
- role_name: "demo_role"
-
Register a project and run a project playbook:
- Tool: register-project
- name: "projectAIOPS"
- root: "/Users/bsahane/GitLab/projectAIOPS/mcp-ansible-server"
- inventory: "/Users/bsahane/GitLab/projectAIOPS/mcp-ansible-server/inventory/hosts.ini"
- make_default: true
- Tool: project-playbooks
- project: "projectAIOPS"
- Tool: project-run-playbook
- playbook_path: absolute path from discovered list
- Tool: register-project
Examples for local inventory suite
-
Parse via ansible.cfg with multiple inventories (merges group_vars/host_vars):
- Tool: inventory-parse
- Args:
- ansible_cfg_path: "/abs/path/to/ansible.cfg"
- include_hostvars: true
-
Parse a specific extensionless inventory file:
- Tool: inventory-parse
- Args:
- project_root: "/abs/path/to/project"
- inventory_paths: ["/abs/path/to/project/inventories/stage/inventory"]
- include_hostvars: true
-
Ping a group from inventory:
- Tool: ansible-ping
- Args:
- project_root: "/abs/path/to/project"
- host_pattern: "aws_mx_ext_stage"
Notes
- The server uses stdio transport. Do not print to stdout; logs go to stderr.
- Ansible connection/auth follows your local Ansible configuration.
Reference
- MCP Quickstart (Python): https://modelcontextprotocol.io/quickstart/server#python
Tool reference (detailed)
Below are all tools with short descriptions, minimal args, an example question you can ask in the MCP UI, and a sample answer.
-
create-playbook: Create an Ansible playbook file from YAML string or object
- Minimal args:
{ "playbook": [{"hosts":"all","tasks":[{"debug":{"msg":"hi"}}]}] } - Example question: "Create a playbook that prints hello for all hosts."
- Possible answer:
{ "path": "/tmp/playbook_x.yml", "bytes_written": 123, "preview": "- hosts: all..." }
- Minimal args:
-
validate-playbook: Syntax check a playbook
- Minimal args:
{ "playbook_path": "/abs/playbook.yml" } - Example question: "Is this playbook syntactically valid?"
- Possible answer:
{ "ok": true, "rc": 0 }
- Minimal args:
-
ansible-playbook: Run a playbook
- Minimal args:
{ "playbook_path": "/abs/playbook.yml", "inventory": "localhost," } - Example question: "Run this playbook against localhost."
- Possible answer:
{ "ok": true, "rc": 0, "stdout": "PLAY [all]..." }
- Minimal args:
-
ansible-task: Run an ad‑hoc module
- Minimal args:
{ "host_pattern": "localhost", "module": "ping", "inventory": "localhost," } - Example question: "Ping localhost."
- Possible answer:
{ "ok": true, "stdout": "pong" }
- Minimal args:
-
ansible-role: Execute a role via a temporary playbook
- Minimal args:
{ "role_name": "myrole", "hosts": "localhost", "inventory": "localhost," } - Example question: "Run role myrole on localhost."
- Possible answer:
{ "ok": true, "rc": 0 }
- Minimal args:
-
create-role-structure: Scaffold a role directory tree
- Minimal args:
{ "base_path": "/tmp", "role_name": "demo" } - Example question: "Create an Ansible role skeleton named demo."
- Possible answer:
{ "created": [".../tasks/main.yml", ...], "role_path": "/tmp/demo" }
- Minimal args:
-
ansible-inventory: List hosts and groups from an inventory
- Minimal args:
{ "inventory": "/abs/inventory" } - Example question: "List hosts in this inventory."
- Possible answer:
{ "hosts": ["host01"], "groups": {"web": ["host01"]} }
- Minimal args:
-
register-project: Register an Ansible project for reuse
- Minimal args:
{ "name": "proj", "root": "/abs/project", "make_default": true } - Example question: "Register my project root and make it default."
- Possible answer:
{ "path": "~/.config/mcp-ansible/config.json", "projects": ["proj"] }
- Minimal args:
-
list-projects: Show registered projects
- Minimal args:
{} - Example question: "What projects are registered and which is default?"
- Possible answer:
{ "default": "proj", "projects": {"proj": {"root": "/abs"}} }
- Minimal args:
-
project-playbooks: Discover playbooks under a project root
- Minimal args:
{ "project": "proj" } - Example question: "List playbooks in my project."
- Possible answer:
{ "ok": true, "playbooks": ["/abs/x.yml", "/abs/y.yml"] }
- Minimal args:
-
project-run-playbook: Run a playbook using project inventory/env
- Minimal args:
{ "playbook_path": "/abs/x.yml", "project": "proj" } - Example question: "Run x.yml in my default project."
- Possible answer:
{ "ok": true, "rc": 0 }
- Minimal args:
-
inventory-parse: Parse inventories (ansible.cfg aware, merges group_vars/host_vars)
- Minimal args:
{ "project_root": "/abs/project", "include_hostvars": true } - Example question: "Resolve all hosts and vars from my project root."
- Possible answer:
{ "hosts": ["h1"], "groups": {"web":["h1"]}, "hostvars": {"h1": {...}} }
- Minimal args:
-
inventory-graph: Show inventory graph
- Minimal args:
{ "project_root": "/abs/project" } - Example question: "Show the inventory graph."
- Possible answer: "@all\n |--@web\n | |--h1"
- Minimal args:
-
inventory-find-host: Show a host’s groups and merged vars
- Minimal args:
{ "project_root": "/abs/project", "host": "h1" } - Example question: "What groups and vars does h1 have?"
- Possible answer:
{ "groups": ["web"], "hostvars": {"ansible_user":"root"} }
- Minimal args:
-
ansible-ping: Ping hosts via ad-hoc
- Minimal args:
{ "project_root": "/abs/project", "host_pattern": "localhost" } - Example question: "Ping localhost."
- Possible answer:
{ "ok": true, "rc": 0 }
- Minimal args:
-
ansible-gather-facts: Run setup and return facts
- Minimal args:
{ "project_root": "/abs/project", "host_pattern": "localhost" } - Example question: "Gather facts from localhost."
- Possible answer:
{ "facts": {"localhost": {"ansible_hostname":"node"}} }
- Minimal args:
-
validate-yaml: Validate YAML files
- Minimal args:
{ "paths": ["/abs/file.yml"] } - Example question: "Validate this YAML file."
- Possible answer:
{ "ok": true, "results": [{"path":"/abs/file.yml","ok":true}] }
- Minimal args:
-
galaxy-install: Install roles/collections from requirements
- Minimal args:
{ "project_root": "/abs/project" } - Example question: "Install galaxy dependencies for my project."
- Possible answer:
{ "ok": true, "executed": [{"kind":"collection","rc":0}] }
- Minimal args:
-
project-bootstrap: Bootstrap project (env info + galaxy install)
- Minimal args:
{ "project_root": "/abs/project" } - Example question: "Bootstrap my project."
- Possible answer:
{ "ok": true, "details": {"ansible_version":"..."} }
- Minimal args:
-
inventory-diff: Diff two inventories
- Minimal args:
{ "left_project_root": "/abs/project", "right_project_root": "/abs/project" } - Example question: "What changed between stage and prod inventories?"
- Possible answer:
{ "added_hosts": [], "removed_hosts": [], "group_membership_changes": {} }
- Minimal args:
-
ansible-test-idempotence: Run playbook twice and assert no changes second run
- Minimal args:
{ "playbook_path": "/abs/playbook.yml", "project_root": "/abs/project" } - Example question: "Is this playbook idempotent?"
- Possible answer:
{ "ok": true, "changed_total_second": 0 }
- Minimal args:
-
galaxy-lock: Generate a lock file of installed roles/collections
- Minimal args:
{ "project_root": "/abs/project" } - Example question: "Create a requirements.lock.yml for my project."
- Possible answer:
{ "ok": true, "path": "/abs/requirements.lock.yml" }
- Minimal args:
-
vault-encrypt / vault-decrypt / vault-view / vault-rekey: Vault operations
- Minimal args (encrypt):
{ "file_paths": ["/abs/group_vars/all/vault.yml"], "project_root": "/abs/project" } - Example question: "Encrypt group_vars/all/vault.yml with my vault password."
- Possible answer:
{ "ok": true, "rc": 0 }
- Minimal args (encrypt):
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。