qlty_distinctCategories
Retrieve unique category values from a specified column in a Teradata database table to analyze data distribution and identify distinct data classifications.
Instructions
Get the destinct categories from column in a table.
Arguments: database_name - name of the database table_name - table name to analyze column_name - column name to analyze
Returns: ResponseType: formatted response with query results + metadata
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| column_name | Yes | ||
| database_name | Yes | ||
| table_name | Yes |
Implementation Reference
- Handler function that executes a Teradata TD_CategoricalSummary query to retrieve distinct categories for the specified column in a table, formats results with metadata, and returns a response.def handle_qlty_distinctCategories( conn: TeradataConnection, database_name: str | None, table_name: str, column_name: str, *args, **kwargs ): """ Get the destinct categories from column in a table. Arguments: database_name - name of the database table_name - table name to analyze column_name - column name to analyze Returns: ResponseType: formatted response with query results + metadata """ logger.debug(f"Tool: handle_qlty_distinctCategories: Args: table_name: {database_name}.{table_name}, column_name: {column_name}") if database_name is not None: table_name = f"{database_name}.{table_name}" with conn.cursor() as cur: rows = cur.execute(f"select * from TD_CategoricalSummary ( on {table_name} as InputTable using TargetColumns ('{column_name}')) as dt") data = rows_to_json(cur.description, rows.fetchall()) metadata = { "tool_name": "qlty_distinctCategories", "database_name": database_name, "table_name": table_name, "column_name": column_name, "distinct_categories": len(data) } logger.debug(f"Tool: handle_qlty_distinctCategories: Metadata: {metadata}") return create_response(data, metadata)
- src/teradata_mcp_server/app.py:270-281 (registration)Dynamic registration code that discovers handle_* functions (including handle_qlty_distinctCategories), derives tool name 'qlty_distinctCategories', wraps the handler, and registers it as an MCP tool if matching profile config.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}")
- Imports helper utilities used in the handler: create_response for formatting output and rows_to_json for converting query results to JSON.from teradata_mcp_server.tools.utils import create_response, rows_to_json logger = logging.getLogger("teradata_mcp_server") #------------------ Tool ------------------# # Missing Values tool def handle_qlty_missingValues(conn: TeradataConnection, database_name: str | None, table_name: str, *args, **kwargs): """ Get the column names that having missing values in a table. Arguments: database_name - name of the database table_name - table name to analyze Returns: ResponseType: formatted response with query results + metadata """ logger.debug(f"Tool: handle_qlty_missingValues: Args: table_name: {database_name}.{table_name}") if database_name is not None: table_name = f"{database_name}.{table_name}" with conn.cursor() as cur: rows = cur.execute(f"select ColumnName, NullCount, NullPercentage from TD_ColumnSummary ( on {table_name} as InputTable using TargetColumns ('[:]')) as dt ORDER BY NullCount desc") data = rows_to_json(cur.description, rows.fetchall()) metadata = { "tool_name": "qlty_missingValues", "database_name": database_name, "table_name": table_name, "rows": len(data) }