mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
feat(opencode-config): redact secrets and add MCP listing to the internal config API (#366)
This commit is contained in:
1 parent
68b13c8e35
commit
a1b7f58aae
31 files changed
+1238
-181
No files matched your search
@@ -53,12 +53,14 @@ export { formatOpenCodeModelRef, parseOpenCodeModelRef } from './modelRef'
|
||||
export {
|
||||
MCP_OAUTH_CALLBACK_PATH,
|
||||
mcpOAuthRedirectUri,
|
||||
mcpServerViewsFromConfig,
|
||||
mcpServersFromConfig,
|
||||
mcpStatusByName,
|
||||
} from './mcp'
|
||||
|
||||
export type {
|
||||
McpServerConfig,
|
||||
McpServerView,
|
||||
McpStatus,
|
||||
McpStatusMap,
|
||||
McpTimeoutConfig,
|
||||
|
||||
@@ -31,6 +31,45 @@ export function mcpServersFromConfig(mcp: unknown): Record<string, McpServerConf
|
||||
return Object.fromEntries(Object.entries(mcp.servers).filter((entry): entry is [string, McpServerConfig] => isMcpServerConfig(entry[1])))
|
||||
}
|
||||
|
||||
export type McpServerShape = 'servers' | 'legacy'
|
||||
|
||||
export interface McpServerView {
|
||||
name: string
|
||||
type: 'local' | 'remote'
|
||||
command?: string[]
|
||||
url?: string
|
||||
enabled: boolean
|
||||
shape: McpServerShape
|
||||
}
|
||||
|
||||
function toMcpServerView(
|
||||
name: string,
|
||||
config: McpServerConfig,
|
||||
enabled: boolean,
|
||||
shape: McpServerShape,
|
||||
): McpServerView {
|
||||
return {
|
||||
name,
|
||||
type: config.type,
|
||||
...(config.type === 'local' ? { command: config.command } : { url: config.url }),
|
||||
enabled,
|
||||
shape,
|
||||
}
|
||||
}
|
||||
|
||||
export function mcpServerViewsFromConfig(mcp: unknown): McpServerView[] {
|
||||
if (!isRecord(mcp)) return []
|
||||
const nativeViews = Object.entries(mcpServersFromConfig(mcp)).map(([name, config]) =>
|
||||
toMcpServerView(name, config, config.disabled !== true, 'servers'),
|
||||
)
|
||||
const legacyViews = Object.entries(mcp).flatMap(([name, value]) => {
|
||||
if (name === 'servers' || name === 'timeout' || !isMcpServerConfig(value)) return []
|
||||
const enabled = (value as { enabled?: unknown }).enabled !== false
|
||||
return [toMcpServerView(name, value, enabled, 'legacy')]
|
||||
})
|
||||
return [...nativeViews, ...legacyViews].sort((left, right) => left.name.localeCompare(right.name))
|
||||
}
|
||||
|
||||
export function mcpStatusByName(servers: McpServer[]): McpStatusMap {
|
||||
return Object.fromEntries(
|
||||
servers.map((server) => [
|
||||
|
||||
Reference in new issue
Block a user