mastra-ai/mastra · error

CursorSDKAgent does not support structuredOutput because the

Error message

CursorSDKAgent does not support structuredOutput because the Cursor TypeScript SDK does not expose a schema-constrained output API.

What it means

assertStructuredOutputUnsupported is called by generate, stream, resumeGenerate, and resumeStream on CursorSDKAgent. If options.structuredOutput contains a 'schema' key it throws, because the Cursor TypeScript SDK has no schema-constrained output API, so structured output cannot be honored.

Source

Thrown at agent-sdks/cursor/src/index.ts:303

  }
}

function validateCursorResumeData(resumeData: CursorSDKAgentResumeData): CursorSDKAgentResumeData {
  if (!toRecord(resumeData) || !('message' in resumeData)) {
    throw new Error('CursorSDKAgent resumeData must include a message.');
  }

  if (resumeData.agentId !== undefined && typeof resumeData.agentId !== 'string') {
    throw new Error('CursorSDKAgent resumeData.agentId must be a string when provided.');
  }

  return resumeData;
}

function assertStructuredOutputUnsupported(options?: unknown): void {
  const structuredOutput = toRecord(toRecord(options)?.structuredOutput);
  if (structuredOutput && 'schema' in structuredOutput) {
    throw new Error(
      'CursorSDKAgent does not support structuredOutput because the Cursor TypeScript SDK does not expose a schema-constrained output API.',
    );
  }
}

async function runCursorGenerate(
  prompt: string,
  options: CursorAgentOptions,
  agent: SDKAgent,
  telemetry: CursorToolTelemetry,
): Promise<SDKModelGenerateResult> {
  const usage = createCursorUsageCollector();
  const run = await agent.send(prompt, createCursorSendOptions(options, usage, telemetry));
  const result = await run.wait();

  if (result.status === 'error' || result.status === 'cancelled') {
    throw new Error(`Cursor run ${result.id} ended with status ${result.status}`);
  }

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Remove structuredOutput.schema from options when using CursorSDKAgent.
  2. Get plain text and parse/validate it yourself with your schema (e.g. zod parse) as a post-processing step.
  3. Use a different SDK agent (Claude/OpenAI) if schema-constrained output is a hard requirement.
  4. Feature-detect per-agent: only pass structuredOutput for agents that support it.

Example fix

// before
await cursorAgent.generate(prompt, { structuredOutput: { schema: MySchema } });
// after
const res = await cursorAgent.generate(prompt);
const output = MySchema.parse(JSON.parse(res.text));
Defensive patterns

Strategy: validation

Validate before calling

const opts = options as { structuredOutput?: { schema?: unknown } } | undefined;
if (opts?.structuredOutput && 'schema' in opts.structuredOutput) {
  delete (opts.structuredOutput as any).schema; // Cursor agent cannot honor schemas
}
await cursorAgent.generate(prompt, opts);

Type guard

function supportsStructuredOutput(agent: unknown): boolean {
  return !(agent instanceof CursorSDKAgent);
}

Try / catch

try {
  return await cursorAgent.generate(prompt, options);
} catch (e) {
  if (e instanceof Error && e.message.includes('does not support structuredOutput')) {
    const res = await cursorAgent.generate(prompt, { ...options, structuredOutput: undefined });
    return Schema.parse(JSON.parse(res.text)); // validate manually
  }
  throw e;
}

Prevention

When it happens

Trigger: agent.generate(prompt, { structuredOutput: { schema: zodSchema } }) (or stream/resume* equivalents) — any call passing structuredOutput.schema to a CursorSDKAgent.

Common situations: Sharing a generate call helper across Claude/OpenAI/Cursor agents where structuredOutput is set unconditionally; porting code from an SDK that supports schemas; expecting parity in the agent-sdks packages' feature sets.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/06c4e18db66e1bc2. Report an issue: GitHub.