Skip to content

fix: add validation and warnings for large MCP tool arguments #6116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

roomote[bot]
Copy link

@roomote roomote bot commented Jul 23, 2025

Fixes #6108

Problem

MCP tool calls were being truncated around 4000 characters when passing large JSON arguments. This was happening because some language models have internal limits on the size of tool call arguments they can generate.

Solution

Added validation in the MCP tool handler to:

  1. Detect when arguments appear to be truncated (invalid JSON ending around 4000 chars)
  2. Show helpful error messages explaining the truncation and suggesting smaller data chunks
  3. Warn users when arguments are large but still valid JSON (over 3800 chars)

Changes

  • Modified useMcpToolTool.ts to add truncation detection and validation
  • Added comprehensive tests for the new validation logic
  • Error messages guide users to break operations into smaller chunks

Testing

  • Added 4 new test cases covering:
    • Large but valid JSON arguments (warning case)
    • Truncated JSON arguments (error case)
    • JSON ending with incomplete array (truncation detection)
    • Normal invalid JSON (existing behavior preserved)
  • All existing tests continue to pass

This provides a better user experience by clearly explaining when and why MCP tool calls fail due to size limitations.


Important

Adds validation and warnings for large MCP tool arguments in useMcpToolTool.ts, improving error handling for truncated JSON.

  • Behavior:
    • Adds validation in useMcpToolTool.ts to detect truncated JSON arguments and warn users for large but valid JSON (over 3800 chars).
    • Provides error messages for truncated JSON, suggesting smaller data chunks.
  • Testing:
    • Adds 4 new test cases in useMcpToolTool.spec.ts for large JSON warnings, truncated JSON errors, incomplete array detection, and normal invalid JSON.
    • Ensures all existing tests pass.
  • Misc:
    • Error messages guide users to break operations into smaller chunks.

This description was created by Ellipsis for 266ee8e. You can customize this summary. It will automatically update as commits are pushed.

- Add detection for potentially truncated MCP tool arguments (around 4000 chars)
- Show helpful error messages when truncation is detected
- Warn users when arguments are large but still valid JSON
- Add comprehensive tests for the new validation logic

Fixes #6108
@roomote roomote bot requested review from mrubens, cte and jr as code owners July 23, 2025 13:32
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jul 23, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 23, 2025
@daniel-lxs
Copy link
Collaborator

The issue doesn't have enough information to propose a fix yet, closing

@daniel-lxs daniel-lxs closed this Jul 24, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 24, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Calls to external tools using use_mcp_tool are truncated
3 participants