Skip to content

feat(mcp): scaffold api/mcp module (T1 #648)#666

Open
DvirDukhan wants to merge 2 commits intostagingfrom
mcp/t1-scaffold
Open

feat(mcp): scaffold api/mcp module (T1 #648)#666
DvirDukhan wants to merge 2 commits intostagingfrom
mcp/t1-scaffold

Conversation

@DvirDukhan
Copy link
Copy Markdown

@DvirDukhan DvirDukhan commented Apr 11, 2026

Summary

  • Adds api/mcp/ module with a bare FastMCP("code-graph") server instance
  • Wires cgraph-mcp console-script entry point in pyproject.toml
  • Adds mcp>=1.0,<2.0 dependency
  • Copies MCP design docs (docs/MCP_SERVER_DESIGN.md, docs/code-graph-mcp-v4.docx) into the repo
  • Includes a protocol smoke test (tests/mcp/test_scaffold.py) that spawns the server over stdio, completes the MCP handshake, and asserts list_tools returns an empty set

Test plan

  • uv run pytest tests/mcp/test_scaffold.py -v — 3/3 pass (import, entry point, stdio round-trip)
  • ruff check api/mcp/ tests/mcp/ — clean
  • cgraph-mcp resolves on PATH after uv sync
  • CI green on this branch

Closes #648

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • MCP server interface available to expose code-graph indexer and query tools over the Model Context Protocol stdio transport
  • Documentation

    • Added comprehensive MCP server design spec covering architecture, tool catalog, phased rollout, and testing strategy
  • Tests

    • Added smoke tests validating MCP server initialization and stdio protocol handshake
  • Chores

    • Added a new CLI command to run the MCP server locally

… entry point

Add the bare MCP server module (api/mcp/) using the official FastMCP SDK,
wire the cgraph-mcp console script in pyproject.toml, and include a protocol
smoke test that spawns the server over stdio and verifies list_tools returns
an empty tool set. Also copies the MCP design docs into docs/.

Closes #648

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fd10535f-7b4e-4851-b9f4-f122a8801958

📥 Commits

Reviewing files that changed from the base of the PR and between 92d6805 and 408efde.

📒 Files selected for processing (2)
  • docs/MCP_SERVER_DESIGN.md
  • tests/mcp/test_scaffold.py
✅ Files skipped from review due to trivial changes (1)
  • tests/mcp/test_scaffold.py

📝 Walkthrough

Walkthrough

Scaffolds an MCP stdio server under api/mcp/, adds the mcp runtime dependency and cgraph-mcp entry point, includes a Phase‑1 design doc, and adds smoke tests that start the server and assert an empty tool list on initialization.

Changes

Cohort / File(s) Summary
MCP Server Scaffolding
api/mcp/__init__.py, api/mcp/server.py
Adds module docstring and a FastMCP("code-graph") app exported as app, plus a main() -> None that runs the stdio MCP server.
Dependency & Entry Point
pyproject.toml
Adds mcp>=1.0.0,<2.0.0 dependency and registers cgraph-mcp = api.mcp.server:main console script.
Design Documentation
docs/MCP_SERVER_DESIGN.md
Adds a Phase‑1 MCP server design describing tool categories, indexing/migration requirements, module layout, testing strategy, and rollout roadmap.
Smoke Tests
tests/mcp/test_scaffold.py
Adds async scaffold tests: import/name check, main callable check, and a stdio-backed protocol round‑trip that asserts tools is empty.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I nibble on new server roots,
A tiny app in cozy boots,
Stdio whispers, tests alight,
Tools are zero — launch tonight.
Hoppity hops — the graph takes flight! 🥕✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: scaffolding the api/mcp module with the entry point, which is the primary objective of this PR.
Linked Issues check ✅ Passed All coding requirements from issue #648 are met: api/mcp/ module created with FastMCP app and main() runner, cgraph-mcp entry point added to pyproject.toml, mcp>=1.0,<2.0 dependency added, MCP_SERVER_DESIGN.md documentation added, and test_scaffold.py smoke tests implemented.
Out of Scope Changes check ✅ Passed All changes are scoped to T1 requirements: module scaffolding, entry point setup, dependency declaration, design docs, and smoke tests. No tool implementations, CI changes, HTTP/SSE transport, GraphRAG plumbing, or auto-init logic are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mcp/t1-scaffold

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Scaffolds an MCP (Model Context Protocol) server module within the existing Python backend so external agents can connect via stdio, and establishes the packaging/test wiring needed to evolve into a full “code-graph” MCP server.

Changes:

  • Add api/mcp/ with a bare FastMCP("code-graph") app plus a stdio main() runner.
  • Wire a new cgraph-mcp console script and add the mcp>=1,<2 dependency (with updated lockfile).
  • Add MCP stdio smoke tests and check in MCP design documentation assets.

Reviewed changes

Copilot reviewed 5 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
api/mcp/server.py Introduces the FastMCP app instance and stdio runner entry point.
api/mcp/__init__.py Adds module-level documentation for the MCP server package.
pyproject.toml Adds mcp dependency and cgraph-mcp console-script wiring.
uv.lock Locks transitive dependencies introduced by mcp (and its dependency graph).
tests/mcp/test_scaffold.py Adds a stdio protocol smoke test verifying handshake + empty tool list.
tests/mcp/__init__.py Establishes the tests.mcp package.
docs/MCP_SERVER_DESIGN.md Adds MCP server design summary and roadmap for Phase 1+.
docs/code-graph-mcp-v4.docx Adds the full design document (binary).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 29 to 32
[project.scripts]
cgraph = "api.cli:app"
cgraph-mcp = "api.mcp.server:main"

Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

The design/issue text specifies the console-script entry point as api.mcp.server:app, but pyproject.toml wires cgraph-mcp to api.mcp.server:main. Please align the entry point target with the documented contract (either change the script target back to :app if supported by the MCP SDK, or update the docs/issue references to :main).

Copilot uses AI. Check for mistakes.
Comment on lines 23 to 27
"javatools>=1.6.0,<2.0.0",
"pygit2>=1.17.0,<2.0.0",
"typer>=0.24.0,<1.0.0",
"mcp>=1.0.0,<2.0.0",
]
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

Adding mcp as a core dependency pulls in heavier transitive deps (notably pyjwt[crypto]cryptography, plus python-multipart, sse-starlette, etc. per uv.lock). Please confirm this footprint is acceptable for all installs of the base package; if MCP is optional, consider moving it under an extra to avoid requiring compiled wheels for users who don’t use cgraph-mcp.

Copilot uses AI. Check for mistakes.
## Key Decisions Made

- **Mono-repo**: Build inside `code-graph/api/mcp/`, not a separate project. One pip package, one repo.
- **Module path is `api/mcp/`, NOT top-level `mcp/`**: A top-level `mcp/` directory would shadow the installed `mcp` PyPI SDK and break `from mcp.server.fastmcp import FastMCP`. Entry point: `cgraph-mcp = "api.mcp.server:app"`.
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

This section documents the entry point as cgraph-mcp = "api.mcp.server:app", but the PR wires the console script to api.mcp.server:main. Please update this doc (and any other occurrences) so the documented entry point matches the actual packaging.

Suggested change
- **Module path is `api/mcp/`, NOT top-level `mcp/`**: A top-level `mcp/` directory would shadow the installed `mcp` PyPI SDK and break `from mcp.server.fastmcp import FastMCP`. Entry point: `cgraph-mcp = "api.mcp.server:app"`.
- **Module path is `api/mcp/`, NOT top-level `mcp/`**: A top-level `mcp/` directory would shadow the installed `mcp` PyPI SDK and break `from mcp.server.fastmcp import FastMCP`. Entry point: `cgraph-mcp = "api.mcp.server:main"`.

Copilot uses AI. Check for mistakes.
Comment on lines +69 to +74
│ ├── test_ask.py # T11 — mocked LLM, real Cypher against fixture
│ ├── test_auto_init.py # T12
│ └── test_init_agent.py # T13
└── pyproject.toml # Adds `cgraph-mcp = "api.mcp.server:app"` and `mcp>=1.0,<2.0`
```

Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

The directory structure example also states cgraph-mcp = "api.mcp.server:app", but the package currently exports cgraph-mcp = "api.mcp.server:main". Please keep the design doc consistent with the actual pyproject.toml script target.

Copilot uses AI. Check for mistakes.
- **GraphRAG SDK powers the ask tool**: `kg.ask()` does NL-to-Cypher. Code-graph's `api/llm.py` already integrates this — repackage for MCP.
- **Reuse the existing hand-coded ontology** from `api/llm.py:_define_ontology()` (lines 26–233) rather than auto-extracting via `Ontology.from_kg_graph()`. The hand-coded version has richer entity attributes and descriptions tuned for code. Refactor: rename `_define_ontology` → `define_ontology` so the MCP module can import it.
- **Ship with 3 languages** (Python/Java/C#), add tree-sitter for broad coverage in Phase 2.
- **No incremental indexing in v1**: Full re-indexing is sufficient. Deferred to Phase 3.
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

The “Key Decisions Made” list says “No incremental indexing in v1” (deferred), but later in this same document it describes incremental indexing as “default-on” in Phase 1. Please reconcile these statements so the design doc has a single, consistent plan.

Suggested change
- **No incremental indexing in v1**: Full re-indexing is sufficient. Deferred to Phase 3.
- **Incremental indexing in v1**: First-time indexing is full; once a `(project, branch)` graph exists, incremental indexing is the default. Allow explicit full re-index via `--full` (CLI) or `incremental=False` (MCP).

Copilot uses AI. Check for mistakes.
Comment on lines +50 to +55
params = StdioServerParameters(command=cgraph_mcp, args=[])
async with stdio_client(params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
result = await session.list_tools()
assert result.tools == []
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

This protocol smoke test can hang indefinitely if the spawned server fails to start or the MCP handshake stalls (no timeout around initialize() / list_tools()). Consider wrapping the stdio session block in an anyio.fail_after(...) (or equivalent pytest timeout) to keep CI runs from blocking forever on failures.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/MCP_SERVER_DESIGN.md`:
- Line 18: Update the documented console-script entry point from
"api.mcp.server:app" to the actual runtime target "api.mcp.server:main" wherever
it appears in the design doc (e.g., the references currently stating
api.mcp.server:app around the console-script/entrypoint description), so the doc
matches the pyproject wiring and avoid misleading setup instructions.
- Line 37: Several fenced code blocks in the document (the ones showing
"code-graph/ ..." the ASCII graph starting with "T1 ──┬─> T2 ..." and the cli
example "claude mcp add-json \"code-graph\" ...") are missing language
identifiers; update those backtick-fenced blocks to include appropriate language
tags (e.g., ```text for directory/listing and ASCII art, ```bash for the CLI
command) so markdownlint MD040 is satisfied and the blocks render correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 208a6980-6e4c-4d2e-92e2-51f4193a35af

📥 Commits

Reviewing files that changed from the base of the PR and between b066064 and 92d6805.

⛔ Files ignored due to path filters (2)
  • docs/code-graph-mcp-v4.docx is excluded by !**/*.docx
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • api/mcp/__init__.py
  • api/mcp/server.py
  • docs/MCP_SERVER_DESIGN.md
  • pyproject.toml
  • tests/mcp/__init__.py
  • tests/mcp/test_scaffold.py

- Fix stale entry point references in design doc: api.mcp.server:app → :main
- Remove contradicting decisions about tree-sitter/incremental indexing scope
- Add language tags to fenced code blocks (MD040)
- Add anyio.fail_after timeout to stdio smoke test to prevent CI hangs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MCP T1] Scaffold api/mcp/ module + cgraph-mcp entry point

2 participants