py-spy MCP Server
MCP server for profiling Python processes using py-spy, supporting flamegraphs, stack dumps, and performance comparisons.
README
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.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.