Skip to content

Support multiple active mcp-remote servers #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

emilisb
Copy link

@emilisb emilisb commented Apr 25, 2025

This is my attempt to solve #25

I found 2 main problems that were causing issues with multiple mcp-remote processes.

I already described the problems in the issue ticket but I will repeat myself here as well (with some updates to my explanation):

Issue 1

Preconditions:

  • User is not authenticated yet.
  • No lock file, no tokens file.
  • No active mcp-remote processes running.
  1. When the first mcp-remote process is started, the auth http server is listening on port 3334 (default).
    1.1. A new lockfile is created (with current timestamp and port 3334).
    1.2. Auth flow starts and new token files are written to disk.
    1.3. client_info.json contains callback url http://127.0.0.1:3334/oauth/callback <- please pay attention to the port being 3334 here.
  2. When additional mcp-remote processes start, they check for an existing lock file. If the lock file is valid, auth flow uses the original process (using port 3334). Everything is working fine here.

The tricky part begins when more than 30 minutes have passed since the original process start time. Lock files older than 30 minutes are considered invalid (link to code), therefore a new lock file will be created. However, this time the port might not be 3334 - if the original process using 3334 is still running, the process will choose a random port and this new process will become the new "master" process (responsible for auth of other processes).

The problem is that now the new process has a different port than the previous one, therefore the new callback url is different. However, client_info.json still contains http://127.0.0.1:3334/oauth/callback. This causes oauth token verification to fail on the remote server and you can no longer connect to the MCP server until you remove old tokens from ~/.mcp-auth.

To fix it, I removed the 30 minutes timestamp limit - I believe pid + port checks might be good enough. @geelen do you remember if there was any specific reason for this check?

Issue 2

Preconditions:

  • User is authenticated and a valid auth token is saved to file.
  • No active mcp-remote processes running.
  1. The initial mcp-remote process is created (on default port 3334) - we now reuse the previously created tokens.
  2. From now on, all future mcp-remote processes will fail to log in because authCompletedPromise is never resolved.

authCompletedPromise is not resolved because the first process already had valid auth token, therefore /oauth/callback was never called.

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