Merge pull request #4129 from code-yeongyu/feature/stage-c-lsp-mcp

Extract LSP tools into Tier-1 MCP server via lsp-tools-mcp submodule
This commit is contained in:
YeonGyu-Kim
2026-05-18 13:39:17 +09:00
committed by GitHub
64 changed files with 290 additions and 3668 deletions
+17 -34
View File
@@ -1,49 +1,31 @@
# src/mcp/ — 3 Built-in Remote MCPs
# src/mcp/ — 4 Built-in MCPs
**Generated:** 2026-05-15
**Generated:** 2026-05-18
## OVERVIEW
Tier 1 of the three-tier MCP system. 3 remote HTTP MCPs created via `createBuiltinMcps(disabledMcps, config)`.
Tier 1 of the three-tier MCP system. Built-ins are created by `createBuiltinMcps(disabledMcps, config)` and now include both remote MCPs and one local stdio MCP.
## BUILT-IN MCPs
| Name | URL | Env Vars | Tools |
|------|-----|----------|-------|
| **websearch** | `mcp.exa.ai` (default) or `mcp.tavily.com` | `EXA_API_KEY` (optional), `TAVILY_API_KEY` (if tavily) | Web search |
| **context7** | `mcp.context7.com/mcp` | `CONTEXT7_API_KEY` (optional) | Library documentation |
| **grep_app** | `mcp.grep.app` | None | GitHub code search |
| Name | Type | Endpoint / Command | Env Vars | Tools |
|------|------|--------------------|----------|-------|
| **websearch** | remote | `mcp.exa.ai` (default) or `mcp.tavily.com` | `EXA_API_KEY` (optional), `TAVILY_API_KEY` (if tavily) | Web search |
| **context7** | remote | `mcp.context7.com/mcp` | `CONTEXT7_API_KEY` (optional) | Library documentation |
| **grep_app** | remote | `mcp.grep.app` | None | GitHub code search |
| **lsp** | local (stdio, node) | `node vendor/lsp-tools-mcp/dist/cli.js mcp` | `LSP_TOOLS_MCP_PROJECT_CONFIG=.opencode/lsp.json` | `status`, diagnostics, goto definition, references, symbols, prepare_rename, rename |
## REGISTRATION PATTERN
## SUBMODULE ARCHITECTURE
```typescript
// Static export (context7, grep_app)
export const context7 = {
type: "remote" as const,
url: "https://mcp.context7.com/mcp",
enabled: true,
oauth: false as const,
}
// Factory with config (websearch)
export function createWebsearchConfig(config?: WebsearchConfig): RemoteMcpConfig
```
## ENABLE/DISABLE
```jsonc
// Method 1: disabled_mcps array
{ "disabled_mcps": ["websearch", "context7"] }
// Method 2: enabled flag
{ "mcp": { "websearch": { "enabled": false } } }
```
- The local `lsp` MCP is vendored as a git submodule at `vendor/lsp-tools-mcp/`.
- Upstream project: https://github.com/code-yeongyu/lsp-tools-mcp
- OMO resolves the CLI path dynamically in `src/mcp/lsp.ts` so both `src/` and `dist/` runtime layouts work.
## THREE-TIER SYSTEM
| Tier | Source | Mechanism |
|------|--------|-----------|
| 1. Built-in | `src/mcp/` | 3 remote HTTP, created by `createBuiltinMcps()` |
| 1. Built-in | `src/mcp/` | 3 remote HTTP MCPs + 1 local stdio MCP (`lsp`) via `createBuiltinMcps()` |
| 2. Claude Code | `.mcp.json` | `${VAR}` expansion via `claude-code-mcp-loader` |
| 3. Skill-embedded | SKILL.md YAML | Managed by `SkillMcpManager` (stdio + HTTP) |
@@ -51,8 +33,9 @@ export function createWebsearchConfig(config?: WebsearchConfig): RemoteMcpConfig
| File | Purpose |
|------|---------|
| `index.ts` | `createBuiltinMcps()` factory |
| `types.ts` | `McpNameSchema`: "websearch" \| "context7" \| "grep_app" |
| `index.ts` | `createBuiltinMcps()` registry for built-in MCPs |
| `types.ts` | `McpNameSchema`: `"websearch" \| "context7" \| "grep_app" \| "lsp"` |
| `websearch.ts` | Exa/Tavily provider with config |
| `context7.ts` | Context7 with optional auth header |
| `grep-app.ts` | Grep.app (no auth) |
| `lsp.ts` | Local stdio MCP config for vendored `lsp-tools-mcp` |
+11 -1
View File
@@ -1,6 +1,7 @@
import { createWebsearchConfig } from "./websearch"
import { context7 } from "./context7"
import { grep_app } from "./grep-app"
import { createLspMcpConfig, type LocalMcpConfig } from "./lsp"
import type { OhMyOpenCodeConfig } from "../config/schema"
export { McpNameSchema, type McpName } from "./types"
@@ -13,8 +14,10 @@ type RemoteMcpConfig = {
oauth?: false
}
type BuiltinMcpConfig = RemoteMcpConfig | LocalMcpConfig
export function createBuiltinMcps(disabledMcps: string[] = [], config?: OhMyOpenCodeConfig) {
const mcps: Record<string, RemoteMcpConfig> = {}
const mcps: Record<string, BuiltinMcpConfig> = {}
if (!disabledMcps.includes("websearch")) {
const websearchConfig = createWebsearchConfig(config?.websearch)
@@ -31,5 +34,12 @@ export function createBuiltinMcps(disabledMcps: string[] = [], config?: OhMyOpen
mcps.grep_app = grep_app
}
if (!disabledMcps.includes("lsp")) {
const lspConfig = createLspMcpConfig()
if (lspConfig) {
mcps.lsp = lspConfig
}
}
return mcps
}
+62
View File
@@ -0,0 +1,62 @@
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 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 = new Set<string>()
try {
const currentFilePath = fileURLToPath(import.meta.url)
const currentDirectory = resolve(currentFilePath, "..")
addCliPathCandidates(currentDirectory, 6, candidates)
} catch {
// ignore and fall through to cwd-based candidates
}
addCliPathCandidates(process.cwd(), 4, candidates)
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"
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>
+21 -3
View File
@@ -1,9 +1,16 @@
import { describe, expect, test } from "bun:test"
import { createBuiltinMcps } from "../index"
import { afterEach, describe, expect, mock, test } from "bun:test"
afterEach(() => {
mock.restore()
})
describe("createBuiltinMcps", () => {
test("should return all MCPs when disabled_mcps is empty", () => {
// given
mock.module("../lsp", () => ({
createLspMcpConfig: () => ({ type: "local", command: ["node", "dist/cli.js", "mcp"], enabled: true }),
}))
const { createBuiltinMcps } = require("../index") as typeof import("../index")
const disabledMcps: string[] = []
// when
@@ -14,10 +21,15 @@ describe("createBuiltinMcps", () => {
expect(result.websearch).toBeDefined()
expect(result.context7).toBeDefined()
expect(result.grep_app).toBeDefined()
expect(result.lsp).toBeDefined()
})
test("should filter out disabled MCPs", () => {
// given
mock.module("../lsp", () => ({
createLspMcpConfig: () => ({ type: "local", command: ["node", "dist/cli.js", "mcp"], enabled: true }),
}))
const { createBuiltinMcps } = require("../index") as typeof import("../index")
const disabledMcps = ["websearch"]
// when
@@ -27,11 +39,16 @@ describe("createBuiltinMcps", () => {
expect(result.websearch).toBeUndefined()
expect(result.context7).toBeDefined()
expect(result.grep_app).toBeDefined()
expect(result.lsp).toBeDefined()
})
test("should return empty array when all MCPs are disabled", () => {
// given - disable all known MCPs
const disabledMcps = ["websearch", "context7", "grep_app"]
mock.module("../lsp", () => ({
createLspMcpConfig: () => ({ type: "local", command: ["node", "dist/cli.js", "mcp"], enabled: true }),
}))
const { createBuiltinMcps } = require("../index") as typeof import("../index")
const disabledMcps = ["websearch", "context7", "grep_app", "lsp"]
// when
const result = createBuiltinMcps(disabledMcps)
@@ -41,6 +58,7 @@ describe("createBuiltinMcps", () => {
expect(remainingMcpNames).not.toContain("websearch")
expect(remainingMcpNames).not.toContain("context7")
expect(remainingMcpNames).not.toContain("grep_app")
expect(remainingMcpNames).not.toContain("lsp")
expect(remainingMcpNames).toEqual([])
})
})