OAuth Integration Guide
MCP servers for providers like Google, Slack, GitHub, Notion, and others use OAuth - the same login flow your users already know ("Sign in with Google"). MewCP handles the entire OAuth lifecycle for you: token exchange, encrypted storage, and automatic refresh. You never touch a raw access token.
What MewCP does for you
- Runs the OAuth handshake with the provider on your behalf
- Encrypts and stores the access token and refresh token in MewCP's vault
- Automatically refreshes tokens before they expire - no token management on your side
- Ties every credential to an
externalUserIdyou supply, so you can identify which of your users connected which account
Before you start
-
Add the MCP server to your subscription - the provider (e.g.
google,github) must be an active server in your MewCP subscription. If it isn't, the API returns403. Do this from Dashboard → Add Server. -
Register your OAuth app and assign it to a business-mode server key: go to Dashboard (mode=business) → Servers → select server → Register OAuth Client, add your
client_idandclient_secretfrom the provider (e.g. Google Cloud Console, Slack API, GitHub OAuth Apps), and set the redirect URI tohttps://gateway.mewcp.com/oauth/callback. -
Get the server's API Key: go to Dashboard (mode=business) → Servers → select server → select key → Copy Key. You'll send this on every
POST /oauth/{provider}/startcall, alongside your Account API Key, see below.
Integration flow
-
Start the OAuth flow
Call
POST /oauth/{provider}/startfrom your backend. Two headers are required: your Account API Key (Authorization) and the API Key of the specific server you're connecting this user to (x-mewcp-key). The OAuth app used is always the one assigned to that server key, so there's no app selection in the request body. Pass the user's ID and, if you have a frontend, a callback URL. You can also pass optional user metadata, which MewCP stores alongside the credential for display in your dashboard:CodeField Required Description externalUserIdYes Your internal user identifier frontendCallbackUrlNo Where MewCP redirects the user after OAuth completes externalUserMeta.nameNo User's display name, stored for your reference externalUserMeta.emailNo User's email, stored for your reference externalUserMeta.usernameNo User's username, stored for your reference If
x-mewcp-keyis missing, invalid, not a business-mode server key, or belongs to a different provider than{provider}in the path, the call fails with401/400before any OAuth URL is generated.You get back:
CodeThe
statevalue is internal: MewCP uses it to verify the callback. You do not need to store or validate it. -
Open the auth URL for your user
If you have a frontend (web app):
Open the URL as a popup, the standard OAuth pattern. The popup must be opened from a user action (e.g. a button click), otherwise browsers will block it.
CodeAfter the user logs in, MewCP redirects the popup to your
frontendCallbackUrl:Result Query params on your callback URL Success ?provider=google&success=trueError ?oauth_error=<message>Your callback page needs to forward this result to the parent window and close the popup:
CodeIf you prefer a full redirect (no popup):
Instead of opening a popup, redirect the user directly to the
authUrl. After OAuth completes, MewCP redirects them back to yourfrontendCallbackUrl. Handle the result there as a normal page load:CodeCodeIf you have no frontend (local tools / server-only setups):
Simply open the
authUrlin a browser, log in, and you're done. MewCP will show a "Connected" confirmation page with a close button. The credential is saved automatically, no further action needed. -
Use the connection 🚀
Once connected, route your user's MCP requests through the gateway with their
externalUserIdin the header:CodeMewCP resolves the stored credential and makes the authenticated call on their behalf.
Security
- Access tokens and refresh tokens are encrypted at rest in MewCP's vault
- Your backend never need to handles raw credentials - only an opaque
externalUserIdreference - Token refresh happens server-side, automatically, before expiry
- You can revoke a user's credential at any time via the Audience API