Skip to main content
Glama
AgentWong
by AgentWong

get_terraform_provider_info

Retrieve comprehensive information about Terraform providers to support Infrastructure-as-Code development, including version tracking and relationship mapping.

Instructions

Retrieve comprehensive information about a Terraform provider

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
provider_nameYesName of the Terraform provider

Implementation Reference

  • The MCP tool handler function that executes the get_terraform_provider_info logic by calling the database helper and formatting the output as text content.
    async def handle_get_terraform_provider_info(
        db: Any, arguments: Dict[str, Any], operation_id: str
    ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        """Handle get_terraform_provider_info tool."""
        try:
            logger.info(
                "Getting Terraform provider info",
                extra={
                    "provider_name": arguments["provider_name"],
                    "operation_id": operation_id,
                },
            )
    
            # Get provider info
            provider = get_terraform_provider_info(db, arguments["provider_name"])
    
            # Format output string
            info_str = f"""Provider: {provider['name']}
                        Version: {provider['version']}
                        Source: {provider['source_url']}
                        Documentation: {provider['doc_url']}
                        Supported Resources:"""
    
            for resource in provider["resources"]:
                info_str += f"\n- {resource['name']} ({resource['type']})"
                info_str += f"\n  Version: {resource['version']}"
    
            return [types.TextContent(type="text", text=info_str)]
    
        except Exception as e:
            error_msg = f"Failed to get provider info: {str(e)}"
            logger.error(error_msg, extra={"operation_id": operation_id})
            return [types.TextContent(type="text", text=error_msg)]
  • JSON schema defining the input parameters for the get_terraform_provider_info tool, requiring 'provider_name'.
    "get_terraform_provider_info": {
        "type": "object",
        "description": "Retrieve comprehensive information about a Terraform provider",
        "required": ["provider_name"],
        "properties": {
            "provider_name": {
                "type": "string",
                "description": "Name of the Terraform provider",
            }
        },
    },
  • Registration mapping the 'get_terraform_provider_info' tool name to its handler function within the terraform tool handlers dictionary.
    terraform_tool_handlers = {
        "get_terraform_provider_info": handle_get_terraform_provider_info,
        "list_provider_resources": handle_list_provider_resources,
        "get_terraform_resource_info": handle_get_terraform_resource_info,
        "add_terraform_provider": handle_add_terraform_provider,
        "add_terraform_resource": handle_add_terraform_resource,
        "update_provider_version": handle_update_provider_version,
    }
  • Helper function that queries the database for Terraform provider details, including associated resources, used by the tool handler.
    def get_terraform_provider_info(db: DatabaseManager, provider_name: str) -> Dict:
        """Get comprehensive information about a Terraform provider.
        
        Args:
            db: Database manager instance
            provider_name: Name of the provider to retrieve
            
        Returns:
            Dictionary containing provider information including metadata and resource count
        """
        logger.info(
            "Getting Terraform provider info",
            extra={
                "provider_name": provider_name,
                "operation": "get_terraform_provider_info"
            }
        )
        
        try:
            with db.get_connection() as conn:
                conn.execute("PRAGMA busy_timeout = 5000")  # 5 second timeout
                
                # Get provider info with resource count
                result = conn.execute(
                    """
                    SELECT
                        p.id,
                        p.name,
                        p.version,
                        p.source_url,
                        p.doc_url,
                        p.updated_at,
                        COUNT(r.id) as resource_count,
                        MAX(r.updated_at) as latest_resource_update
                    FROM terraform_providers p
                    LEFT JOIN terraform_resources r ON p.id = r.provider_id
                    WHERE p.name = ?
                    GROUP BY p.id, p.name, p.version, p.source_url, p.doc_url, p.updated_at
                    """,
                    (provider_name,)
                ).fetchone()
                
                if not result:
                    raise DatabaseError(f"Provider '{provider_name}' not found")
                    
                # Convert row to dict and ensure all necessary fields are present
                provider_info = {
                    "id": result["id"],
                    "name": result["name"],
                    "version": result["version"],
                    "source_url": result["source_url"],
                    "doc_url": result["doc_url"],
                    "updated_at": result["updated_at"],
                    "resource_count": result["resource_count"],
                    "latest_resource_update": result["latest_resource_update"]
                }
                
                # Get resources associated with this provider
                resources = conn.execute(
                    """
                    SELECT name, resource_type, version, doc_url
                    FROM terraform_resources
                    WHERE provider_id = ?
                    ORDER BY updated_at DESC
                    """,
                    (provider_info["id"],)
                ).fetchall()
                
                # Convert resource rows to dicts with explicit field mapping
                provider_info["resources"] = [
                    {
                        "name": r["name"],
                        "type": r["resource_type"],
                        "version": r["version"],
                        "doc_url": r["doc_url"]
                    } for r in resources
                ]
                
                return provider_info
                
        except sqlite3.Error as e:
            error_msg = f"Failed to get provider 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