feat: first-party Google Drive integration - search and read Drive files from chat (stacked on #285)

⛔ closed · #290 · open-legal-products/mike ← amal66/mike · opened 3mo ago by amal66 · closed 2mo ago · +1,530-3 across 11 files · ↗ on GitHub

From the PR description

Stacked on #285 (shares its branch history - review only the last commit here until #285 lands).

What this adds

"Search my Google Drive for X and summarize it" as a one-click-connect experience: a Google Drive card on Account → Connectors runs a first-party OAuth flow, and three read-only chat tools (google_drive_search, google_drive_read_file, google_drive_list_recent) call the GA Drive REST API directly. Google Docs/Sheets/Slides export as text; PDF and Word convert via the existing extractors; results carry the same untrusted-context framing as MCP tool output, and the chat UI renders the calls with the existing connector treatment (no event-pipeline changes).

Why not the Drive MCP server

Google's hosted Drive MCP (drivemcp.googleapis.com) is gated behind the Workspace Developer Preview Program. Verified live during #285's testing: with both APIs enabled and the full advertised scope set, OAuth succeeds and tools/list works, but every tools/call returns a bare PERMISSION_DENIED for non-enrolled accounts - while the same token lists files over plain Drive REST without complaint. The REST API has no such gate, so the reliable path for stock deployments is first-party. (#285's MCP connector support still works for enrolled accounts.)

Design notes

  • OAuth: PKCE (S256) + access_type=offline&prompt=consent (Google issues refresh tokens only with these - same lesson as #185). Tokens AES-GCM-encrypted at rest, hashed + TTL'd state rows, transparent refresh with 60s leeway; invalid_grant deletes the row so status stays honest.
  • Safety: read-only drive.readonly scope; Drive q values escape quotes/backslashes so user input can't break out of the query literal; 60k-char cap per file read.
  • Setup UX: missing OAuth client fails fast with the exact Console steps and this deployment's redirect URI in the message; env vars fall back to GOOGLE_MCP_OAUTH_* so one Cloud client serves both features. README gains a full self-hosting section (APIs to enable, redirect URI, test-mode vs restricted-scope verification).

Testing

  • 8 new unit tests (PKCE URL construction, fail-fast setup error, tool gating, q-escaping, Doc export, invalid_grant cleanup); backend suite 460 passing; frontend tsc + suite clean.
  • Live end-to-end verification (real Google account, consent popup, real Drive files → chat summary) in progress; results will be posted as a comment.

🤖 Generated with Claude Code

Our analysis

Add native Google Drive chat tools — read the full analysis →

Think the analysis missed something the PR description covers?

Capture this PR into my fork

Download a Markdown prompt that tells Claude how to port every commit in this PR into your working tree. Run it via claude -p < capture-pull-290.md from inside the repo you want the changes in.

⬇ Download capture-pull-290.md