MoonshotAI / MoonshotAI/kimi-cli
[Feature] Lazy-load MCP tool schemas into context — only inject when tools are needed
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 11.4k
- Forks
- 1.3k
- Avg merge
- 9h 47m
- Merged PRs (30d)
- 2
Description
Problem
When MCP servers are configured, all tool schemas (names, descriptions, input JSON schemas) are injected into the LLM context at the start of every session. With multiple MCP servers this can consume thousands of tokens of context budget before the user sends a single message.
This leaves less room for conversation history and actual work, and hurts quality on long tasks — especially in sessions that never end up using most of the configured MCP tools.
Related issues
- #1177 — disabling specific tools is a partial mitigation, but tool schema injection still happens upfront at session start
- PR #1486 — deferred async MCP server connection startup (great improvement, but doesn't address schemas being loaded into LLM context)
Proposed solution
Lazy-load MCP tool schemas into the LLM context only when tools are actually needed, rather than injecting all schemas at session start. A few approaches:
- On-demand discovery: inject a lightweight
list_toolsstub first; only fetch and inject full schemas when the model determines a tool domain is relevant to the current task - Task-scoped injection: analyse the user's first message and only inject schemas for servers likely to be relevant
- Deferred full load: keep schemas out of the initial context and inject them progressively as tools are invoked
Prior art
- Claude Code uses a
ToolSearchdeferred-tool primitive — MCP tool schemas are not loaded into context until explicitly fetched, keeping the base context lean - opencode tracks the same request at anomalyco/opencode#8277
Impact
Users with many MCP servers configured (10+ servers, 50+ tools) can lose a significant fraction of their context window before any work begins. Lazy loading would make Kimi Code CLI viable for heavily MCP-configured environments without sacrificing context budget.
Contributor guide
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
The issue names no files, tests, or code entry points. Start by tracing where MCP tool schemas enter the session context, then review related issue #1177 and PR #1486 alongside the three proposed approaches. Done means schemas are not loaded at session start but become available when needed without sacrificing tool functionality.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- ai, cli
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100