Skip to main content
Glama
AgentWong
by AgentWong

get_ansible_collection_info

Retrieve comprehensive information about Ansible collections, including details and metadata, to support Infrastructure-as-Code management and analysis.

Instructions

Retrieve comprehensive information about an Ansible collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collection_nameYesName of the Ansible collection

Implementation Reference

  • The MCP tool handler function that processes the get_ansible_collection_info request, retrieves data using the helper function, formats the output, and handles errors.
    async def handle_get_ansible_collection_info(
        db: Any, arguments: Dict[str, Any], operation_id: str
    ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        """Handle get_ansible_collection_info tool."""
        try:
            logger.info(
                "Getting Ansible collection info",
                extra={
                    "collection_name": arguments["collection_name"],
                    "operation_id": operation_id,
                },
            )
    
            # Get collection info
            collection = get_ansible_collection_info(db, arguments["collection_name"])
    
            # Format output
            output = [
                f"Collection: {collection['name']}",
                f"Version: {collection['version']}",
                f"Source: {collection['source_url']}",
                f"Documentation: {collection['doc_url']}",
                f"Total Modules: {collection['module_count']}",
                f"Last Updated: {collection['updated_at']}",
            ]
    
            if collection["recent_modules"]:
                output.extend(
                    [
                        "\nRecent Modules:",
                        *[
                            f"- {m['name']} ({m['type']}) v{m['version']}"
                            for m in collection["recent_modules"]
                        ],
                    ]
                )
    
            return [TextContent(type="text", text="\n".join(output))]
    
        except Exception as e:
            error_msg = f"Failed to get collection info: {str(e)}"
            logger.error(error_msg, extra={"operation_id": operation_id})
            raise McpError(
                types.ErrorData(
                    code=types.INTERNAL_ERROR,
                    message=error_msg,
                    data={
                        "tool": "get_ansible_collection_info",
                        "operation_id": operation_id,
                    },
                )
            )
  • JSON schema defining the input parameters for the get_ansible_collection_info tool, requiring 'collection_name'.
    "get_ansible_collection_info": {
        "type": "object",
        "description": "Retrieve comprehensive information about an Ansible collection",
        "required": ["collection_name"],
        "properties": {
            "collection_name": {
                "type": "string",
                "description": "Name of the Ansible collection",
            }
        },
    },
  • Registration of the tool handler in the ansible_tool_handlers dictionary mapping tool name 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 the database for Ansible collection information, including module count and recent modules.
    def get_ansible_collection_info(db: DatabaseManager, collection_name: str) -> Dict:
        """Get comprehensive information about an Ansible collection.
    
        Args:
            db: Database manager instance
            collection_name: Name of the collection to retrieve
    
        Returns:
            Dictionary containing collection information including metadata and module count
        """
        logger.info(
            "Getting Ansible collection info",
            extra={
                "collection_name": collection_name,
                "operation": "get_ansible_collection_info",
            },
        )
    
        try:
            with db.get_connection() as conn:
                conn.execute("PRAGMA busy_timeout = 5000")  # 5 second timeout
    
                # Get collection info with module count
                result = conn.execute(
                    """
                    SELECT
                        c.*,
                        COUNT(m.id) as module_count
                    FROM ansible_collections c
                    LEFT JOIN ansible_modules m ON c.id = m.collection_id
                    WHERE c.name = ?
                    GROUP BY c.id
                    """,
                    (collection_name,),
                ).fetchone()
    
                if not result:
                    raise DatabaseError(f"Collection '{collection_name}' not found")
    
                collection_info = dict(result)
    
                # Get recent modules
                recent_modules = conn.execute(
                    """
                    SELECT name, type, version
                    FROM ansible_modules
                    WHERE collection_id = ?
                    ORDER BY updated_at DESC
                    LIMIT 5
                    """,
                    (collection_info["id"],),
                ).fetchall()
    
                collection_info["recent_modules"] = [dict(m) for m in recent_modules]
    
                return collection_info
    
        except sqlite3.Error as e:
            error_msg = f"Failed to get collection info: {str(e)}"
            logger.error(error_msg)
            raise DatabaseError(error_msg)

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