list_views
List all views in a SQL Server database, optionally filtered by schema, to facilitate database exploration.
Instructions
List views, optionally filtered by schema.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| schema | No |
Implementation Reference
- src/db.ts:207-218 (handler)The actual implementation of listViews – queries sys.views and sys.schemas for view names, optionally filtered by schema.
async listViews(schema?: string) { const r = await (await this.getPool()) .request() .input('schema', sql.NVarChar, schema ?? null).query(` SELECT s.name AS schema_name, v.name AS view_name FROM sys.views v INNER JOIN sys.schemas s ON v.schema_id = s.schema_id WHERE (@schema IS NULL OR s.name = @schema) ORDER BY s.name, v.name `); return r.recordset; } - src/index.ts:110-117 (registration)Registers the 'list_views' MCP tool with an optional schema parameter and wires it to db.listViews.
server.tool( 'list_views', 'List views, optionally filtered by schema.', { schema: z.string().optional(), }, async ({ schema }) => runTool(() => db.listViews(schema)) ); - src/index.ts:113-115 (schema)Zod schema definition for the 'list_views' tool: optional schema string parameter.
{ schema: z.string().optional(), }, - src/index.ts:47-59 (helper)The runTool helper wraps the handler call with try/catch and formats the result (success JSON or error).
async function runTool(fn: () => Promise<unknown>): Promise<ToolResult> { try { const value = await fn(); const text = typeof value === 'string' ? value : JSON.stringify(value, null, 2); return { content: [{ type: 'text', text }] }; } catch (err) { return { content: [{ type: 'text', text: formatDbError(err) }], isError: true, }; } }