get_procedure_definition
Retrieve the SQL definition of a stored procedure in a specified schema. Use this tool to inspect procedure logic without executing it.
Instructions
Return the SQL definition of a stored procedure. (Definitions are read-only — this server cannot EXEC procedures.)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| schema | Yes | ||
| procedure | Yes |
Implementation Reference
- src/index.ts:142-154 (registration)Registration of the 'get_procedure_definition' tool on the MCP server, defining its description, input schema (schema, procedure), and handler callback.
server.tool( 'get_procedure_definition', 'Return the SQL definition of a stored procedure. (Definitions are read-only — this server cannot EXEC procedures.)', { schema: z.string(), procedure: z.string(), }, async ({ schema, procedure }) => runTool(async () => { const def = await db.getProcedureDefinition(schema, procedure); return def ?? `[NOT_FOUND] Procedure ${schema}.${procedure} not found.`; }) ); - src/index.ts:149-153 (handler)Handler callback that calls db.getProcedureDefinition(schema, procedure) and returns the result or a NOT_FOUND message.
async ({ schema, procedure }) => runTool(async () => { const def = await db.getProcedureDefinition(schema, procedure); return def ?? `[NOT_FOUND] Procedure ${schema}.${procedure} not found.`; }) - src/db.ts:247-259 (helper)Implementation of getProcedureDefinition in DbManager: queries sys.sql_modules joined with sys.procedures and sys.schemas to return the SQL definition of a stored procedure.
async getProcedureDefinition(schema: string, proc: string): Promise<string | null> { const r = await (await this.getPool()) .request() .input('schema', sql.NVarChar, schema) .input('proc', sql.NVarChar, proc).query(` SELECT m.definition FROM sys.sql_modules m INNER JOIN sys.procedures p ON m.object_id = p.object_id INNER JOIN sys.schemas s ON p.schema_id = s.schema_id WHERE s.name = @schema AND p.name = @proc `); return r.recordset[0]?.definition ?? null; } - src/index.ts:145-148 (schema)Zod schema for the tool's inputs: 'schema' (string) and 'procedure' (string).
{ schema: z.string(), procedure: z.string(), },