eyaltoledano/claude-task-master · error · MCPError

Schema is required for object generation

Error message

Schema is required for object generation

What it means

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.

Source

Thrown at mcp-server/src/custom-sdk/language-model.js:109

			throw mapMCPError(error);
		}
	}

	/**
	 * Generate structured object using MCP session sampling
	 * @param {object} options - Generation options
	 * @param {Array} options.prompt - AI SDK prompt format
	 * @param {import('zod').ZodSchema} options.schema - Zod schema for validation
	 * @param {string} [options.mode='json'] - Generation mode ('json' or 'tool')
	 * @param {AbortSignal} options.abortSignal - Abort signal
	 * @returns {Promise<object>} Generation result with structured object
	 */
	async doGenerateObject(options) {
		try {
			const { schema, mode = 'json', ...restOptions } = options;

			if (!schema) {
				throw new MCPError('Schema is required for object generation');
			}

			// Convert schema to JSON instructions
			const objectName = restOptions.objectName || 'generated_object';
			const jsonInstructions = convertSchemaToInstructions(schema, objectName);

			// Enhance prompt with JSON generation instructions
			const enhancedPrompt = enhancePromptForJSON(
				options.prompt,
				jsonInstructions
			);

			// Convert enhanced prompt to MCP format
			const { messages, systemPrompt } = convertToMCPFormat(enhancedPrompt);

			// Use MCP session.requestSampling with enhanced prompt
			const response = await this.session.requestSampling(
				{

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Pass a schema in options: doGenerateObject({ schema: myZodSchema, prompt })
  2. If no structure is needed, call generateText/doGenerate instead of the object path
  3. Validate at the call site that the schema variable is defined before invoking

Example fix

// before
await model.doGenerateObject({ prompt: 'Get user' });
// after
await model.doGenerateObject({ schema: z.object({ name: z.string() }), prompt: 'Get user' });
Defensive patterns

Strategy: validation

Validate before calling

if (!options || !options.schema) {
  throw new Error('doGenerateObject requires a schema');
}

Type guard

function hasSchema(options) {
  return typeof options === 'object' && options !== null && options.schema != null;
}

Try / catch

try { await model.doGenerateObject(opts); } catch (e) {
  if (e.message === 'Schema is required for object generation') {
    // fall back to generateText or add schema and retry
  } else throw e;
}

Prevention

When it happens

Trigger: Calling generateObject via the MCP language model without options.schema, or with schema explicitly undefined (e.g. spread that drops the key).

Common situations: Dynamic option construction where schema conditionally omitted; switching from generateText to generateObject and forgetting to add the schema; TS types bypassed with `any`.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/871877af45a30bed. Report an issue: GitHub.