Prerequisites

To get the most out of this guide, you’ll need to:

1. Create a Gmail MCP Server

Use the following endpoint to create a new remote Gmail MCP server instance:

Request

curl --request POST \
  --url https://api.klavis.ai/mcp-server/instance/create \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "serverName": "Gmail",
  "userId": "<YOUR_USER_ID>",
  "platformName": "<YOUR_PLATFORM_NAME>"
}'

Response

{
  "serverUrl": "https://gmail-mcp-server.klavis.ai/sse?instance_id=<instance-id>",
  "instanceId": "<instance-id>"
}
serverUrl specifies the endpoint of the Gmail MCP server, which you can connect and use this MCP Server to interact with Gmail data and functionality.
instanceId is used for authentication and identification of your server instance.

2. Gmail OAuth Flow with White Labeling

If you want to enable your MCP server to access private Gmail information, you must use the OAuth flow with White Labeling. General white labeling information can be found in

Google OAuth Security Review Notice

Klavis AI only supports using your own custom Google OAuth application. You must set up and configure your own Google OAuth App to use Gmail functionality with Klavis AI’s MCP server. This ensures proper security, compliance, and reliability for your application.

Please refer to Google’s OAuth documentation to set up your own OAuth application.

After you have set up the white labeling for Gmail, you can then do the following:

const authUrl = `https://api.klavis.ai/oauth/gmail/authorize?instance_id=${instanceId}&client_id=${clientId}`;
window.location.href = authUrl;

Watch the Example

Explore MCP Server Tools