Skip to content

Fix: Store auth tokens with server-specific keys#317

Merged
cliffhall merged 2 commits into
modelcontextprotocol:mainfrom
geelen:fix-auth-server-specific-storage
Apr 16, 2025
Merged

Fix: Store auth tokens with server-specific keys#317
cliffhall merged 2 commits into
modelcontextprotocol:mainfrom
geelen:fix-auth-server-specific-storage

Conversation

@geelen
Copy link
Copy Markdown
Contributor

@geelen geelen commented Apr 16, 2025

This PR adds server-specific storage for auth tokens and client information in sessionStorage.

Problem

When changing the server URL in the sidebar, the inspector would try to reuse any client information or auth tokens that it had stored in sessionStorage, but they wouldn't make any sense to the new server. This was driving me crazy as I kept thinking there was a flake on the server side or in our library: https://github.com/cloudflare/workers-oauth-provider)

Fix

  • Created a helper function to prefix storage keys with server URL
  • Refactored InspectorOAuthClientProvider to require a server URL as a constructor parameter
  • Updated components to create provider instances with their specific server URL
  • Fixed tests to work with the new implementation

This ensures that tokens and client information are properly isolated between different servers:

image

This should be a lot more reliable now.

Changes client information and access tokens to use server-specific keys in sessionStorage. This fixes issues where changing the server URL would try to use tokens from a different server.
@geelen geelen marked this pull request as ready for review April 16, 2025 00:39
Copy link
Copy Markdown
Member

@cliffhall cliffhall left a comment

Choose a reason for hiding this comment

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

Code, build, test, lint, manual inspection all works on my machine. LGTM! 👍

Screenshot 2025-04-16 at 3 31 42 PM

@cliffhall cliffhall merged commit 78cd701 into modelcontextprotocol:main Apr 16, 2025
2 checks passed
@cliffhall
Copy link
Copy Markdown
Member

Thanks for this @geelen!

IgnacioC44 referenced this pull request in MCPJam/inspector Jun 21, 2025
Fix: Store auth tokens with server-specific keys
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.

2 participants