CommandCodeAI / CommandCodeAI/command-code
MCP tool schemas using $ref/$defs cause 400 on every request with Moonshot/Kimi models
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 4k
- Forks
- 350
- PR merge metrics
- No merged PRs in 30d
Description
Summary
When an MCP server exposes a tool whose input schema uses $ref + $defs (valid JSON Schema, and valid per the MCP spec), Command Code passes the schema to the Moonshot/Kimi API in a form it rejects — and because tool definitions accompany every request, every turn of the session fails with a 400, making the CLI unusable with that MCP server attached.
Error
⚠ Error: 400 Invalid request: tools.function.parameters is not a valid moonshot flavored
json schema, details: <At path 'properties.external.$ref': $defs not found for reference:
#/$defs/IdentifySessionExternalParams>
Seen on v0.51.0 and still present after updating to v0.52.1, model moonshotai/Kimi-K2.7-Code-Highspeed.
Repro
- Configure any MCP server that emits a
$ref-based tool schema. In my case: the Solo app's MCP server, whoseidentify_sessiontool declares:
{
"$defs": {
"IdentifySessionExternalParams": {
"properties": {
"agent_id": {"type": "string"},
"metadata": {"additionalProperties": true, "default": {}, "type": "object"},
"name": {"type": "string"}
},
"required": ["name"],
"type": "object"
}
},
"properties": {
"external": {
"$ref": "#/$defs/IdentifySessionExternalParams",
"description": "External actor details for callers that are not Solo-managed processes."
},
"solo_process_id": {"format": "int64", "type": "integer"},
"pid": {"format": "uint32", "minimum": 0, "type": "integer"}
},
"type": "object"
}
- Start
cmdwith a Kimi model and send any message. - Every request 400s with the error above.
Note the schema does include a top-level $defs — the Moonshot error says $defs not found, which suggests the conversion layer strips/loses $defs while leaving the $ref dangling (or Moonshot's "flavored" schema simply doesn't support refs at all).
Expected
Command Code should dereference/inline $refs when converting MCP tool schemas for providers whose "flavored" JSON Schema doesn't support them (Moonshot at minimum). Claude Code and Codex handle the same MCP server fine because the Anthropic/OpenAI APIs accept $ref schemas.
A degraded-but-better alternative: drop the offending tool from the tool list with a warning, instead of letting one incompatible schema hard-fail the entire session.
Workaround
Disable the offending MCP server in ~/.commandcode/mcp.json ("enabled": false).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the cmd entry point and trace how MCP tool schemas are converted before provider requests are sent; the issue names no repository files or tests. Compare the Moonshot path with the Claude Code and Codex paths, then verify that the reported $ref/$defs schema no longer causes a 400 and that the session remains usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- json
- Domain
- api, cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100