Skip to content

Using kimi k2.6 will result in an error. #458

Closed

Description

@gjfmlj

Using kimi k2.6 will result in an error.

..parameters is not a valid moonshot flavoredjson schema, details:<At path '....***. startDateTime.$ref':references must start with #/$defs/>

Activity

  1. eirikb commented on May 12, 2026

    @eirikb
    Contributor

    I believe this is a upstream issue in the modelcontextprotocol sdk.

    We can solve this on our side by hacking the spec on the way out - buuuuut I don't think that is a very good solution.
    If you open an issue on https://github.com/modelcontextprotocol/typescript-sdk that might help.

    What you can do is to try --discovery, since you then only get three tools with simple params (no $refs).

  2. daveCode-dot commented on May 14, 2026

    @daveCode-dot

    Per the JSON Schema specification (https://json-schema.org/draft/2020-12/schema), $ref references must either:

    1. Absolute URI (e.g., https://example.com/schema.json#/defs/DateTime)
    2. Fragment-only reference starting with #/$defs/ (e.g., #/$defs/DateTime)

    The error "references must start with #/$defs/>" suggests your schema is generating $ref values that don't match either pattern. This likely occurs when:

    • Schema objects are being serialized without resolving relative paths to the root definition anchor
    • The Moonshot API's validation is stricter about ref format than other LLM providers

    Have you checked whether the Graph API schemas are using relative $ref paths that need to be resolved to absolute or fragment-only format before passing to Moonshot?

  3. eirikb commented on May 14, 2026

    @eirikb
    Contributor

    Ok so I dug into this a bit. ran the server locally and dumped tools/list: 64 of 311 tools have $refs (1190 of them), and they all look like #/properties/..., just JSON Pointers back into the same tool's own schema. no $defs, no definitions, nothing.

    So the refs aren't actually wrong, fragment-only pointers are perfectly fine JSON Schema. kimi is just being picky.

    Reason they show up: the generated client reuses the same zod instances everywhere (microsoft_graph_dateTimeTimeZone and friends), and the mcp sdk runs them through zod-to-json-schema without setting $refStrategy or target, so it falls back to 'root' + jsonSchema7 and back-refs every duplicate.

    Real fix is in the typescript-sdk, they should either expose $refStrategy or just default tool inputs to 'none'. probably worth poking them about it.

    Anyway, --discovery is still the move for now, confirmed zero $refs there.

  4. daveCode-dot commented on May 15, 2026

    @daveCode-dot

    @eirikb thanks for the deep dive — that's the real root cause, not the surface "refs are malformed" interpretation I went on first.

    I checked modelcontextprotocol/typescript-sdk and there's no open or closed issue about exposing $refStrategy / changing the zod-to-json-schema default for tool inputs. That's a clean gap. Happy to open one upstream citing your analysis (64/311 tools, 1190 back-refs, root strategy fallback, kimi rejection) unless you prefer to file it yourself — your repro is concrete enough to act on directly.

    Worth noting: remove-recursive-refs.js already in this repo explicitly disclaims it won't help "if the tool still struggles with $ref in general" — which is exactly the kimi case. So kimi falls outside what that helper is scoped to fix.

    For now --discovery is the move (confirmed). Long term, the typescript-sdk patch is the right place. Ping me if you want me to draft the upstream issue.

  5. eirikb commented on May 15, 2026

    @eirikb
    Contributor

    @daveCode-dot If you want to create an upstream issue that would be great, thanks 👍

  6. daveCode-dot commented on May 15, 2026

    @daveCode-dot

    @eirikb done — filed upstream as modelcontextprotocol/typescript-sdk#2100.

    Quick recap of what's in the issue, sourced from your dump + a look at the SDK source:

    • The relevant line is packages/core/src/util/standardSchema.ts:200, where z.toJSONSchema is called without reused. That's the knob that controls whether duplicates get $ref'd or inlined.
    • Proposed fix: pass reused: 'inline'. That matches what --discovery mode already produces in practice (no refs).
    • Argued for inline-by-default over an opt-in option, since the alternative (server can't override the picky-client default) is the worse failure mode.

    Offered to put up the PR with a regression test that asserts no $ref in the output of a tool with reused inner schemas. Will wait for upstream direction before pushing code.

    Thanks for the dump — having 64/311 · 1190 refs in hand made the issue concrete instead of speculative.

  7. eirikb commented on Jul 21, 2026

    @eirikb
    Contributor

    Fixed by #576 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions