Support Gmail delegation with runtime delegateFor parameter - #3
Merged
Merged
Conversation
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
force-pushed
the
feat/gmail-delegation-userid
branch
from
April 3, 2026 18:08
7504102 to
09b2fad
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 asuserId.Fix
Adds an optional
delegateForparameter to all 28 Gmail tools. When provided, it overridesuserIdto target the delegated mailbox: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:
delegateFor: Falls back togetAccountEmail(args.account), which returns the account's own email. Gmail treats this identically to'me'.delegateFor: Passes the specified email asuserId, using Gmail's built-in delegation support.Testing
tsc --noEmit.