Skip to main content
Glama

mcp_execute_query

Execute raw SQL queries to retrieve data from SQL Server databases using schema-qualified object references for reliable results.

Instructions

Execute a raw SQL query and return the results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe SQL query to execute. IMPORTANT: When referencing objects, use bracketed, schema-qualified names (e.g., SELECT * FROM [dbo].[Users]).

Implementation Reference

  • The core handler function that performs permission validation using validateQueryPermission, executes the provided SQL query against the database pool, and returns the recordset or an error.
    export const mcp_execute_query = async (args: { query: string }): Promise<ToolResult<any[]>> => {
      const { query } = args;
      console.log('Executing mcp_execute_query with query:', query);
    
      // Security validation for SQL query execution
      const permission = validateQueryPermission(query);
      if (!permission.allowed) {
        return { success: false, error: permission.message || 'Query execution not allowed' };
      }
    
      try {
        const pool = getPool();
        const result = await pool.request().query(query);
        return { success: true, data: result.recordset };
      } catch (error: any) {
        // Only log the error message, not the full stack trace for cleaner output
        console.error(`Error in mcp_execute_query: ${error.message}`);
        return { success: false, error: error.message };
      }
    };
  • Tool schema definition in the MCP_MSQL_TOOLS array, specifying the name, description, and inputSchema requiring a 'query' string parameter.
    {
      name: "mcp_execute_query",
      description: "Execute a raw SQL query and return the results",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "The SQL query to execute. IMPORTANT: When referencing objects, use bracketed, schema-qualified names (e.g., SELECT * FROM [dbo].[Users])."
          }
        },
        required: ["query"]
      }
    },
  • Re-exports the mcp_execute_query handler from dataOperations.js as part of the tools index module.
    export {
      mcp_execute_procedure, // Execute stored procedure
      mcp_execute_query       // Execute SQL query
    } from './dataOperations.js';
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions executing a query and returning results but fails to address critical aspects like whether this is a read-only or write operation, potential risks (e.g., data modification, performance impact), authentication needs, or error handling. For a SQL execution tool, this omission is significant.

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 extremely concise and front-loaded, consisting of a single sentence that directly states the tool's purpose. Every word earns its place, with no redundant or unnecessary information, making it highly efficient for quick comprehension.

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

Completeness2/5

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

Given the complexity of executing raw SQL queries (which can involve reads, writes, or schema changes) and the absence of both annotations and an output schema, the description is incomplete. It does not cover behavioral traits, return formats, error conditions, or safety considerations, leaving the agent with insufficient context for reliable tool invocation.

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 description does not add any parameter-specific information beyond what the input schema provides. Since schema description coverage is 100% (the 'query' parameter is fully documented in the schema), the baseline score of 3 is appropriate. The description neither compensates for gaps nor enhances understanding of the parameter's semantics.

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 action ('Execute a raw SQL query') and outcome ('return the results'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate this tool from its sibling 'mcp_execute_procedure', which might also execute database operations, leaving some ambiguity about when to choose one over the other.

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 like 'mcp_execute_procedure' or other siblings such as 'mcp_preview_data' or 'mcp_quick_data_analysis'. It lacks context about appropriate use cases, prerequisites, or exclusions, leaving the agent to infer usage from the tool name alone.

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

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/hendrickcastro/MCPQL'

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