# MCP Integration
> How CGraph speaks the Model Context Protocol, and the tools it exposes.
[Source](https://open.nxtsoft.io/docs/cgraph/mcp)

`cgraph-mcp` exposes the graph to coding agents over the Model Context Protocol
(MCP). Its tool calls route through the same daemon operation handler as the thin
client, so an agent gets exactly the semantics the CLI does.

## The protocol

`cgraph-mcp` speaks **newline-delimited JSON-RPC 2.0 over stdio**, protocol
version `2024-11-05`. It implements the standard handshake and tool methods:

```text
JSON-RPC 2.0 over stdio (protocol 2024-11-05)
```

| Method | Purpose |
| --- | --- |
| `initialize` | Handshake and capability exchange. |
| `notifications/initialized` | Client signals it's ready. |
| `tools/list` | Enumerate the available tools. |
| `tools/call` | Invoke a tool. |

Invalid JSON receives a JSON-RPC parse error response rather than crashing the
server.

## The request flow

_An agent's tool call, end to end_

```text
agent ── JSON-RPC (stdio) ──> cgraph-mcp ──> daemon operation handler ──> graph
  ^                                                                        |
  └──────────────────── JSON result ──────────────────────────────────────┘
```

## The eight tools

  - **graph_query** — Find nodes matching a query.
  - **graph_explain** — Explain a node and its role.
  - **graph_impact** — The transitive blast radius of a change.
  - **graph_path** — The shortest path between two symbols.
  - **graph_context** — A packed, budgeted neighborhood for the agent.
  - **graph_update** — Fold in changes / trigger a rescan.
  - **graph_status** — Daemon and graph health.
  - **graph_shutdown** — Stop the daemon.

## How it finds the project and the daemon

`cgraph-mcp` resolves the project **root** in priority order:

```text
--root flag  >  CLAUDE_PROJECT_DIR env var  >  working directory
```

and discovers the **daemon** in priority order:

```text
--daemon <path>  >  CGRAPH_DAEMON_PATH env var  >  graphd next to the binary  >  build-tree layout
```

This is why `cgraph-mcp` works from an agent with minimal configuration: an agent
that sets `CLAUDE_PROJECT_DIR` (like Claude Code) and ships `graphd` next to the
binary needs no flags at all.

## Where to go next

- [AI Agent Integration](/docs/cgraph/ai-agents) — registering CGraph with Claude
  Code, Codex, and Cursor.
