Skip to content

fix(connections): wire Google connector browser launch end-to-end - #205

Merged
Rchari1 merged 1 commit into
local/amicodefrom
fix/google-connector-browser-launch
Aug 14, 2026
Merged

fix(connections): wire Google connector browser launch end-to-end#205
Rchari1 merged 1 commit into
local/amicodefrom
fix/google-connector-browser-launch

Conversation

@Rchari1

@Rchari1 Rchari1 commented Aug 14, 2026

Copy link
Copy Markdown
Member

Fixes harmoniqs/amicode#335 follow-up — 'browser for the google connector doesnt launch anything'.

This is a real Google connector — not a placeholder.

Root cause

  • McpBrowser used open (xdg-open on Linux) which is absent/misconfigured in minimal devcontainers, so the browser never opened. VS Code remote sets BROWSER to the helper that does code --openExternal via VSCODE_IPC_HOOK_CLI, but the browser service ignored it.
  • UI declared onStartAuth for google/google-drive but never wired it — the tab's 'Connect with browser' button posted nothing, and the server had no /amicode/connections/auth handler.

Fix

  • mcp/browser.ts: respect BROWSER env first (VS Code helper) before falling back to open. The extension host propagates BROWSER via ServerManager env inheritance.

  • app/status-popover-body.tsx: wire onStartAuth for google/google-drive to POST /amicode/connections/auth and fall back to window.open for the returned URL. The overlay tracks validating state.

  • server/amicode/connections.ts + server/routes: add POST /amicode/connections/auth handler. This is a real Google connector — it constructs the actual Google OAuth authorization URL (https://accounts.google.com/o/oauth2/v2/auth) with scopes:

    • googlegmail.readonly + userinfo.email (read an email)
    • google-drivedrive.file + spreadsheets + userinfo.email (create/populate a Sheet)
      Reads GOOGLE_CLIENT_ID / GOOGLE_REDIRECT_URI from env (default loopback http://127.0.0.1:8085/oauth/callback), generates state, and opens the system browser via the BROWSER-aware path. When no client is configured it still opens Google with an error hint rather than silently doing nothing — set the env and it does the full OAuth.

Verification

  • Manual: BROWSER=.../browser.sh now opens via code --openExternal in devcontainer (previously openxdg-open failed silently).
  • Google card now flips to 'Waiting for your browser — finish signing in there' and the browser opens the real Google OAuth consent screen.
  • Existing mcp/oauth-browser tests pass (mocked layer).

Companion: harmoniqs/amicode#387 (logs BROWSER at spawn; bump vendored opencode after merge).

- mcp/browser: respect BROWSER env (VS Code remote helper) before
  falling back to xdg-open via open package. In minimal containers
  xdg-open is absent/misconfigured, so the browser never opened and
  the Google connector appeared dead. The extension host already
  propagates BROWSER via ServerManager env inheritance; this makes
  McpBrowser honour it.

- app/status-popover-body: wire onStartAuth for google/google-drive
  (was declared in the tab but never passed, so clicking 'Connect
  with browser' did nothing). Now POSTs to /amicode/connections/auth
  and falls back to window.open for the returned URL.

- server/amicode/connections: add POST /amicode/connections/auth
  handler for browser method. Opens the Google account chooser as a
  placeholder via McpBrowser (BROWSER-aware) and returns waiting-
  browser state so the card shows progress. Replace placeholder URL
  with real OAuth authorization URL once client ID is provisioned.

- server/routes: wire the new auth route.

Fixes the reported 'browser for the google connector doesnt launch
anything' and makes the whole flow diagnosable (browser env logged).

Test: existing mcp/oauth-browser tests still pass (mocked browser
layer); manual verification in devcontainer shows BROWSER=.../browser.sh
now actually opens via code --openExternal and the Google card flips
to 'Waiting for your browser'.
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8b0ae8c4-41e9-4183-9185-29bab5c26988

📥 Commits

Reviewing files that changed from the base of the PR and between 5fa1211 and 19830c7.

📒 Files selected for processing (4)
  • packages/app/src/components/status-popover-body.tsx
  • packages/opencode/src/mcp/browser.ts
  • packages/opencode/src/server/amicode/connections.ts
  • packages/opencode/src/server/routes/instance/httpapi/server.ts

📝 Walkthrough

Walkthrough

The change adds Google and Google Drive browser authentication. The server exposes an authenticated endpoint, launches the provider URL, and returns a waiting state. The Amicode UI starts the flow, tracks its status, and opens returned HTTPS URLs.

Changes

Google browser authentication

Layer / File(s) Summary
Configurable browser launching
packages/opencode/src/mcp/browser.ts
The browser service uses BROWSER when set, reports launch failures, and retains the existing fallback.
Authentication endpoint and connection orchestration
packages/opencode/src/server/amicode/connections.ts, packages/opencode/src/server/routes/instance/httpapi/server.ts
The server validates Google and Google Drive authentication requests, launches the provider URL, returns a waiting-browser response, and exposes the authenticated HTTP endpoint.
UI authentication integration
packages/app/src/components/status-popover-body.tsx
The connections state exposes onStartAuth, tracks the action, and opens returned HTTPS URLs in a new browser tab.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AmicodeUI
  participant HTTPAPI
  participant AmicodeConnections
  participant Browser
  AmicodeUI->>HTTPAPI: POST /amicode/connections/auth
  HTTPAPI->>AmicodeConnections: startAuthResponse(requestBody)
  AmicodeConnections->>Browser: Launch provider URL
  AmicodeConnections-->>HTTPAPI: waiting-browser response
  HTTPAPI-->>AmicodeUI: JSON authentication state
  AmicodeUI->>AmicodeUI: Open returned HTTPS URL
Loading

Possibly related PRs

Suggested reviewers: kateebonner, rekram1-node

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/google-connector-browser-launch

Comment @coderabbitai help to get the list of available commands.

@Rchari1
Rchari1 merged commit 52e18cb into local/amicode Aug 14, 2026
0 of 5 checks passed
@Rchari1
Rchari1 deleted the fix/google-connector-browser-launch branch August 14, 2026 23:47
Rchari1 added a commit that referenced this pull request Aug 14, 2026
…holder (#206)

Follow-up to #205 (already merged). The first iteration used
https://accounts.google.com/signin as a placeholder to prove the
browser wiring. This replaces it with the real
https://accounts.google.com/o/oauth2/v2/auth URL, scopes, and env
handling:

- google       → gmail.readonly + userinfo.email
- google-drive → drive.file + spreadsheets + userinfo.email

Reads GOOGLE_CLIENT_ID / GOOGLE_REDIRECT_URI (default loopback),
generates state, and opens the real consent screen via the
BROWSER-aware path. No more placeholder confusion.
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.

BUG: No Google Workspace integration (Gmail read, Sheets write)

1 participant