Skip to main content
Glama
blitzstermayank

Teradata MCP Server

base_tableAffinity

Analyze table usage patterns to identify relationships between database tables, supporting SQL query generation and metadata extraction for Teradata databases.

Instructions

Get tables commonly used together by database users, this is helpful to infer relationships between tables via SQLAlchemy, bind parameters if provided (prepared SQL), and return the fully rendered SQL (with literals) in metadata.

Arguments: database_name - Database name object_name - table or view name

Returns: ResponseType: formatted response with query results + metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
database_nameYes
obj_nameYes

Implementation Reference

  • The handler function implementing the 'base_tableAffinity' tool. It executes a SQL query against DBC.DBQLObjTbl to identify tables frequently queried together with the specified database and object, providing affinity information including query counts and timestamps.
    def handle_base_tableAffinity(conn: TeradataConnection, database_name: str, obj_name: str, *args, **kwargs):
        """
        Get tables commonly used together by database users, this is helpful to infer relationships between tables via SQLAlchemy, bind parameters if provided (prepared SQL), and return the fully rendered SQL (with literals) in metadata.
    
        Arguments:
          database_name - Database name
          object_name - table or view name
    
        Returns:
          ResponseType: formatted response with query results + metadata
        """
        logger.debug(f"Tool: handle_base_tableAffinity: Args: database_name: {database_name}, obj_name: {obj_name}")
        table_affiity_sql="""
        LOCKING ROW for ACCESS
        SELECT   TRIM(QTU2.DatabaseName)  AS "DatabaseName"
                , TRIM(QTU2.TableName)  AS "TableName"
                , COUNT(DISTINCT QTU1.QueryID) AS "QueryCount"
                , (current_timestamp - min(QTU2.CollectTimeStamp)) day(4) as "FirstQueryDaysAgo"
                , (current_timestamp - max(QTU2.CollectTimeStamp)) day(4) as "LastQueryDaysAgo"
        FROM    (
                            SELECT   objectdatabasename AS DatabaseName
                                , ObjectTableName AS TableName
                                , QueryId
                            FROM DBC.DBQLObjTbl /* for DBC */
                            WHERE Objecttype in ('Tab', 'Viw')
                            AND ObjectTableName = '{table_name}'
                            AND objectdatabasename = '{database_name}'
                            AND ObjectTableName IS NOT NULL
                            AND ObjectColumnName IS NULL
                            -- AND LogDate BETWEEN '2017-01-01' AND '2017-08-01' /* uncomment for PDCR */
                            --	AND LogDate BETWEEN current_date - 90 AND current_date - 1 /* uncomment for PDCR */
                            GROUP BY 1,2,3
                        ) AS QTU1
                        INNER JOIN
                        (
                            SELECT   objectdatabasename AS DatabaseName
                                , ObjectTableName AS TableName
                                , QueryId
                                , CollectTimeStamp
                            FROM DBC.DBQLObjTbl /* for DBC */
                            WHERE Objecttype in ('Tab', 'Viw')
                            AND ObjectTableName IS NOT NULL
                            AND ObjectColumnName IS NULL
                            GROUP BY 1,2,3, 4
                        ) AS QTU2
                        ON QTU1.QueryID=QTU2.QueryID
                        INNER JOIN DBC.DBQLogTbl QU /* uncomment for DBC */
                        -- INNER JOIN DBC.DBQLogTbl QU /* uncomment for PDCR */
                        ON QTU1.QueryID=QU.QueryID
        WHERE (TRIM(QTU2.TableName) <> TRIM(QTU1.TableName) OR  TRIM(QTU2.DatabaseName) <> TRIM(QTU1.DatabaseName))
        AND (QU.AMPCPUTime + QU.ParserCPUTime) > 0
        GROUP BY 1,2
        ORDER BY 3 DESC, 5 DESC
    --    having "QueryCount">10
        ;
    
        """
        with conn.cursor() as cur:
            rows = cur.execute(table_affiity_sql.format(table_name=obj_name, database_name=database_name))
            data = rows_to_json(cur.description, rows.fetchall())
        if len(data):
            affinity_info=f'This data contains the list of tables most commonly queried alongside object {database_name}.{obj_name}'
        else:
            affinity_info=f'Object {database_name}.{obj_name} is not often queried with any other table or queried at all, try other ways to infer its relationships.'
        metadata = {
            "tool_name": "handle_base_tableAffinity",
            "database": database_name,
            "object": obj_name,
            "table_count": len(data),
            "comment": affinity_info
        }
        logger.debug(f"Tool: handle_base_tableAffinity: metadata: {metadata}")
        return create_response(data, metadata)
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions that the tool 'bind parameters if provided (prepared SQL), and return the fully rendered SQL (with literals) in metadata', which adds some context about output behavior. However, it lacks details on permissions, rate limits, side effects, or what 'commonly used together' means operationally, leaving significant gaps for a tool that likely queries database metadata.

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 concise with three sentences: purpose statement, parameter binding note, and return information. It's front-loaded with the core purpose. However, the parameter list uses 'object_name' while the schema uses 'obj_name', causing minor confusion that slightly reduces efficiency.

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

Completeness2/5

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

Given no annotations, 0% schema coverage, no output schema, and 2 parameters, the description is incomplete. It mentions SQL binding and metadata returns but doesn't explain the response structure, error handling, or what 'formatted response' entails. For a tool that infers table relationships, more context on methodology or output interpretation is needed.

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

Parameters2/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 for undocumented parameters. It lists 'database_name' and 'object_name' in the Arguments section, but the input schema uses 'obj_name' (not 'object_name'), creating a mismatch. The description adds minimal semantics (e.g., 'table or view name' for object_name), but doesn't clarify format, constraints, or examples, failing to fully address the coverage gap.

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: 'Get tables commonly used together by database users' and mentions it helps 'infer relationships between tables via SQLAlchemy'. It specifies the verb ('Get') and resource ('tables commonly used together'), but doesn't explicitly differentiate from siblings like base_tableUsage or base_tableList, which likely serve different purposes.

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 minimal guidance on when to use this tool, stating it's 'helpful to infer relationships between tables', but doesn't specify when to choose it over alternatives like base_tableUsage or base_tableDDL. No explicit when/when-not instructions or prerequisite context are provided, leaving usage unclear relative to siblings.

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