Skip to main content
Glama
YannBrrd

Simple Snowflake MCP

by YannBrrd

list-databases

Retrieve a comprehensive list of all accessible Snowflake databases to streamline database management and access control behind a corporate proxy.

Instructions

List all accessible Snowflake databases.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The execution handler for the 'list-databases' tool. Constructs and executes a SHOW DATABASES SQL query with optional pattern filter, handles output formatting based on 'include_details' parameter, and returns results as text content.
    elif name == "list-databases":
        pattern = args.get("pattern")
        include_details = args.get("include_details", False)
        
        query = "SHOW DATABASES"
        if pattern:
            query += f" LIKE '{pattern}'"
        
        result = _safe_snowflake_execute(query, "List databases")
        if result["success"]:
            if include_details:
                output = json.dumps(result["data"], indent=2, default=str)
            else:
                databases = [row.get("name", "") for row in result["data"]]
                output = "\n".join(databases)
            return [types.TextContent(type="text", text=output)]
        else:
            return [types.TextContent(type="text", text=f"Snowflake error: {result['error']}")]
  • Registers the 'list-databases' tool in the list_tools() handler, defining its description and input schema for validation of 'pattern' (string with wildcards) and 'include_details' (boolean) parameters.
    types.Tool(
        name="list-databases",
        description="List all accessible Snowflake databases with optional filtering",
        inputSchema={
            "type": "object",
            "properties": {
                "pattern": {
                    "type": "string",
                    "description": "Filter databases by name pattern (supports wildcards)",
                    "examples": ["PROD_%", "%_DEV"]
                },
                "include_details": {
                    "type": "boolean", 
                    "default": False,
                    "description": "Include database details and metadata"
                }
            },
            "additionalProperties": False
        },
    ),
  • JSON schema definition for the 'list-databases' tool inputs, specifying properties for filtering and details inclusion.
    inputSchema={
        "type": "object",
        "properties": {
            "pattern": {
                "type": "string",
                "description": "Filter databases by name pattern (supports wildcards)",
                "examples": ["PROD_%", "%_DEV"]
            },
            "include_details": {
                "type": "boolean", 
                "default": False,
                "description": "Include database details and metadata"
            }
        },
        "additionalProperties": False
    },
  • Helper function that performs safe Snowflake query execution with connection management, result parsing, and error handling, directly called by the list-databases handler.
    def _safe_snowflake_execute(query: str, description: str = "Query") -> Dict[str, Any]:
        """
        Safely execute a Snowflake query with proper error handling and logging.
        """
        try:
            logger.info(f"Executing {description}: {query[:100]}...")
            ctx = snowflake.connector.connect(**SNOWFLAKE_CONFIG)
            cur = ctx.cursor()
            cur.execute(query)
            
            # Handle different query types
            if cur.description:
                rows = cur.fetchall()
                columns = [desc[0] for desc in cur.description]
                result = [dict(zip(columns, row)) for row in rows]
            else:
                result = {"status": "success", "rowcount": cur.rowcount}
                
            cur.close()
            ctx.close()
            logger.info(f"{description} completed successfully")
            return {"success": True, "data": result}
            
        except Exception as e:
            logger.error(f"{description} failed: {str(e)}")
            return {"success": False, "error": str(e), "data": None}
Install Server

Other Tools

Related 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/YannBrrd/simple_snowflake_mcp'

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