Skip to main content

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, transitively
  • callees_of(fqn, depth) — what does this function reach
  • module_callers(module) / module_callees(module) — module-level dependency edges
  • neighborhood(symbol, depth, token_budget) — bounded bidirectional subgraph around a symbol, rank-truncated to fit a token budget
  • file_skeleton(path) — all top-level functions, classes, and methods defined in a file
  • search(query) — substring search over all FQNs
  • stats() — sanity-check the loaded index
  • reload() — re-read the index from disk after running pyscope-mcp build
  • build() — 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:

  1. Install the package

    pip install pyscope-mcp
    
  2. Build the call-graph index

    pyscope-mcp build --root /abs/path/to/repo --package your_package_name
    

    This writes .pyscope-mcp/index.json inside the repo. Run this step first — serve will not build the index automatically.

  3. 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 the env block.

  4. Verify the server loaded

    After restarting Claude Code (or reloading the MCP server), ask Claude:

    Call the stats tool 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.

Metadata

Release files for pyscope-mcp 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyscope-mcp 0.1.0
File Size Uploaded Provenance
pyscope_mcp-0.1.0.tar.gz 230.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pyscope-mcp 0.1.0
File Interpreter ABI Platform
pyscope_mcp-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 308.8 kB

Release files / pyscope_mcp-0.1.0.tar.gz

Download URL pyscope_mcp-0.1.0.tar.gz
Size 230.9 kB
Tags Source
SHA-256 checksum
How to use checksums
38c309869c0a42974133789ec1e09269d306025d808b91e0ddba264cfd45e666
BLAKE2b-256 checksum
How to use checksums
d8fb6d9c44cc6afb52e63c51ca817ea443dabf2427688e3a47b5242de8fcae87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / pyscope_mcp-0.1.0-py3-none-any.whl

Download URL pyscope_mcp-0.1.0-py3-none-any.whl
Size 77.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
98a5f560d0f371a4ed834a66b861e305e82ece618840b18d4351094ff0d65e6a
BLAKE2b-256 checksum
How to use checksums
62b61084790cc90d433a84a1fa24e3f795208ab06d316d4417e41aac829ef62d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Security for pyscope-mcp 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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