Skip to main content
Glama

list_schemas

Retrieve a list of all schemas in a Postgres database to facilitate database management, schema exploration, and structural analysis.

Instructions

List all schemas in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The primary handler implementation for the 'list_schemas' MCP tool. It executes a SQL query against information_schema.schemata to retrieve and categorize schemas (system/user), formats the result, and handles errors. The @mcp.tool decorator also serves as the registration.
    @mcp.tool(description="List all schemas in the database")
    async def list_schemas() -> ResponseType:
        """List all schemas in the database."""
        try:
            sql_driver = await get_sql_driver()
            rows = await sql_driver.execute_query(
                """
                SELECT
                    schema_name,
                    schema_owner,
                    CASE
                        WHEN schema_name LIKE 'pg_%' THEN 'System Schema'
                        WHEN schema_name = 'information_schema' THEN 'System Information Schema'
                        ELSE 'User Schema'
                    END as schema_type
                FROM information_schema.schemata
                ORDER BY schema_type, schema_name
                """
            )
            schemas = [row.cells for row in rows] if rows else []
            return format_text_response(schemas)
        except Exception as e:
            logger.error(f"Error listing schemas: {e}")
            return format_error_response(str(e))
Install Server

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/crystaldba/postgres-mcp'

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