fix(mcp): keep truncated tool descriptions within the length cap#432
Open
Alan-Yu-2077 wants to merge 1 commit into
Open
fix(mcp): keep truncated tool descriptions within the length cap#432Alan-Yu-2077 wants to merge 1 commit into
Alan-Yu-2077 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
truncateMcpToolDescription()is documented as clamping MCP tool descriptions toMAX_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.lengthbefore the marker is appended. The returned string is now at mostMAX_MCP_TOOL_DESCRIPTION_LENGTHcharacters.Fixes #423
Test plan
Added
tests/mcp/truncate.spec.tscovering the boundary:MAX_MCP_TOOL_DESCRIPTION_LENGTHcharacters and still ends with the marker;Full suite (
npm test) stays green.