Repository navigation
fix(mcp): add boundary validation for timeout configurations and fix … - #282
Khush7Chauhan wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
There was a problem hiding this comment.
parseEnvMs direction is right. Number(val) over parseInt(val, 10) is the right choice, and !Number.isSafeInteger(parsed) || parsed <= 0 correctly rejects zero, negatives, non-integers, and >2^53.
Three blockers:
- Missing tests for the boundary cases that are the whole point of the PR (
parseEnvMs('0', 1000)throws,parseEnvMs('-5', 1000)throws,parseEnvMs('5abc', 1000)throws,parseEnvMs(' ', 1000)returns default). - The null-coalescing hunk's comment claims an MCP SDK constraint, but the MCP
Resourcetype only declaresuri,name,title?,description?,mimeType?,size?,_meta?. The APAP fields being coalesced aren't declared there, so the type error isn't where the comment says. Paste the actual compiler error so the real cause is visible. tsconfig.json: "ignoreDeprecations": "6.0"needs the specific deprecation named. The flag suppresses a warning rather than fixing the cause.
Suggest splitting: parseEnvMs alone with the boundary tests, type-and-tsconfig changes as a follow-up PR with the compiler error output. Also worth a release note that this is now a boot-time throw on misconfig instead of a silent default.
3aa719c to
c3349a8
Compare
|
@JayDS22 Thanks for the review and for catching the scope creep! I completely agree with splitting this up and have amended/force-pushed to align exactly with your feedback. 1:Scope Reduced: Reverted the TypeScript/tsconfig changes. I will open a separate follow-up PR with the raw compiler output shortly so we can discuss the best mapping approach. 2:Tests Added: Added the requested unit tests covering all boundary cases (0, negatives, non-integers, and empty strings). 3:Timer Limit Handled : Added an upper-bound check (MAX_TIMEOUT_MS) to prevent Node.js from silently wrapping oversized timers to 1ms, alongside a matching test. Release Note: Added the boot-time throw behavior to the main PR description. |
c3349a8 to
76b75e9
Compare
JayDS22
left a comment
There was a problem hiding this comment.
Scope-split looks right. Six boundary tests cover the cases that were missing, and the MAX_TIMEOUT_MS = 2147483647 catch is a real bonus (Node silently wraps > 2^31-1 to 1ms). Owed as follow-up: the separate PR with the compiler-error output for the null-coalescing / tsconfig change you split out.
Signed-off-by: khush chauhan <khushchauhan2006@gmail.com>
76b75e9 to
16d22f3
Compare
Closes #281
As discussed in review, this PR is now strictly scoped to addressing the missing boundary validation for time-based environment variables in the MCP integration, preventing potential event loop blocking and instantaneous session expirations.
(Note: The TypeScript SDK type mismatch and tsconfig.json deprecation warnings will be addressed in a focused follow-up PR to allow for architectural discussion on data mapping).
Changes
mcp.ts: Introduced parseEnvMs to strictly validate SESSION_TIMEOUT_MS and CLEANUP_INTERVAL_MS as positive integers.
Tests: Added boundary tests for parseEnvMs verifying rejection of 0, negatives, non-integers, oversized 32-bit values, and fallback behavior for empty strings.
Release Note
Breaking / Behavior Change: Invalid time-based MCP configurations (e.g., <= 0, non-integers, or oversized values) will now cause a boot-time throw rather than silently falling back to defaults or causing runtime degradation.
(Note: MAX_TIMEOUT_MS sits directly above parseEnvMs, so the module-level calls for SESSION_TIMEOUT_MS and CLEANUP_INTERVAL_MS explicitly reject oversized values at startup rather than allowing Node.js to silently wrap them to 1ms).
Flags
Prevents resource exhaustion (CPU hot looping) caused by CLEANUP_INTERVAL_MS=0.
Related Issues
Resolves Issue #281