-
Notifications
You must be signed in to change notification settings - Fork 126
Description
Bug description
If the port specified with --remote-auth-callback-port
or in the UI is already in use, it seems ToolHive selects a random port instead. But, the authentication flow fails.
Steps to reproduce
Run a remote MCP server from the CLI or in the UI and specify a port that is already in use (specifically, one that is bound to 127.0.0.1) on your system.
thv run notion-remote --remote-auth-callback-port <SOME_IN_USE_PORT>
One way to reproduce is to run a local MCP using ToolHive, then try to use its port for the remote-auth-callback-port:
thv run fetch
thv list
# get its listening port...
thv run notion-remote --remote-auth-callback-port <FETCH_PORT>
Expected behavior
I would expect ToolHive to error out because the port is already in use.
IF it's going to "silently" select a different, random port, I'd expect a message in the output and for authentication to work using the random port.
Actual behavior
The notion authorization browser flow opens, shows the randomly-selected port in the callback URL, but the auth fails with an error:
failed to exchange code for token: oauth2: "invalid_grant" "Invalid redirect URI"



Environment (if relevant)
- OS/version: macOS, Docker Desktop
- ToolHive version: v0.3.7