feat: Add OAuth 2.1 authentication support for remote MCP servers #4657
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat: Add OAuth 2.1 authentication support for remote MCP servers
Context
Previously, when connecting to remote MCP servers that require OAuth 2.1 authentication (e.g., servers using SSE or Streamable HTTP transports with bearer tokens), KiloCode would fail with authentication errors. Users had no way to authenticate with these servers, making them unusable.
This PR implements OAuth 2.1 authentication support for remote MCP (Model Context Protocol) servers, enabling users to authenticate with MCP servers that require OAuth 2.1 bearer token authentication. This implementation is based on Cline's OAuth 2.1 implementation (PR #7376) and adapted for KiloCode's architecture.
Implementation
This PR adds complete OAuth 2.1 support following the MCP SDK's
OAuthClientProviderinterface:Core Components
McpOAuthManager (
src/services/mcp/McpOAuthManager.ts):OAuthClientProviderinterface from@modelcontextprotocol/sdkSecretStorage(encrypted)McpOAuthCallbackServer (
src/services/mcp/McpOAuthCallbackServer.ts):McpHub Integration (
src/services/mcp/McpHub.ts):connectToServerto handleUnauthorizedErrorand mark servers as requiring OAuthinitiateOAuthmethod to start OAuth flowcompleteOAuthmethod to handle callback and reconnectUI Integration (
webview-ui/src/components/mcp/McpView.tsx):Related
Screenshots
Before -
After -
How to Test
Setup an MCP server requiring OAuth:
Trigger OAuth flow:
Closes #4656