Skip to main content
Glama
sbfulfil

PostgreSQL MCP Server

by sbfulfil

list_tables

Retrieve all tables in a PostgreSQL database with basic information like schema details. Use this tool to explore database structure and understand table relationships.

Instructions

List all tables in the database with basic information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNoSchema name (default: public)public

Implementation Reference

  • The core handler function for the 'list_tables' tool. It connects to the PostgreSQL database, executes a query against information_schema.tables to list tables in the specified schema, formats the results as a text list, and returns the MCP-formatted response.
    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 definition 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:57-70 (registration)
    Registration of the 'list_tables' tool in the ListToolsRequestSchema handler, 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' } }, }, },
  • Dispatch handler in the CallToolRequestSchema switch statement that routes 'list_tables' calls to the listTables method, passing the schema argument.
    case 'list_tables': return await this.listTables(args?.schema || 'public');

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