fix(mcp): harden lsp cli resolution and doctor disable checks

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-05-18 13:20:41 +09:00
parent b149ce5331
commit f7b60e360f
2 changed files with 61 additions and 7 deletions
+40
View File
@@ -1,6 +1,46 @@
import { readFileSync } from "node:fs"
import { join } from "node:path"
import { createLspMcpConfig } from "../../../mcp/lsp"
import { detectPluginConfigFile, getOpenCodeConfigDir, parseJsonc } from "../../../shared"
type OmoConfigForDoctor = {
disabled_mcps?: string[]
}
const PROJECT_CONFIG_DIR = join(process.cwd(), ".opencode")
function readOmoConfig(configDirectory: string): OmoConfigForDoctor | null {
const detected = detectPluginConfigFile(configDirectory)
if (detected.format === "none") {
return null
}
try {
const content = readFileSync(detected.path, "utf-8")
return parseJsonc<OmoConfigForDoctor>(content)
} catch {
return null
}
}
function isLspMcpDisabled(): boolean {
const userConfigDirectory = getOpenCodeConfigDir({ binary: "opencode" })
const userConfig = readOmoConfig(userConfigDirectory)
const projectConfig = readOmoConfig(PROJECT_CONFIG_DIR)
const disabledMcps = new Set<string>([
...(userConfig?.disabled_mcps ?? []),
...(projectConfig?.disabled_mcps ?? []),
])
return disabledMcps.has("lsp")
}
export function getInstalledLspServers(): Array<{ id: string; extensions: string[] }> {
if (isLspMcpDisabled()) {
return []
}
const lspMcpConfig = createLspMcpConfig()
if (!lspMcpConfig) {
+21 -7
View File
@@ -13,21 +13,35 @@ export type LocalMcpConfig = {
environment?: Record<string, string>
}
function addCliPathCandidates(startDirectory: string, maxParentDepth: number, target: Set<string>): void {
let currentDirectory = startDirectory
for (let depth = 0; depth <= maxParentDepth; depth += 1) {
target.add(resolve(currentDirectory, SUBMODULE_REL, CLI_REL))
const parentDirectory = resolve(currentDirectory, "..")
if (parentDirectory === currentDirectory) {
return
}
currentDirectory = parentDirectory
}
}
function resolveLspCliPathCandidates(): string[] {
const candidates: string[] = []
const candidates = new Set<string>()
try {
const currentFilePath = fileURLToPath(import.meta.url)
candidates.push(resolve(currentFilePath, "..", "..", "..", SUBMODULE_REL, CLI_REL))
candidates.push(resolve(currentFilePath, "..", "..", SUBMODULE_REL, CLI_REL))
candidates.push(resolve(currentFilePath, "..", SUBMODULE_REL, CLI_REL))
const currentDirectory = resolve(currentFilePath, "..")
addCliPathCandidates(currentDirectory, 6, candidates)
} catch {
// ignore and fall through to cwd-based candidate
// ignore and fall through to cwd-based candidates
}
candidates.push(resolve(process.cwd(), SUBMODULE_REL, CLI_REL))
addCliPathCandidates(process.cwd(), 4, candidates)
return candidates
return [...candidates]
}
export function createLspMcpConfig(): LocalMcpConfig | null {