fix(mcp): validate and clamp 'days' argument in list_reports/search#409
Open
nankingjing wants to merge 1 commit into
Open
fix(mcp): validate and clamp 'days' argument in list_reports/search#409nankingjing wants to merge 1 commit into
nankingjing wants to merge 1 commit into
Conversation
Author
|
Reviewed — clampDays correctly guards NaN/negative/zero with a fallback; much more robust than the bare Math.min. Ready for review. |
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.
Problem
toolListReportsandtoolSearchinmcp/src/index.tscompute the number of recent days to return with:This only clamps the upper bound. It has no lower bound and no NaN guard, so a malformed
daysargument from an MCP client produces incorrect results when fed todates.slice(0, days):daysargumentdaysvaluedates.slice(0, days)result"abc"(non-numeric)NaNslice(0, NaN)→ 0 reports (silent empty)00-5(negative)-5slice(0, -5)→ "all but the oldest 5"The negative case is the worst:
slice(0, -N)counts from the end, so it returns almost everything and the count is size-dependent — with 3 dates it returns 0, with 10 it returns 5, with 25 it returns 20. A "last -5 days" request should never return more data than "last 3 days".Fix
Add a small
clampDays()helper that parses the argument, rejects non-finite / sub-1 values (falling back to the default), and clamps to the max — then use it in both tools.Behavior is unchanged for all valid inputs (
undefined,null,3,40,"5"all behave exactly as before); only garbage input is corrected to the documented default.Verification
Ran isolated Node tests replicating the
slicelogic against a fake manifest:-5→ size-dependent result).Also ran, on the edited file:
prettier --checkagainst the repo.prettierrc→ clean.tsc --noEmitagainstmcp/tsconfig.json(strict) → no errors.No behavioral change to any other code path; no reformatting.