fix(mcp): show auth URL when browser cannot open in remote sessions (#7884)

This commit is contained in:
Dan Lapid
2026-01-16 01:21:39 +00:00
committed by GitHub
parent 25cb03dbe5
commit b572c68100
3 changed files with 308 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ import { Installation } from "../../installation"
import path from "path"
import { Global } from "../../global"
import { modify, applyEdits } from "jsonc-parser"
import { Bus } from "../../bus"
function getAuthStatusIcon(status: MCP.AuthStatus): string {
switch (status) {
@@ -227,6 +228,16 @@ export const McpAuthCommand = cmd({
const spinner = prompts.spinner()
spinner.start("Starting OAuth flow...")
// Subscribe to browser open failure events to show URL for manual opening
const unsubscribe = Bus.subscribe(MCP.BrowserOpenFailed, (evt) => {
if (evt.properties.mcpName === serverName) {
spinner.stop("Could not open browser automatically")
prompts.log.warn("Please open this URL in your browser to authenticate:")
prompts.log.info(evt.properties.url)
spinner.start("Waiting for authorization...")
}
})
try {
const status = await MCP.authenticate(serverName)
@@ -256,6 +267,8 @@ export const McpAuthCommand = cmd({
} catch (error) {
spinner.stop("Authentication failed", 1)
prompts.log.error(error instanceof Error ? error.message : String(error))
} finally {
unsubscribe()
}
prompts.outro("Done")