Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Dec 17, 2025

Summary

Fixes MCP tool schema normalization for both Bedrock (JSON Schema 2020-12) and OpenAI (strict mode) compatibility.

Root Cause

  1. Bedrock: type: ["string", "null"] is invalid in JSON Schema 2020-12
  2. OpenAI: type: "object" without properties violates strict mode (e.g., launchOptions: { type: "object" })

Changes

  • src/utils/json-schema.ts: Enhanced Zod transform to:

    • Convert type: ["T", "null"]anyOf format (JSON Schema 2020-12)
    • Filter required to only include keys that exist in properties
    • Add properties: {} for type: "object" schemas without properties (OpenAI strict mode)
  • src/core/prompts/tools/native-tools/mcp_server.ts: Use normalizeToolSchema() instead of ToolInputSchema.safeParse()

  • src/utils/__tests__/json-schema.spec.ts: Updated tests to expect properties: {} for bare object schemas

Testing

  • All 21 json-schema and mcp_server tests pass
  • All 4746 tests in the test suite pass

Related

Fixes an error where Bedrock/Claude rejects tool definitions that use
the deprecated type: ["T", "null"] array syntax for nullable types.
This syntax was valid in JSON Schema draft-04 through draft-07, but is
not valid in JSON Schema draft 2020-12 which Claude on Bedrock requires.

The fix adds a normalizeToolSchema() function that uses Zod to:
- Transform type: ["T", "null"] to anyOf: [{type: "T"}, {type: "null"}]
- Set additionalProperties: false by default (required by OpenAI strict mode)
- Recursively apply transformations to nested schemas

Closes: https://us.posthog.com/error_tracking/019b29fd-1546-7f61-b95d-a485cf010623
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. bug Something isn't working labels Dec 17, 2025
@roomote
Copy link
Contributor

roomote bot commented Dec 17, 2025

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The new commit correctly extends JSON Schema 2020-12 normalization to MCP tool schemas. The implementation adds empty properties: {} for object types without explicit properties (required for OpenAI strict mode) and filters required arrays to only include keys that exist in properties. The logic properly handles both single type and type array cases.

Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 17, 2025
- Convert type arrays (e.g., ["string", "null"]) to anyOf format for JSON Schema 2020-12 compliance (Bedrock)
- Filter required array to only include keys that exist in properties
- Add empty properties: {} for type: "object" schemas without properties (OpenAI strict mode)
- Use normalizeToolSchema() in mcp_server.ts instead of ToolInputSchema.safeParse()
- Update tests to expect properties: {} for bare object schemas
@daniel-lxs daniel-lxs changed the title fix(bedrock): normalize tool schemas to JSON Schema draft 2020-12 fix: normalize MCP tool schemas for Bedrock and OpenAI strict mode Dec 17, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Dec 17, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 17, 2025
@cte cte merged commit aa3b4ae into main Dec 17, 2025
10 checks passed
@cte cte deleted the fix/bedrock-json-schema-2020-compliance branch December 17, 2025 21:01
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Dec 17, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Dec 17, 2025
@hannesrudolph hannesrudolph added PR - Needs Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer PR - Needs Review size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants