Skip to content

Commit 8042e68

Browse files
dcramerclaude
andauthored
fix(mcp-core): disable structuredOutputs for embedded agents (#655)
Add structuredOutputs: false alongside strictJsonSchema: false to fully disable OpenAI's strict mode for both tool parameter schemas and output schemas. This ensures Zod's .optional() and .nullable() work correctly in embedded agents (search_events, search_issues). Previously only strictJsonSchema: false was set, which allowed optional output fields but still enforced strict mode on tool parameter schemas. Fixes #623 Co-authored-by: Claude Code <[email protected]>
1 parent 9468bf3 commit 8042e68

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

packages/mcp-core/src/internal/agents/callEmbeddedAgent.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,24 @@ export async function callEmbeddedAgent<
4545
maxSteps: 5,
4646
temperature: 1, // GPT-5 only supports temperature of 1
4747
experimental_output: Output.object({ schema }),
48-
// Disable strict JSON schema validation to allow .optional() in Zod schemas.
49-
// When strictJsonSchema: true, OpenAI requires ALL properties to be in the "required" array,
50-
// which breaks Zod's .optional() (removes fields from "required").
51-
// Setting strictJsonSchema: false still gives us structured outputs (guaranteed valid JSON),
52-
// but allows optional fields to work properly.
48+
// Disable strict schema validation for both output and tool parameter schemas.
49+
//
50+
// OpenAI's structured outputs have limitations:
51+
// - structuredOutputs: true (default) enforces strict mode for BOTH output and tool schemas
52+
// - This requires ALL properties to be in the "required" array, breaking .optional()/.nullable()
53+
//
54+
// By setting both to false:
55+
// - structuredOutputs: false - Disables strict mode for tool parameter schemas
56+
// - strictJsonSchema: false - Disables strict mode for output schema
57+
// - We still get valid JSON, just without the strict "all fields required" constraint
5358
//
5459
// See:
5560
// - Issue: https://github.com/getsentry/sentry-mcp/issues/623
56-
// - AI SDK docs: https://ai-sdk.dev/providers/ai-sdk-providers/openai#strictjsonschema
61+
// - AI SDK docs: https://ai-sdk.dev/providers/ai-sdk-providers/openai#structuredoutputs
5762
// - OpenAI docs: https://platform.openai.com/docs/guides/structured-outputs
5863
providerOptions: {
5964
openai: {
65+
structuredOutputs: false,
6066
strictJsonSchema: false,
6167
},
6268
},

0 commit comments

Comments
 (0)