local-only server
The server can only run on the client’s local machine because it depends on local resources.
Integrations
Provides containerized execution of the pprof analyzer with bundled dependencies like Graphviz, enabling consistent profiling analysis environments across systems.
Enables analysis of pprof profile files hosted on GitHub via raw URLs, allowing examination of performance profiles directly from GitHub repositories.
Offers macOS-specific functionality for launching interactive pprof web UI sessions, with the ability to initiate and manage background profiling processes.
简体中文 | English
Pprof Analyzer MCP Server
This is a Model Context Protocol (MCP) server implemented in Go, providing a tool to analyze Go pprof performance profiles.
Features
analyze_pprof
Tool:- Analyzes the specified Go pprof file and returns serialized analysis results (e.g., Top N list or flame graph JSON).
- Supported Profile Types:
cpu
: Analyzes CPU time consumption during code execution to find hot spots.heap
: Analyzes the current memory usage (heap allocations) to find objects and functions with high memory consumption.goroutine
: Displays stack traces of all current goroutines, used for diagnosing deadlocks, leaks, or excessive goroutine usage.allocs
: Analyzes memory allocations (including freed ones) during program execution to locate code with frequent allocations. (Not yet implemented)mutex
: Analyzes contention on mutexes to find locks causing blocking. (Not yet implemented)block
: Analyzes operations causing goroutine blocking (e.g., channel waits, system calls). (Not yet implemented)
- Supported Output Formats:
text
,markdown
,json
(Top N list),flamegraph-json
(hierarchical flame graph data, default).text
,markdown
: Human-readable text or Markdown format.json
: Outputs Top N results in structured JSON format (implemented forcpu
,heap
,goroutine
).flamegraph-json
: Outputs hierarchical flame graph data in JSON format, compatible with d3-flame-graph (implemented forcpu
,heap
, default format). Output is compact.
- Configurable number of Top N results (
top_n
, defaults to 5, effective fortext
,markdown
,json
formats).
generate_flamegraph
Tool:- Uses
go tool pprof
to generate a flame graph (SVG format) for the specified pprof file, saves it to the specified path, and returns the path and SVG content. - Supported Profile Types:
cpu
,heap
,allocs
,goroutine
,mutex
,block
. - Requires the user to specify the output SVG file path.
- Important: This feature depends on Graphviz being installed.
- Uses
open_interactive_pprof
Tool (macOS Only):- Attempts to launch the
go tool pprof
interactive web UI in the background for the specified pprof file. Uses port:8081
by default ifhttp_address
is not provided. - Returns the Process ID (PID) of the background
pprof
process upon successful launch. - macOS Only: This tool will only work on macOS.
- Dependencies: Requires the
go
command to be available in the system's PATH. - Limitations: Errors from the background
pprof
process are not captured by the server. Temporary files downloaded from remote URLs are not automatically cleaned up until the process is terminated (either manually viadisconnect_pprof_session
or when the MCP server exits).
- Attempts to launch the
disconnect_pprof_session
Tool:- Attempts to terminate a background
pprof
process previously started byopen_interactive_pprof
, using its PID. - Sends an Interrupt signal first, then a Kill signal if Interrupt fails.
- Attempts to terminate a background
Installation (As a Library/Tool)
You can install this package directly using go install
:
This will install the pprof-analyzer-mcp
executable to your $GOPATH/bin
or $HOME/go/bin
directory. Ensure this directory is in your system's PATH to run the command directly.
Building from Source
Ensure you have a Go environment installed (Go 1.18 or higher recommended).
In the project root directory (pprof-analyzer-mcp
), run:
This will generate an executable file named pprof-analyzer-mcp
(or pprof-analyzer-mcp.exe
on Windows) in the current directory.
Using go install
(Recommended)
You can also use go install
to install the executable into your $GOPATH/bin
or $HOME/go/bin
directory. This allows you to run pprof-analyzer-mcp
directly from the command line (if the directory is added to your system's PATH environment variable).
Running with Docker
Using Docker is a convenient way to run the server, as it bundles the necessary Graphviz dependency.
- Build the Docker Image:
In the project root directory (where the
Dockerfile
is located), run:Copy - Run the Docker Container:Copy
- The
-i
flag keeps STDIN open, which is required for the stdio transport used by this MCP server. - The
--rm
flag automatically removes the container when it exits.
- The
- Configure MCP Client for Docker:
To connect your MCP client (like Roo Cline) to the server running inside Docker, update your
.roo/mcp.json
:Make sure theCopypprof-analyzer-mcp
image has been built locally before the client tries to run this command.
Releasing (Automated via GitHub Actions)
This project uses GoReleaser and GitHub Actions to automate the release process. Releases are triggered automatically when a Git tag matching the pattern v*
(e.g., v0.1.0
, v1.2.3
) is pushed to the repository.
Release Steps:
- Make Changes: Develop new features or fix bugs.
- Commit Changes: Commit your changes using Conventional Commits format (e.g.,
feat: ...
,fix: ...
). This is important for automatic changelog generation.Copy - Push Changes: Push your commits to the main branch on GitHub.Copy
- Create and Push Tag: When ready to release, create a new Git tag and push it to GitHub.Copy
- Automatic Release: Pushing the tag will trigger the
GoReleaser
GitHub Action defined in.github/workflows/release.yml
. This action will:- Build binaries for Linux, macOS, and Windows (amd64 & arm64).
- Generate a changelog based on Conventional Commits since the last tag.
- Create a new GitHub Release with the changelog and attach the built binaries and checksums as assets.
You can view the release workflow progress in the "Actions" tab of the GitHub repository.
Configuring the MCP Client
This server uses the stdio
transport protocol. You need to configure it in your MCP client (e.g., Roo Cline extension for VS Code).
Typically, this involves adding the following configuration to the .roo/mcp.json
file in your project root:
Note: Adjust the command
value based on your build method (go build
or go install
) and the actual location of the executable. Ensure the MCP client can find and execute this command.
After configuration, reload or restart your MCP client, and it should automatically connect to the PprofAnalyzer
server.
Dependencies
- Graphviz: The
generate_flamegraph
tool requires Graphviz to generate SVG flame graphs (thego tool pprof
command callsdot
when generating SVG). Ensure Graphviz is installed on your system and thedot
command is available in your system's PATH environment variable.Installing Graphviz:- macOS (using Homebrew):Copy
- Debian/Ubuntu:Copy
- CentOS/Fedora:Copy
- Windows (using Chocolatey):Copy
- Other Systems: Refer to the Graphviz official download page.
- macOS (using Homebrew):
Usage Examples (via MCP Client)
Once the server is connected, you can call the analyze_pprof
and generate_flamegraph
tools using file://
, http://
, or https://
URIs for the profile file.
Example: Analyze CPU Profile (Text format, Top 5)
Example: Analyze Heap Profile (Markdown format, Top 10)
Example: Analyze Goroutine Profile (Text format, Top 5)
Example: Generate Flame Graph for CPU Profile
Example: Generate Flame Graph for Heap Profile (inuse_space)
Example: Analyze CPU Profile (JSON format, Top 3)
Example: Analyze CPU Profile (Default Flame Graph JSON format)
Example: Analyze Heap Profile (Explicitly Flame Graph JSON format)
Example: Analyze Remote CPU Profile (from HTTP URL)
Example: Analyze Online CPU Profile (from GitHub Raw URL)
Example: Generate Flame Graph for Online Heap Profile (from GitHub Raw URL)
Example: Open Interactive Pprof UI for Online CPU Profile (macOS Only)
Example: Disconnect a Pprof Session
Future Improvements (TODO)
- Implement full analysis logic for
allocs
,mutex
,block
profiles. - Implement
json
output format forallocs
,mutex
,block
profile types. - Set appropriate MIME types in MCP results based on
output_format
. - Add more robust error handling and logging level control.
Consider supporting remote pprof file URIs (e.g.,(Done)http://
,https://
).
This server cannot be installed
This is a Model Context Protocol (MCP) server implemented in Go, providing a tool to analyze Go pprof performance profiles.