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.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。