Skip to main content
Glama
AgentWong

IAC Memory MCP Server

by AgentWong

add_ansible_module

Add new Ansible module definitions with schema and version details to the IAC Memory MCP Server for infrastructure-as-code management.

Instructions

Add a new Ansible module definition with its schema and version information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionYesCollection ID or name
nameYesModule name
module_typeYesModule type
schemaYesModule schema
versionYesModule version
doc_urlYesDocumentation URL

Implementation Reference

  • The main handler function for the 'add_ansible_module' tool. Validates input parameters including module_type against VALID_MODULE_TYPES, logs the operation, calls the database add_ansible_module function, and returns a success message with the new module ID or raises an McpError on failure.
    async def handle_add_ansible_module(db: Any, arguments: Dict[str, Any], operation_id: str) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        """Handle add_ansible_module tool."""
        try:
            # Validate module type
            if arguments["module_type"] not in VALID_MODULE_TYPES:
                error_msg = f"Invalid module type: {arguments['module_type']}. Valid types are: {', '.join(sorted(VALID_MODULE_TYPES))}"
                logger.error(error_msg, extra={"operation_id": operation_id})
                return [TextContent(type="text", text=error_msg)]
    
            logger.info(
                "Adding Ansible module",
                extra={
                    "collection": arguments["collection"],
                    "module_name": arguments["name"],
                    "operation_id": operation_id,
                },
            )
    
            # Add module
            module_id = add_ansible_module(
                db,
                arguments["collection"],
                arguments["name"],
                arguments["module_type"],
                arguments["schema"],
                arguments["version"],
                arguments["doc_url"],
            )
    
            return [TextContent(
                type="text",
                text=f"Added module {arguments['name']} with ID: {module_id}"
            )]
    
        except Exception as e:
            error_msg = f"Failed to add module: {str(e)}"
            logger.error(error_msg, extra={"operation_id": operation_id})
            raise McpError(
                types.ErrorData(
                    code=types.INTERNAL_ERROR,
                    message=error_msg,
                    data={
                        "tool": "add_ansible_module",
                        "operation_id": operation_id,
                    },
                )
            )
  • JSON schema for the 'add_ansible_module' tool input, specifying required properties (collection, name, module_type, schema, version, doc_url) all as strings with descriptions.
    "add_ansible_module": {
        "type": "object",
        "description": "Add a new Ansible module definition with its schema and version information",
        "required": [
            "collection",
            "name",
            "module_type",
            "schema",
            "version",
            "doc_url",
        ],
        "properties": {
            "collection": {"type": "string", "description": "Collection ID or name"},
            "name": {"type": "string", "description": "Module name"},
            "module_type": {"type": "string", "description": "Module type"},
            "schema": {"type": "string", "description": "Module schema"},
            "version": {"type": "string", "description": "Module version"},
            "doc_url": {"type": "string", "description": "Documentation URL"},
        },
    },
  • Registration of Ansible tool handlers in a dictionary, mapping the tool name 'add_ansible_module' to its corresponding handler function handle_add_ansible_module.
    ansible_tool_handlers = {
        "get_ansible_collection_info": handle_get_ansible_collection_info,
        "list_ansible_collections": handle_list_ansible_collections,
        "get_collection_version_history": handle_get_collection_version_history,
        "get_ansible_module_info": handle_get_ansible_module_info,
        "list_collection_modules": handle_list_collection_modules,
        "get_module_version_compatibility": handle_get_module_version_compatibility,
        "add_ansible_collection": handle_add_ansible_collection,
        "add_ansible_module": handle_add_ansible_module,
        "update_collection_version": handle_update_collection_version,
        "update_module_version": handle_update_module_version,
    }
  • Database helper function that resolves collection ID, inserts a new record into the ansible_modules table with transaction handling, busy timeout, and error management, returning the new module ID.
    def add_ansible_module(
        db: DatabaseManager,
        collection_id: str,
        name: str,
        module_type: str,
        schema: str,
        version: str,
        doc_url: str,
    ) -> str:
        """Add a new Ansible module."""
        try:
            with db.get_connection() as conn:
                # Set busy timeout before any operations
                conn.execute(
                    "PRAGMA busy_timeout = 5000"
                )  # 5 second timeout per testing rules
                conn.execute("BEGIN IMMEDIATE")  # Start transaction
                try:
                    # Look up collection by ID or name
                    collection = conn.execute(
                        """SELECT id FROM ansible_collections
                        WHERE id = ? OR name = ?""",
                        (collection_id, collection_id),
                    ).fetchone()
    
                    if not collection:
                        raise DatabaseError(
                            f"Collection '{collection_id}' not found. "
                            f"Operation timed out after 5 seconds."
                        )
    
                    collection_id = collection["id"]  # Ensure we have the numeric ID
    
                    cursor = conn.execute(
                        """INSERT INTO ansible_modules
                        (collection_id, name, type, schema, description, version, doc_url)
                        VALUES (?, ?, ?, ?, ?, ?, ?)""",
                        (
                            collection_id,
                            name,
                            module_type,
                            schema,
                            module_type,  # Using type as description for now
                            version,
                            doc_url,
                        ),
                    )
                    module_id = str(cursor.lastrowid)
                    conn.commit()
                    return module_id
                except Exception:
                    conn.rollback()
                    raise
        except sqlite3.Error as e:
            raise DatabaseError(
                f"Failed to add Ansible module: {str(e)}. "
                f"Operation timed out after 5 seconds."
            )
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. While 'Add' implies a write operation, the description doesn't address critical behavioral aspects like required permissions, whether this creates a new record or updates an existing one, potential side effects, or error conditions. This leaves significant gaps for an agent to understand how to use this tool safely and effectively.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that communicates the core purpose without unnecessary words. It's appropriately sized for a tool with clear parameters documented elsewhere. However, it could be slightly more front-loaded by explicitly stating this is for Ansible modules specifically.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a write operation tool with 6 required parameters and no annotations or output schema, the description is insufficient. It doesn't explain what happens after the module is added, what validation occurs, whether there are constraints on the schema format, or how this tool relates to other tools in the ecosystem. The description provides only basic purpose information without the context needed for effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, the input schema already documents all 6 parameters thoroughly. The description adds no additional parameter information beyond what's in the schema, so it meets the baseline expectation but doesn't provide extra value. The description essentially repeats the schema's description field verbatim.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Add a new Ansible module definition') and the resources involved ('with its schema and version information'), making the purpose immediately understandable. However, it doesn't differentiate this tool from similar sibling tools like 'add_ansible_collection' or 'add_terraform_provider', which would require explicit comparison to earn a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With sibling tools like 'add_ansible_collection', 'create_entity', and 'update_module_version' available, there's no indication of the specific context or prerequisites for choosing this tool over others.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AgentWong/iac-memory-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server