Skip to content

Support Gmail delegation with runtime delegateFor parameter - #3

Merged
pm990320 merged 3 commits into
pm990320:mainfrom
pbranchu:feat/gmail-delegation-userid
Apr 3, 2026
Merged

Support Gmail delegation with runtime delegateFor parameter#3
pm990320 merged 3 commits into
pm990320:mainfrom
pbranchu:feat/gmail-delegation-userid

Conversation

@pbranchu

@pbranchu pbranchu commented Mar 21, 2026

Copy link
Copy Markdown

Problem

All Gmail tools hardcode userId: 'me' when calling the Gmail API. This prevents using Gmail delegation, where one authenticated account (e.g., a service/assistant account) accesses another user's mailbox as a delegate.

Google's Gmail API supports passing the delegate's email address as userId (see Gmail API documentation). When delegation is set up between accounts, you can access another user's mailbox by passing their email as userId.

Fix

Adds an optional delegateFor parameter to all 28 Gmail tools. When provided, it overrides userId to target the delegated mailbox:

userId: args.delegateFor || await getAccountEmail(args.account)

This allows a single authenticated account to access multiple delegated mailboxes at runtime without needing separate account configurations for each.

Example usage

{
  "tool": "listGmailMessages",
  "args": {
    "account": "jeeves",
    "delegateFor": "philippe@example.com",
    "query": "is:unread"
  }
}

Backward Compatibility

Fully backward compatible:

  • Without delegateFor: Falls back to getAccountEmail(args.account), which returns the account's own email. Gmail treats this identically to 'me'.
  • With delegateFor: Passes the specified email as userId, using Gmail's built-in delegation support.

Testing

  • Verified the project compiles cleanly with tsc --noEmit.
  • No runtime behavior change for non-delegation users.
  • Tested with a Workspace service account acting as delegate for multiple users.

@pbranchu pbranchu changed the title Support Gmail delegation by using account email as userId Support Gmail delegation with runtime delegateFor parameter Mar 21, 2026
pbranchu and others added 3 commits April 4, 2026 01:08
Replace all hardcoded userId: 'me' with userId: await getAccountEmail(args.account)
in Gmail tool functions to enable Gmail delegation support.
Instead of just replacing userId: 'me' with the account's own email
(which doesn't enable delegation), add an optional delegateFor parameter
to every Gmail tool. When set, the Gmail API calls use the delegate's
email as the userId, allowing the authenticated account to operate on
a mailbox that has granted it delegate access.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pm990320
pm990320 force-pushed the feat/gmail-delegation-userid branch from 7504102 to 09b2fad Compare April 3, 2026 18:08
@pm990320
pm990320 merged commit f248ab9 into pm990320:main Apr 3, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants