Skip to content

Support custom post-auth redirect uri #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ To bypass authentication, or to emit custom headers on all requests to your remo
```json
"command": "npx",
"args": [
"-y"
"-y",
"mcp-remote",
"https://remote.mcp.server/sse"
]
Expand Down Expand Up @@ -131,6 +131,14 @@ npx mcp-remote https://example.remote/server --transport sse-only
- `http-only`: Only uses HTTP transport, fails if the server doesn't support it
- `sse-only`: Only uses SSE transport, fails if the server doesn't support it

### Post-Auth Redirect URI

To customize the redirect behavior after an OAuth flow, include a `postAuthRedirectUri` query parameter in the request to the OAuth callback endpoint. This parameter specifies where users should be redirected after successful authentication.

Ensure that your server appends `postAuthRedirectUri` as a query parameter when invoking the `redirectUri`.

Once authentication is complete, users will be redirected to the specified URI instead of seeing the default "Authorization successful" message. This allows you to deliver a smoother user experience by guiding users to a custom post-authentication page.

### Claude Desktop

[Official Docs](https://modelcontextprotocol.io/quickstart/user)
Expand Down
8 changes: 7 additions & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,12 @@ export function setupOAuthCallbackServerWithLongPoll(options: OAuthCallbackServe
log('Auth code received, resolving promise')
authCompletedResolve(code)

res.send(`
const postAuthRedirectUri = req.query.postAuthRedirectUri as string | undefined
if (postAuthRedirectUri) {
log(`Redirecting to post-auth redirect URI: ${postAuthRedirectUri}`)
res.redirect(postAuthRedirectUri)
} else {
res.send(`
Authorization successful!
You may close this window and return to the CLI.
<script>
Expand All @@ -317,6 +322,7 @@ export function setupOAuthCallbackServerWithLongPoll(options: OAuthCallbackServe
window.close();
</script>
`)
}

// Notify main flow that auth code is available
options.events.emit('auth-code-received', code)
Expand Down