yikart/AiToEarn · error · McpError
InvalidParams
InvalidParams
Error message
Invalid parameters: ${validation.error.message} What it means
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.
Source
Thrown at project/aitoearn-backend/libs/nest-mcp/src/services/handlers/mcp-tools.handler.ts:134
this.mcpModuleId,
request.params.name,
)
if (!toolInfo) {
throw new McpError(
ErrorCode.MethodNotFound,
`Unknown tool: ${request.params.name}`,
)
}
try {
// Validate input parameters against the tool's schema
if (toolInfo.metadata.parameters) {
const validation = toolInfo.metadata.parameters.safeParse(
request.params.arguments || {},
)
if (!validation.success) {
throw new McpError(
ErrorCode.InvalidParams,
`Invalid parameters: ${validation.error.message}`,
)
}
// Use validated arguments to ensure defaults and transformations are applied
request.params.arguments = validation.data
}
const contextId = ContextIdFactory.getByRequest(httpRequest)
this.moduleRef.registerRequestByContextId(httpRequest, contextId)
const toolInstance = await this.moduleRef.resolve(
toolInfo.providerClass,
contextId,
{ strict: false },
)
const context = this.createContext(mcpServer, request)View on GitHub (pinned to d3aa8bea5b)
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
Example fix
// before
await client.callTool({ name: 'createPost', arguments: { title: 'x' } });
// after
const args = parameters.parse({ title: 'x' }); // throws with the same message early
await client.callTool({ name: 'createPost', arguments: args }); Defensive patterns
Strategy: validation
Validate before calling
import { z } from 'zod';
const parsed = inputSchema.safeParse(args);
if (!parsed.success) {
throw new Error(`Invalid arguments: ${parsed.error.message}`);
}
await client.callTool({ name, arguments: parsed.data }); Type guard
function isValidArgs(args: unknown, schema: z.ZodTypeAny): args is z.infer<typeof schema> {
return schema.safeParse(args).success;
} Try / catch
try {
await client.callTool({ name, arguments: args });
} catch (e) {
if (e.code === ErrorCode.InvalidParams) {
console.error('Fix arguments per tool inputSchema:', e.message);
}
throw e;
} Prevention
- 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
When it happens
Trigger: Missing required arguments, wrong argument types (string vs number), arguments passed under wrong keys, or arguments omitted entirely when required fields exist ({} is validated).
Common situations: 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.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- InternalError
- MethodNotFound
- PlatformNotSupported
- Zod validation error (issues + input)
- ResponseCode.ConfigEditorValidationFailed
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/aa90de3537fd0085.
Report an issue: GitHub.