Skip to content

fix(mcp): keep truncated tool descriptions within the length cap#432

Open
Alan-Yu-2077 wants to merge 1 commit into
OpenBMB:mainfrom
Alan-Yu-2077:fix/mcp-tool-description-truncation-limit
Open

fix(mcp): keep truncated tool descriptions within the length cap#432
Alan-Yu-2077 wants to merge 1 commit into
OpenBMB:mainfrom
Alan-Yu-2077:fix/mcp-tool-description-truncation-limit

Conversation

@Alan-Yu-2077

Copy link
Copy Markdown

Summary

truncateMcpToolDescription() is documented as clamping MCP tool descriptions to MAX_MCP_TOOL_DESCRIPTION_LENGTH (2048) characters, but for any over-limit input it sliced the string to 2048 characters and then appended the "… [truncated]" marker. The returned string was therefore 2061 characters — longer than the advertised cap.

This fix reserves the marker length inside the cap, so an over-limit description is sliced to MAX_MCP_TOOL_DESCRIPTION_LENGTH - marker.length before the marker is appended. The returned string is now at most MAX_MCP_TOOL_DESCRIPTION_LENGTH characters.

Fixes #423

Test plan

Added tests/mcp/truncate.spec.ts covering the boundary:

  • input exactly at the limit is returned unchanged;
  • input one character over the limit returns exactly MAX_MCP_TOOL_DESCRIPTION_LENGTH characters and still ends with the marker;
  • a very large (30k) description is clamped to the limit.
$ node --test dist/tests/mcp/truncate.spec.js
# tests 3
# pass 3
# fail 0

Full suite (npm test) stays green.

truncateMcpToolDescription sliced to MAX_MCP_TOOL_DESCRIPTION_LENGTH and
then appended the "… [truncated]" marker, so any over-limit description
returned 2048 + marker characters and contradicted the documented clamp.

Reserve the marker length inside the cap so the returned string is at most
MAX_MCP_TOOL_DESCRIPTION_LENGTH characters, and add regression tests at and
just past the boundary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP tool description truncation can exceed the documented 2048-character limit

1 participant