Skip to main content
Glama

list_schemas

Retrieve all database schemas to understand database structure and organize data access for PostgreSQL databases.

Instructions

List all schemas in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The list_schemas tool is defined as an async function decorated with @mcp.tool. It retrieves schemas by querying information_schema.schemata using an SQL driver.
    @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))

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/moecodeshere/mcptrial'

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