Skip to main content
Glama

extract_metadata

Read-onlyIdempotent

Extract tables, columns, and functions from SQL queries to analyze database structure and dependencies.

Instructions

Extract tables, columns, and functions referenced in SQL.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYesThe SQL string to analyze

Implementation Reference

  • The `extract_metadata` handler function which wraps the underlying C library call and transforms the JSON output into a `Metadata` dataclass.
    def extract_metadata(sql: str) -> Metadata:
        """Extract comprehensive metadata from a SQL statement.
    
        This returns tables, columns, functions, and their qualified variants
        in a single call.
    
        Args:
            sql: The SQL string to analyze.
    
        Returns:
            Metadata object containing all extracted information.
    
        Raises:
            ParseError: If the SQL is syntactically invalid.
            GoSQLXError: If the gosqlx_extract_metadata function is not available.
        """
        if not _has_func("gosqlx_extract_metadata"):
            raise GoSQLXError(
                "gosqlx_extract_metadata not available in this library build. "
                "Rebuild the shared library with the latest cbinding."
            )
        lib = _get_lib()
        data = _call_and_decode(lib.gosqlx_extract_metadata, sql.encode("utf-8"))
    
        _check_parse_error(data)
    
        return Metadata(
            tables=data.get("tables", []),
            columns=data.get("columns", []),
            functions=data.get("functions", []),
            tables_qualified=_parse_qualified_names(
                data.get("tables_qualified", [])
            ),
            columns_qualified=_parse_qualified_names(
                data.get("columns_qualified", [])
            ),
        )
  • The `Metadata` dataclass schema definition used for returning results from the `extract_metadata` tool.
    class Metadata:
        """Comprehensive metadata extracted from a SQL query."""
    
        tables: List[str] = field(default_factory=list)
        columns: List[str] = field(default_factory=list)
        functions: List[str] = field(default_factory=list)
        tables_qualified: List[QualifiedName] = field(default_factory=list)
        columns_qualified: List[QualifiedName] = field(default_factory=list)
Behavior3/5

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

Annotations already provide clear hints: read-only, not open-world, idempotent, and non-destructive. The description adds no behavioral context beyond what annotations cover, such as performance characteristics, error handling, or output format details. However, it does not contradict annotations, so it meets the baseline for having annotations.

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, clear sentence that efficiently conveys the tool's purpose without unnecessary words. It is front-loaded with the core action and resources, making it easy to parse and understand quickly.

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 low complexity (one parameter, no output schema) and rich annotations covering safety and behavior, the description is minimally adequate. However, it lacks details on output format or error handling, which could be helpful for an agent, though annotations provide a solid foundation.

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?

Schema description coverage is 100%, with the single parameter 'sql' fully documented in the schema as 'The SQL string to analyze'. The description does not add any additional meaning or context about the parameter beyond what the schema provides, such as SQL dialect support or input constraints, so it meets the baseline score.

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 specific action ('extract') and the resources involved ('tables, columns, and functions referenced in SQL'), making the purpose immediately understandable. It distinguishes itself from sibling tools like 'analyze_sql', 'format_sql', etc., which have different functions rather than focusing on metadata extraction.

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?

The description provides no guidance on when to use this tool versus alternatives. It does not mention any prerequisites, context for usage, or comparisons to sibling tools like 'parse_sql' or 'analyze_sql', leaving the agent to infer usage based on the name alone.

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/ajitpratap0/GoSQLX'

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