claude-code - 💡(How to fix) Fix MCP tool_use arg validation rejects valid large string payloads (~16KB+) before transit [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#55923Fetched 2026-05-05 06:02:50
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
labeled ×3

Calling an MCP tool with a large string argument (~13–16KB markdown content) fails inside Claude Code's MCP client layer before any HTTP request reaches the MCP server. The MCP server independently accepts payloads 5x larger via direct invocation, indicating the rejection happens client-side, not at the protocol or server boundary.

Error Message

  • Call fails before transit with a validation-shaped error (failure mode looks Zod-flavored)
  • Are documented and surface a clear "size limit exceeded" error to the model so the model can chunk

Root Cause

Calling an MCP tool with a large string argument (~13–16KB markdown content) fails inside Claude Code's MCP client layer before any HTTP request reaches the MCP server. The MCP server independently accepts payloads 5x larger via direct invocation, indicating the rejection happens client-side, not at the protocol or server boundary.

Fix Action

Workaround

Added a defensive UX hint to the affected tool's description telling callers to expect the ~13–16KB limit and chunk longer content. This is a band-aid — the real fix is removing or documenting the client-side cap.

RAW_BUFFERClick to expand / collapse

Summary

Calling an MCP tool with a large string argument (~13–16KB markdown content) fails inside Claude Code's MCP client layer before any HTTP request reaches the MCP server. The MCP server independently accepts payloads 5x larger via direct invocation, indicating the rejection happens client-side, not at the protocol or server boundary.

Environment

  • Claude Code: 2.1.126
  • OS: macOS 26.4.1 (build 25E253)
  • MCP server: custom mcp-lite-based server (Supabase Edge Function backing)
  • Tool affected: save_file (writes a file artifact, accepts content: string)
  • Tool argument schema: standard JSON Schema, content: { type: "string" } with no maxLength declared

Repro

  1. Configure a custom MCP server with a tool accepting a content: string parameter (no maxLength in the declared schema)
  2. From Claude Code, invoke the tool with content containing a markdown payload of ~16KB or more
  3. Observe the call fails inside Claude Code before any HTTP request reaches the MCP server

Expected

The tool call should be transmitted to the MCP server with the content argument intact. Per MCP spec, tool argument validation beyond shape is the server's responsibility — clients should not enforce hidden size ceilings that aren't declared in the tool schema.

Actual

  • Call fails before transit with a validation-shaped error (failure mode looks Zod-flavored)
  • No call log row appears on the MCP server
  • The same call with a smaller payload (e.g., 8KB) succeeds and produces a server log row
  • Direct invocation of the same tool's underlying server function (bypassing the Claude Code MCP client) succeeds with payloads up to 68,117 bytes — over 5x the failing client-side size

Evidence

TestPayload sizeResult
Direct server invocation (bypassing Claude Code MCP client)68,117 bytes✅ Success, returns artifact ID
Via Claude Code MCP client~16KB❌ Fails before transit
Via Claude Code MCP client~8KB✅ Success

The MCP server's storage column is text (unbounded). The tool's JSON Schema declares content: { type: "string" } with no maxLength. There's no documented size limit on the Claude Code side either.

Why it matters

  • Tool authors building large-text tools (markdown editors, code-gen tools, file-write tools, document processors) hit a silent ceiling that's not in their schema or server config
  • The failure mode is opaque — users see a generic validation rejection, not a "size limit" message, making it look like the tool itself is broken
  • Workarounds require defensive client-side chunking the protocol doesn't require, or surfacing the size cap as defensive UX in tool descriptions

Suggested investigation

Check whether Claude Code's MCP client applies argument-value validation (e.g., via a Zod or similar runtime schema layer) on top of MCP's required shape validation. If yes, verify that any implicit string-length caps either:

  • Match the declared tool schema's `maxLength` (if present), or
  • Are configurable, or
  • Are documented and surface a clear "size limit exceeded" error to the model so the model can chunk

Per MCP spec (https://modelcontextprotocol.io/specification), argument validation beyond shape is the server's responsibility. A client-side cap that overrides the declared schema breaks the contract.

Workaround

Added a defensive UX hint to the affected tool's description telling callers to expect the ~13–16KB limit and chunk longer content. This is a band-aid — the real fix is removing or documenting the client-side cap.

extent analysis

TL;DR

The most likely fix is to remove or configure the implicit string-length cap in Claude Code's MCP client to match the declared tool schema or make it configurable.

Guidance

  • Investigate if Claude Code's MCP client uses a runtime schema layer like Zod for argument-value validation and check for any implicit string-length caps.
  • Verify if the implicit string-length caps match the declared tool schema's maxLength or are configurable.
  • Consider surfacing a clear "size limit exceeded" error to the model to allow for chunking.
  • Check the MCP spec to ensure the client-side validation does not override the server's responsibility for argument validation beyond shape.

Example

No code snippet is provided as the issue does not contain sufficient information to generate a specific example.

Notes

The issue seems to be related to the client-side validation in Claude Code's MCP client, which may be using a library like Zod. The exact solution depends on the implementation details of the client.

Recommendation

Apply a workaround by adding a defensive UX hint to the affected tool's description, telling callers to expect the ~13–16KB limit and chunk longer content, while investigating the root cause and removing or configuring the implicit string-length cap.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING