Skip to main content
Glama
vini-cius

SQL Server MCP Service

by vini-cius

execute_procedure

Execute any SQL Server stored procedure by providing its name and parameters, with optional schema specification.

Instructions

Executes a stored procedure with parameters

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
procedureNameYesName of the stored procedure to execute
parametersNoProcedure parameters
schemaNameNoSchema name (default: dbo)dbo

Implementation Reference

  • Core handler function that executes a stored procedure using a DatabaseConnection. Connects to the pool, sanitizes parameters via sanitizeParameters, calls request.execute() with schemaName.procedureName, and returns a CallToolResult with procedure metadata (recordsets, output, returnValue, rowsAffected). Handles errors with a Portuguese error message.
    export async function executeProcedure(
      db: DatabaseConnection,
      procedureName: string,
      parameters?: Record<string, unknown>,
      schemaName: string = 'dbo'
    ): Promise<CallToolResult> {
      try {
        const pool = db.getPool()
        const request = pool.request()
    
        if (parameters) {
          const sanitizedParams = sanitizeParameters(parameters)
    
          for (const [key, value] of Object.entries(sanitizedParams)) {
            request.input(key, value)
          }
        }
    
        const result = await request.execute(`${schemaName}.${procedureName}`)
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  procedure: `${schemaName}.${procedureName}`,
                  recordsets: result.recordsets,
                  recordset: result.recordset,
                  output: result.output || {},
                  returnValue: result.returnValue,
                  rowsAffected: result.rowsAffected,
                },
                null,
                2
              ),
            },
          ],
        }
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Erro: ${error instanceof Error ? error.message : 'Erro desconhecido'}`,
            },
          ],
          isError: true,
        }
      }
    }
  • Zod input schema for execute_procedure. Defines procedureName (string), parameters (optional record of string->unknown), and schemaName (default 'dbo').
    export const executeProcedureInput = z.object({
      procedureName: z.string().describe('Name of the stored procedure to execute'),
      parameters: z
        .record(z.string(), z.unknown())
        .optional()
        .describe('Procedure parameters'),
      schemaName: z.string().default('dbo').describe('Schema name (default: dbo)'),
    })
  • Registration of execute_procedure in the toolsList() array with name 'execute_procedure', description, and inputSchema converted from Zod to JSON Schema.
        {
          name: 'execute_procedure',
          description: 'Executes a stored procedure with parameters',
          inputSchema: zodToJsonSchema(executeProcedureInput),
        },
      ]
    }
  • Handler map registration connecting 'execute_procedure' string to the executeProcedure function, parsing args as ExecuteProcedureInput.
    handlers.set('execute_procedure', async (database, args) => {
      const { procedureName, parameters } = args as ExecuteProcedureInput
      return await executeProcedure(database, procedureName, parameters ?? {})
    })
  • Helper function that validates parameter names (alphanumeric/underscore regex) and enforces max string length of 8000 characters before passing to the SQL request.
    export function sanitizeParameters(
      parameters: Record<string, unknown>
    ): Record<string, unknown> {
      const sanitized: Record<string, unknown> = {}
    
      for (const [key, value] of Object.entries(parameters)) {
        if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(key)) {
          throw new Error(`Nome de parâmetro inválido: ${key}`)
        }
    
        if (typeof value === 'string' && value.length > 8000) {
          throw new Error(`Valor muito longo para parâmetro: ${key}`)
        }
    
        sanitized[key] = value
      }
    
      return sanitized
    }
Behavior2/5

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

With no annotations, the description bears full responsibility for behavioral disclosure, but it only states that the tool executes a procedure with parameters. It does not mention whether the procedure returns results, handles errors, or has side effects, leaving significant ambiguity.

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, concise sentence that efficiently conveys the core purpose. Every word earns its place, and there is no extraneous information.

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?

For a tool that executes stored procedures with no output schema, the description omits critical context such as return values, error handling, and behavior when procedures return multiple result sets. The agent is left to guess the interaction model.

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 input schema already describes all three parameters with 100% coverage, so the description adds no additional meaning. A 3 is appropriate as the schema does the heavy lifting, but the description fails to clarify how to structure the 'parameters' object or any special constraints.

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 ('Executes') and the resource ('stored procedure'), and it distinguishes this tool from sibling tools like 'get_procedure_schema' or 'execute_query'. However, it lacks specificity about the scope or side effects.

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?

No guidance is provided on when to use this tool versus alternatives such as 'execute_query' or 'get_procedure_schema'. The agent receives no context about prerequisites or preferred use cases.

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/vini-cius/mcp-sqlserver'

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