CommandCodeAI / CommandCodeAI/command-code

MCP tool schemas using $ref/$defs cause 400 on every request with Moonshot/Kimi models

Đang mở
#566 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Không có dữ liệu ngôn ngữ
Star
4k
Fork
350
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

  1. Configure any MCP server that emits a $ref-based tool schema. In my case: the Solo app's MCP server, whose identify_session tool 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"
}
  1. Start cmd with a Kimi model and send any message.
  2. 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).

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu tại điểm vào cmd và lần theo cách các schema của công cụ MCP được chuyển đổi trước khi các yêu cầu đến provider được gửi đi; issue không nêu tên tệp hoặc bài kiểm thử nào trong repository. So sánh đường đi của Moonshot với các đường đi của Claude Code và Codex, sau đó xác minh rằng schema $ref/$defs được báo cáo không còn gây ra lỗi 400 và session vẫn có thể sử dụng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
json
Lĩnh vực
api, cli
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.