feat(mcp): re-export UnauthorizedError so hosts can detect auth failures - #7
Merged
Merged
Conversation
A host that wants to react to a mid-session authorization failure — the one case where the transport gives up and needs a human — had no way to recognise it. The SDK's UnauthorizedError never assigns `this.name`, so it reads as "Error"; matching on the name silently never fires, and matching on the message would also catch a tool whose own error text happens to mention "unauthorized". Exporting the class from the subpath gives an identity check that works against the same module instance the connector uses. Found by review of the React bindings, where exactly this check was dead code. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011FKop4At26QqqkwVGEjJur
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.
Why
A host that wants to react to a mid-session authorization failure — the one case where the transport gives up and a human has to re-authorize — had no way to recognise it.
The SDK's
UnauthorizedErrorextendsErrorbut never assignsthis.name:so
err.nameis"Error". A host checkingerr.name === 'UnauthorizedError'silently never matches, and matching on the message would also catch a tool whose own error text happens to say "unauthorized" (our connector throws the server's text verbatim forisErrorresults). Without the class itself, there is no reliable handle.Found by review of the React bindings (dudko-dev/agent-web-react#3), where that check was dead code: the panel kept reporting "connected" while every tool call failed.
What
./mcpre-exportsUnauthorizedErrorfrom the SDK, so an identity check runs against the same module instance the connector uses. One line of surface; no behaviour change.The accompanying test pins the assumption this export exists for — if the SDK ever starts setting
name, the test says so rather than leaving a silently redundant export behind.typecheck,format:check,build,test(90 passing) are green. Version bumped to0.0.12so the release workflow publishes it.Generated by Claude Code