feat: MCP OAuth flow improvements (#123)

Rewrite OAuth flow handle authentication entirely in web app with secure proxy
- Add MCP OAuth proxy with origin validation and callback handling
- Remove auto OAuth method from authentication flow
- Fix TypeScript build errors
- Add directory support for MCP OAuth flows and improve config manager UI
- Reload session caches after MCP connection changes
This commit is contained in:
Chris Scott authored and GitHub committed 2026-02-13 00:10:56 -05:00
1 parent 7824d52fb8
commit 3f9c398b31
31 files changed
+1054 -483

No files matched your search

+21 -2
View File
@@ -33,8 +33,15 @@ export interface AddMcpServerRequest {
export interface McpAuthStartResponse {
authorizationUrl: string
flowId: string
}
export type McpOAuthFlowStatus =
| { status: 'pending' }
| { status: 'completed'; serverName: string }
| { status: 'failed'; error: string }
| { status: 'unknown' }
export const mcpApi = {
async getStatus(): Promise<McpStatusMap> {
const response = await fetch(`${API_BASE}/api/opencode/mcp`)
@@ -79,9 +86,11 @@ export const mcpApi = {
return response.json()
},
async startAuth(name: string): Promise<McpAuthStartResponse> {
const response = await fetch(`${API_BASE}/api/opencode/mcp/${encodeURIComponent(name)}/auth`, {
async startAuth(name: string, serverUrl: string, scope?: string, clientId?: string, clientSecret?: string, directory?: string): Promise<McpAuthStartResponse> {
const response = await fetch(`${API_BASE}/api/mcp-oauth-proxy/start`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ serverName: name, serverUrl, scope, clientId, clientSecret, directory }),
})
if (!response.ok) {
const error = await response.json().catch(() => ({ error: response.statusText }))
@@ -90,6 +99,14 @@ export const mcpApi = {
return response.json()
},
async checkFlowStatus(flowId: string): Promise<McpOAuthFlowStatus> {
const response = await fetch(`${API_BASE}/api/mcp-oauth-proxy/status/${encodeURIComponent(flowId)}`)
if (!response.ok) {
return { status: 'unknown' }
}
return response.json()
},
async completeAuth(name: string, code: string): Promise<McpStatus> {
const response = await fetch(`${API_BASE}/api/opencode/mcp/${encodeURIComponent(name)}/auth/callback`, {
method: 'POST',
@@ -106,6 +123,8 @@ export const mcpApi = {
async authenticate(name: string): Promise<McpStatus> {
const response = await fetch(`${API_BASE}/api/opencode/mcp/${encodeURIComponent(name)}/auth/authenticate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({}),
})
if (!response.ok) {
const error = await response.json().catch(() => ({ error: response.statusText }))
+1 -1
View File
@@ -3,7 +3,7 @@ import { fetchWrapper, FetchError } from "./fetchWrapper"
export interface OAuthAuthorizeResponse {
url: string
method: "auto" | "code"
method: "code"
instructions: string
}