{"record":{"id":"871877af45a30bed","repo":"eyaltoledano/claude-task-master","slug":"schema-is-required-for-object-generation","errorCode":null,"errorMessage":"Schema is required for object generation","messagePattern":"Schema is required for object generation","errorType":"validation","errorClass":"MCPError","httpStatus":null,"severity":"error","filePath":"mcp-server/src/custom-sdk/language-model.js","lineNumber":109,"sourceCode":"\t\t\tthrow mapMCPError(error);\n\t\t}\n\t}\n\n\t/**\n\t * Generate structured object using MCP session sampling\n\t * @param {object} options - Generation options\n\t * @param {Array} options.prompt - AI SDK prompt format\n\t * @param {import('zod').ZodSchema} options.schema - Zod schema for validation\n\t * @param {string} [options.mode='json'] - Generation mode ('json' or 'tool')\n\t * @param {AbortSignal} options.abortSignal - Abort signal\n\t * @returns {Promise<object>} Generation result with structured object\n\t */\n\tasync doGenerateObject(options) {\n\t\ttry {\n\t\t\tconst { schema, mode = 'json', ...restOptions } = options;\n\n\t\t\tif (!schema) {\n\t\t\t\tthrow new MCPError('Schema is required for object generation');\n\t\t\t}\n\n\t\t\t// Convert schema to JSON instructions\n\t\t\tconst objectName = restOptions.objectName || 'generated_object';\n\t\t\tconst jsonInstructions = convertSchemaToInstructions(schema, objectName);\n\n\t\t\t// Enhance prompt with JSON generation instructions\n\t\t\tconst enhancedPrompt = enhancePromptForJSON(\n\t\t\t\toptions.prompt,\n\t\t\t\tjsonInstructions\n\t\t\t);\n\n\t\t\t// Convert enhanced prompt to MCP format\n\t\t\tconst { messages, systemPrompt } = convertToMCPFormat(enhancedPrompt);\n\n\t\t\t// Use MCP session.requestSampling with enhanced prompt\n\t\t\tconst response = await this.session.requestSampling(\n\t\t\t\t{","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/mcp-server/src/custom-sdk/language-model.js#L91-L127","documentation":"doGenerateObject generates a structured object and validates it against a schema; without a schema there is nothing to build JSON instructions from or validate against, so it throws MCPError immediately. A schema (Zod or JSON-schema-like) is mandatory for the object-generation code path.","triggerScenarios":"Calling generateObject via the MCP language model without options.schema, or with schema explicitly undefined (e.g. spread that drops the key).","commonSituations":"Dynamic option construction where schema conditionally omitted; switching from generateText to generateObject and forgetting to add the schema; TS types bypassed with `any`.","solutions":["Pass a schema in options: doGenerateObject({ schema: myZodSchema, prompt })","If no structure is needed, call generateText/doGenerate instead of the object path","Validate at the call site that the schema variable is defined before invoking"],"exampleFix":"// before\nawait model.doGenerateObject({ prompt: 'Get user' });\n// after\nawait model.doGenerateObject({ schema: z.object({ name: z.string() }), prompt: 'Get user' });","handlingStrategy":"validation","validationCode":"if (!options || !options.schema) {\n  throw new Error('doGenerateObject requires a schema');\n}","typeGuard":"function hasSchema(options) {\n  return typeof options === 'object' && options !== null && options.schema != null;\n}","tryCatchPattern":"try { await model.doGenerateObject(opts); } catch (e) {\n  if (e.message === 'Schema is required for object generation') {\n    // fall back to generateText or add schema and retry\n  } else throw e;\n}","preventionTips":["Type options with a required schema field (TypeScript) so omission fails at compile time","Build options objects via helpers that always attach a schema","Use generateText when no structured output is needed"],"tags":["mcp","ai-sdk","schema","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}