MCP server for Python performance testing with py-spy
Project description
py-spy MCP Server
A Model Context Protocol (MCP) server that exposes Python performance testing tools powered by py-spy.
🌐 English | 简体中文
Profile Python in context. Sample live processes, generate flamegraphs, dump stacks, and compare runs — all through MCP.
Features
- Profile by PID or command — sample a running Python process or launch a new one directly.
record_profile— generate profiles in multiple formats:speedscope(interactive JSON)flamegraph(self-contained SVG)raw(stack-count text)chrometrace(Chrome DevTools timeline JSON)
dump_stacks— capture the current Python call stacks of a process as JSON or human-readable text.list_python_processes— list running Python processes on the machine to pick a target.analyze_profile— parse an existing profile and return the hottest frames.compare_profiles— compare two speedscope profiles and show percentage changes.top_profile— run a shortpy-spy topsession and return a summary.- On Windows,
py-spy topcannot be captured through a pipe, so this tool falls back to a short raw recording and returns the hottest frames.
- On Windows,
- Low-overhead sampling — powered by py-spy; reads process memory without modifying or running inside the target process.
- Cross-platform — works on Linux, macOS, and Windows (subject to OS permissions).
- Local-source friendly — during development the server automatically prefers a
py-spybinary built from the sibling Rust source (src/pyspy/). - Optional native/C extension profiling — enable
--nativewhere the platform supports it. - GIL and idle filtering — focus on active threads or GIL-holding threads.
Installation (from PyPI)
Using pip:
pip install pyspy-mcp
Using uv:
uv pip install pyspy-mcp
# or install as a global tool
uv tool install pyspy-mcp
This will automatically install the compatible py-spy binary wheel for your platform.
Running with Claude Desktop / Claude Code
Add the server as a Local command connector:
{
"mcpServers": {
"pyspy": {
"command": "pyspy-mcp"
}
}
}
Or run directly:
pyspy-mcp
The server speaks MCP over stdio.
Development (from source)
If you want to use the local py-spy Rust source instead of the PyPI package:
# Build py-spy from the local Rust source
cargo build --release
# The binary will be at:
# target/release/py-spy (Linux / macOS)
# target/release/py-spy.exe (Windows)
# Install the Python MCP package in editable mode
pip install -e ".[dev]"
# Or using uv
uv pip install -e ".[dev]"
# Run tests
python -m pytest tests/pyspy_mcp -v
The server will automatically prefer a locally built binary at target/release/py-spy[.exe] over the py-spy installed from PyPI. You can also force a specific binary by setting the environment variable:
export PYSPY_MCP_BINARY=/path/to/py-spy
Publishing to PyPI
python -m build
python -m twine upload dist/*
The published wheel is a pure-Python py3-none-any package and depends on the upstream py-spy PyPI package. If you modify the Rust source and want to ship those changes, you will need to build platform-specific wheels (or bundle the rebuilt py-spy binary as package data).
Permissions
- On Linux, profiling an existing PID usually requires
ptracepermissions (sudoorcap_sys_ptrace). - On macOS, profiling often requires root due to System Integrity Protection (SIP).
- On Windows, running as Administrator may be needed for some processes.
Configuration
Set PYSPY_MCP_BINARY to override the bundled/development py-spy binary location.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyspy_mcp-0.1.0.tar.gz.
File metadata
- Download URL: pyspy_mcp-0.1.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d66c0b58a9eb9df432bdaf7f9f8f9c14ff419b158e868bc6df24c62db997249
|
|
| MD5 |
fd41fc37c85138a44bf97647de4e26b6
|
|
| BLAKE2b-256 |
43a57f0272d6dfbb6bcf9751e40b633003482de1f209fc4a33ba3f8f899aabf6
|
Provenance
The following attestation bundles were made for pyspy_mcp-0.1.0.tar.gz:
Publisher:
publish.yml on LBurny/pyspy-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyspy_mcp-0.1.0.tar.gz -
Subject digest:
9d66c0b58a9eb9df432bdaf7f9f8f9c14ff419b158e868bc6df24c62db997249 - Sigstore transparency entry: 2149489642
- Sigstore integration time:
-
Permalink:
LBurny/pyspy-mcp@f0b58be44cfe3c6fe5bd3b1b38893d38f76f1b4b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/LBurny
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f0b58be44cfe3c6fe5bd3b1b38893d38f76f1b4b -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyspy_mcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyspy_mcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efaf2e00cf650572937a60ff9519af9f833eb379ea75eb822181987e20e6636c
|
|
| MD5 |
7b142bac4da1b91e525703a451cd901c
|
|
| BLAKE2b-256 |
ac55c7b5dd19bd877ce5abe8d72801b29a1dc9c2d18ccdc9eeb51e7c0beb2070
|
Provenance
The following attestation bundles were made for pyspy_mcp-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on LBurny/pyspy-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyspy_mcp-0.1.0-py3-none-any.whl -
Subject digest:
efaf2e00cf650572937a60ff9519af9f833eb379ea75eb822181987e20e6636c - Sigstore transparency entry: 2149490025
- Sigstore integration time:
-
Permalink:
LBurny/pyspy-mcp@f0b58be44cfe3c6fe5bd3b1b38893d38f76f1b4b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/LBurny
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f0b58be44cfe3c6fe5bd3b1b38893d38f76f1b4b -
Trigger Event:
release
-
Statement type: