Skip to main content

MCP server

The mcp command exposes a saved graph to LLM agents over the Model Context Protocol as a set of query tools. Instead of dumping an entire codebase into a prompt, an agent can ask graphlens precise questions — "who calls this?", "what does this talk to?" — and get structured answers.

Install and run

pip install "graphlens-cli[mcp]"

# First produce a graph
graphlens analyze ./my-project --output graph.json

# Then serve it (stdio transport)
graphlens mcp --graph graph.json
OptionDefaultDescription
--graph, -gPath to a graph JSON file from analyze --output (required)

The server speaks MCP over stdio, which is what desktop agent clients expect.

Exposed tools

ToolReturns
statsnode/relation counts by kind and the resolver status
findnodes whose name matches a query
callersfunctions/methods that call a node
calleesfunctions/methods a node calls
referencesnodes that reference a node
neighborsnodes within depth hops of a node
boundariesevery cross-language boundary with its exposers and consumers
communicates_withconsumer → provider edges across languages

Node results are returned as compact dicts (id, kind, qualified_name, name, file_path), which keeps responses small enough to fit comfortably in an agent's context.

Wiring it into a client

Most MCP clients are configured with a command to launch. Point the client at the graphlens mcp invocation, for example:

{
"mcpServers": {
"graphlens": {
"command": "graphlens",
"args": ["mcp", "--graph", "/absolute/path/to/graph.json"]
}
}
}

Regenerate graph.json (with graphlens analyze --output) whenever the code changes so the agent is querying a current graph — for example as a step in the same CI job that indexes the repository.

Why serve a graph instead of files?

  • Precision — the agent gets resolved CALLS/REFERENCES edges, not a best-effort text search.
  • Token efficiency — answers are small structured lists, not file dumps.
  • Cross-language awarenesscommunicates_with and boundaries surface relationships no single-language tool can see.