ai-agent-google-workspace-mcp-server
v1.0.0
Published
MCP server for Google Workspace integration (Gmail, Calendar, Meet)
Maintainers
Readme
Google Workspace MCP Server
A Model Context Protocol (MCP) server that provides comprehensive Google Workspace integration for AI agents. This server enables AI agents to interact with Gmail, Google Calendar, and Google Meet through a secure, well-structured API.
Features
📧 Gmail Integration
- Search emails with Gmail query syntax
- Send emails with attachment support (requires confirmation)
- Create drafts for later editing
- Extract attachments from emails with optional content analysis
📅 Google Calendar Integration
- List events with flexible filtering
- Create events with attendees and recurrence
- Update existing events
- Delete events (requires confirmation)
- List available calendars
- Create meetings with Google Meet integration
🎥 Google Meet Integration
- List conference records with filtering
- Access transcripts and transcript entries
- Retrieve recordings and metadata
- Get meeting details and participant information
Installation
npm install
npm run buildSetup
1. Google Cloud Console Setup
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the required APIs:
- Gmail API
- Google Calendar API
- Google Meet API
- Create OAuth2 credentials:
- Go to "Credentials" → "Create Credentials" → "OAuth 2.0 Client IDs"
- Choose "Desktop application"
- Download the credentials JSON
2. Environment Configuration
cp .env.example .envEdit .env with your Google OAuth2 credentials:
GOOGLE_CLIENT_ID=your_google_client_id_here
GOOGLE_CLIENT_SECRET=your_google_client_secret_here3. Authentication
This MCP server supports two authentication methods:
Option A: OAuth2 Authentication (User-based)
For user-specific access where each user authenticates individually:
- Run the server
- When prompted, visit the authentication URL in your browser
- Grant the necessary permissions
- Tokens will be stored locally for future use
You can also set these environment variables directly:
GOOGLE_ACCESS_TOKEN- OAuth access tokenGOOGLE_REFRESH_TOKEN- OAuth refresh tokenGOOGLE_TOKEN_TYPE- Token type (usually "Bearer")GOOGLE_TOKEN_EXPIRY- Token expiration timestampGOOGLE_TOKENS_JSON- Complete token object as JSON string
Option B: Service Account Authentication (Recommended for Organizations)
For server-to-server authentication without user interaction:
Using Service Account Key File:
export GOOGLE_SERVICE_ACCOUNT_KEY_PATH=/path/to/service-account-key.json
export [email protected] # Optional: for domain-wide delegationUsing Service Account Key JSON Content:
export GOOGLE_SERVICE_ACCOUNT_KEY_JSON='{"type":"service_account","project_id":"...","private_key_id":"...",...}'
export [email protected] # Optional: for domain-wide delegationUsing Individual Service Account Fields:
export GOOGLE_SERVICE_ACCOUNT_EMAIL=my-service-account@myproject.iam.gserviceaccount.com
export GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC...
-----END PRIVATE KEY-----"
export [email protected] # Optional: for domain-wide delegationSetting up Service Account:
- Go to Google Cloud Console
- Select your project or create a new one
- Go to "IAM & Admin" > "Service Accounts"
- Click "Create Service Account"
- Fill in the details and create
- Click on the created service account
- Go to "Keys" tab and create a new JSON key
- Enable the required APIs (Gmail, Calendar, Meet, etc.)
Domain-wide Delegation (Optional):
For accessing users' data across your organization:
- In Google Cloud Console, edit your service account
- Check "Enable Google Workspace Domain-wide Delegation"
- Note the "Client ID" shown
- In Google Admin Console, go to Security > API Controls > Domain-wide Delegation
- Add the Client ID with these scopes:
https://www.googleapis.com/auth/gmail.readonlyhttps://www.googleapis.com/auth/gmail.sendhttps://www.googleapis.com/auth/gmail.composehttps://www.googleapis.com/auth/calendarhttps://www.googleapis.com/auth/meetings.space.readonly
Then set GOOGLE_SERVICE_ACCOUNT_SUBJECT to the email address you want to impersonate.
Usage
Running the Server
# Development mode
npm run dev
# Production mode
npm startAvailable Tools
Gmail Tools
gmail_search- Search emails using Gmail query syntaxgmail_send- Send emails (requiresconfirm: true)gmail_create_draft- Create draft emailsgmail_get_attachments- Extract attachments from emails
Calendar Tools
calendar_list_events- List calendar eventscalendar_create_event- Create new events (requiresconfirm: true)calendar_update_event- Update existing events (requiresconfirm: true)calendar_delete_event- Delete events (requiresconfirm: true)calendar_list_calendars- List available calendarscalendar_create_meeting- Create meeting with Google Meet (requiresconfirm: true)
Meet Tools
meet_list_conference_records- List past conference recordsmeet_get_transcript- Get specific transcriptmeet_list_transcripts- List transcripts for a conferencemeet_get_recording- Get specific recordingmeet_list_recordings- List recordings for a conferencemeet_list_transcript_entries- List individual transcript entries
Tool Examples
Search Gmail
{
"name": "gmail_search",
"arguments": {
"query": "from:[email protected] is:unread"
}
}Send Email
{
"name": "gmail_send",
"arguments": {
"to": "[email protected]",
"subject": "Hello from AI Agent",
"body": "This email was sent via the MCP server!",
"confirm": true
}
}Create Calendar Event
{
"name": "calendar_create_event",
"arguments": {
"summary": "Team Meeting",
"description": "Weekly team sync",
"start_time": "2024-01-15T10:00:00Z",
"end_time": "2024-01-15T11:00:00Z",
"attendees": ["[email protected]"],
"confirm": true
}
}Create Meeting with Google Meet
{
"name": "calendar_create_meeting",
"arguments": {
"summary": "Project Discussion",
"start_time": "2024-01-15T14:00:00Z",
"end_time": "2024-01-15T15:00:00Z",
"attendees": ["[email protected]", "[email protected]"],
"confirm": true
}
}Security Features
- Multiple Authentication Methods: Support for both OAuth2 and Service Account authentication
- OAuth2 Authentication: Secure token-based authentication with automatic refresh
- Service Account Authentication: Server-to-server authentication for organizational use
- Domain-wide Delegation: Optional support for impersonating users in your organization
- Confirmation Required: Destructive operations (send, create, update, delete) require explicit confirmation
- Scoped Permissions: Only requests necessary Google API scopes
- Token Storage: Encrypted local token storage with automatic cleanup
Multi-User Support
The server supports multiple Google accounts through the user_id parameter:
{
"name": "gmail_search",
"arguments": {
"user_id": "work_account",
"query": "is:unread"
}
}Error Handling
The server provides comprehensive error handling with:
- Clear error messages
- Authentication guidance
- Structured error responses
- Graceful fallbacks
Development
# Install dependencies
npm install
# Run in development mode
npm run dev
# Type checking
npm run typecheck
# Linting
npm run lint
# Code formatting
npm run formatArchitecture
src/
├── auth/ # OAuth2 authentication management
├── handlers/ # Service-specific handlers (Gmail, Calendar, Meet)
├── types/ # TypeScript type definitions
├── utils/ # Utility functions (email formatting, etc.)
└── server.ts # Main MCP server implementationContributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
MIT License - see LICENSE file for details.
Support
For issues and questions:
- Check the existing issues
- Review the Google Workspace API documentation
- Create a new issue with detailed information
Requirements
- Node.js 18+
- Google Cloud project with Workspace APIs enabled
- Valid OAuth2 credentials OR Service Account credentials
