Fix: Ensure OAuth server is listening before accessing its address #152
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.
Summary
This PR fixes a race condition where
server.address()
could returnnull
if called before the Express server finished binding to its port, causing a TypeError when trying to access theport
property.Problem
When using mcp-remote with OAuth-enabled servers (like Atlassian), the application would crash with:
This occurred because:
app.listen()
is asynchronous and returns immediatelyserver.address()
returnsnull
until the server has started listeningSolution
Modified
setupOAuthCallbackServerWithLongPoll
to return a Promise that resolves only after the server has successfully started listening. This ensuresserver.address()
will always return a valid address object.Changes
setupOAuthCallbackServerWithLongPoll
async and wrap the server creation in a PromisesetupOAuthCallbackServer
to await the async functioncoordinateAuth
to await the setup functionTesting
Tested locally by:
npm run build
npm link
mcp-remote https://mcp.atlassian.com/v1/sse
Related Issues
This fixes issues reported by users when connecting to OAuth-enabled MCP servers, particularly Atlassian's MCP implementation.