Skip to main content
Glama
andyWang1688

sql-query-mcp

list_schemas

List all visible schemas in a PostgreSQL database by providing a connection ID.

Instructions

List visible schemas for a PostgreSQL connection.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connection_idYes

Implementation Reference

  • The 'list_schemas' tool is registered as an MCP tool via the @mcp.tool() decorator in create_app(). It accepts a connection_id string and delegates to metadata.list_schemas(connection_id).
    @mcp.tool()
    def list_schemas(connection_id: str) -> dict:
        """List visible schemas for a PostgreSQL connection."""
    
        return _run_tool(lambda: metadata.list_schemas(connection_id))
  • The MetadataService.list_schemas method is the core handler. It retrieves the connection config, enforces that the engine is 'postgres', opens a connection, calls adapter.list_schemas(conn), and returns the results with audit logging.
    def list_schemas(self, connection_id: str) -> Dict[str, object]:
        started = time.perf_counter()
        config = None
        try:
            config = self._registry.get_connection_config(connection_id)
            require_engine(config, "postgres", "list_schemas")
            with self._registry.connection_from_config(config) as (conn, adapter):
                _apply_statement_timeout(
                    adapter, conn, self._settings.statement_timeout_ms
                )
                schemas = adapter.list_schemas(conn)
            duration_ms = _elapsed_ms(started)
            self._audit.log(
                tool="list_schemas",
                connection_id=connection_id,
                success=True,
                duration_ms=duration_ms,
                row_count=len(schemas),
                extra={"engine": config.engine},
            )
            return {
                "connection_id": connection_id,
                "engine": "postgres",
                "schemas": schemas,
            }
        except Exception as exc:
            duration_ms = _elapsed_ms(started)
            sanitized = sanitize_error_message(str(exc))
            self._audit.log(
                tool="list_schemas",
                connection_id=connection_id,
                success=False,
                duration_ms=duration_ms,
                error=sanitized,
                extra=_build_audit_extra(config),
            )
            raise QueryExecutionError(sanitized) from exc
  • The PostgresAdapter.list_schemas method executes the actual SQL query against PostgreSQL's information_schema.schemata, filtering out 'information_schema' and pg_* schemas, and returns the list of schema names.
    def list_schemas(self, conn: object) -> List[str]:
        with conn.cursor() as cur:
            cur.execute(
                """
                SELECT schema_name
                FROM information_schema.schemata
                WHERE schema_name NOT IN ('information_schema')
                  AND schema_name NOT LIKE 'pg_%'
                ORDER BY schema_name
                """
            )
            return [row["schema_name"] for row in cur.fetchall()]
  • The require_engine function validates that the connection engine is 'postgres' for list_schemas, raising a SecurityError if not.
    def require_engine(config: ConnectionConfig, engine: str, tool_name: str) -> None:
        if config.engine != engine:
            raise SecurityError(f"{tool_name} 仅适用于 {engine} 连接,当前连接 engine={config.engine}")
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description should disclose behavioral traits. It mentions 'visible' schemas, implying permission-dependent filtering, but does not elaborate on side effects, data volume, ordering, or return format.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence, direct, and no wasted words. Efficiently communicates the core functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple list tool with no output schema, the minimal description may suffice for basic understanding. However, it lacks details on input constraints and expected behavior, which could lead to user confusion.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The only parameter, connection_id, is not described beyond its name and type. With 0% schema description coverage, the description should provide clarity on what a valid connection_id is (e.g., UUID, name, or how to obtain it), but it does not.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('list'), the resource ('visible schemas'), and the context ('for a PostgreSQL connection'). It is specific and distinguishes itself from sibling tools like list_databases and list_tables.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No indication of when to use this tool versus alternatives (e.g., when to list schemas vs databases or tables). No preconditions or exclusions are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/andyWang1688/sql-query-mcp'

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