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:
Behavior3/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 discloses key behavioral traits: execution via SQLAlchemy, parameter binding for prepared SQL, and metadata inclusion of rendered SQL. However, it lacks details on permissions, error handling, rate limits, or what 'formatted response' entails. For a tool that executes arbitrary SQL queries, this is a moderate gap in safety and operational context.

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 appropriately sized and front-loaded, with the core purpose in the first sentence and parameter details in a structured 'Arguments' section. Every sentence adds value, though the 'Returns' section could be more specific. It avoids redundancy and is efficiently organized for quick comprehension.

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 complexity (executing arbitrary SQL queries), lack of annotations, no output schema, and 0% schema coverage, the description is moderately complete. It covers the basic action and parameter intent but omits critical context like security implications, result formatting, error cases, or how it differs from sibling tools. This is adequate but has clear gaps for safe and effective use.

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 0%, so the description must compensate. It adds meaning by explaining that 'sql' is 'SQL text, with optional bind-parameter placeholders', which clarifies the parameter's purpose beyond the schema's generic 'string/null' type. However, it doesn't detail placeholder syntax, SQL dialect, or constraints, leaving some ambiguity for a critical parameter.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Execute a SQL query via SQLAlchemy, bind parameters if provided (prepared SQL), and return the fully rendered SQL (with literals) in metadata.' This specifies the action (execute SQL query), technology (SQLAlchemy), and key behavior (return rendered SQL in metadata). However, it doesn't explicitly differentiate from sibling tools like 'sql_Execute_Full_Pipeline' or 'rag_Execute_Workflow' that might also execute queries.

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. With many sibling tools (e.g., 'sql_Execute_Full_Pipeline', 'base_tablePreview'), there's no indication of whether this is for raw SQL execution, specific query types, or particular contexts. Usage is implied only by the action described, with no explicit when/when-not instructions or named alternatives.

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/blitzstermayank/MCP'

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