Skip to main content
Glama
vini-cius

SQL Server MCP Service

by vini-cius

get_function_schema

Retrieve the schema and parameter details for a specified SQL Server function. Input the function name; schema name is optional and defaults to dbo.

Instructions

Gets the schema and parameters of a specific function

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
functionNameYesName of the function
schemaNameNoSchema name (default: dbo)dbo

Implementation Reference

  • Core handler: queries INFORMATION_SCHEMA for function parameters, return type, and definition, returning formatted JSON result.
    export async function getFunctionSchema(
      db: DatabaseConnection,
      functionName: 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,
            r.DATA_TYPE as RETURN_TYPE,
            CASE 
              WHEN r.DATA_TYPE = 'TABLE' THEN 'TABLE-VALUED'
              ELSE 'SCALAR'
            END AS FUNCTION_TYPE
          FROM INFORMATION_SCHEMA.PARAMETERS p
          INNER JOIN INFORMATION_SCHEMA.ROUTINES r 
            ON p.SPECIFIC_NAME = r.SPECIFIC_NAME
          WHERE r.ROUTINE_NAME = @functionName 
            AND r.ROUTINE_SCHEMA = @schemaName
            AND r.ROUTINE_TYPE = 'FUNCTION'
          ORDER BY p.ORDINAL_POSITION
        `.trim()
    
        const request = pool.request()
    
        request.input('functionName', functionName)
        request.input('schemaName', schemaName)
    
        const result = await request.query(query)
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  function: `${schemaName}.${functionName}`,
                  functionType: result.recordset[0]?.FUNCTION_TYPE || 'UNKNOWN',
                  returnType: result.recordset[0]?.RETURN_TYPE || 'UNKNOWN',
                  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,
        }
      }
    }
  • Registration of the tool handler in the MCP service's handler map, delegating to the main getFunctionSchema function.
    handlers.set('get_function_schema', async (database, args) => {
      const { functionName, schemaName } = args as GetFunctionSchemaInput
      return await getFunctionSchema(database, functionName, schemaName)
    })
  • Zod input schema defining required functionName and optional schemaName (defaults to 'dbo').
    export const getFunctionSchemaInput = z.object({
      functionName: z.string().describe('Name of the function'),
      schemaName: z.string().default('dbo').describe('Schema name (default: dbo)'),
    })
  • Tool listing registration exposing the tool name, description, and JSON Schema converted input schema.
        {
          name: 'get_function_schema',
          description: 'Gets the schema and parameters of a specific function',
          inputSchema: zodToJsonSchema(getFunctionSchemaInput),
        },
        {
          name: 'execute_procedure',
          description: 'Executes a stored procedure with parameters',
          inputSchema: zodToJsonSchema(executeProcedureInput),
        },
      ]
    }
Behavior2/5

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

No annotations are provided, so the description must fully disclose behavior. It implies a read-only operation but does not mention permissions, side effects, or response format. Minimal transparency for a schema retrieval tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence of 9 words is very concise and front-loaded, but the brevity sacrifices necessary detail for completeness.

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 no output schema, the description does not explain the return value (e.g., column names, types). Lacks behavioral or contextual information that would help an agent judge completeness.

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 coverage is 100% with clear descriptions for both parameters. The description adds no extra meaning beyond what the input schema provides, so baseline score applies.

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 tool retrieves the schema and parameters of a specific function, distinguishing it from sibling tools like get_procedure_schema or get_table_schema. However, it could be more precise about what 'schema' includes (e.g., DDL metadata).

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 on when to use this tool vs. alternatives like list_functions for listing function names or get_procedure_schema for procedures. The description does not mention prerequisites or when not to use it.

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