anthropics / anthropics/claude-ai-mcp

"Load tools when needed" does not defer connector tool schemas — full definitions loaded upfront, context limit hit before first message

Aberta
#401 2 comentários 2 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Sem dados de linguagem
Estrelas
471
Forks
76
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

### What happened?

On claude.ai (web; also reported on Desktop/mobile), enabling **Settings → Connectors → Tool access → "Load tools when needed"** does **not** actually defer connector tool schemas. The full JSON tool definitions for every enabled connector are still injected into the conversation context up front, regardless of the setting.

With enough connectors enabled, this exhausts the context window **before the first user message**, producing:

> This conversation is too long to continue. Start a new chat, or remove some tools to free up space.

A brand-new chat overflows after a single message. One connector alone (PostHog) exposes ~270 tools; across ~15 connectors that is ~500 tool definitions / roughly 90–100K tokens of schemas loaded before anything is typed.

The same account's connectors load correctly in **Claude Code CLI**: only tool *names* are loaded up front and full schemas are fetched on demand (tool search). So the deferral mechanism exists and works — the consumer apps just aren't honoring the toggle.

### What did you expect to happen?

With "Load tools when needed" enabled, connector tool **schemas should be excluded from the system-prompt prefix**. Only the tool catalog (names/short descriptions) plus the tool-search mechanism should be in context initially; a tool's full definition should be expanded inline only when Claude actually needs it — exactly as Claude Code CLI and the API's `defer_loading: true` / Tool Search Tool already do. A fresh chat with many connectors enabled should start with the bulk of the context window free.

### Steps to reproduce

1. On claude.ai, connect a large set of MCP connectors (~11+, or one large server such as PostHog which exposes ~270 tools).
2. Open Settings → Connectors → Tool access and select **"Load tools when needed"**.
3. Start a new chat and send one short message.
4. Observe the "This conversation is too long to continue… remove some tools to free up space" error — the context is already full from tool schemas, despite the setting.

Control (works): add the same servers to Claude Code CLI — they load deferred (names only) and a fresh session has full headroom.

### Area

Tool Discovery / Invocation

### MCP Server (if applicable)

Not server-specific — reproduces with any sufficiently large set of connectors (e.g. PostHog, ~270 tools).

### Error messages or logs

```
This conversation is too long to continue. Start a new chat, or remove some tools to free up space.
```

Related claude-code reports cite "This request exceeds Claude's context limit by about 33,609 tokens" before the first message.

### Additional context — recommended fix

The setting appears to change only the *timing* of schema injection, not *whether* full schemas enter the prefix. Suggested fixes, in priority order:

1. **Actually defer schemas (primary).** When "Load tools when needed" is on, exclude connector tool schemas from the prompt prefix and use the existing Tool Search Tool / `defer_loading: true` path the API and Claude Code already support — load only the searchable catalog up front and expand a tool to its full definition inline when invoked. This also preserves prompt-cache hits on the prefix.
2. **Fix the toggle-persistence bug.** "Tool access" silently reverts to "Auto" when changed before the first message of a new chat, so on-demand loading often can't be enabled at all.
3. **Surface per-connector context cost** in Settings → Connectors (token footprint per server) so users can see which connectors are expensive.
4. **Per-chat / per-project connector enablement**, so a heavy connector can default off and be toggled on only when needed.

### References

Filed previously against the Claude Code repo and auto-labeled "invalid" (consumer-app/MCP scope), re-filing here in the correct tracker:
- anthropics/claude-code#62175 — "Load tools when needed" doesn't defer connector schemas (open)
- anthropics/claude-code#25892 — "Tool Access / On Demand" doesn't persist or defer (closed, not planned)

Environment: claude.ai web (also Desktop/mobile). Surfaces unaffected: Claude Code CLI.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.