Skip to main content
Glama
tushar3006

Snowflake MCP Server

by tushar3006

read_query

Execute SELECT queries on Snowflake databases to retrieve and analyze data for reporting and insights.

Instructions

Execute a SELECT query.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSELECT SQL query to execute

Implementation Reference

  • The handler function that implements the logic for the read_query tool. It validates the input, checks for write operations using write_detector, executes the query on the Snowflake database, formats the output as YAML and JSON, and returns it as TextContent and EmbeddedResource.
    async def handle_read_query(arguments, db, write_detector, *_):
        if not arguments or "query" not in arguments:
            raise ValueError("Missing query argument")
    
        if write_detector.analyze_query(arguments["query"])["contains_write"]:
            raise ValueError("Calls to read_query should not contain write operations")
    
        data, data_id = await db.execute_query(arguments["query"])
    
        output = {
            "type": "data",
            "data_id": data_id,
            "data": data,
        }
        yaml_output = data_to_yaml(output)
        json_output = json.dumps(output, default=data_json_serializer)
        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"),
            ),
        ]
  • The input schema for the read_query tool, defining it as an object with a required 'query' property of type string describing the SELECT SQL query.
    input_schema={
        "type": "object",
        "properties": {"query": {"type": "string", "description": "SELECT SQL query to execute"}},
        "required": ["query"],
    },
  • The registration of the read_query tool in the all_tools list, specifying its name, description, input schema, and handler function.
    Tool(
        name="read_query",
        description="Execute a SELECT query.",
        input_schema={
            "type": "object",
            "properties": {"query": {"type": "string", "description": "SELECT SQL query to execute"}},
            "required": ["query"],
        },
        handler=handle_read_query,
    ),

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