Issue
Users see redirect_uri mismatch OAuth error when restarting their MCP client.
What's happening
From the information I managed to gather, here is what I think is happening :
- port 3334 is used by another process on the machine, a random port is chosen to start the callback server
- the only location the port is written to is the lockfile (together with pid)
- a new OAuth client is registered with a callback uri including the random port
- first auth is happening without any issue
- at first MCP client shutdown, lockfile is cleaned by
cleanupHandler process
- when restarted, the MCP client uses port 3334 if free, or chose another random port
- there is a redirect_uri mismatch error because the port in the redirect URL used during client creation differs from the one used at the moment
Temporary solution
In the meantime, I'll add a less frequently used port in the config to increase chances request port is actually used all the time by mcp-remote.
Long term solution
Here is my proposal, happy to submit a PR if you're fine with it :) :
- add port to
client_info.json (or keep it as it is, and parse the first URL in redirect_uris to extract port information)
- use this value as port target value for callback server starting
- on server started, check that this port is actually the one being used by the server (it did not fallback to another port) - exit early if it does, not a chance the process will succeed
Issue
Users see redirect_uri mismatch OAuth error when restarting their MCP client.
What's happening
From the information I managed to gather, here is what I think is happening :
cleanupHandlerprocessTemporary solution
In the meantime, I'll add a less frequently used port in the config to increase chances request port is actually used all the time by mcp-remote.
Long term solution
Here is my proposal, happy to submit a PR if you're fine with it :) :
client_info.json(or keep it as it is, and parse the first URL inredirect_uristo extract port information)