# MCP tools

> Run codeweb as a Model Context Protocol server and query the graph from Claude Desktop, Cursor, or any MCP client.

---

LLMS index: [llms.txt](/codeweb/llms.txt)

---

## Start the MCP server {#start-the-mcp-server}

Built with the `mcp` feature, `codeweb mcp` speaks JSON-RPC over stdio:

```bash
cargo build --release --features mcp
codeweb mcp --project /path/to/your/project
```

Register it in an MCP client, for example Claude Desktop's `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "codeweb": {
      "command": "/path/to/codeweb",
      "args": ["mcp", "--project", "/path/to/your/project"]
    }
  }
}
```

## Lifecycle {#lifecycle}

The server starts even when the directory has no `codeweb.toml` yet: queries then return `status: "uninitialized"` instead of the process exiting.

1. `codeweb_init` writes `codeweb.toml` and `.codeweb/` under the served directory. It never analyzes on its own.
2. `codeweb_analyze` builds or incrementally refreshes the graph and hot-swaps it into the running server, so later queries see the new graph without a restart.
3. `codeweb_diff` lists files added, modified, or deleted since the last analysis.

## Tools {#tools}

| Tool | Parameters | Description |
| ---- | ---------- | ----------- |
| `codeweb_init` | `name` (optional, defaults to directory name), `paths` (optional, defaults to `["."]`) | Initialize the project; no analysis |
| `codeweb_analyze` | — | Build/refresh the graph and hot-swap it in |
| `codeweb_diff` | — | Changes since the last analysis |
| `codeweb_stats` | — | Node counts by type, edge count, status; call this first |
| `codeweb_nodes` | `search`, `node_type`, `limit`, `offset` | List nodes with filtering and pagination |
| `codeweb_node_detail` | `ids` (list), `depth` (`1` direct, `0` unlimited, `N` hops) | Properties, callers, callees |
| `codeweb_trace` | `from`, `depth`, `max_nodes` | Bidirectional call chain as nested trees |
| `codeweb_search_sql` | `sql` | Search `mapper`/`sql` nodes by SQL text with relevance scoring |
| `codeweb_query` | `spec` | Execute a [QuerySpec](/codeweb/docs/trace-and-query/#declarative-queries) |
| `codeweb_column_analysis` | `procedure` or `package` (exactly one), `table` (optional) | Same JSON schema as `codeweb columns --format json` |
| `codeweb_lineage` | `target`, `direction`, `depth` | Same functions and JSON shape as `codeweb lineage --format json` |

## Security boundaries {#security-boundaries}

Reads may point at any directory listed in `analysis.paths`, but every write is confined to the served directory: a tampered `store.path` that escapes it is rejected. The server exposes no shell execution and no file-write tools beyond the lifecycle above.

---

Backlinks:

- [CLI reference](/codeweb/docs/cli-reference/)
- [Getting started](/codeweb/docs/getting-started/)
