Skip to content

fix: structured success:false envelope for session-lifecycle failures in all session-scoped tools - #205

Merged
debugmcpdev merged 1 commit into
mainfrom
fix-203-session-not-found-envelope
Jul 23, 2026
Merged

fix: structured success:false envelope for session-lifecycle failures in all session-scoped tools#205
debugmcpdev merged 1 commit into
mainfrom
fix-203-session-not-found-envelope

Conversation

@debugmcpdev

Copy link
Copy Markdown
Collaborator

What

Fixes #203.

For an unknown/stale sessionId, pause_execution and list_threads threw protocol-level McpError while sibling tools returned structured {success: false, error} results.

Investigation showed the drift is wider than the issue reports: validateSession threw a plain McpError, never the typed SessionNotFoundError/SessionTerminatedError — so the typed-error conversion branches in get_variables/get_stack_trace/get_scopes were dead code too, and those tools also threw protocol errors for unknown sessions. Their unit tests masked this with try/catch shims that normalized a thrown error into the asserted {success:false} shape.

Changes

  • validateSession throws the typed SessionNotFoundError / SessionTerminatedError (same codes/messages, both extend McpError) — the issue's suggested fix: the dead typed-error branches become live.
  • handlePause: typed-error conversion moved ahead of the McpError re-throw that made it unreachable.
  • handleListThreads, handleGetSourceContext: same typed-conversion branch added.
  • Every session-scoped tool now returns {success: false, error} for unknown/terminated sessions, matching the contract already documented in docs/error-handling-guide.md (Pattern 2). Protocol-level McpError remains for invalid parameters (missing sessionId) and unexpected internal errors.
  • Tests pin the envelope (shims removed); new terminated-session coverage for pause/list_threads.
  • Docs: error-handling-guide layer descriptions tightened; tool-reference no longer lists "session not found" under -32603.

Verification

  • Targeted suites (server-control-tools, server-coverage, server-inspection-tools): 126 passed.
  • Full unit suite: 154 files / 2,490 tests passed; integration green via pre-push hook; lint clean.

🤖 Generated with Claude Code

…n all session-scoped tools (#203)

For an unknown or terminated sessionId, pause_execution and list_threads
threw protocol-level McpError while sibling tools returned structured
{success: false, error} results. Investigation showed the drift was wider
than reported: validateSession threw a plain McpError, so the typed-error
conversion branches in get_variables / get_stack_trace / get_scopes were
dead code and those tools also threw; their unit tests masked it by
normalizing thrown errors into the asserted shape.

Align everything with the contract documented in
docs/error-handling-guide.md (Pattern 2):

- validateSession now throws the typed SessionNotFoundError /
  SessionTerminatedError (same codes and messages, both extend McpError),
  making the existing typed-conversion branches live.
- handlePause: typed-error conversion moved ahead of the McpError
  re-throw (it was unreachable dead code behind it).
- handleListThreads and handleGetSourceContext: same typed-conversion
  branch added ahead of the McpError re-throw.
- Protocol-level McpError remains for invalid-parameter checks (missing
  sessionId etc.) and unexpected internal errors.

Tests updated to pin the envelope (including removing the try/catch
shims that tolerated either behavior) plus new terminated-session
coverage for pause/list_threads. Docs: error-handling-guide wording
tightened; tool-reference no longer lists session-not-found under -32603.

Fixes #203

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/server.ts 90.90% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@debugmcpdev
debugmcpdev merged commit be84732 into main Jul 23, 2026
10 checks passed
@debugmcpdev
debugmcpdev deleted the fix-203-session-not-found-envelope branch July 23, 2026 20:31
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.

Inconsistent session-not-found error envelope: pause_execution and list_threads throw McpError while sibling tools return structured success:false

2 participants