Skip to content

fix: detect auth errors from error.code property (StreamableHTTPError…#94

Open
KentonYu wants to merge 1 commit intosteipete:mainfrom
KentonYu:fix/error-code-auth-detection
Open

fix: detect auth errors from error.code property (StreamableHTTPError…#94
KentonYu wants to merge 1 commit intosteipete:mainfrom
KentonYu:fix/error-code-auth-detection

Conversation

@KentonYu
Copy link

@KentonYu KentonYu commented Mar 3, 2026

Summary

  • MCP SDK's StreamableHTTPError(401, ...) and SseError store the HTTP status code in error.code, but the message
    text may not contain the numeric status code (e.g., "Error POSTing to endpoint: {}")
  • analyzeConnectionError previously only parsed the message string to extract status codes, missing error.code
    entirely
  • This caused OAuth promotion to not trigger for Streamable HTTP 401 responses, falling back to legacy SSE transport
    (GET), which the server doesn't support — resulting in a confusing 404 error

Changes

  • src/error-classifier.ts: Add extractErrorCode() helper that reads error.code as a numeric HTTP status
    (100–599). This source takes priority over message-text parsing in analyzeConnectionError
  • tests/error-classifier.test.ts: Add tests for error.code extraction — 401/403 → auth, 404 → http, 500 →
    http, no code → regression check
  • tests/runtime-oauth-detection.test.ts: Add test confirming isUnauthorizedError returns true for errors with
    code: 401 even when message lacks "401"

Test plan

  • npx vitest run tests/error-classifier.test.ts tests/runtime-oauth-detection.test.ts — 21 tests pass
  • Full test suite — no regressions from this change

…/SseError)

MCP SDK's StreamableHTTPError/SseError store the HTTP status code in
error.code, but the message text may not contain the numeric status.
analyzeConnectionError now reads error.code (100-599) before falling
back to message-text parsing, so OAuth promotion triggers correctly
for 401 responses on Streamable HTTP transport.
@KentonYu
Copy link
Author

@steipete Could you take a look at this PR? Currently, its logic for judging 401 is not very standard

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.

1 participant