MoonshotAI / MoonshotAI/kimi-cli

ToolSearch / MCP tool_reference messages poison session on api.kimi.com/coding/ and cause persistent HTTP 400 invalid_request_error

Open
#2,223 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
11.4k
Forks
1.3k
Avg merge
9h 47m
Merged PRs (30d)
2

Description

Description

When using the Anthropic-compatible Kimi Code endpoint at https://api.kimi.com/coding/, sessions appear to break permanently after ToolSearch introduces MCP tool_reference messages into the conversation context.

The provider then starts returning:

HTTP 400
invalid_request_error: Invalid request Error

Once the session contains tool_reference content, follow-up requests continue to fail until a new session is started.

This looks like a provider-side schema / content-type compatibility issue rather than a generic tool failure.

What version of Kimi Code CLI is running?

Observed across:

  • 2.1.123
  • 2.1.138

Which open platform/subscription were you using?

api.kimi.com/coding/ (Kimi Code subscription / Anthropic-compatible endpoint)

Which model were you using?

Kimi Code model via api.kimi.com/coding/.

What platform is your computer?

macOS / Darwin arm64

What issue are you seeing?

A failing session and a healthy session were compared side by side.

Problematic session:

  • Real API 400 errors: 5
  • ToolSearch calls: 1
  • MCP tool_reference messages: present
  • Native tools like Agent/Bash: normal
  • Claude Code version: issue persisted from 2.1.123 to 2.1.138

Healthy session:

  • Real API 400 errors: 0
  • ToolSearch calls: 0
  • MCP tool_reference messages: absent
  • Native tools like Agent/Bash: normal
  • Claude Code version: 2.1.138

Suspected failure chain:

  1. Assistant calls ToolSearch
  2. ToolSearch returns 3 MCP Playwright tool references
  3. Those tool_reference items are added to the conversation context
  4. The provider gateway encounters an unsupported / unrecognized content type while parsing the request
  5. The request fails with HTTP 400 invalid_request_error
  6. Because the bad content remains in context, follow-up requests continue to fail

What steps can reproduce the bug?

  1. Use https://api.kimi.com/coding/ in an Anthropic-compatible coding client
  2. Start a fresh session
  3. Invoke ToolSearch so the tool returns MCP tool references
  4. Let those tool_reference messages enter the conversation history
  5. Send the next normal assistant/user turn
  6. Observe HTTP 400 invalid_request_error: Invalid request Error

What is the expected behavior?

The provider should either:

  • fully support tool_reference / MCP-related message content in the conversation schema, or
  • safely ignore / normalize unsupported content instead of permanently poisoning the session.

A session should not become unrecoverable just because ToolSearch returned MCP references.

Additional information

What seems ruled out:

  • Not ordinary tool usage in general, because native tools continued to work in healthy sessions
  • Not purely a client-version issue, because the correlation is with tool_reference presence, not just CLI version

Please investigate:

  • schema compatibility for tool_reference content in api.kimi.com/coding/
  • provider gateway parsing for MCP-related message content
  • fallback behavior for unknown content types
  • support status for ToolSearch / MCP / tool_reference under the Anthropic-compatible endpoint

I can provide redacted logs / context snippets if needed.


中文补充:

当 ToolSearch / MCP 返回的 tool_reference 被写入上下文后,api.kimi.com/coding/ 后续请求会开始持续返回 400,像是 provider 网关不认识这种消息内容类型。一旦上下文被污染,这个 session 基本就废掉了,只能开新 session。这个问题在未触发 ToolSearch 的新 session 中不会出现。

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start by reproducing the issue against https://api.kimi.com/coding/ with a fresh session, invoking ToolSearch and then sending a normal turn; compare the request context with a healthy session. Done means the resulting session no longer persistently returns HTTP 400 after MCP tool_reference messages are present.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.