pyscope-mcp
MCP server that exposes Python function- and module-level call graphs for agentic coding clients, enabling tools like callers_of, callees_of, and neighborhood queries.
README
pyscope-mcp
A deployable MCP server that exposes Python function- and module-level call graphs over any Python repo, for use by agentic coding clients (Claude Code, etc.).
What it gives an agent
Instead of grepping blindly:
callers_of(fqn, depth)— who calls this function, transitivelycallees_of(fqn, depth)— what does this function reachmodule_callers(module)/module_callees(module)— module-level dependency edgesneighborhood(symbol, depth, token_budget)— bounded bidirectional subgraph around a symbol, rank-truncated to fit a token budgetfile_skeleton(path)— all top-level functions, classes, and methods defined in a filesearch(query)— substring search over all FQNsstats()— sanity-check the loaded indexreload()— re-read the index from disk after runningpyscope-mcp buildbuild()— trigger a rebuild via subprocess and reload the in-process index in one call
The graph is precomputed and saved — pyscope-mcp build runs the analyzer once and writes a JSON index; pyscope-mcp serve loads that index and answers MCP queries without re-running analysis.
Install
pip install pyscope-mcp
Build the index
pyscope-mcp build --root /path/to/repo --package my_pkg
Writes to .pyscope-mcp/index.json inside the repo by default. Override with --output or $PYSCOPE_MCP_INDEX.
Serve
pyscope-mcp serve --root /path/to/repo
Errors out if no index exists. Env-var equivalents: PYSCOPE_MCP_ROOT, PYSCOPE_MCP_INDEX.
Register with Claude Code
{
"mcpServers": {
"pyscope": {
"command": "pyscope-mcp",
"args": ["serve"],
"env": {
"PYSCOPE_MCP_ROOT": "/abs/path/to/repo"
}
}
}
}
Setup for an agent in your repo (Claude Code)
If you are an agent setting up pyscope-mcp in a new repo, follow these steps:
-
Install the package
pip install pyscope-mcp -
Build the call-graph index
pyscope-mcp build --root /abs/path/to/repo --package your_package_nameThis writes
.pyscope-mcp/index.jsoninside the repo. Run this step first —servewill not build the index automatically. -
Register the MCP server in
.claude/settings.json{ "mcpServers": { "pyscope": { "command": "pyscope-mcp", "args": ["serve"], "env": { "PYSCOPE_MCP_ROOT": "/abs/path/to/repo" } } } }If the index lives at a non-default path, add
"PYSCOPE_MCP_INDEX": "/abs/path/to/index.json"to theenvblock. -
Verify the server loaded
After restarting Claude Code (or reloading the MCP server), ask Claude:
Call the
statstool on the pyscope-mcp server.You should see node and edge counts in the response. If the output is non-empty the index loaded correctly and the MCP tools are ready to use.
Query logging (opt-in)
Every tools/call dispatch can append a structured JSONL entry to a local rotating log file so you can measure tool-use patterns, truncation rates, hub-suppression hits, and latency without parsing claude's session transcripts.
The logger is off by default. Set PYSCOPE_MCP_LOG=1 to enable.
Log location
Default: .pyscope-mcp/query.jsonl next to the index file (already .gitignored).
Override: PYSCOPE_MCP_LOG_PATH=/abs/path/to/query.jsonl.
Enable / disable
# Enable
PYSCOPE_MCP_LOG=1 pyscope-mcp serve ...
# Disable explicitly (or leave PYSCOPE_MCP_LOG unset — off is the default)
PYSCOPE_MCP_LOG=0 pyscope-mcp serve ...
Log entry schema (v1)
{
"v": 1,
"ts": "2026-04-25T21:00:00.000+00:00",
"server_id": "550e8400-e29b-41d4-a716-446655440000",
"rpc_id": 3,
"tool": "neighborhood",
"args": {"symbol": "pkg.mod.Foo.run", "depth": 2, "token_budget": 500},
"duration_ms": 12,
"is_error": false,
"truncated": true,
"result_count": null,
"edge_count": 7,
"hub_suppressed_count": 2,
"depth_full": 1,
"token_budget_used": 487,
"index_version": 5,
"index_git_sha": "a1b2c3d4...",
"index_content_hash": "abcdef12..."
}
server_id partitions entries by session (the MCP server is spawned per-session as a stdio subprocess by Claude Code). To join log entries with claude's own session transcript, match by (ts, tool, args) or rpc_id.
Rotation: files rotate at 10 MB; up to 5 historical files are kept (query.jsonl.1 … query.jsonl.5), giving a ~50 MB ceiling.
Index schema v5 note
The index format was bumped from v4 to v5 to add git_sha and content_hash header fields (used by the logger to tie each log entry to a specific graph version). Existing v4 index files are not migrated — re-run pyscope-mcp build to generate a v5 index.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。