feat(google): multi-account Gmail/Calendar via in-process MCP#53
Merged
Conversation
Replaces the broken `gws mcp` external server (the subcommand was removed from @googleworkspace/cli v0.22.5) with an in-process MCP that wraps gws CLI calls. The wrapper exposes typed gmail_* / calendar_* tools to the agent and adds native multi-account support along the way. Multi-account follows the convention from indentcorp/gws-multi-account (see googleworkspace/cli#78): each account lives in ~/.config/gws/<email>/ with its own client_secret.json + credentials.enc, and gws is invoked with GOOGLE_WORKSPACE_CLI_CONFIG_DIR pointing at the right dir. ~/.config/gws/accounts.json is the manifest; the integrations DB row is just a cache. What's new: - src/auth/gws-accounts.ts — manifest CRUD + per-account runGws/runGwsJson helper that injects the env var - src/sdk/google-workspace-mcp.ts — in-process MCP with 12 tools: gmail_search, gmail_get_message, gmail_get_thread, gmail_create_draft, gmail_send_draft, gmail_list_labels, calendar_list_events, calendar_get_event, calendar_create_event, calendar_update_event, calendar_delete_event, google_list_accounts. Each takes an optional `account` arg (defaults to the manifest's default). - Settings UI gains "Add another account" + per-account "Make default" - OAuth start route now runs each auth attempt in a pending dir, then resolves the email from the granted token and promotes the dir to its final ~/.config/gws/<email>/ home. Multiple accounts coexist; re-auth atomically replaces just that one. - Ingest: gmail.ts iterates every account in the manifest by default; `nomos ingest gmail --account <email>` scopes to one. Also rolls in two fixes from earlier in this session that hadn't landed yet: - gmail.ts now passes `--unmasked` to `gws auth export` (without it, gws returns truncated client_secret/refresh_token that fail token refresh with `invalid_client`). - embeddings.ts honors Gemini's `retryDelay` on 429 free-tier quota hits instead of bailing on the whole ingest. Legacy single-account installs keep working: the manifest is empty until the first multi-account auth migrates them, and every code path falls back to the original single-account behavior. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
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.
Summary
gws mcpexternal server (the subcommand was removed from@googleworkspace/cliv0.22.5) with an in-process MCP that exposes 12 typedgmail_*/calendar_*/google_list_accountstools to the agent./.config/gws//` with its own `client_secret.json` + `credentials.enc`; every gws call gets `GOOGLE_WORKSPACE_CLI_CONFIG_DIR` pointed at the right one. The manifest at `/.config/gws/accounts.json` is the source of truth.Also bundled (uncommitted bug fixes from earlier in the session)
Backwards compatibility
Legacy single-account installs keep working: the manifest is empty until the first multi-account auth migrates them, and every code path falls back to the original single-account behavior. After the first re-auth via Settings UI, the install transitions to the per-account layout automatically.
Test plan
/.config/gws//` is created and `/.config/gws/accounts.json` contains the email with `isDefault: true`.Known gaps
🤖 Generated with Claude Code