-
Notifications
You must be signed in to change notification settings - Fork 23
Improve Headless/Remote VM Authentication Experience #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
In headless/VM environments, auth URL messages were printed to stdout via console.log, breaking MCP clients that expect only JSON-RPC on stdout. Changed console.log to console.error in: - open-wrapper.ts (browser launch failure messages) - AuthManager.ts (waiting for auth message)
Print the auth URL immediately before attempting browser launch, ensuring the URL is always visible in headless/VM environments even when DISPLAY is set for port-forwarding.
Changes: - Redirect auth messages to stderr (keep stdout clean for MCP JSON-RPC) - Add GEMINI_CLI_WORKSPACE_HEADLESS env var for port-forwarding setups - Print port-forwarding instructions when in headless mode - Improve manual flow credentials page with OS-specific instructions: - Linux CLI (secret-tool command, expanded by default) - macOS Keychain Access - Windows Credential Manager - Add PR.md with full documentation
Added section explaining how to use GEMINI_CLI_WORKSPACE_HEADLESS with port-forwarding for authentication on remote VMs.
Summary of ChangesHello @philschmid, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the user experience for authenticating the Google Workspace MCP server, particularly for those operating in headless or remote virtual machine environments. It addresses several pain points by separating authentication messages to Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request significantly improves the authentication experience for headless and remote VM environments. The changes are well-structured and address the key problems described. By redirecting authentication messages to stderr, you've cleanly separated them from the JSON-RPC protocol on stdout. The introduction of the GEMINI_CLI_WORKSPACE_HEADLESS environment variable provides a much-needed explicit way to handle non-GUI scenarios, and the updated instructions on the credentials page are a great improvement for user experience. My main feedback is a suggestion to refactor the duplicated logic for checking the headless mode environment variable into a shared utility function to improve code maintainability.
| const isHeadless = process.env['GEMINI_CLI_WORKSPACE_HEADLESS'] === 'true' || | ||
| process.env['GEMINI_CLI_WORKSPACE_HEADLESS'] === '1'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check for headless mode is duplicated in AuthManager.ts (here and on line 290) and in secure-browser-launcher.ts. To improve maintainability and avoid potential inconsistencies, it would be better to extract this logic into a single, shared utility function.
For example:
// In a shared utility file
export function isHeadlessMode(): boolean {
const headlessEnv = process.env['GEMINI_CLI_WORKSPACE_HEADLESS'];
return headlessEnv === 'true' || headlessEnv === '1';
}You could then call isHeadlessMode() in all three places.
References
- Avoid duplicating code. Duplicated code makes the software harder to maintain. When a bug is found in a piece of duplicated code, it must be fixed in every place it appears.
This PR improves the authentication experience for users running the Google Workspace MCP server in headless or remote VM environments where traditional browser-based OAuth flows don't work well.
Problem
When running the Extension as standalone MCP server in a VM/headless environment:
stdout, breaking MCP clients that expect only JSON-RPCChanges
1. Redirect Auth Messages to stderr
Files:
workspace-server/src/utils/open-wrapper.ts,workspace-server/src/auth/AuthManager.tsconsole.logtoconsole.errorfor all auth-related messages2. Add
GEMINI_CLI_WORKSPACE_HEADLESSEnvironment VariableFiles:
workspace-server/src/utils/secure-browser-launcher.ts,workspace-server/src/auth/AuthManager.tsNew environment variable for headless environments with port-forwarding:
Behavior:
3. Improved Manual Flow Instructions
Files:
cloud_function/index.jsEnhanced the "Success! Credentials Ready" page with:
secret-toolcommand for remote VMsUsage
Option A: Headless Mode with Port-Forwarding
ssh -L 8585:localhost:8585 your-vmOption B: Manual Flow (No Port-Forwarding)
GEMINI_CLI_WORKSPACE_HEADLESS)secret-tool(Linux) or Keychain/Credential Manager