Skip to main content
Glama
AgentWong
by AgentWong

list_ansible_collections

Retrieve cached Ansible collections with metadata to manage Infrastructure-as-Code components. 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

  • MCP tool handler that executes the list_ansible_collections tool: fetches collections from DB, applies optional filters, formats output as text.
    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 definition for the list_ansible_collections tool parameters.
    "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",
                    }
                },
            }
        },
    },
  • Registration of Ansible tool handlers, mapping 'list_ansible_collections' to its handler function.
    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,
    }
  • Database helper function that queries and returns list of Ansible collections with module counts and latest updates.
    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 the full burden of behavioral disclosure. It states it's a list operation with basic metadata, implying it's read-only and non-destructive, but doesn't cover aspects like pagination, rate limits, authentication needs, or what 'cached' entails (e.g., freshness of data). This leaves significant gaps for a tool with potential complexity.

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 that front-loads the core purpose ('List all cached Ansible collections with basic metadata'). There's no wasted verbiage, and it directly communicates the essential information without unnecessary elaboration.

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 the lack of annotations and output schema, the description is incomplete for a list tool. It doesn't explain what 'basic metadata' includes, the format of the returned data, or any behavioral traits like error handling. For a tool that might return complex data structures, this leaves the agent with insufficient context to use it effectively.

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?

The schema description coverage is 100%, with the single parameter 'filter_criteria' and its nested 'name_pattern' property well-documented in the schema. The description doesn't add any parameter-specific details beyond what the schema provides, so it meets the baseline for high schema coverage without compensating value.

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 'basic metadata', providing a specific purpose. However, it doesn't explicitly differentiate from sibling tools like 'get_ansible_collection_info' or 'get_collection_version_history', which might offer more detailed or historical information about collections.

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 sibling tools like 'get_ansible_collection_info' for detailed info or 'list_provider_resources' for other resource types, leaving the agent to infer usage based on tool names alone.

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-project'

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