Repository navigation
Description
What
Add a sanitizeOpenAISchema(schema) lowering pass in
src/providers/transform.ts and apply it to every MCP inputSchema
before tools are registered with an OpenAI-shaped SAP AI Core
deployment, so JSON Schema 2020-12 features that OpenAI rejects
(prefixItems, boolean schemas, unknown composition keywords) are
either dropped or rewritten to the closest legal shape.
This ports the algorithm sst/opencode shipped in #32489 (commit
213ff3f2, 2026-06-17, +95 -0 impl + +201 -0 tests) directly
ported from Codex.
Why
src/mcp/client.ts:124-150 (mapToolInfo) forwards MCP inputSchema
verbatim. When a session routes to a SAP AI Core OpenAI deployment
(gpt-*, o1-*, o3-*, or any deployment whose metadata reports
@ai-sdk/openai), the OpenAI function-tool registration path rejects
unknown / unsupported schema features with Invalid schema for function. The tool registers with a green checkmark but every
subsequent call rejects, so the user sees the tool listed in the
session and gets a runtime error each time the model calls it.
Two of three example MCP servers in our docs (filesystem, ast-grep)
use $ref-heavy schemas that today fail this way against OpenAI
deployments. opencode hit the exact same wall and ported the lowering
algorithm from Codex; the test fixtures cover the failure modes we
need.
Source: .github/research/2026-06-19-research.md Detailed Finding #1.
How
- Implement
sanitizeOpenAISchema(schema: unknown): unknownin
src/providers/transform.ts. The algorithm (mirroring opencode's
lowering, in order):- If
schemaistrueorfalse(boolean schema), return
{ type: 'object' }(open) or{ not: {} }equivalent (closed)
— match opencode's choice exactly. - If
schemais not a non-null object, return{}. - Recurse into
properties(preserve key order),items,
prefixItems,$defs,definitions,anyOf,oneOf,allOf. - Drop
typevalues not in the OpenAI-accepted set
(['string','number','integer','boolean','object','array','null']). - Fold
const: Xintoenum: [X]when both are absent. - Filter
requiredto only string entries. - Infer
type: 'object'when absent butproperties,
required, oradditionalPropertiesare present. - Infer
type: 'array'when absent butitemsorprefixItems
are present. - Keep
$refanddescriptionas-is. - Drop unknown JSON Schema keywords (
if/then/else,
dependentSchemas,unevaluatedProperties, etc.) — opencode's
allowlist is the authority, copy it verbatim.
- If
- Detection: add a helper
isOpenAIShapedModel(model: string, providerMeta?: { sdk?: string }): booleanthat returns true for
model ids matching/^(gpt-|o[13]-)/iOR when
providerMeta?.sdk === '@ai-sdk/openai'. Place it next to
sanitizeOpenAISchemainsrc/providers/transform.ts. - Apply at the call site that ships MCP
inputSchemato the
provider tool registration. Search for whereMcpToolInfo.inputSchema
is converted into the provider-facingtoolspayload (likely
src/providers/sapAiCore.tsor wherever tools are assembled before
chat.completions). WhenisOpenAIShapedModelreturns true, run
each tool'sinputSchemathroughsanitizeOpenAISchemaimmediately
before serialization. Do NOT mutate the cachedMcpToolInfo—
produce a new object per request. - Tests: port the opencode
transform.test.tsfixtures into
tests/providers/transform.test.ts(orsrc/providers/transform.test.ts
if conventions prefer co-located tests). Cover at minimum:- boolean schemas (
true/false) $refchains preservedprefixItemslowered to legal shapeconst->enum- inferred
type: 'object'fromproperties - inferred
type: 'array'fromitems - non-string entries filtered out of
required - unknown composition keywords dropped
descriptionpreserved verbatim
The opencode test file is small (~200 LOC) — port the table of
fixtures and assert deep equality with the lowered output.
- boolean schemas (
- No behaviour change for non-OpenAI deployments. SAP AI Core
Anthropic / Mistral / Gemini deployments must NOT see the lowered
schema; they accept JSON Schema 2020-12 fine and the lowering would
strip semantically meaningful constraints. - Ship in its own PR separate from the smaller MCP fixes — this
touches a 100+ LOC transform plus full test fixtures and benefits
from independent review.
Done when
-
sanitizeOpenAISchemaandisOpenAIShapedModelexported from
src/providers/transform.ts. - OpenAI-shaped MCP tool registration runs every
inputSchema
throughsanitizeOpenAISchemabefore serialization. - Non-OpenAI deployments are unaffected (assert via test that an
Anthropic / SAP AI Core anthropic model id leaves the schema
untouched). - Test suite covers the opencode fixture set listed above.
- No mutation of cached
McpToolInfo; the lowering produces a new
object per request. -
npm run lint && npm run typecheck && npm run format:check && npm run test:coverage && npm run buildall green.
Activity
docs(ci): planning brief 2026-06-19 [alexi-bot]
github-actions commentedon Jun 19, 2026
🤖 Kilo is starting to implement this feature automatically.
auto/805-provider-codex-style-sanitizeopenaischema-for-mcp-Implementation in progress...
feat(providers): Codex-style sanitizeOpenAISchema for MCP tool schemas
feat(providers): Codex-style sanitizeOpenAISchema for MCP tool schemas (
github-actions commentedon Jun 19, 2026
❌ Kilo was unable to implement this feature automatically.
The AI agent encountered issues during implementation.
Manual implementation may be required.
View workflow run