fix(mcp): make tool input schemas portable to single-type dialects

Nullable inputs were emitted as `type: ["number", "null"]` (or a `null`
anyOf branch), which clients that map tool schemas onto an OpenAPI-style
subset (e.g. Gemini function declarations) may reject.

- Make read_asset's startPage, endPage, and degree optional instead of
  nullable.
- Move null handling into a shared dropNullOptionals helper in
  @shumai/operations that also strips nulls inside nested config
  objects. The agent uses it, and the MCP server applies it before the
  SDK validates arguments, so models that send null keep working.
- Test that no Operation input schema (and no listed MCP tool) uses a
  nullable type.
This commit is contained in:
yiling
2026-10-26 17:24:34 +08:00
parent 4fc8476b0f
commit b7dccad6e5
11 changed files with 164 additions and 28 deletions
@@ -99,7 +99,7 @@ export const documentReader: AssetReader<'document'> = {
}
if (startPage !== null || endPage !== null) {
throw badRequest(
'startPage and endPage must be null when docConfig mode is "text". To inspect specific page numbers, use mode: "pages".',
'startPage and endPage must be left out when docConfig mode is "text". To inspect specific page numbers, use mode: "pages".',
)
}
if (!isPlainTextAsset(asset.mediaTypeLower, asset.filenameLower)) {
@@ -150,11 +150,9 @@ describe('model3dReader', () => {
} as unknown as PrismaJson.MediaInfo,
})
it('accepts null as "show the overview"', async () => {
expect(() =>
model3dReader.validate(model, { degree: null }, { hasAnnotation: false }),
).not.toThrow()
const plan = await model3dReader.plan(model, { degree: null }, noAnnotation)
it('shows the overview when no degree is given', async () => {
expect(() => model3dReader.validate(model, {}, { hasAnnotation: false })).not.toThrow()
const plan = await model3dReader.plan(model, {}, noAnnotation)
expect(plan.status).toBe('ready')
})