Skip to main content
Glama
adetxt

SQL MCP Server

by adetxt

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
NameRequiredDescriptionDefault
db_typeYes
connection_stringYes

Implementation Reference

  • 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), } ], } },
  • 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), } ], } }, )

Other 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