Skip to main content
Glama
sbfulfil

PostgreSQL MCP Server

by sbfulfil

list_tables

Query and retrieve a list of tables along with their basic details from a PostgreSQL database schema, aiding in database exploration and structure analysis.

Instructions

List all tables in the database with basic information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNoSchema name (default: public)public

Implementation Reference

  • The handler function that executes the list_tables tool. It connects to the PostgreSQL database, queries information_schema.tables for the specified schema, formats the table list, and returns it as MCP content.
    async listTables(schema = 'public') { const client = await this.connectToDatabase(); try { const query = ` SELECT table_name, table_type, is_insertable_into, is_typed FROM information_schema.tables WHERE table_schema = $1 ORDER BY table_name; `; const result = await client.query(query, [schema]); return { content: [ { type: 'text', text: `Tables in schema "${schema}":\n\n` + result.rows.map(row => `• ${row.table_name} (${row.table_type})` ).join('\n'), }, ], }; } finally { await client.end(); } }
  • Input schema for the list_tables tool, defining an optional 'schema' parameter with default 'public'.
    inputSchema: { type: 'object', properties: { schema: { type: 'string', description: 'Schema name (default: public)', default: 'public' } }, },
  • src/index.js:58-70 (registration)
    Registration of the list_tables tool in the ListToolsRequestHandler response, including name, description, and input schema.
    name: 'list_tables', description: 'List all tables in the database with basic information', inputSchema: { type: 'object', properties: { schema: { type: 'string', description: 'Schema name (default: public)', default: 'public' } }, }, },
  • src/index.js:145-146 (registration)
    Dispatch/registration in the CallToolRequestHandler switch statement that routes 'list_tables' calls to the listTables method.
    case 'list_tables': return await this.listTables(args?.schema || 'public');

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/sbfulfil/pg-mcp'

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