Skip to main content
Glama
vini-cius

SQL Server MCP Service

by vini-cius

get_procedure_schema

Retrieve the schema and parameters of a stored procedure by specifying its name and optional schema, enabling clear understanding of procedure structure.

Instructions

Gets the schema and parameters of a specific stored procedure

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
procedureNameYesName of the stored procedure
schemaNameNoSchema name (default: dbo)dbo

Implementation Reference

  • Main handler function for get_procedure_schema. Queries INFORMATION_SCHEMA.PARAMETERS and INFORMATION_SCHEMA.ROUTINES to retrieve parameter definitions and routine definition for a stored procedure.
    export async function getProcedureSchema(
      db: DatabaseConnection,
      procedureName: string,
      schemaName: string = 'dbo'
    ): Promise<CallToolResult> {
      try {
        const pool = db.getPool()
    
        const query = `
          SELECT 
            p.PARAMETER_NAME,
            p.DATA_TYPE,
            p.PARAMETER_MODE,
            p.CHARACTER_MAXIMUM_LENGTH,
            p.NUMERIC_PRECISION,
            p.NUMERIC_SCALE,
            p.ORDINAL_POSITION,
            r.ROUTINE_DEFINITION
          FROM INFORMATION_SCHEMA.PARAMETERS p
          INNER JOIN INFORMATION_SCHEMA.ROUTINES r 
            ON p.SPECIFIC_NAME = r.SPECIFIC_NAME
          WHERE r.ROUTINE_NAME = @procedureName 
            AND r.ROUTINE_SCHEMA = @schemaName
            AND r.ROUTINE_TYPE = 'PROCEDURE'
          ORDER BY p.ORDINAL_POSITION
        `.trim()
    
        const request = pool.request()
    
        request.input('procedureName', procedureName)
        request.input('schemaName', schemaName)
    
        const result = await request.query(query)
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  procedure: `${schemaName}.${procedureName}`,
                  parameters: result.recordset.map((row) => ({
                    name: row.PARAMETER_NAME,
                    dataType: row.DATA_TYPE,
                    mode: row.PARAMETER_MODE,
                    maxLength: row.CHARACTER_MAXIMUM_LENGTH,
                    precision: row.NUMERIC_PRECISION,
                    scale: row.NUMERIC_SCALE,
                    position: row.ORDINAL_POSITION,
                  })),
                  definition: result.recordset[0]?.ROUTINE_DEFINITION || null,
                },
                null,
                2
              ),
            },
          ],
        }
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Erro: ${error instanceof Error ? error.message : 'Erro desconhecido'}`,
            },
          ],
          isError: true,
        }
      }
    }
  • Zod input validation schema for get_procedure_schema. Defines procedureName (required string) and schemaName (optional, defaults to 'dbo').
    export const getProcedureSchemaInput = z.object({
      procedureName: z.string().describe('Name of the stored procedure'),
      schemaName: z.string().default('dbo').describe('Schema name (default: dbo)'),
    })
  • Tool registration in the tools list. Sets name to 'get_procedure_schema' with description and inputSchema using zodToJsonSchema conversion.
    {
      name: 'get_procedure_schema',
      description:
        'Gets the schema and parameters of a specific stored procedure',
      inputSchema: zodToJsonSchema(getProcedureSchemaInput),
    },
  • Handler registration in SqlServerMCPService.createHandlerMap(). Maps the 'get_procedure_schema' string to an async function that delegates to the getProcedureSchema function.
    handlers.set('get_procedure_schema', async (database, args) => {
      const { procedureName, schemaName } = args as GetProcedureSchemaInput
      return await getProcedureSchema(database, procedureName, schemaName)
    })
  • Re-export of the getProcedureSchema function from the tools barrel module.
    export { getProcedureSchema } from './get-procedure-schema'
Behavior3/5

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

No annotations are provided, so the description carries the burden. It indicates a read operation with no side effects, but does not detail what 'schema and parameters' entails (e.g., types, defaults, permissions). The description is adequate but lacks depth.

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, well-structured sentence that directly conveys the tool's purpose with no superfluous words. It is front-loaded and efficient.

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

Completeness4/5

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

The tool is simple with two parameters and no output schema. The description sufficiently explains the tool's function for a read-only schema retrieval, though it could briefly mention what the returned schema includes.

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 input schema already describes both parameters. The description does not add any additional meaning beyond what is in the schema, meeting the baseline.

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 gets the schema and parameters of a stored procedure, using a specific verb and resource. It distinguishes from sibling tools like execute_procedure (execution) and get_table_schema (table schema).

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

Usage Guidelines3/5

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

The description implies use for stored procedures but does not provide explicit guidance on when to use this tool versus alternatives like get_function_schema. No exclusions or when-not conditions are mentioned.

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