Skip to content

Conversation

@clouatre
Copy link
Contributor

Fixes #25

Problem

Multiple instances connecting to the same server URL with different --resource flags share OAuth sessions and connect to the wrong tenant.

Solution

Include authorizeResource and custom headers in the serverUrlHash calculation to isolate OAuth sessions per unique configuration.

Changes

  • Modified getServerUrlHash() to include resource and headers in hash calculation
  • Calculate hash once in parseCommandLineArgs() with all parameters
  • Pass hash through stack to NodeOAuthClientProvider
  • Each unique config gets isolated lockfile and token storage

Testing

  • ✅ Added 6 unit tests for hash generation (all passing, 50/50 total)
  • ✅ Tested with real multi-tenant Atlassian setup
  • ✅ Both instances connect to correct tenants
  • ✅ Separate OAuth sessions maintained
  • ✅ Backward compatible (one-time re-auth for existing users)

Example (multiple Atlassian tenants)

{
  "mcpServers": {
    "atlassian_tenant1": {
      "command": "npx",
      "args": ["mcp-remote", "https://mcp.atlassian.com/v1/sse", "--resource", "https://tenant1.atlassian.net/"]
    },
    "atlassian_tenant2": {
      "command": "npx",
      "args": ["mcp-remote", "https://mcp.atlassian.com/v1/sse", "--resource", "https://tenant2.atlassian.net/"]
    }
  }
}

Multiple instances connecting to the same server URL with different
--resource flags or custom headers now maintain separate OAuth sessions.

Changes:
- Include authorizeResource and headers in serverUrlHash calculation
- Calculate hash once in parseCommandLineArgs with all parameters
- Pass hash through stack to eliminate duplicate calculations
- Each unique config gets isolated lockfile and token storage
- Backward compatible: existing configs trigger one-time re-auth

Fixes geelen#25
@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 4, 2025

Open in StackBlitz

npx https://pkg.pr.new/mcp-remote@175

commit: 2e769c2

@geelen geelen merged commit 5224f7a into geelen:main Nov 5, 2025
3 checks passed
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.

Can't Run Multiple mcp-remote Servers at the Same Time

2 participants