Skip to content

fix(mcp): add boundary validation for timeout configurations and fix … - #282

Open
Khush7Chauhan wants to merge 1 commit into
accordproject:mainfrom
Khush7Chauhan:fix/mcp-timeout-validation
Open

Khush7Chauhan wants to merge 1 commit into
accordproject:mainfrom
Khush7Chauhan:fix/mcp-timeout-validation

Conversation

@Khush7Chauhan

@Khush7Chauhan Khush7Chauhan commented Nov 10, 2026 •

Copy link
Copy Markdown

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

Copilot AI balanced review requested due to automatic review settings November 10, 2026 13:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@JayDS22 JayDS22 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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).
  2. The null-coalescing hunk's comment claims an MCP SDK constraint, but the MCP Resource type only declares uri, 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.
  3. 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.

@Khush7Chauhan
Khush7Chauhan force-pushed the fix/mcp-timeout-validation branch from 3aa719c to c3349a8 Compare November 11, 2026 04:47
@Khush7Chauhan

Khush7Chauhan commented Nov 11, 2026 •

Copy link
Copy Markdown
Author

@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.
Summary of updates:

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.
Let me know if these tests cover everything you had in mind, or if any further adjustments are needed!

@JayDS22 JayDS22 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@Khush7Chauhan
Khush7Chauhan force-pushed the fix/mcp-timeout-validation branch from 76b75e9 to 16d22f3 Compare November 15, 2026 16:42
@Khush7Chauhan

Khush7Chauhan commented Nov 15, 2026 •

Copy link
Copy Markdown
Author

@JayDS22 — the follow-up PR is up: #299
#299
It restores the two hunks split out of #282:

  • the full ?? undefined mappings in the agreement and template listResources callbacks
  • "ignoreDeprecations": "6.0" in server/tsconfig.json

Let me know if you need any changes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/kind:bugfix maintainer-engaged A maintainer has commented or reviewed this item

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Invalid MCP timeout configurations cause immediate session expiration or cleanup hot loops

3 participants