Skip to main content
Glama
ydb-platform

YDB MCP

Official
by ydb-platform

ydb_explain_query_with_params

Explains parameterized SQL queries against YDB by providing the SQL and parameters, returning the execution plan.

Instructions

Explain a parameterized SQL query against YDB

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYes
paramsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The ydb_explain_query_with_params handler function: takes sql and params, parses params via _parse_params_str, calls server.explain(sql, params), serializes the result, and returns TextContent. Wraps in try/except to return error JSON on failure.
    async def ydb_explain_query_with_params(sql: str, params: str | dict) -> list[TextContent]:
        """Explain a parameterized SQL query against YDB."""
        try:
            result = await server.explain(sql, _parse_params_str(params))
            return [TextContent(type="text", text=serialize_ydb_response(result))]
        except Exception as e:
            return [TextContent(type="text", text=json.dumps({"error": str(e)}, indent=2))]
  • The YDBGenericTool enum defines EXPLAIN_WITH_PARAMS = 'ydb_explain_query_with_params' as the tool name string.
    class YDBGenericTool(str, Enum):
        """Names of the built-in generic YDB tools."""
    
        QUERY = "ydb_query"
        QUERY_WITH_PARAMS = "ydb_query_with_params"
        EXPLAIN = "ydb_explain_query"
        EXPLAIN_WITH_PARAMS = "ydb_explain_query_with_params"
        STATUS = "ydb_status"
        LIST_DIRECTORY = "ydb_list_directory"
        DESCRIBE_PATH = "ydb_describe_path"
  • The registration loop in register_generic_tools maps YDBGenericTool.EXPLAIN_WITH_PARAMS to the ydb_explain_query_with_params handler with description, then calls server.add_tool() if the tool is in the enabled set.
    for tool, fn, description in [
        (YDBGenericTool.QUERY, ydb_query, "Run a SQL query against YDB database"),
        (YDBGenericTool.QUERY_WITH_PARAMS, ydb_query_with_params, "Run a parameterized SQL query with JSON parameters"),
        (YDBGenericTool.EXPLAIN, ydb_explain_query, "Explain a SQL query against YDB"),
        (YDBGenericTool.EXPLAIN_WITH_PARAMS, ydb_explain_query_with_params,
         "Explain a parameterized SQL query against YDB"),
        (YDBGenericTool.STATUS, ydb_status, "Get the current YDB connection status"),
        (YDBGenericTool.LIST_DIRECTORY, ydb_list_directory, "List directory contents in YDB"),
        (YDBGenericTool.DESCRIBE_PATH, ydb_describe_path, "Get detailed information about a YDB path"),
    ]:
        if tool in enabled:
            server.add_tool(fn, name=tool.value, description=description)  # type: ignore[arg-type]
  • The server.explain() method called by the handler: ensures connection, builds YDB params via _build_ydb_params, calls self._pool.explain_with_retries() with query, parameters, and result_format=ydb.QueryExplainResultFormat.DICT, then stringifies keys for JSON.
    async def explain(self, sql: str, params: dict | None = None) -> dict:
        """Explain a SQL query and return the execution plan as a dict."""
        await self._ensure_connected()
        assert self._pool is not None
        ydb_params = _build_ydb_params(params) if params else None
        plan = await self._pool.explain_with_retries(
            query=sql,
            parameters=ydb_params,
            result_format=ydb.QueryExplainResultFormat.DICT,
        )
        return dict(_stringify_keys(plan))
  • The _parse_params_str helper used by the handler to parse parameters from JSON string or dict into normalized YDB params.
    def _parse_params_str(params_str: str | dict) -> dict:
        """Parse a JSON params string (or dict) and normalize it for YDB."""
        if not params_str:
            return {}
        if isinstance(params_str, dict):
            return _build_ydb_params(params_str)
        if not params_str.strip():
            return {}
        return _build_ydb_params(json.loads(params_str))
Behavior2/5

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

No annotations are provided, so the description must carry the full burden. It states 'Explain', implying a read-only operation, but does not disclose any behavioral traits such as side effects, permissions, rate limits, or output format beyond what is in the schema.

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

Conciseness3/5

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

The description is a single sentence with no extraneous words. However, it is too brief and could include more essential information without being verbose. It is concise but at the expense of completeness.

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 absence of annotations and only 2 parameters, the description is insufficiently complete. It does not mention that both parameters are required, or provide context on how to supply parameters. An output schema exists but is not referenced.

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

Parameters2/5

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

Schema has 0% description coverage. The description does not explain the format or meaning of the 'params' parameter, which accepts a string or object. This lack of semantic guidance increases ambiguity for the AI agent.

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?

Description uses verb 'Explain' and specifies resource 'parameterized SQL query against YDB', which clearly indicates the tool's action and target. However, it does not differentiate from sibling tool 'ydb_explain_query' which likely does the same without parameters.

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 vs ydb_explain_query or other siblings. The description implies it is for queries with parameters but does not explicitly state when it should be preferred.

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/ydb-platform/ydb-mcp'

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