fix: detect auth errors from error.code property (StreamableHTTPError…#94
Open
KentonYu wants to merge 1 commit intosteipete:mainfrom
Open
fix: detect auth errors from error.code property (StreamableHTTPError…#94KentonYu wants to merge 1 commit intosteipete:mainfrom
KentonYu wants to merge 1 commit intosteipete:mainfrom
Conversation
…/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.
Author
|
@steipete Could you take a look at this PR? Currently, its logic for judging 401 is not very standard |
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.
Summary
StreamableHTTPError(401, ...)andSseErrorstore the HTTP status code inerror.code, but the messagetext may not contain the numeric status code (e.g.,
"Error POSTing to endpoint: {}")analyzeConnectionErrorpreviously only parsed the message string to extract status codes, missingerror.codeentirely
(GET), which the server doesn't support — resulting in a confusing 404 error
Changes
src/error-classifier.ts: AddextractErrorCode()helper that readserror.codeas a numeric HTTP status(100–599). This source takes priority over message-text parsing in
analyzeConnectionErrortests/error-classifier.test.ts: Add tests forerror.codeextraction — 401/403 → auth, 404 → http, 500 →http, no code → regression check
tests/runtime-oauth-detection.test.ts: Add test confirmingisUnauthorizedErrorreturns true for errors withcode: 401even when message lacks "401"Test plan
npx vitest run tests/error-classifier.test.ts tests/runtime-oauth-detection.test.ts— 21 tests pass