Skip to main content
Glama
adetxt

SQL MCP Server

by adetxt

get_tables

Retrieve a list of tables from SQL databases (Postgres, MySQL, SQLite) using a connection string to manage and analyze database structures efficiently.

Instructions

Get list of table in database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connection_stringYes
db_typeYes

Implementation Reference

  • The handler function that implements the core logic of the 'get_tables' tool. It uses Sequelize to connect to the database, executes dialect-specific queries to fetch table names, processes the results (e.g., filtering system schemas in Postgres), and returns the list as a JSON-formatted text response in MCP protocol format.
    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), } ], } },
  • The input schema for the 'get_tables' tool, defined with Zod validators for 'db_type' (Postgres, MySQL, SQLite) and 'connection_string', along with tool metadata like title and description.
    { title: 'Get Tables', description: 'Get list of table in database', inputSchema: { db_type: z.enum(['postgres', 'mysql', 'sqlite']), connection_string: z.string(), }, },
  • src/tools.ts:6-50 (registration)
    The registration of the 'get_tables' tool using McpServer.registerTool, including the tool name, schema, and inline 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), } ], } }, )

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/adetxt/sql-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server