Skip to main content
Glama
ydb-platform

YDB MCP

Official
by ydb-platform

ydb_query_with_params

Execute parameterized SQL queries with JSON parameters to interact with YDB databases through the MCP server, enabling secure and structured database operations.

Instructions

Run a parameterized SQL query with JSON parameters

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sqlYes
paramsYes

Implementation Reference

  • Primary handler function that implements the core logic for the 'ydb_query_with_params' tool. Parses the JSON params string and executes the query using the shared query method.
    async def query_with_params(self, sql: str, params: str) -> List[TextContent]:
        """Run a parameterized SQL query with JSON parameters.
    
        Args:
            sql: SQL query to execute
            params: Parameters as a JSON string
    
        Returns:
            Query results as a list of TextContent objects or a dictionary
        """
        # Handle authentication errors
        if self.auth_error:
            logger.error(f"Authentication error: {self.auth_error}")
            safe_error = self._stringify_dict_keys({"error": f"Authentication error: {self.auth_error}"})
            return [TextContent(type="text", text=json.dumps(safe_error, indent=2))]
        try:
            ydb_params = self._parse_str_to_ydb_params(params)
    
            return await self.query(sql, ydb_params)
        except json.JSONDecodeError as e:
            logger.error(f"Error parsing JSON parameters: {str(e)}")
            safe_error = self._stringify_dict_keys({"error": f"Error parsing JSON parameters: {str(e)}"})
            return [TextContent(type="text", text=json.dumps(safe_error, indent=2))]
        except Exception as e:
            error_message = f"Error executing parameterized query: {str(e)}"
            logger.error(error_message)
            safe_error = self._stringify_dict_keys({"error": error_message})
            return [TextContent(type="text", text=json.dumps(safe_error, indent=2))]
  • Tool specification in the register_tools method, defining name, description, handler reference, and parameters schema. This spec is used to register the tool with both FastMCP.add_tool and ToolManager.register_tool.
    {
        "name": "ydb_query_with_params",
        "description": "Run a parameterized SQL query with JSON parameters",
        "handler": self.query_with_params,  # Use real handler
        "parameters": {
            "properties": {
                "sql": {"type": "string", "title": "Sql"},
                "params": {"type": "string", "title": "Params"},
            },
            "required": ["sql", "params"],
            "type": "object",
        },
    },
  • JSON schema defining the input parameters for the ydb_query_with_params tool: sql (string) and params (string). Used for validation.
    "parameters": {
        "properties": {
            "sql": {"type": "string", "title": "Sql"},
            "params": {"type": "string", "title": "Params"},
        },
        "required": ["sql", "params"],
        "type": "object",
    },
  • Supporting helper function called by the handler to parse the input params JSON string into a YDB-compatible parameters dictionary, handling typed parameters.
    def _parse_str_to_ydb_params(self, params: str) -> Dict:
        parsed_params = {}
        if params and params.strip():
            parsed_params = json.loads(params)
    
        # Convert [value, type] to YDB type if needed
        ydb_params = {}
        for key, value in parsed_params.items():
            param_key = key if key.startswith("$") else f"${key}"
            if isinstance(value, (list, tuple)) and len(value) == 2:
                param_value, type_name = value
                if isinstance(type_name, str) and hasattr(ydb.PrimitiveType, type_name):
                    ydb_type = getattr(ydb.PrimitiveType, type_name)
                    ydb_params[param_key] = (param_value, ydb_type)
                else:
                    ydb_params[param_key] = param_value
            else:
                ydb_params[param_key] = value
    
        return ydb_params
  • Dispatch code in the call_tool method that specifically routes requests for this tool to the query_with_params handler.
    elif tool_name == "ydb_query_with_params" and "sql" in params and "params" in params:
        result = await self.query_with_params(sql=params["sql"], params=params["params"])
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 states the tool runs queries but doesn't disclose behavioral traits such as whether it's read-only or mutative, authentication needs, rate limits, error handling, or what happens with invalid SQL/params. This is a significant gap for a query execution tool.

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, efficient sentence with zero waste. It's appropriately sized and front-loaded, directly stating the tool's purpose without unnecessary elaboration.

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 no annotations, 0% schema coverage, and no output schema, the description is incomplete. It lacks details on query behavior, parameter formats, return values, and usage context. For a tool that executes SQL with parameters, this leaves critical gaps for an AI agent.

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 description coverage is 0%, so the description must compensate. It mentions 'JSON parameters' for the 'params' field, adding some meaning beyond the schema's generic 'string' type. However, it doesn't explain the 'sql' parameter format (e.g., YQL dialect) or provide examples, leaving key semantics unclear.

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 action ('Run') and resource ('parameterized SQL query'), specifying it uses JSON parameters. It distinguishes from the sibling 'ydb_query' by mentioning parameterization, but doesn't explicitly contrast with 'ydb_explain_query_with_params' which likely explains rather than executes 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 alternatives like 'ydb_query' (non-parameterized) or 'ydb_explain_query_with_params' (explanation). The description implies parameterized queries but doesn't specify scenarios or prerequisites for usage.

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