Skip to main content
Glama
tushar3006

Snowflake MCP Server

by tushar3006

list_schemas

Retrieve all schema names from a specified Snowflake database to explore database structure and organize data objects.

Instructions

List all schemas in a database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesDatabase name to list schemas from

Implementation Reference

  • Core handler function that executes the logic to list schemas from a specified Snowflake database. It runs a SQL query, applies exclusion filters if configured, formats results as YAML and JSON, and returns them as TextContent and EmbeddedResource.
    async def handle_list_schemas(arguments, db, *_, exclusion_config=None):
        if not arguments or "database" not in arguments:
            raise ValueError("Missing required 'database' parameter")
    
        database = arguments["database"]
        query = f"SELECT SCHEMA_NAME FROM {database.upper()}.INFORMATION_SCHEMA.SCHEMATA"
        data, data_id = await db.execute_query(query)
    
        # Filter out excluded schemas
        if exclusion_config and "schemas" in exclusion_config and exclusion_config["schemas"]:
            filtered_data = []
            for item in data:
                schema_name = item.get("SCHEMA_NAME", "")
                exclude = False
                for pattern in exclusion_config["schemas"]:
                    if pattern.lower() in schema_name.lower():
                        exclude = True
                        break
                if not exclude:
                    filtered_data.append(item)
            data = filtered_data
    
        output = {
            "type": "data",
            "data_id": data_id,
            "database": database,
            "data": data,
        }
        yaml_output = data_to_yaml(output)
        json_output = json.dumps(output)
        return [
            types.TextContent(type="text", text=yaml_output),
            types.EmbeddedResource(
                type="resource",
                resource=types.TextResourceContents(uri=f"data://{data_id}", text=json_output, mimeType="application/json"),
            ),
        ]
  • Input schema validation for the tool, requiring a single 'database' string parameter.
    input_schema={
        "type": "object",
        "properties": {
            "database": {
                "type": "string",
                "description": "Database name to list schemas from",
            },
        },
        "required": ["database"],
    },
  • Registers the 'list_schemas' tool in the all_tools list, which is used by handle_list_tools() to expose the tool to MCP clients and by handle_call_tool() to dispatch calls to the handler.
    Tool(
        name="list_schemas",
        description="List all schemas in a database",
        input_schema={
            "type": "object",
            "properties": {
                "database": {
                    "type": "string",
                    "description": "Database name to list schemas from",
                },
            },
            "required": ["database"],
        },
        handler=handle_list_schemas,
    ),

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/tushar3006/MCP'

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