Skip to main content
Glama
andyWang1688

sql-query-mcp

list_databases

Retrieve all visible databases from a MySQL or Hive connection to explore available data sources.

Instructions

List visible databases for a MySQL or Hive connection.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connection_idYes

Implementation Reference

  • MCP tool handler that exposes list_databases as a FastMCP tool, delegating to MetadataService.list_databases.
    @mcp.tool()
    def list_databases(connection_id: str) -> dict:
        """List visible databases for a MySQL or Hive connection."""
    
        return _run_tool(lambda: metadata.list_databases(connection_id))
  • MetadataService.list_databases: validates engine (mysql/hive), gets connection, delegates to adapter, and returns databases with auditing.
    def list_databases(self, connection_id: str) -> Dict[str, object]:
        started = time.perf_counter()
        config = None
        try:
            config = self._registry.get_connection_config(connection_id)
            if config.engine not in {"mysql", "hive"}:
                require_engine(config, "mysql", "list_databases")
            with self._registry.connection_from_config(config) as (conn, adapter):
                _apply_statement_timeout(
                    adapter, conn, self._settings.statement_timeout_ms
                )
                databases = adapter.list_databases(conn)
            duration_ms = _elapsed_ms(started)
            self._audit.log(
                tool="list_databases",
                connection_id=connection_id,
                success=True,
                duration_ms=duration_ms,
                row_count=len(databases),
                extra={"engine": config.engine},
            )
            return {
                "connection_id": connection_id,
                "engine": config.engine,
                "databases": databases,
            }
        except Exception as exc:
            duration_ms = _elapsed_ms(started)
            sanitized = sanitize_error_message(str(exc))
            self._audit.log(
                tool="list_databases",
                connection_id=connection_id,
                success=False,
                duration_ms=duration_ms,
                error=sanitized,
                extra=_build_audit_extra(config),
            )
            raise QueryExecutionError(sanitized) from exc
  • Input schema: accepts a single string parameter 'connection_id'. Returns a dict.
    @mcp.tool()
    def list_databases(connection_id: str) -> dict:
  • Hive adapter implementation: executes 'SHOW DATABASES'.
    def list_databases(self, conn: object) -> List[str]:
        with conn.cursor() as cur:
            cur.execute("SHOW DATABASES")
            return [self._first_value(row) for row in cur.fetchall()]
  • MySQL adapter implementation: queries information_schema.schemata, excluding system databases.
    def list_databases(self, conn: object) -> List[str]:
        with conn.cursor() as cur:
            cur.execute(
                """
                SELECT schema_name AS database_name
                FROM information_schema.schemata
                WHERE schema_name NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')
                ORDER BY schema_name
                """
            )
            return [row["database_name"] for row in cur.fetchall()]
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states 'list visible databases', which implies a read operation, but does not disclose what 'visible' means, required permissions, rate limits, or output format. More context is needed for a safe invocation.

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?

The description is a single, front-loaded sentence without unnecessary words. It efficiently conveys the tool's purpose.

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?

Given the tool's simplicity and lack of output schema, the description does not explain the return format (e.g., list of database names). For completeness, a brief note on the response structure would be beneficial, but it is minimal and adequate.

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

Parameters3/5

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

The schema has 0% description coverage for the only parameter connection_id. The description adds context by mentioning 'MySQL or Hive connection', linking the parameter to connection types, but does not explain its format or constraints beyond the schema.

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 verb 'list' and resource 'databases', specifically for MySQL or Hive connections. It distinguishes from sibling tools like list_schemas and list_tables by naming the resource type.

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

Usage Guidelines3/5

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

The description implies usage for listing databases from a MySQL or Hive connection, but does not provide explicit when-to-use or when-not-to-use guidance, nor does it compare with alternatives like list_schemas or list_tables.

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