{"record":{"id":"bc4a2e019864d8f5","repo":"mastra-ai/mastra","slug":"missing-required-argument-arg-name","errorCode":null,"errorMessage":"Missing required argument: ${arg.name}","messagePattern":"Missing required argument: (.+?)","errorType":"validation","errorClass":"ProtocolError","httpStatus":null,"severity":"error","filePath":"packages/mcp/src/server/server.ts","lineNumber":1449,"sourceCode":"      serverInstance.setRequestHandler(\n        'prompts/get',\n        async (request: { params: { name: string; arguments?: any } }, ctx) => {\n          const startTime = Date.now();\n          const { name, arguments: args } = request.params;\n          const extra = toMCPRequestHandlerExtra(ctx);\n          const prompts = await capturedPromptOptions.listPrompts?.({ extra });\n          if (!prompts) throw new Error('Failed to load prompts');\n          for (const definedPrompt of prompts) {\n            PromptSchema.parse(definedPrompt);\n          }\n          // Select prompt by name\n          const prompt = prompts.find(p => p.name === name);\n          if (!prompt) throw new Error(`Prompt \"${name}\" not found`);\n          // Validate required arguments\n          if (prompt.arguments) {\n            for (const arg of prompt.arguments) {\n              if (arg.required && (args?.[arg.name] === undefined || args?.[arg.name] === null)) {\n                throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Missing required argument: ${arg.name}`);\n              }\n            }\n          }\n          try {\n            let messages: any[] = [];\n            if (capturedPromptOptions.getPromptMessages) {\n              messages = await capturedPromptOptions.getPromptMessages({\n                name,\n                version: prompt.version,\n                args,\n                extra,\n              });\n            }\n            const duration = Date.now() - startTime;\n            this.logger.info('Prompt retrieved successfully', { prompt: name, duration });\n            return { description: prompt.description, messages };\n          } catch (error) {\n            const duration = Date.now() - startTime;","sourceCodeStart":1431,"sourceCodeEnd":1467,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/mcp/src/server/server.ts#L1431-L1467","documentation":"After finding the requested prompt, MCPServer validates each prompt argument declared `required: true` in the prompt's `arguments` definition. This MCP ProtocolError (InvalidParams, -32602) is thrown when the caller omits that argument or passes null/undefined. It mirrors JSON-RPC invalid-params semantics for prompt invocation.","triggerScenarios":"Calling server.getPrompt(name, args) where a prompt argument marked required: true is missing from args, explicitly null, or explicitly undefined; sending a prompts/get JSON-RPC request whose arguments object lacks a required field.","commonSituations":"Client UI renders only optional fields; args object built from optional form fields where empty values become undefined; key-name mismatch (e.g. 'fileName' vs 'file_name') so the required key is absent; passing an empty object when the prompt requires arguments.","solutions":["Inspect the prompt's `arguments` definition (from prompts/list) and supply every argument with required: true","Ensure the key names match the argument `name` fields exactly","Convert empty/null form values to the expected strings before calling, or prompt the user for the missing value","If you own the prompt definition and the argument should be optional, set required: false"],"exampleFix":"// before\nawait server.getPrompt('code_review', {});\n// after\nawait server.getPrompt('code_review', { file: 'src/index.ts' }); // all required args present","handlingStrategy":"validation","validationCode":"function validatePromptArgs(promptDef, args = {}) {\n  const missing = (promptDef.arguments ?? [])\n    .filter(a => a.required && (args[a.name] === undefined || args[a.name] === null))\n    .map(a => a.name);\n  if (missing.length) throw new Error(`Missing required prompt arguments: ${missing.join(', ')}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const result = await server.getPrompt(name, args);\n} catch (e) {\n  if (e instanceof ProtocolError && e.code === -32602) {\n    // surface which argument is missing: parse e.message 'Missing required argument: X'\n  } else throw e;\n}","preventionTips":["Fetch the prompt's arguments definition and render required fields as mandatory in your UI","Never pass null/undefined for unfilled optional form fields — omit the key entirely","Match argument keys exactly to the `name` fields in the prompt definition"],"tags":["mcp","invalid-params","missing-argument","validation"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}