MCP Server

ContextGraph exposes its knowledge graph to AI agents over the Model Context Protocol (MCP) via stdio. Start the server with:

Terminal
./gradlew :modules:cli:run --args="serve-mcp"

Claude Desktop

claude_desktop_config.json
{
  "mcpServers": {
    "contextgraph": {
      "command": "/absolute/path/to/context-graph/gradlew",
      "args": [
        "-p", "/absolute/path/to/context-graph",
        ":modules:cli:run",
        "--args=serve-mcp"
      ]
    }
  }
}

Tools

The server registers 10 tools that agents can call to query the knowledge graph.

contextgraph.index_project

Index a project directory into the graph.

ParameterTypeRequiredDescription
pathstringyesAbsolute path to the project directory

contextgraph.search_nodes

Full-text search across all nodes, with optional type filtering.

ParameterTypeRequiredDescription
querystringyesSearch query
typesstringnoComma-separated node types e.g. Class,Function
minConfidencenumbernoMinimum confidence 0–1 (default: 0.5)
limitnumbernoMax results (default: 20)

contextgraph.get_node

Fetch a single node by ID, including its properties and provenance (source file + line numbers).

ParameterTypeRequired
nodeIdstringyes

contextgraph.expand_node

BFS neighborhood expansion — returns all nodes reachable within depth hops.

ParameterTypeDefault
nodeIdstring
depthnumber2

contextgraph.find_path

Find the shortest explanation path between two nodes using Dijkstra's algorithm.

ParameterType
fromIdstring
toIdstring

contextgraph.get_evidence

Return the full provenance chain for a node — every file and line number that contributed to it.

contextgraph.impact_analysis

Reverse dependency analysis: what nodes depend on this one? Useful before making changes to understand blast radius.

contextgraph.related_files

Return all source file paths associated with a node via provenance records.

contextgraph.build_context

The most powerful tool for agents. Given a task description, it searches the graph, expands neighborhoods, and returns a ranked set of nodes and edges most relevant to the task.

ParameterTypeDefault
taskstring
depthnumber2

contextgraph.generate_report

Generate GRAPH_REPORT.md and graph.html in the specified output directory.

Resources

The server also exposes read-only MCP resources:

URIDescription
contextgraph://projectArtifact, node, and edge counts
contextgraph://graph/nodesAll nodes (up to 500, confidence ≥ 0.5)
contextgraph://graph/edgesAll edges (up to 500, confidence ≥ 0.5)
contextgraph://artifactsAll indexed source files
contextgraph://reports/summaryLive Markdown report
contextgraph://clustersConnected component summary

Prompts

PromptDescription
explain_codebaseGuide the agent to explain the overall architecture
find_context_for_taskFind relevant graph context for a given task
analyze_change_impactAnalyze the impact of changing a specific node
summarize_researchSummarize a research document collection