Skip to main content
Glama
iskakaushik

ClickHouse MCP Server

by iskakaushik

run_select_query

Execute SQL SELECT queries on ClickHouse MCP Server to retrieve and analyze data. Simplify database interactions by directly querying structured information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes

Implementation Reference

  • The main handler function for the 'run_select_query' MCP tool. It executes the provided SELECT query on a ClickHouse database using a readonly setting, formats the result rows into a list of dictionaries with column names as keys, logs the operation, and returns an error message if the query fails.
    @mcp.tool()
    def run_select_query(query: str):
        logger.info(f"Executing SELECT query: {query}")
        client = create_clickhouse_client()
        try:
            res = client.query(query, settings={"readonly": 1})
            column_names = res.column_names
            rows = []
            for row in res.result_rows:
                row_dict = {}
                for i, col_name in enumerate(column_names):
                    row_dict[col_name] = row[i]
                rows.append(row_dict)
            logger.info(f"Query returned {len(rows)} rows")
            return rows
        except Exception as err:
            logger.error(f"Error executing query: {err}")
            return f"error running query: {err}"
  • Helper function used by 'run_select_query' (and other tools) to create a ClickHouse client connection based on 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"),
        )
  • Initialization of the FastMCP server instance where tools like 'run_select_query' are registered via decorators.
    mcp = FastMCP(MCP_SERVER_NAME, dependencies=deps)
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