Skip to main content
Glama
bpamiri

CockroachDB MCP Server

by bpamiri

validate_query

Validate SQL queries for safety before execution to identify potential issues without running the query.

Instructions

Check if a query is safe to execute without running it.

Args:
    sql: SQL statement to validate.

Returns:
    Validation result with any issues found.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool handler for 'validate_query' that wraps and delegates to the core validation logic in the query module.
    @mcp.tool()
    async def validate_query(sql: str) -> dict[str, Any]:
        """Check if a query is safe to execute without running it.
    
        Args:
            sql: SQL statement to validate.
    
        Returns:
            Validation result with any issues found.
        """
        try:
            return await query.validate_query(sql)
        except Exception as e:
            return {"status": "error", "error": str(e)}
  • Core implementation of query validation logic, including checks for blocked commands, read-only mode compliance, query type classification, and issue reporting.
    async def validate_query(query: str) -> dict[str, Any]:
        """Validate a SQL query without executing it.
    
        Args:
            query: SQL query to validate.
    
        Returns:
            Validation result with is_valid and any issues.
        """
        issues: list[str] = []
    
        # Check for empty query
        if not query or not query.strip():
            return {
                "is_valid": False,
                "issues": ["Query is empty"],
                "query_type": None,
            }
    
        # Check for blocked commands
        is_blocked, blocked_cmd = _is_blocked_command(query)
        if is_blocked:
            issues.append(f"Blocked command: {blocked_cmd}")
    
        # Check read-only mode
        if settings.read_only and not _is_read_only_query(query):
            issues.append("Server is in read-only mode; only SELECT/SHOW/EXPLAIN allowed")
    
        # Determine query type
        query_upper = query.strip().upper()
        if query_upper.startswith("SELECT") or query_upper.startswith("WITH"):
            query_type = "SELECT"
        elif query_upper.startswith("INSERT"):
            query_type = "INSERT"
        elif query_upper.startswith("UPDATE"):
            query_type = "UPDATE"
        elif query_upper.startswith("DELETE"):
            query_type = "DELETE"
        elif query_upper.startswith("SHOW"):
            query_type = "SHOW"
        elif query_upper.startswith("EXPLAIN"):
            query_type = "EXPLAIN"
        else:
            query_type = "OTHER"
    
        return {
            "is_valid": len(issues) == 0,
            "issues": issues,
            "query_type": query_type,
            "is_read_only": _is_read_only_query(query),
        }
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes the core behavior (validation without execution) and hints at the return type ('Validation result with any issues found'), but lacks details on error handling, performance implications, or validation scope (e.g., syntax vs. permissions).

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, using three brief sentences that front-load the purpose, detail the parameter, and summarize the return value. Every sentence adds value without redundancy, making it easy for an agent to parse quickly.

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

Completeness4/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 (validation without execution), no annotations, and the presence of an output schema (implied by 'Returns'), the description is mostly complete. It covers purpose, usage, and parameter semantics, but could benefit from more behavioral details like validation limits or error cases to fully compensate for the lack of annotations.

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 'sql' by specifying it as a 'SQL statement to validate,' which clarifies its purpose beyond the schema's minimal title ('Sql'). With 0% schema description coverage and only one parameter, this compensates well, though it doesn't detail format constraints or examples.

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 the tool's purpose with a specific verb ('check') and resource ('query'), distinguishing it from siblings like execute_query or explain_query. It explicitly mentions the safety aspect ('safe to execute without running it'), which differentiates it from execution tools.

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

Usage Guidelines5/5

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

The description provides explicit usage guidance by stating 'without running it,' which clearly indicates when to use this tool (for validation) versus alternatives like execute_query (for actual execution). This helps the agent choose between validation and execution scenarios.

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