Skip to main content
Glama
AgentWong

IAC Memory MCP Server

by AgentWong

list_ansible_collections

Retrieve cached Ansible collections with metadata to manage Infrastructure-as-Code resources. Filter results by name pattern for targeted access.

Instructions

List all cached Ansible collections with basic metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filter_criteriaNoOptional filtering criteria

Implementation Reference

  • The handler function that processes the tool call, fetches collections from DB, applies optional filters, formats and returns the response as TextContent.
    async def handle_list_ansible_collections(
        db: Any, arguments: Dict[str, Any], operation_id: str
    ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        """Handle list_ansible_collections tool."""
        try:
            logger.info("Listing Ansible collections", extra={"operation_id": operation_id})
    
            # Get all collections
            collections = list_ansible_collections(db)
    
            # Apply any filters from criteria
            filter_criteria = arguments.get("filter_criteria", {})
            if filter_criteria and "name_pattern" in filter_criteria:
                pattern = re.compile(filter_criteria["name_pattern"])
                collections = [c for c in collections if pattern.match(c["name"])]
    
            # Format output
            if not collections:
                return [TextContent(type="text", text="No collections found")]
    
            output = ["Available Ansible Collections:"]
            for c in collections:
                output.append(
                    f"\n- {c['name']} v{c['version']}"
                    f"\n  Modules: {c['module_count']}"
                    f"\n  Updated: {c['updated_at']}"
                    f"\n  Latest Module Update: {c.get('latest_module_update', 'N/A')}"
                    f"\n  Docs: {c['doc_url']}"
                )
    
            return [TextContent(type="text", text="\n".join(output))]
    
        except Exception as e:
            error_msg = f"Failed to list collections: {str(e)}"
            logger.error(error_msg, extra={"operation_id": operation_id})
            raise McpError(
                types.ErrorData(
                    code=types.INTERNAL_ERROR,
                    message=error_msg,
                    data={
                        "tool": "list_ansible_collections",
                        "operation_id": operation_id,
                    },
                )
            )
  • JSON schema defining the input parameters for the list_ansible_collections tool, including optional filter_criteria with name_pattern.
    "list_ansible_collections": {
        "type": "object",
        "description": "List all cached Ansible collections with basic metadata",
        "required": [],
        "properties": {
            "filter_criteria": {
                "type": "object",
                "description": "Optional filtering criteria",
                "properties": {
                    "name_pattern": {
                        "type": "string",
                        "description": "Regex pattern to filter collection names",
                    }
                },
            }
        },
    },
  • Dictionary mapping tool names to their handler functions, registering list_ansible_collections to handle_list_ansible_collections.
    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 queries the database for all Ansible collections, including module counts and latest updates, used by the handler.
    def list_ansible_collections(db: DatabaseManager) -> List[Dict]:
        """Get all Ansible collections with basic metadata.
    
        Args:
            db: Database manager instance
    
        Returns:
            List of collections with metadata including module counts
        """
        logger.info(
            "Listing Ansible collections", extra={"operation": "list_ansible_collections"}
        )
    
        try:
            with db.get_connection() as conn:
                conn.execute("PRAGMA busy_timeout = 5000")  # 5 second timeout
    
                # Get collections with module counts
                collections = conn.execute(
                    """
                    SELECT
                        c.*,
                        COUNT(m.id) as module_count,
                        MAX(m.updated_at) as latest_module_update
                    FROM ansible_collections c
                    LEFT JOIN ansible_modules m ON c.id = m.collection_id
                    GROUP BY c.id
                    ORDER BY c.name
                    """
                ).fetchall()
    
                return [dict(c) for c in collections]
    
        except sqlite3.Error as e:
            error_msg = f"Failed to list collections: {str(e)}"
            logger.error(error_msg)
            raise DatabaseError(error_msg)
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It states it lists 'cached' collections, implying a read-only operation from a cache, but doesn't disclose what 'cached' means, whether it requires authentication, rate limits, pagination behavior, or what 'basic metadata' includes. For a tool with zero annotation coverage, this leaves significant gaps.

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

Conciseness5/5

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

The description is a single, efficient sentence with zero waste. It's front-loaded with the core purpose and appropriately sized for a simple list operation. Every word earns its place without redundancy.

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?

Given no annotations, no output schema, and a simple parameter structure, the description is incomplete. It doesn't explain what 'cached' entails, the format or examples of 'basic metadata', or behavioral aspects like error handling. For a tool in a server with many siblings, more context is needed to guide proper 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?

Schema description coverage is 100%, so the schema fully documents the single optional parameter 'filter_criteria' with its nested 'name_pattern'. The description doesn't add any parameter-specific information beyond what's in the schema, such as examples of regex patterns or filtering behavior. Baseline 3 is appropriate when the schema does the heavy lifting.

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 verb ('List') and resource ('cached Ansible collections') with scope ('all') and output type ('basic metadata'). It distinguishes from siblings like 'get_ansible_collection_info' by focusing on listing multiple collections rather than detailed info about one. However, it doesn't explicitly differentiate from other list tools like 'list_terraform_providers' beyond the resource type.

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. It doesn't mention when to choose this over 'get_ansible_collection_info' for detailed info, or how it relates to other list tools like 'list_terraform_providers'. There's also no indication of prerequisites or context for use.

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