list_tables
Retrieve the names of all tables in the current PostgreSQL database. This provides an overview of the database schema for exploration and analysis.
Instructions
List all tables in the current database schema
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- main.py:14-53 (registration)The @app.list_tools() decorator registers 'list_tables' as one of the available tools, specifying its name, description, and input schema (no parameters required).
@app.list_tools() async def list_tools() -> list[Tool]: return [ Tool( name="list_tables", description="List all tables in the current database schema", inputSchema={ "type": "object", "properties": {}, } ), Tool( name="get_schema", description="Get the schema (columns, types) of a specific table", inputSchema={ "type": "object", "properties": { "table_name": { "type": "string", "description": "Name of the table" } }, "required": ["table_name"] } ), Tool( name="run_query", description="Run a read-only SQL query against the database. ONLY SELECT queries are allowed for safety.", inputSchema={ "type": "object", "properties": { "query": { "type": "string", "description": "The read-only SQL query to execute" } }, "required": ["query"] } ) ] - main.py:17-23 (schema)The input schema for 'list_tables' defines an empty object with no required properties (this tool takes no arguments).
Tool( name="list_tables", description="List all tables in the current database schema", inputSchema={ "type": "object", "properties": {}, } - main.py:60-71 (handler)The handler for 'list_tables' queries information_schema.tables for all BASE TABLE entries in the 'public' schema, returning a formatted list of table names.
if name == "list_tables": async with pool.acquire() as conn: records = await conn.fetch(""" SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE' """) tables = [record["table_name"] for record in records] if not tables: return [TextContent(type="text", text="No tables found in public schema.")] return [TextContent(type="text", text=f"Tables in public schema:\n" + "\n".join(f"- {t}" for t in tables))]