Uh oh!
There was an error while loading. Please reload this page.
fix(opencode): sanitize OpenAI MCP tool schemas - #32489
Conversation
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
5bc6b68Compare5bc6b68 to
aa7e6f4CompareThanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Uh oh!
There was an error while loading. Please reload this page.
* 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 ...
- 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)
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>
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]
#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>
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>
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>
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>
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>
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>
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>
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>
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>
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