fix(opencode): sanitize OpenAI MCP tool schemas#32489
Merged
rekram1-node merged 4 commits intoJun 17, 2026
Merged
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: I found one related PR: Related PR:
Why it's related: This PR also deals with sanitizing OpenAI schemas. It may address similar compatibility issues between MCP tool schemas and OpenAI's schema requirements. This should be reviewed to ensure there's no overlapping work or to determine if it's a complementary fix. The current PR (32489) is not a duplicate of itself, and the other results appear to be unrelated to schema sanitization work. |
dba7bab to
5bc6b68
Compare
5bc6b68 to
aa7e6f4
Compare
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
This was referenced Jun 17, 2026
johnko
added a commit
to johnko/opencode
that referenced
this pull request
Jun 17, 2026
* upstream: (4536 commits) fix(opencode): sanitize OpenAI MCP tool schemas (anomalyco#32489) chore: update nix node_modules hashes fix(provider): pass apiKey to createUnified for Cloudflare AI Gateway (anomalyco#32052) chore: generate feat(app): make session timelines much faster AND without flicker or scroll jumps (anomalyco#32331) chore: update nix node_modules hashes chore: generate experiment: better web picker using @pierre/tree (anomalyco#31208) fix(mcp): default tool schema properties (anomalyco#32568) fix(web): persist docs language selection (anomalyco#32551) fix(tui): render move errors inline (anomalyco#32241) Revert "fix(mcp): type tool error content" fix(mcp): enable progress timeout resets (anomalyco#32477) fix(mcp): stop idle OAuth callback server (anomalyco#32245) chore: generate chore: update nix node_modules hashes fix(mcp): type tool error content fix(stats): align homepage model ranks fix(mcp): handle tool result errors (anomalyco#32244) fix(stats): rank model pages by week ...
LuisAlbertoMK
added a commit
to LuisAlbertoMK/opencode
that referenced
this pull request
Jun 17, 2026
- fix(tui): render move errors inline (anomalyco#32241) - fix(mcp): enable progress timeout resets (anomalyco#32477) - fix(mcp): default tool schema properties (anomalyco#32568) - fix(opencode): sanitize OpenAI MCP tool schemas (anomalyco#32489)
davidgut1982
pushed a commit
to davidgut1982/opencode
that referenced
this pull request
Jun 19, 2026
Co-authored-by: jquense <jquense@ramp.com> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
ausard
pushed a commit
to ausardcompany/alexi
that referenced
this pull request
Jun 19, 2026
Add a JSON schema lowering pass for MCP tool inputSchemas that targets SAP AI Core OpenAI deployments (gpt-*, o1-*, o3-*, or any deployment whose ai-sdk wrapper is @ai-sdk/openai or @ai-sdk/azure). Mirrors the Codex / opencode lowering algorithm shipped in anomalyco/opencode#32489 so JSON Schema 2020-12 features OpenAI rejects (boolean schemas, prefixItems, if/then/else, dependentSchemas, unevaluatedProperties, patternProperties, ...) are dropped or rewritten to the closest legal shape before tool registration. Exports from src/providers/transform.ts: - sanitizeOpenAISchema(schema) - pure lowering pass; never mutates input. - isOpenAIShapedModel(model, providerMeta?) - detects gpt-/o1-/o3- ids or @ai-sdk/openai|azure providerMeta. - lowerMcpToolsForOpenAIShaped(tools, model, providerMeta?) - call-site helper that produces NEW tool descriptors per request so the cached McpToolInfo in McpClientManager is safe for non-OpenAI deployments in the same process. Non-OpenAI SAP AI Core deployments (anthropic--*, gemini-*, mistralai--*, amazon--*, deepseek-ai--*) pass through untouched - they accept JSON Schema 2020-12 fine and the lowering would strip semantically meaningful constraints. Tests port the opencode transform.test.ts fixtures, covering boolean schemas, ref preservation, tuple/prefixItems lowering, const -> enum folding, type inference from properties/items, required filtering of non-string entries, dropped composition keywords, description preservation, and a non-mutation guarantee. Closes #805 [alexi-bot]
ausard
added a commit
to ausardcompany/alexi
that referenced
this pull request
Jun 19, 2026
#809) Add a JSON schema lowering pass for MCP tool inputSchemas that targets SAP AI Core OpenAI deployments (gpt-*, o1-*, o3-*, or any deployment whose ai-sdk wrapper is @ai-sdk/openai or @ai-sdk/azure). Mirrors the Codex / opencode lowering algorithm shipped in anomalyco/opencode#32489 so JSON Schema 2020-12 features OpenAI rejects (boolean schemas, prefixItems, if/then/else, dependentSchemas, unevaluatedProperties, patternProperties, ...) are dropped or rewritten to the closest legal shape before tool registration. Exports from src/providers/transform.ts: - sanitizeOpenAISchema(schema) - pure lowering pass; never mutates input. - isOpenAIShapedModel(model, providerMeta?) - detects gpt-/o1-/o3- ids or @ai-sdk/openai|azure providerMeta. - lowerMcpToolsForOpenAIShaped(tools, model, providerMeta?) - call-site helper that produces NEW tool descriptors per request so the cached McpToolInfo in McpClientManager is safe for non-OpenAI deployments in the same process. Non-OpenAI SAP AI Core deployments (anthropic--*, gemini-*, mistralai--*, amazon--*, deepseek-ai--*) pass through untouched - they accept JSON Schema 2020-12 fine and the lowering would strip semantically meaningful constraints. Tests port the opencode transform.test.ts fixtures, covering boolean schemas, ref preservation, tuple/prefixItems lowering, const -> enum folding, type inference from properties/items, required filtering of non-string entries, dropped composition keywords, description preservation, and a non-mutation guarantee. Closes #805 [alexi-bot] Co-authored-by: alexi-bot <alexi-bot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Addresses #32488. Tuple-style
itemsremain unsupported and will be handled separately.Type of change
What does this PR do?
MCP servers can expose tool input schemas with JSON Schema keywords that OpenAI tool schemas do not support. This sanitizes tool schemas for models using the OpenAI or Azure AI SDK adapters before sending them to the model, mirroring Codex's compatibility lowering: unsupported keywords are dropped,
constbecomesenum, and missing object/array children get permissive defaults.Scoping by adapter covers direct OpenAI and Azure providers as well as OpenCode Zen and custom providers configured with
@ai-sdk/openai. Models using other adapters keep their schemas unchanged.How did you verify your code works?
bun test test/provider/transform.test.ts --timeout 30000bun typecheckfrompackages/opencodebun turbo typechecksuccessfullyScreenshots / recordings
N/A - non-UI change.
Checklist