Skip to main content

ConnectContext

An MCP server that exposes ContextAI's code-graph engine as tools an LLM agent can call: build a knowledge graph of a Python project (functions/classes as nodes, calls/relationships as edges), query it, and confirm it against real runtime behavior.

Stability

Tier Tools Notes
Stable build_graph, load_graph, find_node, get_context, get_edge_path, list_gaps Read-only static analysis. Never executes code. Tested against real multi-thousand-node codebases.
Experimental run_trace, merge_trace run_trace executes the target's code (in a subprocess, in a chosen interpreter). Tested on synchronous, dependency-light Python. Async/threaded/network-dependent targets, and cross-platform/cross-version behavior, are not yet validated. Use on trusted code only.

Tools

Tool What it does
build_graph(project_root, output="graph.json") Statically analyze a project; save the graph. Run this first.
load_graph(graph_path) Load/validate a graph; report node/edge counts.
find_node(graph_path, query) Substring search for nodes; returns slim records with ids.
get_context(graph_path, node_id, depth=2, direction="in", include_code=True) Focal node + neighbors + edges. Focal and (by default) each neighbor include their source code, so an agent can read the whole neighborhood in one call; pass include_code=false for a slim response.
get_edge_path(graph_path, from_id, to_id) Direct edges between two nodes.
list_gaps(graph_path, node_id) Unresolved calls / dynamic-dispatch gaps for a node.
run_trace(project_root, target, static_graph, entry=None, python=None, timeout_seconds=120, ...) Execute a target under the tracer in a subprocess and return the ordered execution path with each step's source code, mapped onto the graph. On a crash it returns the path up to the failure plus the error and traceback — trace-to-context debugging in one call. Pass python=".venv/bin/python" to trace a project in its own venv (that interpreter must have contextai installed). Pass entry=<function> to get an exact, lossless split between import-time setup and real execution — without it, a long path falls back to a head/tail approximation. Always merges onto a fresh static graph; refuses a static_graph that already carries runtime data, so traced actions never silently accumulate.
merge_trace(base_graph, call_log, project_root, ...) Fold a previously captured call log onto a pristine graph (no code execution). Same no-accumulation guarantee as run_trace.

The long-running-session tracers (start_trace / stop_trace) are intentionally not exposed: they hook the process they're called in, so driven across separate MCP tool calls they capture nothing useful — they're meant to be embedded inside a long-running app (e.g. a FastAPI startup/shutdown hook), not called remotely.

Setup

pip install -r requirements.txt   # mcp[cli]<2 + contextai

Run

contextai-mcp   # or: python -m contextai_mcp   or: python server.py   — stdio transport

For interactive inspection: mcp dev server.py.

contextai-mcp --help / --version work and exit immediately. Running it directly in an interactive terminal (no real MCP client attached) prints the tool list and exits instead of hanging — it's designed to be launched by a client over a pipe, not run by a human directly.

Using with an MCP client

The server is the same regardless of client — only where each client looks for its config differs.

Published on PyPI as contextai-mcp, so any client can run it with zero manual install via uvx — this is the recommended way to configure it, since it also sidesteps a common pip install gotcha: the contextai-mcp console script can land somewhere not on your shell's PATH (e.g. ~/.local/bin on a --user install), which makes a bare "command": "contextai-mcp" config fail with "command not found." uvx manages its own isolated environment and invocation, so this never comes up. If you do use a plain pip install, either put the script's directory on PATH or use an absolute path in your config (see the local examples below) — python -m contextai_mcp also works as a command/args alternative that doesn't depend on the console script at all.

Client Config file Format
Claude Code .mcp.json (project) JSON
Claude Desktop claude_desktop_config.json JSON
Cursor .cursor/mcp.json (project) or ~/.cursor/mcp.json (global) JSON, same shape as Claude
Codex CLI .codex/config.toml (project) or ~/.codex/config.toml (global) TOML

Claude Code / Claude Desktop / Cursor (JSON):

{ "mcpServers": { "contextai-graph": { "command": "uvx", "args": ["contextai-mcp"] } } }

Codex CLI (TOML):

[mcp_servers.contextai-graph]
command = "uvx"
args = ["contextai-mcp"]

Before publishing (local development), point at the installed console script directly instead — see .mcp.json, .cursor/mcp.json, and .codex/config.toml in this repo for working examples against this workspace's interpreter.

Typical flow

  1. build_graph("/path/to/project") → writes graph.json.
  2. find_node("graph.json", "process_data") → grab a node id.
  3. get_context("graph.json", "<id>") → see callers/callees.
  4. list_gaps / get_edge_path for deeper inspection.
  5. run_trace(..., entry="the_function") → confirm what actually executes, or get the exact path to a bug.

Layout

server.py                     # entrypoint: create_server().run()
contextai_mcp/
├── __main__.py               # python -m contextai_mcp
├── app.py                    # create_server() factory + --help/--version/main()
├── _helpers.py               # GraphStore cache, JSON coercion, stdout guard, no-accumulation guard
└── tools/                    # one file per tool, each with register(mcp)
    ├── __init__.py           # register_all(mcp)
    ├── build_graph.py  load_graph.py  find_node.py
    ├── get_context.py  get_edge_path.py  list_gaps.py
    └── run_trace.py    merge_trace.py
.mcp.json  .cursor/mcp.json  .codex/config.toml   # client configs for this workspace

See docs/PROBLEMS_AND_SOLUTIONS.md for the full build log: every issue hit, why, and how it was fixed.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

contextai_mcp-0.1.2.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

contextai_mcp-0.1.2-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file contextai_mcp-0.1.2.tar.gz.

File metadata

  • Download URL: contextai_mcp-0.1.2.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for contextai_mcp-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8dbaac13e14f594d43fcf08c8264431d0ef0cb840912f822db1863f120e5ae25
MD5 0fabc510caab205a3c000da1501e803b
BLAKE2b-256 4471e56b2a3dc3cfd94ab1e9a3deb27f5f88670bc8284e39970b0fc848a00609

See more details on using hashes here.

File details

Details for the file contextai_mcp-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: contextai_mcp-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for contextai_mcp-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7be351f5bd433cbcf90d8b7114107886932224f8b671e3d8d6fa7f50fc474832
MD5 c7735eca732468abb5a4ee727949a8dc
BLAKE2b-256 4a1c0d1c6d337effe311407f90e411fe79ff7ee7f1a0cf8c69950958724bca17

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page