Skip to main content
Glama
tndfame
by tndfame

query_mssql

Execute read-only MSSQL queries to retrieve data from databases. Returns query results with column information, row counts, and preview data for analysis.

Instructions

Run a read-only MSSQL query (SELECT/WITH). Returns columns, rowCount, and sliced rows for preview.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesRead-only SQL beginning with SELECT or WITH. Parameters as @name.
paramsNoKey-value parameters for @name placeholders in SQL.
limitNoMaximum rows to return (client-side slice).
maxCharsNoMax characters in serialized preview.

Implementation Reference

  • The handler function for the 'query_mssql' tool. It executes a read-only SQL query using the queryReadOnly helper, slices the rows to the specified limit, truncates large JSON previews, and returns a structured success response with columns, row count, and preview rows, or an error response.
    async ({ sql, params, limit, maxChars }) => {
      try {
        const { rows, columns } = await queryReadOnly(sql, params);
        const sliced = rows.slice(0, limit);
        const payload = { columns, rowCount: rows.length, rows: sliced };
        let text = JSON.stringify(payload);
        if (text.length > maxChars) {
          text = text.slice(0, maxChars) + "... (truncated)";
        }
        return createSuccessResponse({
          columns,
          rowCount: rows.length,
          rows: sliced,
        });
      } catch (e: any) {
        return createErrorResponse(`MSSQL query failed: ${e?.message || e}`);
      }
    },
  • Zod schemas defining the input parameters for the query_mssql tool: sql (string), params (optional record), limit (number 1-500 default 100), maxChars (number 1000-200000 default 12000).
    const sqlSchema = z
      .string()
      .min(1)
      .describe(
        "Read-only SQL beginning with SELECT or WITH. Parameters as @name.",
      );
    const paramsSchema = z
      .record(z.any())
      .optional()
      .describe("Key-value parameters for @name placeholders in SQL.");
    const limitSchema = z
      .number()
      .int()
      .min(1)
      .max(500)
      .default(100)
      .describe("Maximum rows to return (client-side slice).");
    const maxCharsSchema = z
      .number()
      .int()
      .min(1000)
      .max(200000)
      .default(12000)
      .describe("Max characters in serialized preview.");
  • src/index.ts:76-76 (registration)
    Top-level registration of the QueryMssql tool instance on the MCP server in the main index file.
    new QueryMssql().register(server);
  • Core helper function that validates the SQL is read-only SELECT/WITH, connects to the MSSQL connection pool, binds parameters, executes the query, and returns rows and column names.
    export async function queryReadOnly(
      sql: string,
      params?: QueryParams,
    ): Promise<{ rows: any[]; columns: string[] }> {
      if (!isReadOnlySelect(sql)) {
        throw new Error("Only read-only SELECT/WITH queries are allowed");
      }
      const pool = await getPool();
      const request = pool.request();
      if (params && typeof params === "object") {
        for (const [k, v] of Object.entries(params)) {
          request.input(k, mapJsToSqlType(v), v);
        }
      }
      const result = await request.query<any>(sql);
      const rows: any[] = (result.recordset as any[]) || [];
      const columns: string[] = rows[0] ? Object.keys(rows[0]) : [];
      return { rows, columns };
    }
Behavior3/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 does well by stating the tool is 'read-only' and describing the return format (columns, rowCount, sliced rows for preview), but lacks details on error handling, performance characteristics, or authentication requirements. It provides some context but leaves gaps for a database query tool.

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 efficiently communicates the tool's purpose, constraints, and output. Every word earns its place with no wasted information, making it easy for an agent to parse quickly.

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's complexity (database queries with 4 parameters) and no output schema, the description is moderately complete. It covers the basic operation and output format but lacks details on error cases, result limitations, or connection specifics. With no annotations and no output schema, it should do more to guide usage fully.

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%, so the schema already documents all parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema (e.g., it doesn't explain SQL syntax or parameter binding further). Baseline score of 3 is appropriate as the schema does the heavy lifting.

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

Purpose5/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 specific verbs ('run a read-only MSSQL query') and resource ('MSSQL'), and distinguishes it from siblings by specifying it handles SELECT/WITH queries only. It explicitly mentions what it returns (columns, rowCount, sliced rows), making its function unambiguous.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool (for read-only SELECT/WITH queries) and implies when not to use it (for non-read-only operations), but does not explicitly name alternatives or provide detailed exclusions. It gives basic guidance without being comprehensive about sibling tools.

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/tndfame/mcp_management'

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