Skip to content

Redirect_uri mismatch for remote server with OAuth authentification on 2nd start when default port is taken #72

Description

@fredericbarthelet

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions