feat(mcp): register lsp tier-1 stdio MCP server

This commit is contained in:
YeonGyu-Kim
2026-05-18 12:11:21 +09:00
parent d95a45c872
commit c2c078fec3
5 changed files with 71 additions and 8 deletions
+7 -5
View File
@@ -1,9 +1,11 @@
import { getAllServers } from "../../../tools/lsp/config" import { createLspMcpConfig } from "../../../mcp/lsp"
export function getInstalledLspServers(): Array<{ id: string; extensions: string[] }> { export function getInstalledLspServers(): Array<{ id: string; extensions: string[] }> {
const servers = getAllServers() const lspMcpConfig = createLspMcpConfig()
return servers if (!lspMcpConfig) {
.filter((s) => s.installed && !s.disabled) return []
.map((s) => ({ id: s.id, extensions: s.extensions })) }
return [{ id: "lsp-tools-mcp", extensions: ["*"] }]
} }
+11 -1
View File
@@ -1,6 +1,7 @@
import { createWebsearchConfig } from "./websearch" import { createWebsearchConfig } from "./websearch"
import { context7 } from "./context7" import { context7 } from "./context7"
import { grep_app } from "./grep-app" import { grep_app } from "./grep-app"
import { createLspMcpConfig, type LocalMcpConfig } from "./lsp"
import type { OhMyOpenCodeConfig } from "../config/schema" import type { OhMyOpenCodeConfig } from "../config/schema"
export { McpNameSchema, type McpName } from "./types" export { McpNameSchema, type McpName } from "./types"
@@ -13,8 +14,10 @@ type RemoteMcpConfig = {
oauth?: false oauth?: false
} }
type BuiltinMcpConfig = RemoteMcpConfig | LocalMcpConfig
export function createBuiltinMcps(disabledMcps: string[] = [], config?: OhMyOpenCodeConfig) { export function createBuiltinMcps(disabledMcps: string[] = [], config?: OhMyOpenCodeConfig) {
const mcps: Record<string, RemoteMcpConfig> = {} const mcps: Record<string, BuiltinMcpConfig> = {}
if (!disabledMcps.includes("websearch")) { if (!disabledMcps.includes("websearch")) {
const websearchConfig = createWebsearchConfig(config?.websearch) const websearchConfig = createWebsearchConfig(config?.websearch)
@@ -31,5 +34,12 @@ export function createBuiltinMcps(disabledMcps: string[] = [], config?: OhMyOpen
mcps.grep_app = grep_app mcps.grep_app = grep_app
} }
if (!disabledMcps.includes("lsp")) {
const lspConfig = createLspMcpConfig()
if (lspConfig) {
mcps.lsp = lspConfig
}
}
return mcps return mcps
} }
+48
View File
@@ -0,0 +1,48 @@
import { existsSync } from "node:fs"
import { resolve } from "node:path"
import { fileURLToPath } from "node:url"
const SUBMODULE_REL = "vendor/lsp-tools-mcp"
const CLI_REL = "dist/cli.js"
const PROJECT_LSP_CONFIG = ".opencode/lsp.json"
export type LocalMcpConfig = {
type: "local"
command: string[]
enabled: boolean
environment?: Record<string, string>
}
function resolveLspCliPathCandidates(): string[] {
const candidates: 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))
} catch {
// ignore and fall through to cwd-based candidate
}
candidates.push(resolve(process.cwd(), SUBMODULE_REL, CLI_REL))
return candidates
}
export function createLspMcpConfig(): LocalMcpConfig | null {
const cliPath = resolveLspCliPathCandidates().find((candidatePath) => existsSync(candidatePath))
if (!cliPath) {
return null
}
return {
type: "local",
command: ["node", cliPath, "mcp"],
enabled: true,
environment: {
LSP_TOOLS_MCP_PROJECT_CONFIG: PROJECT_LSP_CONFIG,
},
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
import { z } from "zod" import { z } from "zod"
export const McpNameSchema = z.enum(["websearch", "context7", "grep_app"]) export const McpNameSchema = z.enum(["websearch", "context7", "grep_app", "lsp"])
export type McpName = z.infer<typeof McpNameSchema> export type McpName = z.infer<typeof McpNameSchema>
+4 -1
View File
@@ -14,6 +14,7 @@ describe("createBuiltinMcps", () => {
expect(result.websearch).toBeDefined() expect(result.websearch).toBeDefined()
expect(result.context7).toBeDefined() expect(result.context7).toBeDefined()
expect(result.grep_app).toBeDefined() expect(result.grep_app).toBeDefined()
expect(result.lsp).toBeDefined()
}) })
test("should filter out disabled MCPs", () => { test("should filter out disabled MCPs", () => {
@@ -27,11 +28,12 @@ describe("createBuiltinMcps", () => {
expect(result.websearch).toBeUndefined() expect(result.websearch).toBeUndefined()
expect(result.context7).toBeDefined() expect(result.context7).toBeDefined()
expect(result.grep_app).toBeDefined() expect(result.grep_app).toBeDefined()
expect(result.lsp).toBeDefined()
}) })
test("should return empty array when all MCPs are disabled", () => { test("should return empty array when all MCPs are disabled", () => {
// given - disable all known MCPs // given - disable all known MCPs
const disabledMcps = ["websearch", "context7", "grep_app"] const disabledMcps = ["websearch", "context7", "grep_app", "lsp"]
// when // when
const result = createBuiltinMcps(disabledMcps) const result = createBuiltinMcps(disabledMcps)
@@ -41,6 +43,7 @@ describe("createBuiltinMcps", () => {
expect(remainingMcpNames).not.toContain("websearch") expect(remainingMcpNames).not.toContain("websearch")
expect(remainingMcpNames).not.toContain("context7") expect(remainingMcpNames).not.toContain("context7")
expect(remainingMcpNames).not.toContain("grep_app") expect(remainingMcpNames).not.toContain("grep_app")
expect(remainingMcpNames).not.toContain("lsp")
expect(remainingMcpNames).toEqual([]) expect(remainingMcpNames).toEqual([])
}) })
}) })