get_tables
Retrieve a list of all tables in your SQL database to understand its structure and available data. Connect using your database type and connection string to view tables.
Instructions
Get list of table in database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| db_type | Yes | ||
| connection_string | Yes |
Implementation Reference
- src/tools.ts:16-49 (handler)The main handler function for the 'get_tables' tool. It creates a Sequelize connection based on db_type and connection_string, queries the database for tables depending on the dialect (postgres, mysql, sqlite), processes the results into a list of tables, and returns them as JSON text content.async ({db_type, connection_string}) => { const sequelize = new Sequelize(connection_string, { dialect: db_type, }) let result: any[] = [] let tables: string[] = [] switch (db_type) { case 'postgres': [result] = await sequelize.query('SELECT * FROM information_schema.tables') tables = result .filter((table: any) => table.table_schema !== 'information_schema' && table.table_schema !== 'pg_catalog') .map((table: any) => `${table.table_schema}.${table.table_name}`) break case 'mysql': [result] = await sequelize.query('SELECT * FROM information_schema.tables') tables = result.map((table: any) => table.table_name) break case 'sqlite': [result] = await sequelize.query('SELECT * FROM sqlite_master WHERE type = "table"') tables = result.map((table: any) => table.name) break } return { content: [ { type: 'text', text: JSON.stringify(tables), } ], } },
- src/tools.ts:11-14 (schema)Input schema definition for the 'get_tables' tool using Zod schemas for db_type (enum: postgres, mysql, sqlite) and connection_string (string).inputSchema: { db_type: z.enum(['postgres', 'mysql', 'sqlite']), connection_string: z.string(), },
- src/tools.ts:6-50 (registration)Registers the 'get_tables' tool with the MCP server, specifying the tool name, metadata, input schema, and handler function.server.registerTool( 'get_tables', { title: 'Get Tables', description: 'Get list of table in database', inputSchema: { db_type: z.enum(['postgres', 'mysql', 'sqlite']), connection_string: z.string(), }, }, async ({db_type, connection_string}) => { const sequelize = new Sequelize(connection_string, { dialect: db_type, }) let result: any[] = [] let tables: string[] = [] switch (db_type) { case 'postgres': [result] = await sequelize.query('SELECT * FROM information_schema.tables') tables = result .filter((table: any) => table.table_schema !== 'information_schema' && table.table_schema !== 'pg_catalog') .map((table: any) => `${table.table_schema}.${table.table_name}`) break case 'mysql': [result] = await sequelize.query('SELECT * FROM information_schema.tables') tables = result.map((table: any) => table.table_name) break case 'sqlite': [result] = await sequelize.query('SELECT * FROM sqlite_master WHERE type = "table"') tables = result.map((table: any) => table.name) break } return { content: [ { type: 'text', text: JSON.stringify(tables), } ], } }, )