dba_databaseSpace
Retrieve database space allocations in Teradata by specifying a database name; if unspecified, fetch space details for all databases. Returns formatted query results with metadata.
Instructions
Get database space if database name is provided, otherwise get all databases space allocations.
Arguments: database_name - database name
Returns: ResponseType: formatted response with query results + metadata
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database_name | Yes |
Implementation Reference
- The handler function that implements the core logic of the 'dba_databaseSpace' tool. It queries the DBC.DiskSpaceV view to compute space allocated, used, free space in GB, and percent used for a specific database or all databases.def handle_dba_databaseSpace(conn: TeradataConnection, database_name: str | None | None, *args, **kwargs): """ Get database space if database name is provided, otherwise get all databases space allocations. Arguments: database_name - database name Returns: ResponseType: formatted response with query results + metadata """ logger.debug(f"Tool: handle_dba_databaseSpace: Args: database_name: {database_name}") database_name_filter = f"AND objectdatabasename = '{database_name}'" if database_name else "" with conn.cursor() as cur: if not database_name: logger.debug("No database name provided, returning all databases and space information.") rows = cur.execute(""" SELECT DatabaseName, CAST(SUM(MaxPerm)/1024/1024/1024 AS DECIMAL(10,2)) AS SpaceAllocated_GB, CAST(SUM(CurrentPerm)/1024/1024/1024 AS DECIMAL(10,2)) AS SpaceUsed_GB, CAST((SUM(MaxPerm) - SUM(CurrentPerm))/1024/1024/1024 AS DECIMAL(10,2)) AS FreeSpace_GB, CAST((SUM(CurrentPerm) * 100.0 / NULLIF(SUM(MaxPerm),0)) AS DECIMAL(10,2)) AS PercentUsed FROM DBC.DiskSpaceV WHERE MaxPerm > 0 GROUP BY 1 ORDER BY 5 DESC; """) else: logger.debug(f"Database name: {database_name}, returning space information for this database.") rows = cur.execute(f""" SELECT DatabaseName, CAST(SUM(MaxPerm)/1024/1024/1024 AS DECIMAL(10,2)) AS SpaceAllocated_GB, CAST(SUM(CurrentPerm)/1024/1024/1024 AS DECIMAL(10,2)) AS SpaceUsed_GB, CAST((SUM(MaxPerm) - SUM(CurrentPerm))/1024/1024/1024 AS DECIMAL(10,2)) AS FreeSpace_GB, CAST((SUM(CurrentPerm) * 100.0 / NULLIF(SUM(MaxPerm),0)) AS DECIMAL(10,2)) AS PercentUsed FROM DBC.DiskSpaceV WHERE MaxPerm > 0 AND DatabaseName = '{database_name}' GROUP BY 1; """) data = rows_to_json(cur.description, rows.fetchall()) metadata = { "tool_name": "dba_databaseSpace", "database_name": database_name, "total_databases": len(data) } logger.debug(f"Tool: handle_dba_databaseSpace: metadata: {metadata}") return create_response(data, metadata)
- src/teradata_mcp_server/app.py:344-364 (registration)Dynamic registration code that discovers all functions starting with 'handle_' via module loader, extracts tool name by removing 'handle_' prefix, wraps the handler for MCP compatibility (injects DB connection, sets QueryBand), and registers it as an MCP tool if it matches the profile configuration.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}") logger.debug(f"Tool Docstring: {wrapped.__doc__}")