get_ansible_collection_info
Retrieve detailed Ansible collection data to enhance Infrastructure-as-Code management, supporting version tracking and resource mapping within the MCP server environment.
Instructions
Retrieve comprehensive information about an Ansible collection
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection_name | Yes | Name of the Ansible collection |
Input Schema (JSON Schema)
{
"description": "Retrieve comprehensive information about an Ansible collection",
"properties": {
"collection_name": {
"description": "Name of the Ansible collection",
"type": "string"
}
},
"required": [
"collection_name"
],
"type": "object"
}
Implementation Reference
- MCP tool handler that executes the get_ansible_collection_info logic: validates input, calls DB helper, formats and returns textual output with collection details and recent modules.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 tool (requires 'collection_name' string). Used for validation."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", } }, },
- src/iac_memory_mcp_server/tools/ansible.py:473-482 (registration)Registration of the tool handler in the ansible_tool_handlers dictionary, mapping 'get_ansible_collection_info' to its async 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, }
- Core database helper function that queries the SQLite database for collection details (name, version, URLs, module_count, updated_at) and top 5 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)