APerf MCP Server

May 27, 2026 · View on GitHub

APerf includes a built-in MCP (Model Context Protocol) server that lets AI assistants record performance data, generate reports, and analyze APerf reports interactively.

Usage

aperf server --mcp

This starts the MCP server on stdio. It's designed to be launched by an MCP client (Kiro, Claude Desktop, etc.), not run manually.

MCP Client Configuration

Kiro (~/.kiro/settings/mcp.json)

{
  "mcpServers": {
    "aperf-mcp": {
      "command": "/path/to/aperf",
      "args": ["server", "--mcp"],
      "disabled": false
    }
  }
}

Replace /path/to/aperf with the actual binary path.

Available Tools

Read-only tools (report analysis)

load_report

Load an APerf report and return metadata + available metrics. Must be called first before other analysis tools.

ParameterTypeDescription
report_pathstringAbsolute or relative path to the APerf report directory

get_metrics

Query available metrics from the loaded report. Supports filtering.

ParameterTypeDescription
file_namestring (optional)JS filename, e.g. "cpu_utilization.js"
categorystring (optional)Data category, e.g. "meminfo"

get_metric_values

Retrieve actual data values for a specific metric.

ParameterTypeDescription
metric_namestringName of the metric (e.g. "user", "system")
file_namestring (optional)JS filename containing the metric
categorystring (optional)Category/data_name (e.g. "cpu_utilization")
output_typestring (optional)Output format (default: summary, see below)
cpu_idsstring[] (optional)Filter to specific CPUs. If omitted, averages across all.
run_idstring (optional)Specific run ID (default: all runs)
from_timeint (optional)Start of time range in seconds. Negative = relative to end (e.g. -60 = last 60s)
to_timeint (optional)End of time range in seconds. Negative = relative to end (e.g. -10 = stop 10s before end)

Output types:

TypeDescriptionToken cost
summarySmart text with all stats (avg/min/max/std/p50/p90/p99), trend direction, spike and drop detectionMinimal (default)
statsAggregated statistics only (avg, std, min, max, p50, p90, p99, p99.9)Minimal
timeseriesFull raw time-series data with timestamps and valuesHigh
compactDelta-encoded notation with run-length encoding~80% less than timeseries
downsampledFixed 50 buckets with min/avg/max per bucketBounded

get_analytical_findings

Get analytical findings from the report's analytical engine. Findings represent rule-based detections (regressions, improvements, configuration mismatches). Sorted by absolute score (severity) descending.

ParameterTypeDescription
offsetint (optional)Start index for pagination, default 0
limitint (optional)Max results per page, default 50

get_statistical_findings

Get statistical findings (metric stat deltas between runs). Computes the percentage change of each time-series metric's statistics compared to the base run (first run). Sorted by absolute delta descending. Requires a multi-run report.

ParameterTypeDescription
offsetint (optional)Start index for pagination, default 0
limitint (optional)Max results per page, default 50
statstring (optional)Filter by stat type: avg, std, min, max, p50, p90, p99, p99_9
data_typestring (optional)Filter by data category (e.g. cpu_utilization, meminfo)
min_delta_pctfloat (optional)Minimum absolute delta percentage to include (e.g. 5.0)

get_flamegraph

Query flamegraph data from the loaded report. Returns top functions by default (sorted by percentage), with optional regex filtering to search for specific functions. Supports normal, reverse, diff, and reverse-diff modes. Returns data for all runs by default, or specific runs if run_id is provided. In diff/reverse-diff mode, run_id must contain exactly 2 run IDs.

ParameterTypeDescription
flamegraph_typestring (optional)normal (default), reverse, diff, or reverse-diff
run_idstring[] (optional)Run ID(s). Normal/reverse: omit for all runs, or list specific ones. Diff: exactly 2 IDs [base, comparison], or omit for first two.
limitint (optional)Max functions to return per run, default 30
min_pctfloat (optional)Minimum percentage threshold (default 0.1). In diff mode, min absolute delta % (default 0.5).
filterstring (optional)Regex filter for function names (case-insensitive). Example: "compact|migrate"

Examples:

# Top 10 hottest functions across all runs
get_flamegraph(limit=10)

# Search for compaction-related functions
get_flamegraph(filter="compact|kcompactd|migrate")

# Reverse flamegraph for a specific run, filtered
get_flamegraph(flamegraph_type="reverse", run_id=["run1"], filter="lock")

# Diff between two runs — what got hotter/cooler
get_flamegraph(flamegraph_type="diff")

# Diff with explicit run IDs, filtered
get_flamegraph(flamegraph_type="diff", run_id=["run1", "run2"], filter="compact|writeback")

# Reverse diff
get_flamegraph(flamegraph_type="reverse-diff", run_id=["run1", "run2"])

Write tools (data collection and report generation)

record

Record performance data on the current system. Runs aperf record as a subprocess.

ParameterTypeDescription
run_namestring (optional)Name of the run (default: aperf_<timestamp>)
intervalint (optional)Collection interval in seconds (default: 1)
periodint (optional)Recording duration in seconds (default: 10)
profilebool (optional)Enable CPU profiling using perf (default: false)
perf_frequencyint (optional)Perf profiling frequency in Hz (default: 99)
memory_allocationbool (optional)Collect memory allocation data (default: false)
dont_collectstring (optional)Comma-separated data types to skip
collect_onlystring (optional)Comma-separated data types to collect exclusively
profile_javastring (optional)Profile JVMs — empty for all, or comma-separated PIDs/names
pmu_configstring (optional)Path to custom PMU config file

Requires Linux and appropriate kernel permissions. See the main README for details.

generate_report

Generate an HTML report from one or more recorded APerf runs. For multi-run comparison, provide multiple run paths — the first run is used as the base for statistical findings.

ParameterTypeDescription
runsstring[]Paths to run directories or archives (at least one required)
namestring (optional)Report name (default: aperf_report_<timestamp>)

Building

The MCP server is included in the default aperf build:

cargo build --release
# Binary at target/release/aperf
# Usage: aperf server --mcp

Architecture

The MCP server code lives in src/server/mcp/:

src/server/
├── mod.rs              ← Server subcommand dispatch
└── mcp/
    ├── mod.rs          ← MCP entry point (tokio runtime + stdio transport)
    ├── tools.rs        ← Tool definitions (#[tool_router] / #[tool_handler])
    ├── report.rs       ← Report loading, validation, metric extraction
    ├── metadata.rs     ← systeminfo.js parsing
    └── js_parser.rs    ← JS variable prefix stripping + JSON extraction

MCP dependencies (rmcp, schemars) are feature-gated behind the mcp feature (enabled by default).

Running Tests

# All MCP server tests
cargo test --lib server

# Specific test
cargo test --lib server::mcp::tools::tests::test_build_record_args_full