anthropics / anthropics/claude-code

MCP tool description truncation at 2048 chars is silent, unconfigurable, and can leave a misleading prefix (follow-up to #41593, #81268)

Đang mở
#87,650 0 bình luận 2 reaction 0 người được giao Xem trên GitHub
area:mcp bug stale
Ngôn ngữ chính
Python
Star
145k
Fork
23.1k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

## Summary

MCP tool `description` fields are silently truncated to 2048 chars before being assembled into the model's context. There is no log line, no setting to override it, and the `/mcp` UI shows the *untruncated* text — so an author verifying their tool description in `/mcp` sees content the model never receives. Worse, for tools whose description embeds a usage contract (e.g. a TypeScript interface for a generic "execute" tool), the surviving 2048-char prefix can look complete and closed while critical fields are documented only past the cut — the model then confidently uses a wrong, narrower API with no signal anything is missing.

This is a follow-up to #41593 and #81268, adding a controlled same-day comparison and a new "misleading prefix" failure mode neither prior issue covered.

## Verification

Binary: `/Users/victorb/.local/share/claude/versions/2.1.234` (Claude Code v2.1.234, macOS darwin 25.5.0).

```
LC_ALL=C grep -aoE '.{160}Tpe\b.{80}' /Users/victorb/.local/share/claude/versions/2.1.234 | head
```

The minified constant `Tpe=2048` gates it. The MCP tool wrapper contains (verbatim from the binary):

```js
async description(){return W},async prompt(){return W.length>Tpe?ei(W,Tpe)+"… [truncated]":W}
```

`description()` — surfaced in the `/mcp` UI — returns the full string `W`. `prompt()` — what actually gets assembled into the model's context — truncates it. So the UI and the model see different text, with no indication of that divergence anywhere in the UI.

Server `instructions` truncation does log a debug line ("Server instructions truncated from X to 2048 chars"). Tool `description` truncation logs nothing anywhere.

## Impact

Controlled comparison on one MCP server (an OpenAPI code-execution MCP server whose `execute` tool embeds its full usage contract in the tool description), same server, same day:

- **claude.ai** receives the full description: **16,275 chars**.
- **Claude Code** (including Cowork)

receives **2,061 chars** (2,048 + the 13-char `"… [truncated]"` marker) — **12.7%** of the document.

Verbatim captures of the same server's tool schemas as received by Claude Code (truncated) and by claude.ai (complete) are attached to this issue.

The surviving prefix contains a TypeScript `RequestOptions` interface listing `method, path, query, body, contentType, rawBody` that *looks* complete and closed — but `headers`, `bodyBase64`, `multipart`, and `returnAs` are documented only past char 2048 (see attachments). The model has no way to know the interface it's looking at is incomplete, so it confidently calls the tool with a narrower, wrong API. None of this is logged, and `/mcp` shows the author the full, untruncated text, so the author has no way to notice the model is working from a different (and misleading) document.

## Prior issues

- #41593 — "MCP tool descriptions truncated at 2KB breaks code execution tools". Same diagnosis, on an earlier build (then `WoH=2048`, v2.1.84). Closed by the stale-bot with no decision.
- #81268 (open) — "MCP truncation at 2048 chars is invisible". Documents the no-log and `/mcp`-mismatch aspects; reports 502 truncation events on one machine, worst case 10,780 → 2,048 chars.

This issue adds: a controlled claude.ai-vs-Claude-Code comparison on the same server/day, and documentation of the misleading-closed-interface failure mode (the truncated prefix isn't just short, it's shaped like a complete spec).

## Requested fixes

1. A server-settable per-tool override, e.g. `_meta["anthropic/maxDescriptionChars"]`, mirroring the existing `_meta["anthropic/maxResultSizeChars"]` pattern already read by the binary (`O._meta?.["anthropic/maxResultSizeChars"]`) for result-size overrides. Keeps the tight default while letting code-execution tools opt in to a longer description.
2. Log every tool-description truncation the same way server-`instructions` truncation is already logged.
3. Make `/mcp` display the truncated text the model actually receives (or at minimum mark the cut point), so authors aren't debugging against a document the model never saw.
4. Alternatively/additionally: a `maxToolDescriptionLength` setting in `settings.json`.

## Environment

- Claude Code v2.1.234
- macOS darwin 25.5.0

## Attachments

[toolsearch_results_gmail_ba_codemode_sessionB.html](https://github.com/user-attachments/files/31182966/toolsearch_results_gmail_ba_codemode_sessionB.html)
[toolsearch_results_gmail_ba_codemode.html](https://github.com/user-attachments/files/31182967/toolsearch_results_gmail_ba_codemode.html)

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

Hướng nghiên cứu

Start with the reported Claude Code v2.1.234 binary and the MCP tool wrapper's description() and prompt() paths; reproduce the 2048-character difference and inspect how /mcp renders descriptions. Compare this with server-instructions logging and the _meta maxResultSizeChars handling. Done should include an agreed treatment for truncation, visibility, and configuration, with verification that the model and /mcp show consistent information.

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

Đánh giá

Công nghệ
python
Lĩnh vực
api, devtools
Loại issue
Lỗi
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/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.