mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Switch MCP management to use OpenCode server API with version requirement >=1.0.137
This commit is contained in:
1 parent
9608d1ce19
commit
b739c5266f
8 files changed
+547
-138
No files matched your search
@@ -0,0 +1,127 @@
|
||||
import { API_BASE_URL } from '@/config'
|
||||
|
||||
const API_BASE = API_BASE_URL
|
||||
|
||||
export type McpStatus =
|
||||
| { status: 'connected' }
|
||||
| { status: 'disabled' }
|
||||
| { status: 'failed'; error: string }
|
||||
| { status: 'needs_auth' }
|
||||
| { status: 'needs_client_registration'; error: string }
|
||||
|
||||
export type McpStatusMap = Record<string, McpStatus>
|
||||
|
||||
export interface McpServerConfig {
|
||||
type: 'local' | 'remote'
|
||||
enabled?: boolean
|
||||
command?: string[]
|
||||
url?: string
|
||||
environment?: Record<string, string>
|
||||
headers?: Record<string, string>
|
||||
timeout?: number
|
||||
oauth?: boolean | {
|
||||
clientId?: string
|
||||
clientSecret?: string
|
||||
scope?: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface AddMcpServerRequest {
|
||||
name: string
|
||||
config: McpServerConfig
|
||||
}
|
||||
|
||||
export interface McpAuthStartResponse {
|
||||
authorizationUrl: string
|
||||
}
|
||||
|
||||
export const mcpApi = {
|
||||
async getStatus(): Promise<McpStatusMap> {
|
||||
const response = await fetch(`${API_BASE}/api/opencode/mcp`)
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to get MCP status: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async addServer(name: string, config: McpServerConfig): Promise<McpStatusMap> {
|
||||
const response = await fetch(`${API_BASE}/api/opencode/mcp`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name, config }),
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to add MCP server: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async connect(name: string): Promise<boolean> {
|
||||
const response = await fetch(`${API_BASE}/api/opencode/mcp/${encodeURIComponent(name)}/connect`, {
|
||||
method: 'POST',
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to connect MCP server: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async disconnect(name: string): Promise<boolean> {
|
||||
const response = await fetch(`${API_BASE}/api/opencode/mcp/${encodeURIComponent(name)}/disconnect`, {
|
||||
method: 'POST',
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to disconnect MCP server: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async startAuth(name: string): Promise<McpAuthStartResponse> {
|
||||
const response = await fetch(`${API_BASE}/api/opencode/mcp/${encodeURIComponent(name)}/auth`, {
|
||||
method: 'POST',
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to start MCP auth: ${response.statusText}`)
|
||||
}
|
||||
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',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ code }),
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to complete MCP auth: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async authenticate(name: string): Promise<McpStatus> {
|
||||
const response = await fetch(`${API_BASE}/api/opencode/mcp/${encodeURIComponent(name)}/auth/authenticate`, {
|
||||
method: 'POST',
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to authenticate MCP server: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
|
||||
async removeAuth(name: string): Promise<{ success: true }> {
|
||||
const response = await fetch(`${API_BASE}/api/opencode/mcp/${encodeURIComponent(name)}/auth`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ error: response.statusText }))
|
||||
throw new Error(error.error || `Failed to remove MCP auth: ${response.statusText}`)
|
||||
}
|
||||
return response.json()
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user