list_procedures
Retrieve all stored procedures from a SQL Server database. Filter results by schema name to identify available database procedures for execution or analysis.
Instructions
Lists all stored procedures in the database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| schemaName | No | Schema name to filter procedures |
Implementation Reference
- src/tools/list-procedures.ts:5-60 (handler)Core handler function that executes the SQL query to list stored procedures from INFORMATION_SCHEMA.ROUTINES, optionally filtered by schemaName, and returns formatted JSON result or error.export async function listProcedures( db: DatabaseConnection, schemaName?: string ): Promise<CallToolResult> { try { const pool = db.getPool() let query = ` SELECT ROUTINE_SCHEMA, ROUTINE_NAME, ROUTINE_TYPE, CREATED, LAST_ALTERED FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE' `.trim() const request = pool.request() if (schemaName) { query += ' AND ROUTINE_SCHEMA = @schemaName' request.input('schemaName', schemaName) } query += ' ORDER BY ROUTINE_SCHEMA, ROUTINE_NAME' const result = await request.query(query) return { content: [ { type: 'text', text: JSON.stringify( { procedures: 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, } } }
- src/schemas.ts:30-35 (schema)Zod input schema for list_procedures tool, defining optional schemaName parameter.export const listProceduresInput = z.object({ schemaName: z .string() .optional() .describe('Schema name to filter procedures'), })
- src/tools/index.ts:47-51 (registration)Tool registration in toolsList() function, providing name, description, and JSON schema for the MCP tools list response.{ name: 'list_procedures', description: 'Lists all stored procedures in the database', inputSchema: zodToJsonSchema(listProceduresInput), },
- src/services/SqlServerMCPService.ts:108-111 (registration)Registers the thin wrapper handler for 'list_procedures' in the SqlServerMCPService's toolHandlers Map, which parses args and delegates to the core listProcedures function.handlers.set('list_procedures', async (database, args) => { const { schemaName } = args as ListProceduresInput return await listProcedures(database, schemaName) })