Skip to content

Fix/vscode mcp oauth sign in#8910

Open
eolbrych wants to merge 7 commits intoKilo-Org:mainfrom
eolbrych:fix/vscode-mcp-oauth-sign-in
Open

Fix/vscode mcp oauth sign in#8910
eolbrych wants to merge 7 commits intoKilo-Org:mainfrom
eolbrych:fix/vscode-mcp-oauth-sign-in

Conversation

@eolbrych
Copy link
Copy Markdown

Context

Remote MCP servers with OAuth showed needs auth in VS Code settings but
provided no way to trigger the sign-in flow. Fixes #8904.

Two separate bugs caused this:

  1. The settings UI had no control to start authentication when status was needs_auth.
  2. The OAuth callback server (127.0.0.1:19876) was never bound in the VS Code
    process because ensureRunning() short-circuited on isPortInUse(), so the
    browser redirect always hit ERR_CONNECTION_REFUSED.

Implementation

UI fix (packages/kilo-vscode)

  • AgentBehaviourTab — renders a Sign in button when MCP status is needs_auth;
    sends authenticateMcp message which calls POST /mcp/{name}/auth/authenticate.
  • KiloProvider — listens for mcp.browser.open.failed SSE and opens the auth
    URL via vscode.env.openExternal. The CLI's subprocess open() fails silently
    inside the VS Code extension host on some platforms, so the fallback is
    necessary. Deduped so multiple webviews don't open the same URL twice.
  • Logic extracted to kilo-provider/mcp-oauth.ts to stay within ESLint
    max-lines / complexity limits.

Callback server fix (packages/opencode)

  • Removed the isPortInUse probe in McpOAuthCallback.ensureRunning().
    The old assumption — that a port already in use means another instance is
    serving the callback — was wrong: when VS Code spawns the CLI in-process,
    there is no other instance. Now Bun.serve is always attempted here.
  • Concurrent ensureRunning() calls are serialized via startInFlight.
  • EADDRINUSE is logged with an actionable hint instead of being swallowed.

Screenshots

before after
needs auth with no action available Sign in button → browser opens → Authorization Successful

How to Test

  1. Add a remote MCP server with OAuth (e.g. http://localhost:8080/mcp) in
    Agent Behaviour → MCP Servers.
  2. Toggle it ON — status shows needs auth.
  3. A Sign in button appears next to the server — click it.
  4. The browser opens to the OAuth authorization page.
  5. Authorize — browser shows Authorization Successful.
  6. Return to VS Code: MCP server status changes to connected.

e.olbrych and others added 4 commits April 14, 2026 13:47
- Add Sign in control when MCP status is needs_auth; posts authenticateMcp
  to run CLI POST /mcp/{name}/auth/authenticate.
- On SSE mcp.browser.open.failed, open the auth URL via
  vscode.env.openExternal (CLI subprocess open() often fails under VS Code).
- Dedupe openExternal when multiple webviews receive the same event.

Fixes UI regression described in GitHub issue Kilo-Org#8904.

Made-with: Cursor
- Move MCP connect/disconnect/authenticate and openExternal dedupe to
  kilo-provider/mcp-oauth.ts.
- eslint-disable-next-line complexity for the webview message router.

Made-with: Cursor
ensureRunning() used to return early when isPortInUse() was true, assuming
another instance served /mcp/oauth/callback. That left this process without
Bun.serve while authenticate() still registered waitForCallback here — the
browser redirect to 127.0.0.1:19876 could hit nothing (ERR_CONNECTION_REFUSED).

- Remove the port-probe short-circuit; always attempt Bun.serve in-process.
- Serialize concurrent ensureRunning with startInFlight.
- Clear startInFlight in stop(); log bind errors (EADDRINUSE) with a hint.
- Drop unused isPortInUse helper.

Made-with: Cursor
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot bot commented Apr 14, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (6 files)
  • packages/kilo-vscode/src/KiloProvider.ts
  • packages/kilo-vscode/src/kilo-provider/mcp-oauth.ts
  • packages/kilo-vscode/webview-ui/src/components/settings/AgentBehaviourTab.tsx
  • packages/kilo-vscode/webview-ui/src/context/session.tsx
  • packages/kilo-vscode/webview-ui/src/types/messages.ts
  • packages/opencode/src/mcp/oauth-callback.ts

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.

MCP Auth not working on 7.x.x on VSCode

1 participant