Skip to main content
Glama
iskakaushik

ClickHouse MCP Server

by iskakaushik

list_tables

Retrieve a list of tables from a specified database in ClickHouse, optionally filtered by a pattern, to simplify database exploration and management.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYes
likeNo

Implementation Reference

  • The handler function for the 'list_tables' tool, registered via @mcp.tool(). It executes SHOW TABLES, enriches results with DESCRIBE TABLE and SHOW CREATE TABLE for each table, returning structured data including database, name, columns, and create query.
    @mcp.tool()
    def list_tables(database: str, like: str = None):
        logger.info(f"Listing tables in database '{database}'")
        client = create_clickhouse_client()
        query = f"SHOW TABLES FROM {database}"
        if like:
            query += f" LIKE '{like}'"
        result = client.command(query)
    
        def get_table_info(table):
            logger.info(f"Getting schema info for table {database}.{table}")
            schema_query = f"DESCRIBE TABLE {database}.`{table}`"
            schema_result = client.query(schema_query)
    
            columns = []
            column_names = schema_result.column_names
            for row in schema_result.result_rows:
                column_dict = {}
                for i, col_name in enumerate(column_names):
                    column_dict[col_name] = row[i]
                columns.append(column_dict)
    
            create_table_query = f"SHOW CREATE TABLE {database}.`{table}`"
            create_table_result = client.command(create_table_query)
    
            return {
                "database": database,
                "name": table,
                "columns": columns,
                "create_table_query": create_table_result,
            }
    
        tables = []
        if isinstance(result, str):
            # Single table result
            for table in (t.strip() for t in result.split()):
                if table:
                    tables.append(get_table_info(table))
        elif isinstance(result, Sequence):
            # Multiple table results
            for table in result:
                tables.append(get_table_info(table))
    
        logger.info(f"Found {len(tables)} tables")
        return tables
  • Helper function used by list_tables (and other tools) to establish a ClickHouse client connection from environment variables.
    def create_clickhouse_client():
        host = os.getenv("CLICKHOUSE_HOST")
        port = os.getenv("CLICKHOUSE_PORT")
        username = os.getenv("CLICKHOUSE_USER")
        logger.info(f"Creating ClickHouse client connection to {host}:{port} as {username}")
        return clickhouse_connect.get_client(
            host=host,
            port=port,
            username=username,
            password=os.getenv("CLICKHOUSE_PASSWORD"),
        )
  • The @mcp.tool() decorator registers the list_tables function with the FastMCP server.
    @mcp.tool()
Behavior1/5

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

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

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

Completeness1/5

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

Tool has no description.

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

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

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

Related 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/iskakaushik/mcp-clickhouse'

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