Skip to content

Commit 1c542ad

Browse files
Add multi-account support (#19)
Allow managing multiple Gmail accounts from a single server instance. Each tool accepts an optional `account` parameter; omitting it uses the default account for full backwards compatibility. - Replace singleton OAuth2Client with per-account Gmail client map - Add loadAllAccounts() to discover credentials-*.json files - Add authenticate(accountName) for per-account auth flow - Add `account` param to all 19 existing tool schemas - Add list_accounts tool to show configured accounts - Update README with multi-account usage docs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9b1c3ba commit 1c542ad

2 files changed

Lines changed: 272 additions & 119 deletions

File tree

README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ A Model Context Protocol (MCP) server for Gmail integration in Claude Desktop wi
2323

2424
## Features
2525

26+
- **Multi-account support** - manage multiple Gmail accounts from a single server instance
2627
- Send emails with subject, content, **attachments**, and recipients
2728
- **Full attachment support** - send and receive file attachments
2829
- **Download email attachments** to local filesystem
@@ -194,11 +195,66 @@ npx @gongrzhe/server-gmail-autoauth-mcp auth https://gmail.gongrzhe.com/oauth2ca
194195

195196
This approach allows authentication flows to work properly in environments where localhost isn't accessible, such as containerized applications or cloud servers.
196197

198+
## Multi-Account Support
199+
200+
You can configure multiple Gmail accounts and switch between them using the optional `account` parameter on any tool.
201+
202+
### Authenticating Additional Accounts
203+
204+
```bash
205+
# Authenticate your default account (same as before)
206+
npx @gongrzhe/server-gmail-autoauth-mcp auth
207+
208+
# Authenticate a "work" account
209+
npx @gongrzhe/server-gmail-autoauth-mcp auth work
210+
211+
# Authenticate a "personal" account
212+
npx @gongrzhe/server-gmail-autoauth-mcp auth personal
213+
214+
# With custom callback URL for cloud environments
215+
npx @gongrzhe/server-gmail-autoauth-mcp auth work https://gmail.example.com/oauth2callback
216+
```
217+
218+
Credentials are stored as:
219+
- `~/.gmail-mcp/credentials.json` - "default" account
220+
- `~/.gmail-mcp/credentials-work.json` - "work" account
221+
- `~/.gmail-mcp/credentials-personal.json` - "personal" account
222+
223+
### Using Multiple Accounts
224+
225+
All tools accept an optional `account` parameter. Omit it to use the default account:
226+
227+
```json
228+
// Search default account
229+
{ "query": "from:boss@company.com" }
230+
231+
// Search work account
232+
{ "query": "from:boss@company.com", "account": "work" }
233+
234+
// Search personal account
235+
{ "query": "from:friend@gmail.com", "account": "personal" }
236+
```
237+
238+
Use `list_accounts` to see all configured accounts.
239+
240+
### Backwards Compatibility
241+
242+
- Existing single-account setups work without any changes
243+
- The `GMAIL_CREDENTIALS_PATH` environment variable still works (loads as "default")
244+
- All tools work without the `account` parameter (uses default)
245+
197246
## Available Tools
198247

199248
The server provides the following tools that can be used through Claude Desktop:
200249

201-
### 1. Send Email (`send_email`)
250+
### 1. List Accounts (`list_accounts`)
251+
Lists all configured Gmail accounts.
252+
253+
```json
254+
{}
255+
```
256+
257+
### 2. Send Email (`send_email`)
202258

203259
Sends a new email immediately. Supports plain text, HTML, or multipart emails **with optional file attachments**.
204260

0 commit comments

Comments
 (0)