list_table
Lists tables in an MSSQL database, with optional filtering by specific schemas to help users identify and navigate database structures.
Instructions
Lists tables in an MSSQL Database, or list tables in specific schemas
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| parameters | No | Schemas to filter by (optional) |
Implementation Reference
- src/tools/ListTableTool.ts:23-42 (handler)The `run` method implements the core logic of the `list_table` tool, executing an SQL query to list tables from INFORMATION_SCHEMA.TABLES, optionally filtered by schemas.async run(params: any) { try { const { parameters } = params; const request = new sql.Request(); const schemaFilter = parameters && parameters.length > 0 ? `AND TABLE_SCHEMA IN (${parameters.map((p: string) => `'${p}'`).join(", ")})` : ""; const query = `SELECT TABLE_SCHEMA + '.' + TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ${schemaFilter} ORDER BY TABLE_SCHEMA, TABLE_NAME`; const result = await request.query(query); return { success: true, message: `List tables executed successfully`, items: result.recordset, }; } catch (error) { console.error("Error listing tables:", error); return { success: false, message: `Failed to list tables: ${error}`, }; } }
- src/tools/ListTableTool.ts:8-21 (schema)Defines the input schema for the `list_table` tool, specifying an optional array of schema names to filter the tables.inputSchema = { type: "object", properties: { parameters: { type: "array", description: "Schemas to filter by (optional)", items: { type: "string" }, minItems: 0 }, }, required: [], } as any;
- src/index.ts:115-119 (registration)Registers the `listTableTool` instance in the list of available tools returned by the ListToolsRequestHandler, conditionally based on readonly mode.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: isReadOnly ? [listTableTool, readDataTool, describeTableTool] // todo: add searchDataTool to the list of tools available in readonly mode once implemented : [insertDataTool, readDataTool, describeTableTool, updateDataTool, createTableTool, createIndexTool, dropTableTool, listTableTool], // add all new tools here }));
- src/index.ts:141-143 (registration)Dispatches calls to the `list_table` tool by matching the tool name and invoking its `run` method in the CallToolRequestHandler.case listTableTool.name: result = await listTableTool.run(args); break;
- src/index.ts:225-225 (helper)Applies a wrapper to the `listTableTool` (and others) to ensure SQL connection is established before executing the tool.[insertDataTool, readDataTool, updateDataTool, createTableTool, createIndexTool, dropTableTool, listTableTool, describeTableTool].forEach(wrapToolRun);