Pprof Analyzer MCP Serverのロゴ

Pprof Analyzer MCP Server

コミュニティ
ZephyrDeng

This is a Model Context Protocol (MCP) server implemented in Go, providing a tool to analyze Go pprof performance profiles.

公開者ZephyrDeng
リポジトリpprof-analyzer-mcp
言語Go
フォーク
7
スター
50
利用可能なツール
5
通信方式stdio
カテゴリ
ライセンスMIT
リンク
  • ツールをAIワークフローに接続

    Pprof Analyzer MCP Serverは、対応するAIクライアントやAIエージェントから利用できるMCP機能を提供します。

  • 利用可能なツール(5個)

    呼び出し可能なアクションを以下で確認できます。サーバーから提供されている場合は、名前や説明も表示されます。

  • コピーして使える設定

    セットアップ用の設定例を使って、お好みのMCPクライアントにこのサーバーを設定できます。

  • オープンソースプロジェクトの注目度

    リンク先のリポジトリには50件のスターと7件のフォークがあります。

简体中文 | English

Pprof Analyzer MCP Server

smithery badge Build Status License Go Version GoDoc

This is a Model Context Protocol (MCP) server implemented in Go, providing a tool to analyze Go pprof performance profiles. Built with the official Model Context Protocol Go SDK.

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. Enhanced with object count, allocation site, and type information.
      • 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. Provides detailed allocation site and object count information.
      • mutex: Analyzes contention on mutexes to find locks causing blocking. Provides detailed statistics including contention counts, delay times, and percentages.
      • block: Analyzes operations causing goroutine blocking (e.g., channel waits, system calls). Provides comprehensive blocking statistics with average delay calculations.
    • 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 for cpu, heap, goroutine, allocs, mutex, block).
      • flamegraph-json: Outputs hierarchical flame graph data in JSON format, compatible with d3-flame-graph (implemented for cpu, heap, allocs, default format). Output is compact.
    • Configurable number of Top N results (top_n, defaults to 5, effective for text, 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.
  • 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 if http_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 via disconnect_pprof_session or when the MCP server exits).
  • detect_memory_leaks Tool:
    • Compares two heap profile snapshots to identify potential memory leaks.
    • Analyzes memory growth by object type and allocation site.
    • Provides detailed statistics on memory growth, including absolute and percentage changes.
    • Configurable growth threshold and result limit.
    • Helps identify memory leaks by comparing profiles taken at different points in time.
  • disconnect_pprof_session Tool:
    • Attempts to terminate a background pprof process previously started by open_interactive_pprof, using its PID.
    • Sends an Interrupt signal first, then a Kill signal if Interrupt fails.
  • compare_profiles Tool:
    • Compares two profile files (e.g., baseline vs. target) to identify performance regressions or improvements.
    • Supports all profile types (cpu, heap, allocs, mutex, block).
    • Provides detailed diff statistics including improved/regressed functions, added/removed functions.
    • Visual indicators: 🔴 regression, 🟢 improvement, 🆕 added, ❌ removed.
    • Supports text, markdown, and JSON output formats.
  • analyze_heap_time_series Tool:
    • Analyzes multiple heap profiles over time to identify memory growth trends and potential leaks.
    • Requires at least 3 heap profiles provided in chronological order.
    • Calculates growth rates (bytes, percentage, MB per minute).
    • Identifies trending object types with directional indicators (📈 increasing, 📉 decreasing, ➡️ stable).
    • Supports custom labels for each time point or auto-generates default labels.
    • Supports text, markdown, and JSON output formats.

Installation (As a Library/Tool)

You can install this package directly using go install:

bash
go install github.com/ZephyrDeng/pprof-analyzer-mcp@latest

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:

bash
go build

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).

bash
# Installs the executable using the module path defined in go.mod
go install .
# Or directly using the GitHub path (recommended after publishing)
# go install github.com/ZephyrDeng/pprof-analyzer-mcp@latest

Running with Docker

Using Docker is a convenient way to run the server, as it bundles the necessary Graphviz dependency.

  1. Build the Docker Image: In the project root directory (where the Dockerfile is located), run:

    bash
    docker build -t pprof-analyzer-mcp .
  2. Run the Docker Container:

    bash
    docker run -i --rm pprof-analyzer-mcp
    • 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.
  3. Configure MCP Client for Docker: To connect your MCP client (like Roo Cline) to the server running inside Docker, update your .roo/mcp.json:

    json
    {
      "mcpServers": {
        "pprof-analyzer-docker": {
          "command": "docker run -i --rm pprof-analyzer-mcp"
        }
      }
    }

    Make sure the pprof-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.

Pre-release Checklist:

Before creating a release tag, ensure:

  • ✅ All tests pass: go test ./...
  • ✅ Code compiles successfully: go build
  • ✅ Documentation is up to date (README, CHANGELOG, etc.)
  • ✅ Commit messages follow Conventional Commits format

Release Steps:

  1. Make Changes: Develop new features or fix bugs.
  2. Commit Changes: Commit your changes using Conventional Commits format (e.g., feat: ..., fix: ..., docs: ...). This is important for automatic changelog generation.
    bash
    git add .
    git commit -m "feat: Add awesome new feature"
    # or
    git commit -m "fix: Resolve issue #42"
    # or
    git commit -m "docs: Update README for new feature"
  3. Push Changes: Push your commits to the main branch on GitHub.
    bash
    git push origin main
  4. Run Pre-release Tests: Optionally, run tests locally before tagging:
    bash
    go test ./... -v
    go build -v
  5. Create and Push Tag: When ready to release, create a new Git tag and push it to GitHub.
    bash
    # Example: Create tag v0.2.0
    git tag v0.2.0
    
    # Push the tag to GitHub
    git push origin v0.2.0
  6. 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.

Monitoring the Release:

You can view the release workflow progress in the "Actions" tab of the GitHub repository. Once complete, the release will be available at:

https://github.com/ZephyrDeng/pprof-analyzer-mcp/releases

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:

json
{
  "mcpServers": {
    "pprof-analyzer": {
      "command": "pprof-analyzer-mcp"
    }
  }
}

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 (the go tool pprof command calls dot when generating SVG). Ensure Graphviz is installed on your system and the dot command is available in your system's PATH environment variable.

    Installing Graphviz:

    • macOS (using Homebrew):
      bash
      brew install graphviz
    • Debian/Ubuntu:
      bash
      sudo apt-get update && sudo apt-get install graphviz
    • CentOS/Fedora:
      bash
      sudo yum install graphviz
      # or
      sudo dnf install graphviz
    • Windows (using Chocolatey):
      bash
      choco install graphviz
    • Other Systems: Refer to the Graphviz official download page.

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)

json
{
  "tool_name": "analyze_pprof",
  "arguments": {
    "profile_uri": "file:///path/to/your/cpu.pprof",
    "profile_type": "cpu"
  }
}

Example: Analyze Heap Profile (Markdown format, Top 10)

json
{
  "tool_name": "analyze_pprof",
  "arguments": {
    "profile_uri": "file:///path/to/your/heap.pprof",
    "profile_type": "heap",
    "top_n": 10,
    "output_format": "markdown"
  }
}

Example: Analyze Goroutine Profile (Text format, Top 5)

json
{
  "tool_name": "analyze_pprof",
  "arguments": {
    "profile_uri": "file:///path/to/your/goroutine.pprof",
    "profile_type": "goroutine"
  }
}

Example: Generate Flame Graph for CPU Profile

json
{
  "tool_name": "generate_flamegraph",
  "arguments": {
    "profile_uri": "file:///path/to/your/cpu.pprof",
    "profile_type": "cpu",
    "output_svg_path": "/path/to/save/cpu_flamegraph.svg"
  }
}

Example: Generate Flame Graph for Heap Profile (inuse_space)

json
{
  "tool_name": "generate_flamegraph",
  "arguments": {
    "profile_uri": "file:///path/to/your/heap.pprof",
    "profile_type": "heap",
    "output_svg_path": "/path/to/save/heap_flamegraph.svg"
  }
}

Example: Analyze CPU Profile (JSON format, Top 3)

json
{
  "tool_name": "analyze_pprof",
  "arguments": {
    "profile_uri": "file:///path/to/your/cpu.pprof",
    "profile_type": "cpu",
    "top_n": 3,
    "output_format": "json"
  }
}

Example: Analyze CPU Profile (Default Flame Graph JSON format)

json
{
  "tool_name": "analyze_pprof",
  "arguments": {
    "profile_uri": "file:///path/to/your/cpu.pprof",
    "profile_type": "cpu"
    // output_format defaults to "flamegraph-json"
  }
}

Example: Analyze Heap Profile (Explicitly Flame Graph JSON format)

json
{
  "tool_name": "analyze_pprof",
  "arguments": {
    "profile_uri": "file:///path/to/your/heap.pprof",
    "profile_type": "heap",
    "output_format": "flamegraph-json"
  }
}

Example: Analyze Remote CPU Profile (from HTTP URL)

json
{
  "tool_name": "analyze_pprof",
  "arguments": {
    "profile_uri": "https://example.com/profiles/cpu.pprof",
    "profile_type": "cpu"
  }
}

Example: Analyze Online CPU Profile (from GitHub Raw URL)

json
{
  "tool_name": "analyze_pprof",
  "arguments": {
    "profile_uri": "https://raw.githubusercontent.com/google/pprof/refs/heads/main/profile/testdata/gobench.cpu",
    "profile_type": "cpu",
    "top_n": 5
  }
}

Example: Generate Flame Graph for Online Heap Profile (from GitHub Raw URL)

json
{
  "tool_name": "generate_flamegraph",
  "arguments": {
    "profile_uri": "https://raw.githubusercontent.com/google/pprof/refs/heads/main/profile/testdata/gobench.heap",
    "profile_type": "heap",
    "output_svg_path": "./online_heap_flamegraph.svg"
  }
}

Example: Open Interactive Pprof UI for Online CPU Profile (macOS Only)

json
{
  "tool_name": "open_interactive_pprof",
  "arguments": {
    "profile_uri": "https://raw.githubusercontent.com/google/pprof/refs/heads/main/profile/testdata/gobench.cpu"
    // Optional: "http_address": ":8082" // Example of overriding the default port
  }
}

Example: Detect Memory Leaks Between Two Heap Profiles

json
{
  "tool_name": "detect_memory_leaks",
  "arguments": {
    "old_profile_uri": "file:///path/to/your/heap_before.pprof",
    "new_profile_uri": "file:///path/to/your/heap_after.pprof",
    "threshold": 0.05,  // 5% growth threshold
    "limit": 15         // Show top 15 potential leaks
  }
}

Example: Disconnect a Pprof Session

json
{
  "tool_name": "disconnect_pprof_session",
  "arguments": {
    "pid": 12345 // Replace 12345 with the actual PID returned by open_interactive_pprof
  }
}

Future Improvements (TODO)

  • Add MIME type handling in MCP results based on output_format.
  • Add more robust error handling and logging level control.
  • Add integration tests for end-to-end MCP tool interactions.
  • Performance optimizations for large profile files (>1GB).

Recently Completed (v0.3.0)

  • ✅ Implement differential flame graphs to visualize changes between profiles. (Done - compare_profiles tool)
  • ✅ Add time-series analysis for memory profiles to track growth over multiple snapshots. (Done - analyze_heap_time_series tool)
  • ✅ Add automated CI/CD with GitHub Actions testing on every PR.
  • ✅ Implement full analysis logic for mutex, block profiles. (Done in v0.2.0)
  • ✅ Implement json output format for mutex, block profile types. (Done in v0.2.0)
  • ✅ Migrated to official Model Context Protocol Go SDK.
  • ✅ Consider supporting remote pprof file URIs (e.g., http://, https://). (Done in v0.2.0)
  • ✅ Implement full analysis logic for allocs profiles. (Done in v0.2.0)
  • ✅ Implement json output format for allocs profile type. (Done in v0.2.0)
  • ✅ Add memory leak detection capabilities. (Done in v0.2.0)

インストール

TypingMind
前提条件:

Node.js 18+

{
  "mcpServers": {
    "zephyrdeng-pprof-analyzer-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "pprof-analyzer-mcp"
      ]
    }
  }
}

利用可能なツール

  • analyze_pprof

    分析指定的 Go pprof 文件,并返回序列化的分析结果 (例如 Top N 列表或火焰图 JSON)。

  • detect_memory_leaks

    Compare two heap profile files to identify potential memory leaks.

  • disconnect_pprof_session

    尝试终止由 'open_interactive_pprof' 启动的指定后台 pprof 进程。

  • generate_flamegraph

    使用 'go tool pprof' 为指定的 pprof 文件生成火焰图 (SVG 格式),将其保存到指定路径,并返回路径和 SVG 内容。

  • open_interactive_pprof

    【仅限 macOS】尝试在后台启动 'go tool pprof' 交互式 Web UI。成功启动后会返回进程 PID,用于后续手动断开连接。

Pprof Analyzer MCP ServerのMCPを複数のAIモデルで活用

TypingMindはワークスペース単位でMCPツールに接続します。そのため、一度Pprof Analyzer MCP Serverに接続すれば、モデルごとに個別に設定することなく、TypingMind内のさまざまなAIモデルで利用できます。 このMCPは、デバイス上のTypingMind MCPコネクタを通じてローカルで動作します。

ローカルコネクタのセットアップガイド

MCPサーバーが、お使いのコンピューター上のローカルファイル、アプリ、非公開リソースにアクセスする必要がある場合は、この方法を使います。

1

MCP設定を開く

TypingMindで「設定」→「詳細設定」→「Model Context Protocol」の順に進み、「コネクタを設定」を選択してください。

  1. ブラウザでTypingMindを開いてください。
  2. 設定アイコンをクリックしてください。
  3. 「詳細設定」に移動してください。
  4. 「Model Context Protocol」セクションを開いてください。
  5. 「コネクタを設定」をクリックし、「このデバイス」を選択してください。
「このデバイス」が選択されたTypingMindのMCPコネクタ設定画面
2

コネクタのコマンドを実行

「このデバイス」を選択し、TypingMindからコマンドをコピーしてターミナルで実行してください。MCPの使用中は、プロセスを実行したままにしてください。

  1. TypingMindに表示されるセットアップコマンドをコピーしてください。
  2. macOSではターミナルを、WindowsではWindows Terminalを開いてください。
  3. コマンドを貼り付けて実行してください。
  4. ターミナルで続行の確認を求められた場合は、パッケージのインストールを承認してください。
  5. MCPツールの使用中は、ターミナルウィンドウを開いたまま、プロセスの実行を継続してください。
3

Pprof Analyzer MCP Serverをサーバーとして追加

コネクタのステータスが「準備完了」になったら、「サーバーを編集」をクリックし、MCPサーバーの設定を貼り付けてください。

  1. コネクタのステータスが「準備完了」になるまでお待ちください。
  2. 「サーバーを編集」をクリックしてください。
  3. Pprof Analyzer MCP ServerのMCPサーバー設定を貼り付けてください。
  4. サーバー一覧を保存してください。
  5. コネクタのステータスが「準備完了」のままか確認するには、画面を更新してください。
稼働中のサーバーと「サーバーを編集」ボタンが表示されたTypingMindのMCP設定画面
{
  "mcpServers": {
    "zephyrdeng-pprof-analyzer-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "pprof-analyzer-mcp"
      ]
    }
  }
}
4

複数のモデルで同じ接続を使用

サーバー一覧を保存し、「プラグイン」を開いてPprof Analyzer MCP ServerのMCPツールを有効にしてください。その後、TypingMindで対応するAIモデルを選択し、チャットでツールを使うか、AIエージェントに割り当ててください。

  1. TypingMindの「プラグイン」ページを開いてください。
  2. Pprof Analyzer MCP ServerのMCPツールを有効にしてください。
  3. チャットを開始し、使用するAIモデルを選択してください。
  4. MCPツールをチャットで使うか、AIエージェントに割り当ててください。
  5. MCPに再接続することなく、必要に応じて別のAIモデルに切り替えられます。
選択したAIモデルと有効なMCPツールを使用したTypingMindのチャット
Pprof Analyzer MCP Serverを使ってこのタスクを手伝ってもらえますか?
Pprof Analyzer MCP Server
はい、読みました。
Pprof Analyzer MCP Serverで調べた結果をお伝えします。

よくある質問

Pprof Analyzer MCP Server MCPサーバーは何に使いますか?

Pprof Analyzer MCP Serverは、対応するAIクライアントを外部ツールやコンテキストに接続するためのMCPサーバーです。TypingMindでは、このMCPサーバーを一度追加するだけで、AIワークスペース内でそのツールを利用できるようになります。

TypingMindでは、複数のAIモデルでPprof Analyzer MCP Server MCPを利用できますか?

はい。TypingMindはワークスペース単位でMCPツールに接続するため、モデルごとにMCPサーバーを設定する必要はありません。Claude、ChatGPT、Geminiや、TypingMindで設定したその他のAIモデルでPprof Analyzer MCP Serverを利用できます。

TypingMindでPprof Analyzer MCP Server MCPを使うメリットは何ですか?

TypingMindは、複数のAIモデル、プロンプト、プラグイン、AIエージェント、APIキー、MCPツールを1つのワークスペースにまとめられる、LLMチャット向けのトップクラスのフロントエンドです。Pprof Analyzer MCP Serverを接続すると、TypingMindでチャットのワークフローを整理しながら、お好みのモデルでそのMCPツールを利用できます。

Pprof Analyzer MCP Server MCPをTypingMindに接続するにはどうすればよいですか?

Pprof Analyzer MCP ServerはTypingMindのローカルMCPコネクタ経由で動作します。MCPサーバーがコンピューター上のローカルファイル、デスクトップアプリ、コマンドラインツール、プライベートリソースにアクセスする必要がある場合に最適です。

TypingMindでPprof Analyzer MCP Server MCPのどのようなツールを利用できますか?

Pprof Analyzer MCP Serverは5個のMCPツールを提供しています。TypingMindのプラグインページで有効にすると、チャットで使用したり、AIエージェントに割り当てたりできます。

Pprof Analyzer MCP Server MCPを使うには、APIキーをTypingMindと共有する必要がありますか?

いいえ。TypingMindはローカルファーストの設計で、モデルプロバイダー、APIキー、プロンプト、MCP設定をご自身で管理できます。Pprof Analyzer MCP Serverで認証が必要な場合は、接続の作成時に、そのMCPサーバーに必要なヘッダー、OAuth設定、またはローカル設定を追加してください。

関連するMCPサーバー

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇