Skip to content

feat(mcp): add code-graph-context as optional built-in MCP#2718

Open
nguyentamdat wants to merge 1 commit intocode-yeongyu:devfrom
nguyentamdat:feat/code-graph-context-mcp
Open

feat(mcp): add code-graph-context as optional built-in MCP#2718
nguyentamdat wants to merge 1 commit intocode-yeongyu:devfrom
nguyentamdat:feat/code-graph-context-mcp

Conversation

@nguyentamdat
Copy link
Copy Markdown

@nguyentamdat nguyentamdat commented Mar 20, 2026

Summary

  • Add code-graph-context as a 4th built-in MCP for graph-based code analysis (callers, dead code, complexity, relationships)
  • Unlike existing remote HTTP MCPs, this is a local stdio MCP requiring the cgc binary
  • Disabled by default — users opt in via config: code_graph_context.enabled = true

Changes

New Files (3)

  • src/mcp/code-graph-context.ts — Factory with LocalMcpConfig type, binary auto-detection (~/.local/bin/cgc, /usr/local/bin/cgc, /usr/bin/cgc), sensible FalkorDB environment defaults
  • src/config/schema/code-graph-context.ts — Zod schema: enabled (default false), optional binary_path override
  • src/mcp/code-graph-context.test.ts — Unit tests for factory function

Modified Files (10)

  • src/mcp/types.ts — Added "code_graph_context" to McpNameSchema enum
  • src/mcp/index.ts — New BuiltinMcpConfig union type (RemoteMcpConfig | LocalMcpConfig), wired into createBuiltinMcps()
  • src/config/schema/oh-my-opencode-config.ts — Added code_graph_context field to root config
  • src/config/schema.ts — Barrel export
  • src/tools/skill-mcp/constants.ts — Tool hints for 7 code-graph-context tools
  • src/cli/doctor/checks/tools-mcp.ts — Added to BUILTIN_MCP_SERVERS
  • src/mcp/index.test.ts — 3 new tests
  • src/agents/explore.ts — Added code-graph-context tools to Tool Strategy
  • src/agents/oracle.ts — Added graph analysis tools to <tool_usage_rules>
  • assets/oh-my-opencode.schema.json — Auto-generated schema update

Usage

// .opencode/oh-my-opencode.jsonc
{
  "code_graph_context": {
    "enabled": true
    // optional: "binary_path": "/custom/path/to/cgc"
  }
}

Design Decisions

  • Optional via config — requires cgc binary locally, unlike zero-config remote HTTP MCPs
  • No tool permission changes — tools not globally denied, all agents can call them
  • Agent prompts updated for Explore and Oracle only — their missions align with graph analysis

Checklist

  • Code follows project conventions
  • bun run typecheck passes
  • bun run build succeeds
  • No version changes in package.json
  • Tests added and passing

Summary by cubic

Adds code-graph-context as an optional built-in MCP for local, graph-based code analysis powered by the cgc binary. Enables callers/dead-code/complexity queries and integrates tools into Explore and Oracle when enabled.

  • New Features

    • Optional local stdio MCP code-graph-context (requires cgc); off by default via code_graph_context.enabled.
    • Auto-detects cgc in ~/.local/bin, /usr/local/bin, /usr/bin; supports code_graph_context.binary_path; FalkorDB defaults under ~/.codegraphcontext/.
    • Exposes 7 tools (find code, relationships, dead code, complexity, Cypher, etc.); integrated into createBuiltinMcps, doctor checks, and tool hints; Explore/Oracle prompts updated; respects disabled_mcps.
    • Config schema, JSON schema, and tests added.
  • Migration

    • Install cgc and ensure it’s in a common path, or set code_graph_context.binary_path.
    • Enable with code_graph_context.enabled: true in .opencode/oh-my-opencode.jsonc.

Written for commit 97d58ee. Summary will update on new commits.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 20, 2026

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

Add code-graph-context as a 4th built-in MCP for graph-based code
analysis (callers, dead code, complexity, relationships). Unlike the
existing remote HTTP MCPs, this is a local stdio MCP requiring the
cgc binary.

- Disabled by default, users opt in via config:
  code_graph_context.enabled = true
- Auto-detects cgc binary in ~/.local/bin, /usr/local/bin, /usr/bin
- Sensible FalkorDB environment defaults (~/.codegraphcontext/)
- New LocalMcpConfig type extending BuiltinMcpConfig union
- Tool hints for 7 code-graph-context tools in skill-mcp constants
- Agent prompt updates for Explore and Oracle to leverage graph tools
- Config schema, barrel exports, doctor check, and tests included
@nguyentamdat nguyentamdat force-pushed the feat/code-graph-context-mcp branch from c58e2bb to 97d58ee Compare March 20, 2026 07:30
@nguyentamdat
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Mar 20, 2026
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 issues found across 13 files

Confidence score: 1/5

  • src/mcp/index.ts introduces a high-risk security regression: workspace-local code_graph_context.binary_path can be executed as a local MCP command, which could allow arbitrary code execution when opening untrusted repositories.
  • There are concrete functional regressions in src/mcp/code-graph-context.ts (Windows probe uses cgc instead of cgc.exe, and PATH-based command names like cgc are rejected), so valid setups may fail across common environments.
  • Validation coverage is weakened: src/mcp/index.test.ts has a vacuous filter assertion and src/mcp/code-graph-context.test.ts misses the auto-detection fallback path, reducing confidence that these behaviors are protected from regressions.
  • Pay close attention to src/mcp/index.ts, src/mcp/code-graph-context.ts, src/cli/doctor/checks/tools-mcp.ts, src/mcp/index.test.ts, src/mcp/code-graph-context.test.ts - security-sensitive command execution and MCP enablement/detection logic need tightening before merge.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/cli/doctor/checks/tools-mcp.ts">

<violation number="1" location="src/cli/doctor/checks/tools-mcp.ts:8">
P2: Doctor MCP check now treats `code_graph_context` as always enabled by adding it to a static built-in list that is mapped to `enabled: true`, ignoring its conditional config-based enablement.</violation>
</file>

<file name="src/mcp/index.test.ts">

<violation number="1" location="src/mcp/index.test.ts:133">
P2: The new filtering test for `code_graph_context` is vacuous because the MCP is disabled by default, so the assertion passes regardless of whether disabled-list filtering works.</violation>
</file>

<file name="src/mcp/code-graph-context.ts">

<violation number="1" location="src/mcp/code-graph-context.ts:15">
P2: Windows auto-detection is broken because binary lookup uses `cgc` instead of `cgc.exe` for path probes.</violation>

<violation number="2" location="src/mcp/code-graph-context.ts:22">
P2: `binary_path` validation incorrectly rejects PATH-resolved command names (e.g., `cgc`), causing valid MCP setups to be disabled.</violation>
</file>

<file name="src/mcp/code-graph-context.test.ts">

<violation number="1" location="src/mcp/code-graph-context.test.ts:26">
P2: Auto-detection branch (`enabled: true` without `binary_path`) is untested, leaving the core fallback binary resolution path unverified.</violation>
</file>

<file name="src/mcp/index.ts">

<violation number="1" location="src/mcp/index.ts:35">
P1: Workspace-local config can supply `code_graph_context.binary_path`, which is used as an executed local MCP command, enabling arbitrary code execution from untrusted repos.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

}

if (!disabledMcps.includes("code_graph_context")) {
const cgcConfig = createCodeGraphContextConfig(config?.code_graph_context)
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Workspace-local config can supply code_graph_context.binary_path, which is used as an executed local MCP command, enabling arbitrary code execution from untrusted repos.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/mcp/index.ts, line 35:

<comment>Workspace-local config can supply `code_graph_context.binary_path`, which is used as an executed local MCP command, enabling arbitrary code execution from untrusted repos.</comment>

<file context>
@@ -28,5 +31,12 @@ export function createBuiltinMcps(disabledMcps: string[] = [], config?: OhMyOpen
   }
 
+  if (!disabledMcps.includes("code_graph_context")) {
+    const cgcConfig = createCodeGraphContextConfig(config?.code_graph_context)
+    if (cgcConfig) {
+      mcps.code_graph_context = cgcConfig
</file context>
Fix with Cubic

import { parseJsonc } from "../../../shared"

const BUILTIN_MCP_SERVERS = ["context7", "grep_app"]
const BUILTIN_MCP_SERVERS = ["context7", "grep_app", "code_graph_context"]
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Doctor MCP check now treats code_graph_context as always enabled by adding it to a static built-in list that is mapped to enabled: true, ignoring its conditional config-based enablement.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/cli/doctor/checks/tools-mcp.ts, line 8:

<comment>Doctor MCP check now treats `code_graph_context` as always enabled by adding it to a static built-in list that is mapped to `enabled: true`, ignoring its conditional config-based enablement.</comment>

<file context>
@@ -5,7 +5,7 @@ import { join } from "node:path"
 import { parseJsonc } from "../../../shared"
 
-const BUILTIN_MCP_SERVERS = ["context7", "grep_app"]
+const BUILTIN_MCP_SERVERS = ["context7", "grep_app", "code_graph_context"]
 
 interface McpConfigShape {
</file context>
Fix with Cubic

const disabledMcps = ["code_graph_context"]

// when
const result = createBuiltinMcps(disabledMcps)
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The new filtering test for code_graph_context is vacuous because the MCP is disabled by default, so the assertion passes regardless of whether disabled-list filtering works.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/mcp/index.test.ts, line 133:

<comment>The new filtering test for `code_graph_context` is vacuous because the MCP is disabled by default, so the assertion passes regardless of whether disabled-list filtering works.</comment>

<file context>
@@ -103,4 +103,36 @@ describe("createBuiltinMcps", () => {
+    const disabledMcps = ["code_graph_context"]
+
+    // when
+    const result = createBuiltinMcps(disabledMcps)
+
+    // then
</file context>
Fix with Cubic

}

const COMMON_BINARY_LOCATIONS = [
join(homedir(), ".local", "bin", "cgc"),
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Windows auto-detection is broken because binary lookup uses cgc instead of cgc.exe for path probes.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/mcp/code-graph-context.ts, line 15:

<comment>Windows auto-detection is broken because binary lookup uses `cgc` instead of `cgc.exe` for path probes.</comment>

<file context>
@@ -0,0 +1,76 @@
+}
+
+const COMMON_BINARY_LOCATIONS = [
+  join(homedir(), ".local", "bin", "cgc"),
+  "/usr/local/bin/cgc",
+  "/usr/bin/cgc",
</file context>
Fix with Cubic


function findCgcBinary(overridePath?: string): string | undefined {
if (overridePath) {
return existsSync(overridePath) ? overridePath : undefined
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: binary_path validation incorrectly rejects PATH-resolved command names (e.g., cgc), causing valid MCP setups to be disabled.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/mcp/code-graph-context.ts, line 22:

<comment>`binary_path` validation incorrectly rejects PATH-resolved command names (e.g., `cgc`), causing valid MCP setups to be disabled.</comment>

<file context>
@@ -0,0 +1,76 @@
+
+function findCgcBinary(overridePath?: string): string | undefined {
+  if (overridePath) {
+    return existsSync(overridePath) ? overridePath : undefined
+  }
+
</file context>
Fix with Cubic

@@ -0,0 +1,69 @@
import { describe, expect, test } from "bun:test"
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Auto-detection branch (enabled: true without binary_path) is untested, leaving the core fallback binary resolution path unverified.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/mcp/code-graph-context.test.ts, line 26:

<comment>Auto-detection branch (`enabled: true` without `binary_path`) is untested, leaving the core fallback binary resolution path unverified.</comment>

<file context>
@@ -0,0 +1,69 @@
+    })
+  })
+
+  describe("#given config is enabled", () => {
+    test("#when binary_path points to nonexistent file #then returns undefined", () => {
+      // given
</file context>
Fix with Cubic

@code-yeongyu code-yeongyu added the triage:feature PR: Feature or enhancement label Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage:feature PR: Feature or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants