Skip to main content
Glama
Teradata

Teradata MCP Server

Official
by Teradata

base_tablePreview

Preview sample data and structure from Teradata database tables or views to understand content before querying.

Instructions

This function returns data sample and inferred structure from a database table or view via SQLAlchemy, bind parameters if provided (prepared SQL), and return the fully rendered SQL (with literals) in metadata.

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

Returns: ResponseType: formatted response with query results + metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_nameYes
database_nameNo

Implementation Reference

  • The core handler function for the 'base_tablePreview' tool. It executes a 'SELECT TOP 5 * FROM table' query to preview table data, extracts column metadata, converts rows to JSON, and returns a formatted response with sample data and metadata.
    def handle_base_tablePreview(conn: TeradataConnection, table_name: str, database_name: str | None = None, *args, **kwargs):
        """
        This function returns data sample and inferred structure from a database table or view via SQLAlchemy, bind parameters if provided (prepared SQL), and return the fully rendered SQL (with literals) in metadata.
    
        Arguments:
          table_name - table or view name
          database_name - Database name
    
        Returns:
          ResponseType: formatted response with query results + metadata
        """
        logger.debug(f"Tool: handle_base_tablePreview: Args: tablename: {table_name}, databasename: {database_name}")
    
        if database_name is not None:
            table_name = f"{database_name}.{table_name}"
        with conn.cursor() as cur:
            cur.execute(f'select top 5 * from {table_name}')
            columns = cur.description
            sample = rows_to_json(cur.description, cur.fetchall())
    
            metadata = {
                "tool_name": "base_tablePreview",
                "database": database_name,
                "table_name": table_name,
                "columns": [
                    {
                        "name": c[0],
                        "type": c[1].__name__ if hasattr(c[1], '__name__') else str(c[1]),
                        "length": c[3]
                    }
                    for c in columns
                ],
                "sample_size": len(sample)
            }
            logger.debug(f"Tool: handle_base_tablePreview: metadata: {metadata}")
            return create_response(sample, metadata)
  • Dynamic registration of all 'handle_*' functions as MCP tools. Converts 'handle_base_tablePreview' to tool name 'base_tablePreview' and registers it with FastMCP using a wrapper that handles DB connection injection and QueryBand setting.
    # Register code tools via module loader
    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
            # Skip chat completion tools if chat completion functionality is disabled
            if tool_name.startswith("chat_") and not enableChat:
                logger.info(f"Skipping chat completion tool: {tool_name} (chat completion 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__}")
    else:

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/Teradata/teradata-mcp-server'

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