Prerequisites
- A Google OAuth application configured with the scope
https://www.googleapis.com/auth/gmail.send(see below for guide) - Client ID and Client Secret from your OAuth app
- A backend server to handle the OAuth flow
How to create a Google OAuth app
How to create a Google OAuth app
1. Create the APP
- Select Web application
- Choose a name. It will be displayed when your user logins through Google
- The redirect URIs will be the URL where your user will be redirected to after Google authorizes the request. It must be server-side as it will need to access secret credentials.
2. Configure scope
Scopes are used to request sufficient access on the user’s account. In this example, we want to connect his account to the MCP server to send emails.- Go to Data access
- Click on “Add or remove scopes”
- Add
gmail.send
Some scopes (like this one) require an HTTPS callback URL. You won’t be able to test them easily locally without using ngrok or a similar tool which allows you to have an HTTPS URL bound to your localhost.
By default, it will work with your own account without any review by Google. You can look for the Audience tab on left to add more users. To make it global, you will need to launch a review process from Google with the “Publish app” button.
We recommend creating a separate OAuth flow specifically for the Gmail integration. Don’t simply add the Gmail scope to an existing OAuth flow, as this would require all users to grant email permissions even when they don’t need Gmail functionality.
Overview of the OAuth flow
The integration follows this redirect pattern:Step-by-step guide
Step 1: User initiates connection
- In your app’s UI, user clicks a button to “connect with Google” (or equivalent) during integration setup
- UI redirects to your backend OAuth endpoint
Step 2: Backend initiates Google OAuth
Your backend should redirect to Google’s OAuth URL with these parameters: Required Scopes:https://www.googleapis.com/auth/gmail.sendopenidprofileemail
Step 3: Google authorization
- Google prompts user to login and approve requested scopes
- Google redirects back to your redirect_uri with a temporary authorization code
Step 4: Exchange Code for Tokens
Your backend exchanges the authorization code for access and refresh tokens: Example: Token Exchange (Python)Step 5: Create integration
Once you have the refresh token, create the integration on Blaxel (for an MCP server in this case) with these parameters:CLIENT_ID: Your Google OAuth application client IDCLIENT_SECRET: Your Google OAuth application client secretREFRESH_TOKEN: The refresh token obtained from the OAuth flow
Step 6: Complete Integration
- Save MCP configuration in your system
- Redirect user back to frontend with success confirmation
- Integration is now ready for use
Troubleshooting
- Invalid scope error: Ensure Gmail API is enabled in Google Cloud Console
- Redirect URI mismatch: Verify redirect URI matches exactly in Google OAuth app settings
- Token refresh issues: Check that
access_type=offlineis included in initial OAuth request
