Skip to main content
Glama
cwilby

SQL Server MCP

by cwilby

query

Execute SQL statements directly on Microsoft SQL Server databases through a Model Context Protocol server designed for AI assistant integration.

Instructions

Query the database with a SQL statement

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe SQL query to execute

Implementation Reference

  • The handler function for the "query" MCP tool. It executes the provided SQL query using the database helper, handles empty results, and formats the output using toResult.
    async query({ query }: { query: string }) {
        const results = await database.query(query);
        if (!results.length) return this.toResult("No results found for the query.");
        return this.toResult(JSON.stringify(results));
    }
  • Input schema definition for the "query" tool using Zod, specifying a string parameter for the SQL query.
    { query: z.string().describe("The SQL query to execute") },
  • Registration of the "query" tool on the MCP server, including name, description, input schema, and binding to the handler method.
    server.tool(
        "query",
        "Query the database with a SQL statement",
        { query: z.string().describe("The SQL query to execute") },
        tools.query.bind(tools)
    );
  • Database query helper function called by the tool handler to execute SQL queries against the MSSQL database.
    export async function query(query: string, interpolations: any = null): Promise<mssql.IRecordSet<any>> {
    	let connection = null;
    	try {
    		connection = await connect();
    		const request = connection.request();
    		if (interpolations) {
    			Object.entries(interpolations).forEach(([key, value]) => request.input(key, value));
    		}
    		const { recordset } = await request.query(query);
    		return recordset;
    	} finally {
    		await connection?.close();
    	}
    }
  • Helper method from BaseTools used by the handler to format tool results as MCP CallToolResult.
    protected toResult(content: string): CallToolResult {
        return { content: [{ type: "text", text: content }] };
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states 'Query the database' but doesn't disclose critical behavioral traits: whether it's read-only or can modify data, authentication requirements, error handling, result format, or performance implications. For a database tool with zero annotation coverage, this leaves significant gaps in understanding how the tool behaves.

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 with zero wasted words. It's front-loaded with the core purpose and appropriately sized for a simple tool with one parameter. Every word earns its place by conveying essential information about the tool's function.

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 database operations and lack of annotations/output schema, the description is incomplete. It doesn't address whether queries are read-only or can modify data, what happens with invalid SQL, how results are returned, or security considerations. For a tool that could potentially alter data or expose sensitive information, this minimal description is insufficient.

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?

Schema description coverage is 100%, with the single parameter 'query' documented as 'The SQL query to execute'. The description adds no additional meaning beyond what the schema provides—it merely restates that execution involves a SQL statement. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't enhance parameter understanding.

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 ('Query') and resource ('the database') with the method ('with a SQL statement'). It distinguishes from siblings like transaction tools by focusing on query execution rather than transaction management or metadata retrieval. However, it doesn't explicitly differentiate from 'get-stored-procedure' which might also involve query-like operations.

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 'get-table' for metadata or transaction tools for write operations. It mentions SQL execution but doesn't specify if it's for read-only queries, data manipulation, or both, leaving the agent to infer usage context 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

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/cwilby/mcp-node-mssql'

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