{"record":{"id":"aa90de3537fd0085","repo":"yikart/AiToEarn","slug":"invalidparams","errorCode":"InvalidParams","errorMessage":"Invalid parameters: ${validation.error.message}","messagePattern":"Invalid parameters: (.+?)","errorType":"error_code","errorClass":"McpError","httpStatus":null,"severity":"error","filePath":"project/aitoearn-backend/libs/nest-mcp/src/services/handlers/mcp-tools.handler.ts","lineNumber":134,"sourceCode":"          this.mcpModuleId,\n          request.params.name,\n        )\n\n        if (!toolInfo) {\n          throw new McpError(\n            ErrorCode.MethodNotFound,\n            `Unknown tool: ${request.params.name}`,\n          )\n        }\n\n        try {\n          // Validate input parameters against the tool's schema\n          if (toolInfo.metadata.parameters) {\n            const validation = toolInfo.metadata.parameters.safeParse(\n              request.params.arguments || {},\n            )\n            if (!validation.success) {\n              throw new McpError(\n                ErrorCode.InvalidParams,\n                `Invalid parameters: ${validation.error.message}`,\n              )\n            }\n            // Use validated arguments to ensure defaults and transformations are applied\n            request.params.arguments = validation.data\n          }\n\n          const contextId = ContextIdFactory.getByRequest(httpRequest)\n          this.moduleRef.registerRequestByContextId(httpRequest, contextId)\n\n          const toolInstance = await this.moduleRef.resolve(\n            toolInfo.providerClass,\n            contextId,\n            { strict: false },\n          )\n\n          const context = this.createContext(mcpServer, request)","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-backend/libs/nest-mcp/src/services/handlers/mcp-tools.handler.ts#L116-L152","documentation":"Before executing a tool, the handler validates request.params.arguments against the tool's Zod parameters schema. If safeParse fails, it throws McpError InvalidParams (JSON-RPC -32602), because the arguments do not satisfy the tool's declared input contract.","triggerScenarios":"Missing required arguments, wrong argument types (string vs number), arguments passed under wrong keys, or arguments omitted entirely when required fields exist ({} is validated).","commonSituations":"Client built arguments by hand instead of from the tool's inputSchema; schema changed server-side while the client cached an older version; nested object/array arguments malformed; numbers sent as strings from LLM-generated arguments.","solutions":["Read the validation.error.message for the exact failing field and fix the arguments","Validate arguments client-side against the tool's inputSchema before calling","Refetch tools/list to get the current inputSchema after any server update","Coerce types (e.g. Number(id)) for arguments supplied as strings"],"exampleFix":"// before\nawait client.callTool({ name: 'createPost', arguments: { title: 'x' } });\n// after\nconst args = parameters.parse({ title: 'x' }); // throws with the same message early\nawait client.callTool({ name: 'createPost', arguments: args });","handlingStrategy":"validation","validationCode":"import { z } from 'zod';\nconst parsed = inputSchema.safeParse(args);\nif (!parsed.success) {\n  throw new Error(`Invalid arguments: ${parsed.error.message}`);\n}\nawait client.callTool({ name, arguments: parsed.data });","typeGuard":"function isValidArgs(args: unknown, schema: z.ZodTypeAny): args is z.infer<typeof schema> {\n  return schema.safeParse(args).success;\n}","tryCatchPattern":"try {\n  await client.callTool({ name, arguments: args });\n} catch (e) {\n  if (e.code === ErrorCode.InvalidParams) {\n    console.error('Fix arguments per tool inputSchema:', e.message);\n  }\n  throw e;\n}","preventionTips":["Validate arguments against the tool's inputSchema before calling","Refetch tools/list after server updates to catch schema changes","Coerce LLM-generated arguments to correct types (numbers, booleans)","Never send undefined/null for required fields; omit or supply real values"],"tags":["mcp","zod","invalid-params","tools"],"backgroundTag":"schema-validation-failed","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}