Add gmail_reauth MCP tool for SSH-compatible token refresh #6
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo_admin/gmail-mcp#6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type
Feature
Lineage
pal-e-platform#162(parent: Gmail OAuth re-auth lifecycle)Repo
forgejo_admin/gmail-mcpUser Story
As a platform operator on SSH
I want to re-authorize Gmail OAuth from within the MCP session
So that I never need to leave Claude Code or have a local browser on the server
Context
The Gmail OAuth flow currently requires
GmailClient.authorize()which callswebbrowser.open()and starts a local HTTP server on port 8090. This fails on SSH sessions (no browser, no display).When the 7-day refresh token expires (Google Testing mode), the only option is to manually generate an auth URL, open it on a local machine, grab the redirect code, and exchange it via Python one-liners. This needs to be a proper MCP tool.
The gmail-sdk
AuthMixinalready has all the building blocks:get_auth_url()— generates the consent URLexchange_code()— exchanges auth code for tokens_save_token()— persists to disk_load_credentials()— reads client_id/secretFile Targets
Files to create:
src/gmail_mcp/tools/reauth.py— new MCP tool moduleFiles to modify:
src/gmail_mcp/tools/__init__.py— register the new toolFiles NOT to touch:
src/gmail_mcp/auth.py— just paths, no changes needed~/gmail-sdk/— SDK already has the primitivesAcceptance Criteria
gmail_reauth_start(account)tool returns the OAuth consent URL + instructionsgmail_reauth_complete(account, callback_url)tool accepts the full redirect URL (or bare code), exchanges for tokens, saves to disk, and confirms successgmail_messages_listworks immediately (no MCP restart needed — clear the client cache)gmail.readonly,gmail.send,gmail.modify,gmail.settings.basic,mail.google.comTest Expectations
test_reauth_startreturns valid Google OAuth URL with all scopestest_reauth_completewith mocked exchange saves token correctlygmail_get_profileworkscd ~/gmail-mcp && uv run pytest tests/ -k reauthConstraints
_clientscache inserver.pyafter successful reauth so stale GmailClient is replacedhttp://localhost:8090for Desktop type) — the page will fail to load on the user's browser, they copy the URL bargmail-{alias}.jsonChecklist
Related
project-pal-e-platform— platform infrastructurepal-e-platform#162— parent lifecycle issueplan-pal-e-mail— Phase 2c sender registry also needs re-auth flowScope Review: READY
Review note:
review-361-2026-03-25All template sections present, all file targets verified against codebase, SDK primitives confirmed (get_auth_url, exchange_code, _save_token, _load_credentials). Import pattern from
..serveris established across all 8 existing tool modules. No blockers, no missing dependencies.