Skip to main content
Glama
vini-cius

SQL Server MCP Service

by vini-cius

list_functions

Retrieve all scalar and table-valued functions from a SQL Server database, with optional filtering by schema and function type for targeted results.

Instructions

Lists all functions (scalar and table-valued) in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNameNoSchema name to filter functions
functionTypeNoType of function to filter

Implementation Reference

  • The core handler function that executes the 'list_functions' tool logic. It queries INFORMATION_SCHEMA.ROUTINES for functions, optionally filtering by schema name and function type (SCALAR/TABLE), returning a JSON list of functions.
    export async function listFunctions(
      db: DatabaseConnection,
      schemaName?: string,
      functionType?: 'SCALAR' | 'TABLE'
    ): Promise<CallToolResult> {
      try {
        const pool = db.getPool()
    
        let query = `
          SELECT 
            ROUTINE_SCHEMA,
            ROUTINE_NAME,
            ROUTINE_TYPE,
            DATA_TYPE,
            CREATED,
            LAST_ALTERED,
            CASE 
              WHEN DATA_TYPE = 'TABLE' THEN 'TABLE-VALUED'
              ELSE 'SCALAR'
            END AS FUNCTION_TYPE
          FROM INFORMATION_SCHEMA.ROUTINES
          WHERE ROUTINE_TYPE = 'FUNCTION'
        `.trim()
    
        const request = pool.request()
    
        if (schemaName) {
          query += ' AND ROUTINE_SCHEMA = @schemaName'
          request.input('schemaName', schemaName)
        }
    
        if (functionType) {
          if (functionType === 'SCALAR') {
            query += " AND DATA_TYPE != 'TABLE'"
          } else if (functionType === 'TABLE') {
            query += " AND DATA_TYPE = 'TABLE'"
          }
        }
    
        query += ' ORDER BY ROUTINE_SCHEMA, ROUTINE_NAME'
    
        const result = await request.query(query)
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  functions: result.recordset,
                  count: result.recordset.length,
                },
                null,
                2
              ),
            },
          ],
        }
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Erro: ${error instanceof Error ? error.message : 'Erro desconhecido'}`,
            },
          ],
          isError: true,
        }
      }
    }
  • Zod schema defining the input validation for the 'list_functions' tool: optional schemaName (string) and optional functionType (enum: SCALAR or TABLE).
    export const listFunctionsInput = z.object({
      schemaName: z.string().optional().describe('Schema name to filter functions'),
      functionType: z
        .enum(['SCALAR', 'TABLE'])
        .optional()
        .describe('Type of function to filter'),
    })
  • Registration of the 'list_functions' tool in the tool list with its name, description, and JSON-schema input definition.
    {
      name: 'list_functions',
      description:
        'Lists all functions (scalar and table-valued) in the database',
      inputSchema: zodToJsonSchema(listFunctionsInput),
    },
  • Handler mapping that connects the 'list_functions' tool name to the actual listFunctions implementation, unpacks args (schemaName, functionType) and delegates.
    handlers.set('list_functions', async (database, args) => {
      const { schemaName, functionType } = args as ListFunctionsInput
      return await listFunctions(database, schemaName, functionType)
    })
  • Exports the listFunctions implementation from the tools index file, making it available for import by the service.
    export { listFunctions } from './list-functions'
Behavior3/5

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

No annotations exist, so description carries burden. It implies a read operation but does not explicitly confirm safety, side effects, or permissions. Adequate for a simple listing 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 clear sentence, front-loaded with purpose, and contains no redundant words.

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 no output schema, the description does not explain return format or what fields are included (e.g., name, schema). It covers the purpose but lacks completeness for a tool with no output schema.

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 parameter descriptions already present. The tool description adds no further meaning beyond the schema, so baseline score of 3 applies.

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 uses a specific verb 'lists' and resource 'functions', includes the scope 'in the database', and clarifies both scalar and table-valued types, distinguishing it from sibling tools like list_procedures and list_tables.

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 usage guidelines provided; no indication of when to use this versus other listing tools, or any prerequisites or filters behavior.

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