Skip to main content
Glama

mcp_validate

Validate parameters for read or write operations to check if calls will succeed before execution, returning validation results and estimated token counts.

Instructions

Validate parameters for mcp_read or mcp_write without executing.

Use to check if a call will succeed before making it.

Parameters:

  • tool (required): "read" | "write"

  • params (required): Parameters object to validate

Returns:

  • valid: true/false

  • errors: List of error codes and messages

  • warnings: List of warnings

  • estimated_tokens: Estimated response token count

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toolYesTool to validate
paramsYesParameters to validate

Implementation Reference

  • Core handler function for the mcp_validate tool. Validates input parameters for mcp_read or mcp_write tools, collects errors and warnings, estimates token count, and returns a formatted validation result.
    async def mcp_validate( tool: str, params: dict, ) -> str: """ Validate parameters for mcp_read or mcp_write without executing. Returns validation result with errors and warnings. """ errors: list[str] = [] warnings: list[str] = [] if tool == "read": errors, warnings = await _validate_read(params) elif tool == "write": errors, warnings = await _validate_write(params) else: errors.append(f"INVALID_TOOL: Unknown tool '{tool}'. Valid: read, write") if errors: return f"valid:false|errors:[{'; '.join(errors)}]" warning_str = f"|warnings:[{'; '.join(warnings)}]" if warnings else "" estimated_tokens = _estimate_tokens(tool, params) return f"valid:true{warning_str}|estimated_tokens:{estimated_tokens}"
  • Registers the mcp_validate tool in the MCP server's list_tools() handler, including name, description, and JSON input schema.
    Tool( name="mcp_validate", description="""Validate parameters for mcp_read or mcp_write without executing. Use to check if a call will succeed before making it. Parameters: - tool (required): "read" | "write" - params (required): Parameters object to validate Returns: - valid: true/false - errors: List of error codes and messages - warnings: List of warnings - estimated_tokens: Estimated response token count""", inputSchema={ "type": "object", "properties": { "tool": { "type": "string", "enum": ["read", "write"], "description": "Tool to validate" }, "params": { "type": "object", "description": "Parameters to validate" } }, "required": ["tool", "params"] } )
  • Dispatches tool calls to the mcp_validate handler function in the server's call_tool method.
    elif name == "mcp_validate": result = await mcp_validate(**arguments)
  • Pydantic model defining the input schema for mcp_validate tool parameters.
    class ValidateRequest(BaseModel): """Parameters for mcp_validate tool.""" tool: Literal["read", "write"] = Field(..., description="Tool to validate") params: dict = Field(..., description="Parameters to validate")
  • Helper function to validate parameters specifically for the 'read' tool.
    async def _validate_read(params: dict) -> tuple[list[str], list[str]]: """Validate mcp_read parameters.""" errors: list[str] = [] warnings: list[str] = [] mode = params.get("mode") tab = params.get("tab", "") index = params.get("index") query = params.get("query") search_in = params.get("search_in", "all") max_depth = params.get("max_depth", 2) max_items = params.get("max_items", 20) skip = params.get("skip", 0) # Validate mode valid_modes = [m.value for m in ReadMode] if not mode: errors.append("MISSING_PARAM: mode is required") elif mode not in valid_modes: errors.append(f"INVALID_MODE: '{mode}' not in {valid_modes}") # Mode-specific validation if mode == "list" or mode == "item": if not tab: errors.append(f"MISSING_PARAM: tab is required for mode={mode}") elif not await client.tab_exists(tab): errors.append(f"TAB_NOT_FOUND: {tab}") if mode == "item": if index is None: errors.append("MISSING_PARAM: index is required for mode=item") elif tab and await client.tab_exists(tab): count = await client.get_count(tab) if index < 0 or index >= count: errors.append(f"INDEX_OUT_OF_BOUNDS: {index} (count: {count})") if mode == "search": if not query: errors.append("MISSING_PARAM: query is required for mode=search") if search_in not in [s.value for s in SearchIn]: errors.append(f"INVALID_PARAM: search_in '{search_in}' invalid") # Validate numeric params if max_depth < 1 or max_depth > 10: warnings.append(f"max_depth={max_depth} clamped to 1-10") if max_items < 1 or max_items > 100: warnings.append(f"max_items={max_items} clamped to 1-100") if skip < 0: errors.append("INVALID_PARAM: skip must be >= 0") return errors, warnings
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/list91/mcp-copyq'

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