kimi-code icon indicating copy to clipboard operation
kimi-code copied to clipboard

400 error: "tools.function.parameters is not a valid moonshot flavored json schema" when using custom API endpoint with MCP tools

Open skydzx opened this issue 4 months ago • 2 comments

What version of Kimi Code is running?

0.23.6

Which open platform/subscription were you using?

Allegretto subscription

Which model were you using?

kimi-for-coding

What platform is your computer?

Windows 11 Home China 10.0.26200 x64

What issue are you seeing?

When using a custom API endpoint with multiple MCP servers configured,the LLM request fails with: APIStatusError: 400 tools.function.parameters is not a valid moonshot flavored json schema, details: <At path 'properties.workFlow.items.required': required property 'codecType' is not defined in properties> At the time of the error, 255 tools were registered across multiple MCP servers. The Moonshot API appears to do stricter JSON Schema validation than standard OpenAI-compatible APIs.

What steps can reproduce the bug?

  1. Configure multiple MCP servers (playwright, firecrawl, etc.)
  2. Set a custom API endpoint
  3. Send any prompt
  4. Request fails before reaching the model

What is the expected behavior?

  • Client-side schema validation to filter invalid tool schemas before sending
    • Or graceful degradation: retry with problematic tools removed
    • Or a clearer error message indicating which MCP server/tool caused the issue @

Additional information

One of the MCP tools has a "required" array referencing "codecType" which is not defined in "properties" of that object. This violates strict JSON Schema validation.

session_d40255e5-91fc-4529-821b-2a4835b2df2a.zip

skydzx avatar Jul 13 '26 11:07 skydzx

A fix for this issue is available in PR #830 (fix(agent-core/mcp): sanitize MCP JSON Schemas for Moonshot MFJS validator).

Summary of Fix

  • When registering MCP tools, various MCP servers emit JSON Schema constructs (e.g. required keys not present in properties, draft-07 tuple items, invalid default types, unsupported keywords) that cause Moonshot API's strict Moonshot Flavored JSON Schema (MFJS) validator to fail with 400 tools.function.parameters is not a valid moonshot flavored json schema.
  • PR #830 introduces client-side sanitization of tool schemas before dispatching them to the API, pruning phantom required properties, normalizing tuple items, and ensuring schema compliance.
  • Covered by unit tests (75+ test assertions) and includes a changeset.

Per the updated CONTRIBUTING.md policy for bug fixes, could a maintainer please review and provide an /approve so PR #830 can proceed? Thank you!

creatiVision avatar Sep 01 '26 16:09 creatiVision

Hello. I vibecoded the standalone MCP proxy, rather than https://github.com/MoonshotAI/kimi-code/pull/830 and https://github.com/MoonshotAI/kimi-code/pull/1720. These are unlikely to get merged, it seems.

https://github.com/cnt0/mcp-mfjs-proxy - it seems to work for me, enjoy.

cnt0 avatar Nov 07 '26 11:11 cnt0