Skip to main content
Glama
blitzstermayank

Teradata MCP Server

base_readQuery

Execute SQL queries on Teradata databases using SQLAlchemy, returning results with rendered SQL metadata for analysis and management.

Instructions

Execute a SQL query via SQLAlchemy, bind parameters if provided (prepared SQL), and return the fully rendered SQL (with literals) in metadata.

Arguments: sql - SQL text, with optional bind-parameter placeholders

Returns: ResponseType: formatted response with query results + metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlNo

Implementation Reference

  • The core handler function implementing the base_readQuery tool. It executes the provided SQL on a SQLAlchemy Connection, handles bind parameters, fetches and formats results as JSON, compiles the final rendered SQL, builds metadata including columns and row count, and returns a structured response.
    def handle_base_readQuery(
        conn: Connection,
        sql: str | None = None,
        tool_name: str | None = None,
        *args,
        **kwargs
    ):
        """
        Execute a SQL query via SQLAlchemy, bind parameters if provided (prepared SQL), and return the fully rendered SQL (with literals) in metadata.
    
        Arguments:
          sql    - SQL text, with optional bind-parameter placeholders
    
        Returns:
          ResponseType: formatted response with query results + metadata
        """
        logger.debug(f"Tool: handle_base_readQuery: Args: sql: {sql}, args={args!r}, kwargs={kwargs!r}")
    
        # 1. Build a textual SQL statement
        stmt = text(sql)
    
        # 2. Execute with bind parameters if provided
        result = conn.execute(stmt, kwargs) if kwargs else conn.execute(stmt)
    
        # 3. Fetch rows & column metadata
        cursor = result.cursor  # underlying DB-API cursor
        raw_rows = cursor.fetchall() or []
        data = rows_to_json(cursor.description, raw_rows)
        columns = [
            {
                "name": col[0],
                "type": getattr(col[1], "__name__", str(col[1]))
            }
            for col in (cursor.description or [])
        ]
    
        # 4. Compile the statement with literal binds for “final SQL”
        #    Fallback to DefaultDialect if conn has no `.dialect`
        dialect = getattr(conn, "dialect", default.DefaultDialect())
        compiled = stmt.compile(
            dialect=dialect,
            compile_kwargs={"literal_binds": True}
        )
        final_sql = str(compiled)
    
        # 5. Build metadata using the rendered SQL
        metadata = {
            "tool_name": tool_name if tool_name else "base_readQuery",
            "sql": final_sql,
            "columns": columns,
            "row_count": len(data),
        }
        logger.debug(f"Tool: handle_base_readQuery: metadata: {metadata}")
        return create_response(data, metadata)
  • Automatic registration of all handle_* functions (including handle_base_readQuery as 'base_readQuery') as MCP tools using the module_loader. The tool schema is inferred from the function signature after wrapping to remove internal parameters like 'conn' and 'tool_name'.
    module_loader = td.initialize_module_loader(config)
    if module_loader:
        all_functions = module_loader.get_all_functions()
        for name, func in all_functions.items():
            if not (inspect.isfunction(func) and name.startswith("handle_")):
                continue
            tool_name = name[len("handle_"):]
            if not any(re.match(p, tool_name) for p in config.get('tool', [])):
                continue
            wrapped = make_tool_wrapper(func)
            mcp.tool(name=tool_name, description=wrapped.__doc__)(wrapped)
            logger.info(f"Created tool: {tool_name}")
    else:

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A3.6/5.0
Behavior3/5

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

No annotations are provided, so the description bears full responsibility. It mentions SQL execution and bind parameters, suggesting some safety, but does not disclose whether the tool is read-only or allows modifications. The name 'readQuery' implies read-only, but the description does not confirm this or address potential risks.

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

Conciseness4/5

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

The description is concise at two sentences plus an Arguments section. It is front-loaded with the primary action. However, the Arguments section is somewhat redundant with the schema, slightly reducing efficiency.

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?

The tool complexity (executing SQL) and missing output schema require more detail. The description mentions returns include query results and metadata but lacks specifics on result format, pagination, limits, or safety constraints. With one parameter and no nested objects, completeness is adequate but not thorough.

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

Parameters4/5

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

Schema description coverage is 0%, but the description adds meaningful context: it explains that 'sql' is SQL text with optional bind-parameter placeholders, clarifying the parameter's role beyond the type definition.

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 tool executes a SQL query via SQLAlchemy, with bind parameters, and returns the rendered SQL in metadata. It distinguishes itself from sibling tools like base_tablePreview and base_tableDDL by offering arbitrary SQL execution.

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. Sibling tools include specialized query tools, but no explicit when-to-use or when-not-to-use information is given.

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