Skip to main content
Glama
bpamiri

CockroachDB MCP Server

by bpamiri

switch_database

Change the active database context in CockroachDB to execute queries against a different database. Specify the target database name to switch your session's focus.

Instructions

Switch the active database context.

Args:
    database_name: Database to switch to.

Returns:
    Switch status.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
database_nameYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool handler and registration for 'switch_database'. Decorated with @mcp.tool() and delegates execution to connection_manager.switch_database.
    @mcp.tool()
    async def switch_database(database_name: str) -> dict[str, Any]:
        """Switch the active database context.
    
        Args:
            database_name: Database to switch to.
    
        Returns:
            Switch status.
        """
        try:
            return await connection_manager.switch_database(database_name)
        except Exception as e:
            return {"status": "error", "error": str(e)}
  • Implementation of the switch_database method in ConnectionManager class, which handles reconnecting to the specified database.
    async def switch_database(self, database: str) -> dict[str, Any]:
        """Switch to a different database.
    
        Args:
            database: Database name to switch to.
    
        Returns:
            Switch status.
        """
        # Check if database is blocked
        if database in settings.blocked_databases_list:
            return {"status": "error", "error": f"Database '{database}' is blocked"}
    
        async with self._lock:
            if self._state.connection is not None:
                try:
                    await self._state.connection.close()
                except Exception:
                    pass
    
            # Reconnect with new database
            old_database = settings.database
            # Temporarily modify settings for reconnection
            # Note: This is a workaround; in production, use a new connection
            self._state = ConnectionState()
    
        # Create new connection to the target database
        conn_params: dict[str, Any] = {
            "host": settings.host,
            "port": settings.port,
            "user": settings.user,
            "dbname": database,
            "row_factory": dict_row,
            "autocommit": True,
        }
    
        if settings.password:
            conn_params["password"] = settings.password
    
        if settings.sslmode != "disable":
            conn_params["sslmode"] = settings.sslmode
            if settings.sslrootcert:
                conn_params["sslrootcert"] = settings.sslrootcert
    
        if settings.cluster:
            conn_params["options"] = f"--cluster={settings.cluster}"
    
        try:
            conn = await asyncio.wait_for(
                psycopg.AsyncConnection.connect(**conn_params),
                timeout=settings.timeout,
            )
    
            async with self._lock:
                self._state.connection = conn
                self._state.connected_at = datetime.now()
                self._state.database = database
                self._state.in_transaction = False
    
            return {
                "status": "switched",
                "previous_database": old_database,
                "current_database": database,
            }
        except Exception as e:
            return {"status": "error", "error": str(e)}
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the action ('Switch') but lacks critical details: whether this requires specific permissions, if it affects ongoing transactions/queries, what happens on failure, or any side effects. This is inadequate for a mutation tool with zero annotation coverage.

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 highly concise and well-structured: a clear purpose statement followed by brief, labeled sections for Args and Returns. Every sentence earns its place with no wasted words, making it easy to parse quickly.

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

Completeness3/5

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

Given the tool's moderate complexity (a mutation with one parameter) and the presence of an output schema (which covers return values), the description is minimally adequate. However, it lacks behavioral context (e.g., error conditions, side effects) and usage guidelines, leaving gaps that reduce completeness.

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

Parameters4/5

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

The description adds meaningful context for the single parameter by explaining that 'database_name' is the 'Database to switch to', which clarifies its role beyond the schema's basic type/requirement. With 0% schema description coverage, this compensates well, though it doesn't specify format constraints (e.g., case sensitivity).

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

Purpose4/5

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

The description clearly states the tool's purpose with a specific verb ('Switch') and resource ('active database context'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from sibling tools like 'connect' or 'list_databases', which prevents a perfect score.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an existing connection), exclusions, or relationships with siblings like 'connect' or 'list_databases', leaving usage context unclear.

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/bpamiri/cockroachdb-mcp'

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