Support multiple active mcp-remote servers #39
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.
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:
mcp-remote
processes running.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 urlhttp://127.0.0.1:3334/oauth/callback
<- please pay attention to the port being3334
here.mcp-remote
processes start, they check for an existing lock file. If the lock file is valid, auth flow uses the original process (using port3334
). 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 using3334
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 containshttp://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:
mcp-remote
processes running.mcp-remote
process is created (on default port 3334) - we now reuse the previously created tokens.mcp-remote
processes will fail to log in becauseauthCompletedPromise
is never resolved.authCompletedPromise
is not resolved because the first process already had valid auth token, therefore/oauth/callback
was never called.