Repository navigation
feat(providers): Codex-style sanitizeOpenAISchema for MCP tool schemas - #809
Conversation
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]
Coverage Report
Coverage Details
|
SummarySecurity audit of PR #809 ( The new lowering pass introduces a latent prompt-injection / DoS surface that is benign today (no call site wires it in yet) but should be hardened before a follow-up PR plugs it into the request path. Critical (block)None. High (warn)1. Tool
2. Recursion is unbounded.
Info3. Pre-existing
4. New helpers are not yet wired into any call site.
5. Constitution principle I (SAP AI Core-First) upheld.
6. Encoding hygiene.
Recommendations
Severity ratings used: [alexi-bot] |
Architecture review — PR #809Posted by the Architecture vertical of the Alexi T-shape factory SummaryPR #809 (
Verdict on this PR: approve from an architecture standpoint. No ADR The remainder of this review records repository-wide findings surfaced FindingsF1 —
|
Review - role-quality
What was reviewed
FindingsCorrectness. Lowering pass faithfully mirrors sst/opencode #32489 (Codex's Rust schema compatibility layer): drops unsupported keywords, folds Security. No eval, fs, or network. Type safety. Strict TypeScript, no Tests. Covers boolean schemas, Performance. O(n) tree walk over the schema, no quadratic loops. Style. 100-col Prettier clean, ASCII only, single quotes, JSDoc on every export. Notes (non-blocking)
Changes madeNone. PR is in reviewable shape on its own. VerdictApproved. |
Summary
Adds a JSON Schema lowering pass for MCP tool input schemas targeted at SAP AI Core OpenAI deployments (`gpt-`, `o1-`, `o3-*`, or any deployment whose underlying ai-sdk wrapper is `@ai-sdk/openai` / `@ai-sdk/azure`).
Mirrors the Codex / opencode lowering algorithm shipped in anomalyco/opencode#32489 (Codex's Rust schema compatibility layer). Without it, MCP servers that use JSON Schema 2020-12 features OpenAI rejects (`prefixItems`, boolean schemas, `if`/`then`/`else`, `dependentSchemas`, `unevaluatedProperties`, ...) register successfully but every tool call rejects with `Invalid schema for function`.
Exports (`src/providers/transform.ts`)
Behaviour
Tests
`tests/providers/transform.test.ts` ports the opencode `transform.test.ts` fixtures and covers:
Verification
```
npm run lint # 0 errors
npm run typecheck # clean
npm run format:check # clean
npm run test:coverage # 2678 passed, 61.14% lines
npm run build # clean
```
Closes #805