dba_tableSqlList
Retrieve a list of SQL queries executed against a specific table in Teradata over a defined period. Input table name and number of days for targeted query history tracking.
Instructions
Get a list of SQL run against a table in the last number of days.
Arguments: table_name - table name no_days - number of days
Returns: ResponseType: formatted response with query results + metadata
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| no_days | No | ||
| table_name | Yes |
Implementation Reference
- The handler function that implements the core logic of the 'dba_tableSqlList' tool. It executes a SQL query against Teradata's DBC.QryLogSqlV and DBC.QryLogV to fetch recent SQL statements referencing the provided table_name, processes the results, and returns a formatted response with metadata.def handle_dba_tableSqlList(conn: TeradataConnection, table_name: str, no_days: int | None = 7, *args, **kwargs): """ Get a list of SQL run against a table in the last number of days. Arguments: table_name - table name no_days - number of days Returns: ResponseType: formatted response with query results + metadata """ logger.debug(f"Tool: handle_dba_tableSqlList: Args: table_name: {table_name}, no_days: {no_days}") with conn.cursor() as cur: if table_name == "": logger.debug("No table name provided") else: logger.debug(f"Table name provided: {table_name}, returning SQL queries for this table.") rows = cur.execute(f"""SELECT t1.QueryID, t1.ProcID, t1.CollectTimeStamp, t1.SqlTextInfo, t2.UserName FROM DBC.QryLogSqlV t1 JOIN DBC.QryLogV t2 ON t1.QueryID = t2.QueryID WHERE t1.CollectTimeStamp >= CURRENT_TIMESTAMP - INTERVAL '{no_days}' DAY AND t1.SqlTextInfo LIKE '%{table_name}%' ORDER BY t1.CollectTimeStamp DESC;""") data = rows_to_json(cur.description, rows.fetchall()) metadata = { "tool_name": "dba_tableSqlList", "table_name": table_name, "no_days": no_days, "total_queries": len(data) } logger.debug(f"Tool: handle_dba_tableSqlList: metadata: {metadata}") return create_response(data, metadata)
- src/teradata_mcp_server/app.py:344-363 (registration)Dynamic registration code that scans loaded modules for functions named 'handle_*', extracts the tool name (e.g., 'dba_tableSqlList' from 'handle_dba_tableSqlList'), wraps them for MCP compatibility (injecting DB connection, QueryBand, etc.), and registers them as MCP tools if they match the profile's tool patterns.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 # Skip template tools (used for developer reference only) if tool_name.startswith("tmpl_"): logger.debug(f"Skipping template tool: {tool_name}") continue # Skip BAR tools if BAR functionality is disabled if tool_name.startswith("bar_") and not enableBAR: logger.info(f"Skipping BAR tool: {tool_name} (BAR functionality disabled)") continue wrapped = make_tool_wrapper(func) mcp.tool(name=tool_name, description=wrapped.__doc__)(wrapped) logger.info(f"Created tool: {tool_name}")
- Module map configuration that includes the 'dba' module, enabling lazy loading of dba_tools.py when dba_* tools are required by the profile configuration.MODULE_MAP = { 'bar': 'teradata_mcp_server.tools.bar', 'base': 'teradata_mcp_server.tools.base', 'dba': 'teradata_mcp_server.tools.dba', 'fs': 'teradata_mcp_server.tools.fs', 'qlty': 'teradata_mcp_server.tools.qlty', 'rag': 'teradata_mcp_server.tools.rag', 'sql_opt': 'teradata_mcp_server.tools.sql_opt', 'sec': 'teradata_mcp_server.tools.sec', 'tmpl': 'teradata_mcp_server.tools.tmpl', 'plot': 'teradata_mcp_server.tools.plot', 'tdvs': 'teradata_mcp_server.tools.tdvs' }
- src/teradata_mcp_server/tools/dba/__init__.py:1-2 (registration)Package init file that imports all symbols from dba_tools.py (including handle_dba_tableSqlList), making them available for dynamic discovery by the module loader.from .dba_resources import * from .dba_tools import *