Skip to main content
Glama
arjshiv

BlazeSQL MCP Server

by arjshiv

blazesql_query

Execute natural language queries on BlazeSQL databases by specifying the database ID and query request for quick, intuitive data retrieval and analysis.

Instructions

Executes a natural language query against a specified BlazeSQL database.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
db_idYesThe ID of the BlazeSQL database connection to query.
natural_language_requestYesThe query expressed in natural language (e.g., 'show me total users per city').

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe SQL query generated and executed by BlazeSQL.
data_resultYesThe structured data returned by the query, as a map of column names to value arrays.
agent_responseYesNatural language explanation of the results from BlazeSQL.

Implementation Reference

  • Tool handler function that destructures input params, calls queryBlazeSQL helper, formats the response with agent answer, SQL, and JSON data as Markdown text, or returns error content.
    async (params) => {
        const { db_id, natural_language_request } = params;
    
        // Input validation is handled by Zod schema above
    
        console.error(`Executing BlazeSQL query for DB ID: ${db_id}`);
        console.error(`Natural Language Request: "${natural_language_request}"`);
    
        // Call the BlazeSQL API function - apiKey is guaranteed non-null here
        const result: BlazeSQLResponse = await queryBlazeSQL(db_id, natural_language_request, apiKey!);
    
        if (result.success) {
            console.error("BlazeSQL query successful. Returning structured results as formatted text.");
    
            // Format the output into a single text block with Markdown
            const outputText = `**Agent Response:**\n${result.agent_response}\n\n**Generated SQL:**\n\`\`\`sql\n${result.query ?? "-- No SQL query returned"}\n\`\`\`\n\n**Data Result (JSON):**\n\`\`\`json\n${JSON.stringify(result.data_result ?? {}, null, 2)}\n\`\`\`\n`;
    
            // Return a single text content block
            return {
                content: [
                    {
                        type: "text",
                        text: outputText
                    }
                ]
            };
        } else {
            // Handle API errors - Throwing an error is standard for tool failures
            console.error(`BlazeSQL API Error (Code ${result.error_code}): ${result.error}`);
            // Return error message as text content
            return {
                content: [
                    { type: "text", text: `BlazeSQL API Error: ${result.error}` }
                ],
                isError: true // Indicate it's an error response
            };
        }
    }
  • Core helper function implementing the HTTP request to BlazeSQL API, constructs request body, handles HTTP errors, parses JSON responses, and returns typed success/error objects.
    export async function queryBlazeSQL(
        dbId: string,
        naturalLanguageRequest: string,
        apiKey: string
    ): Promise<BlazeSQLResponse> {
        if (!apiKey) {
            throw new Error('BlazeSQL API key is missing. Ensure BLAZE_API_KEY is set in your environment.');
        }
    
        const requestBody: BlazeSQLRequest = {
            db_id: dbId,
            natural_language_request: naturalLanguageRequest,
            api_key: apiKey,
        };
    
        try {
            const response = await fetch(BLAZE_API_ENDPOINT, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify(requestBody),
            });
    
    
            if (!response.ok) {
                // Attempt to parse error response from Blaze, otherwise throw generic error
                try {
                    const errorData: BlazeSQLErrorResponse = await response.json() as BlazeSQLErrorResponse;
                     return { // Return a structured error matching BlazeSQLErrorResponse
                         success: false,
                         error: errorData.error || `HTTP error! status: ${response.status}`,
                         error_code: errorData.error_code || response.status,
                     };
                } catch (parseError) {
                     return { // Return a structured error matching BlazeSQLErrorResponse
                         success: false,
                         error: `HTTP error! status: ${response.status}. Failed to parse error response.`,
                         error_code: response.status,
                     };
                }
            }
    
            const data: BlazeSQLResponse = await response.json() as BlazeSQLResponse;
            return data;
    
        } catch (error) {
            console.error('Error querying BlazeSQL:', error);
             return { // Return a structured error matching BlazeSQLErrorResponse
                 success: false,
                 error: error instanceof Error ? error.message : 'An unknown error occurred during the API request.',
                 error_code: 500, // Generic internal/network error
             };
        }
    }
  • Zod schema defining input parameters for the blazesql_query tool: db_id and natural_language_request.
    {
        db_id: z.string().describe("The ID of the BlazeSQL database connection to query."),
        natural_language_request: z.string().describe("The query expressed in natural language (e.g., 'show me total users per city').")
    },
  • src/index.ts:34-79 (registration)
    Registers the 'blazesql_query' tool on the McpServer instance, specifying name, input schema, and handler function.
    server.tool(
        "blazesql_query", // Tool name
        {
            db_id: z.string().describe("The ID of the BlazeSQL database connection to query."),
            natural_language_request: z.string().describe("The query expressed in natural language (e.g., 'show me total users per city').")
        },
        // Tool handler function - TS should infer params type from raw shape now
        async (params) => {
            const { db_id, natural_language_request } = params;
    
            // Input validation is handled by Zod schema above
    
            console.error(`Executing BlazeSQL query for DB ID: ${db_id}`);
            console.error(`Natural Language Request: "${natural_language_request}"`);
    
            // Call the BlazeSQL API function - apiKey is guaranteed non-null here
            const result: BlazeSQLResponse = await queryBlazeSQL(db_id, natural_language_request, apiKey!);
    
            if (result.success) {
                console.error("BlazeSQL query successful. Returning structured results as formatted text.");
    
                // Format the output into a single text block with Markdown
                const outputText = `**Agent Response:**\n${result.agent_response}\n\n**Generated SQL:**\n\`\`\`sql\n${result.query ?? "-- No SQL query returned"}\n\`\`\`\n\n**Data Result (JSON):**\n\`\`\`json\n${JSON.stringify(result.data_result ?? {}, null, 2)}\n\`\`\`\n`;
    
                // Return a single text content block
                return {
                    content: [
                        {
                            type: "text",
                            text: outputText
                        }
                    ]
                };
            } else {
                // Handle API errors - Throwing an error is standard for tool failures
                console.error(`BlazeSQL API Error (Code ${result.error_code}): ${result.error}`);
                // Return error message as text content
                return {
                    content: [
                        { type: "text", text: `BlazeSQL API Error: ${result.error}` }
                    ],
                    isError: true // Indicate it's an error response
                };
            }
        }
    );
  • TypeScript interfaces defining the BlazeSQL API request body, success response, error response, and union type used throughout the tool.
    export interface BlazeSQLRequest {
        db_id: string;
        natural_language_request: string;
        api_key: string;
    }
    
    export interface BlazeSQLSuccessResponse {
        success: true;
        message: string;
        query: string;
        agent_response: string;
        data_result: {
            [columnName: string]: (string | number | boolean | null)[];
        };
    }
    
    export interface BlazeSQLErrorResponse {
        success: false;
        error: string;
        error_code: number;
    }
    
    export type BlazeSQLResponse = BlazeSQLSuccessResponse | BlazeSQLErrorResponse;
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool executes queries but doesn't describe traits like error handling, performance implications, authentication needs, or rate limits. For a query execution tool with zero annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is front-loaded and appropriately sized, making it easy to understand quickly. Every part of the sentence contributes to clarifying the tool's function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has an output schema (which handles return values), 100% schema coverage, and no annotations, the description is minimally complete. It covers the basic purpose but lacks behavioral context and usage guidelines. For a query tool with no annotations, it should do more to compensate, but the output schema mitigates some gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so the schema already documents both parameters (db_id and natural_language_request) with clear descriptions. The description adds no additional meaning beyond what the schema provides, such as examples or constraints. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('executes') and resource ('natural language query against a specified BlazeSQL database'). It distinguishes what it does (execute natural language queries) from potential alternatives (like SQL queries), though without sibling tools, differentiation isn't needed. However, it could be more specific about the type of queries or results.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or exclusions. It mentions the tool's function but lacks context on appropriate scenarios, such as when natural language queries are supported or if there are limitations. With no sibling tools, this gap is less critical but still present.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/arjshiv/blaze-sql-mcp-server'

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