Skip to main content
Glama
burakdirin

clickhouse-mcp-server

connect_database

Connect to a specified ClickHouse database for executing queries.

Instructions

Connect to a specific ClickHouse database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYes

Implementation Reference

  • The main handler function for the 'connect_database' tool. It uses the MCP tool decorator (@mcp.tool()), takes a database name and context, executes a USE statement via QueryExecutor, and returns the result as JSON.
    def connect_database(database: str, ctx: Context) -> str:
        """Connect to a specific ClickHouse database"""
        try:
            executor = _get_executor(ctx)
            result = executor.execute_single_query(f"USE {database}")
            return json.dumps(result, indent=2)
        except (ConnectionError, QueryError) as e:
            return str(e)
  • The tool is registered with the FastMCP server via the @mcp.tool() decorator on the connect_database function.
    @mcp.tool()
    def connect_database(database: str, ctx: Context) -> str:
  • Helper function _get_executor creates the QueryExecutor from the MCP context's lifespan context (ClickHouseContext).
    def _get_executor(ctx: Context) -> QueryExecutor:
        """Helper function to get QueryExecutor from context"""
        clickhouse_ctx = ctx.request_context.lifespan_context
        return QueryExecutor(clickhouse_ctx)
  • The execute_single_query method of QueryExecutor handles USE statements by switching the database context and executing the USE command on the ClickHouse client.
    def execute_single_query(self, query: str) -> Dict[str, Any]:
        """Execute a single query and return results"""
        self.context.ensure_connected()
    
        try:
            # Handle USE statements
            if self._is_use_statement(query):
                db_name = query.strip().split()[-1].strip('`').strip()
                self.context.database = db_name
                self.context.client.execute(f'USE {db_name}')
                return {"message": f"Switched to database: {db_name}"}
  • The function signature defines the schema: takes a string 'database' parameter and returns a string.
    def connect_database(database: str, ctx: Context) -> str:
        """Connect to a specific ClickHouse database"""
Behavior2/5

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

No annotations are provided, so the description carries full burden. It only says 'Connect', omitting details about side effects, authentication requirements, or state changes (e.g., establishing a session).

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

Conciseness5/5

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

The description is a single, clear sentence with no unnecessary words. It is effectively concise.

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

Completeness2/5

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

Given the tool's role as a connection setter, the description lacks information on prerequisites, return values, or how it interacts with 'execute_query'. It is incomplete for operational context.

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?

Schema coverage is 0% and the description adds no additional meaning beyond the parameter name 'database'. It does not explain valid values or expected format.

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

Purpose5/5

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

The description clearly states 'Connect to a specific ClickHouse database', using a specific verb and resource. It effectively distinguishes from the sibling tool 'execute_query' which presumably runs queries.

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

Usage Guidelines2/5

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

No guidance on when to use this tool versus the sibling 'execute_query' or any prerequisites. The description merely states functionality without usage context.

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

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/burakdirin/clickhouse-mcp-server'

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