perfonext-profiler-mcp
Summary: perfonext-profiler-mcp is an MCP server that analyzes V8/Chrome CPU profiles of Next.js servers and scripts, turning raw profile dumps into hotspot rankings, per-package costs, and source-annotated hot lines that AI agents can reason over.
Capabilities:
Capture profiles —
how_to_collectreturns a ready-to-run command and step-by-step recipe for profiling a Next.js production server (next-server) or a standaloneserver.js/Node entry (script).Load profiles —
load_profileparses.cpuprofilefiles and Chrome DevTools Trace JSON exports from disk, returning a profile ID for later tools.Find hotspots —
get_hotspotsranks the top N functions by self-time and tags each with its originating npm package (or(user code)).Explain a function —
explain_functionshows self-time, total-time, callers and callees, optionally with annotated source lines viaincludeSource: true.Read annotated source —
read_source_contextreturns the real source of a hot function with per-line V8 tick counts, resizing the window to cover actual hot lines (only files inside the project root; flagshiddenTicks/warningif ticks fall outside).Attribute cost to packages —
get_package_costsaggregates CPU self-time per npm package (including scoped ones like@babel/core), separating own time from time spent in callbacks, to reveal expensive dependencies.Compare profiles —
compare_profilesdiffs a baseline vs. current profile to surface regressions, improvements, and new/removed hotspots.Suggest optimizations —
suggest_optimizationsemits structured, deduplicated suggestions detecting patterns likehigh-fan-in,recursion,hot-caller,gc-pressure,json-serialization,regex-cost, andv8-deopt.Summarize profiles —
get_profile_summaryreports duration, sample count, a depth-limited call tree, and idle time, or lists all loaded profiles.Guide the workflow — every tool result carries a
nextStepbreadcrumb so clients can walk the collect → analyze → fix loop; works with any stdio MCP client (VS Code Copilot, Claude Desktop/Code, Cursor).
Analyzes V8 and Chrome CPU profiles for Next.js servers and scripts, providing hotspot rankings, per-package CPU costs, annotated source lines, profile comparisons, and optimization suggestions.
perfonext-profiler-mcp
Analyze V8 and Chrome CPU profiles to find hotspots in Next.js servers and scripts.
perfonext-profiler-mcp is a Model Context Protocol (MCP) server that gives GitHub Copilot, Claude Desktop,
Claude Code, and other MCP clients structured CPU profiling data for Next.js performance work. It loads V8 and
Chrome CPU profiles and turns them into hotspot rankings, per-package costs, and source-annotated hot lines —
evidence agents can reason over instead of ingesting multi-megabyte profile dumps.
Quick Start
perfonext-profiler-mcp is a standard MCP stdio server, so it works with any MCP-compatible client
(GitHub Copilot in VS Code, Claude Desktop, Claude Code, Cursor, and others). Run it directly with npx:
npx -y @perfonext/profiler-mcpOr install globally:
npm install -g @perfonext/profiler-mcpThe executable command remains perfonext-profiler-mcp after installation.
VS Code
Add the server to .vscode/mcp.json (the workspace MCP configuration file):
{
"servers": {
"perfonext-profiler": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@perfonext/profiler-mcp"]
}
}
}Reload the VS Code window and run MCP: List Servers to start it, or accept the trust prompt when it appears.
Claude Desktop
Add the server to claude_desktop_config.json:
{
"mcpServers": {
"perfonext-profiler": {
"command": "npx",
"args": ["-y", "@perfonext/profiler-mcp"]
}
}
}Restart Claude Desktop to pick up the new server.
Claude Code
Add the server with the CLI:
claude mcp add perfonext-profiler -- npx -y @perfonext/profiler-mcpOr add the same mcpServers entry to .mcp.json.
Other MCP clients
Any client that supports stdio MCP servers can launch npx -y @perfonext/profiler-mcp. Consult your
client's documentation for its MCP server configuration format.
For a locally-built checkout, point command/args at node and the repo's dist/index.js instead.
Related MCP server: Debugger MCP Server
Troubleshooting
spawn npx ENOENT / spawn node ENOENT on macOS with nvm
If the server fails to start with this error, your GUI MCP client likely cannot see nvm. GUI apps on
macOS do not load shell config (.zshrc/.bashrc), so nvm-installed npx/node are not on PATH.
Use an absolute npx path and include the same Node directory in PATH:
{
"servers": {
"perfonext-profiler": {
"type": "stdio",
"command": "/Users/YOU/.nvm/versions/node/v<version>/bin/npx",
"args": ["-y", "@perfonext/profiler-mcp"],
"env": {
"PATH": "/Users/YOU/.nvm/versions/node/v<version>/bin:/usr/bin:/bin"
}
}
}
}Merge these fields into your client's server entry, under servers for VS Code or mcpServers for
Claude Desktop/Code. Then ask your assistant: "How do I capture a CPU profile of my Next.js server?"
What It Does
loads
.cpuprofilefiles and Chrome trace exports that contain CPU profile dataidentifies the hottest functions by self time, annotated with the originating npm package
explains caller and callee relationships for a selected function
reads actual source code for hot functions and annotates each line with V8 sample counts (v0.2.0)
aggregates CPU self-time per npm package to find expensive third-party dependencies (v0.3.0)
compares two profiles to surface regressions and improvements
returns deterministic optimization suggestions for common hotspots
summarizes loaded profiles so an MCP client can keep context tight
Tools
Tool | Description |
| Return a ready-to-run command and step-by-step recipe for capturing a |
| Parse and load a |
| Find top functions by self-time. Each entry includes a |
| Explain a function's timing, callers, and callees. Pass |
| Read the actual source file for a hot function and annotate each line with tick counts from |
| Aggregate CPU self-time by npm package — shows which dependencies are most expensive |
| Compare two profiles and highlight regressions |
| Generate structured, multi-pattern optimization suggestions for hot functions. Detects high fan-in, recursion, dominant callers, and V8-specific patterns. Deduplicates functions split across multiple call sites |
| Summarize one profile or list all loaded profiles |
Every tool result carries a nextStep breadcrumb pointing at the natural follow-up call, so an MCP client can walk the collect → analyze → fix loop without guessing.
Example Prompts
"How do I capture a CPU profile of my Next.js server?"
"Load the CPU profile at
./profile.cpuprofileand show me the top hotspots.""Which npm packages are consuming the most CPU in this profile?"
"Explain why
processDatais expensive in the loaded profile.""Show me the actual source lines for
processDataand mark which lines are hottest.""Explain
transformResultand include the annotated source code.""Compare my baseline and current CPU profiles and tell me what got slower."
"Suggest optimizations for the top three hotspots."
Deep Tool Reference
how_to_collect details
// Input
{ "scenario": "next-server" } // or "script"; defaults to "next-server"
// Output
{
"scenario": "next-server",
"summary": "Profile a production Next.js server while it handles a single request. ...",
"command": "node --cpu-prof --cpu-prof-dir=./.perf-profiles ./node_modules/next/dist/bin/next start",
"steps": [ "...", "load_profile({ filePath: \"./.perf-profiles/<file>.cpuprofile\" })" ],
"outputDir": "./.perf-profiles",
"nextStep": "After stopping the server, call load_profile with the .cpuprofile ..."
}next-server profiles a production Next.js server while it serves a single request. If next start says standalone output is unsupported, use the script scenario with .next/standalone/server.js. script profiles that standalone server (or another Node entry). Keep the scenario to one route and one hit. Node writes one .cpuprofile per process/worker thread into the output directory. The Next server command uses Node CLI flags (not NODE_OPTIONS) so it is the same on Unix and Windows.
read_source_context details
// Input
{ "profileId": "<id>", "functionName": "myFn", "contextLines": 10 }
// Output (per line)
{
"lineNumber": 42,
"content": " for (let i = 0; i < items.length; i++) {",
"ticks": 18, // V8 samples that landed on this line
"isHot": true // true when ticks >= 50% of peak ticks for this function
}The returned window is sized to cover the function's actual hot lines, not just a fixed radius
around its declaration — a function's real bottleneck is often well past its function line.
contextLines (default 10) sets the minimum padding around both the declaration and the hot
lines; if any ticks still fall outside the returned window, the top-level result includes
hiddenTicks (a count) and a warning telling you to retry with a larger contextLines.
explain_function also accepts contextLines when called with includeSource: true.
Only files inside the current working directory can be read. file:// URLs and absolute paths are both handled; http://, node: builtins, and paths outside the project root are rejected.
suggest_optimizations details
// Input
{ "profileId": "<id>", "limit": 5 }
// Output (per function)
{
"function": "processData",
"file": "file:///app/src/processor.js",
"line": 10,
"selfPercent": "18.2%",
"patterns": [
{
"pattern": "high-fan-in",
"detail": "Called from 6 distinct call sites (e.g. renderRow, buildTree, …)",
"suggestion": "This function is a shared hot path. Ensure it is well-optimised and monomorphic …"
},
{
"pattern": "hot-caller",
"detail": "84% of calls come from \"renderRow\"",
"suggestion": "Focus optimisation effort on \"renderRow\" rather than this function …"
}
],
"topSuggestion": "This function is a shared hot path …"
}Patterns detected (multiple can fire for the same function):
Pattern | Trigger |
| Function name matches GC/Scavenge/MarkCompact |
|
|
| RegExp / |
| Compile / Recompile / Optimize / Deoptimize |
| ≥ 3 distinct parent call sites |
| Function appears in its own descendant sub-tree |
| One caller accounts for ≥ 80% of call-site occurrences |
| Fallback when no other pattern matches |
Functions that appear at multiple call sites are automatically merged before ranking so the same logical function is only reported once.
get_package_costs details
// Input
{ "profileId": "<id>", "limit": 10 }
// Output (per package)
{
"rank": 1,
"package": "lodash",
"selfTime": "42.3ms",
"selfPercent": "14.1%",
"totalTimeIncludingCallbacks": "58.0ms",
"totalPercentIncludingCallbacks": "19.3%",
"topFunctions": [
{ "function": "chunk", "file": "lodash/chunk.js", "line": 41, "selfTime": "28.0ms", "selfPercent": "9.3%" }
]
}selfTime is the time spent inside the package's own code. totalTimeIncludingCallbacks also counts everything the package called into — including your own callbacks handed back to it — so it can exceed what removing the package would actually save.
Scoped packages (@babel/core, @next/env, etc.) are handled correctly. User code and native builtins (no node_modules in the path) are excluded.
Generating a CPU Profile
Ask Copilot to call how_to_collect for a ready-to-run recipe, or generate one manually:
Next.js production server (profile a single request):
node --cpu-prof --cpu-prof-dir=./.perf-profiles ./node_modules/next/dist/bin/next start
# hit the route once, then stop the process so it can exit and write the profileIf next start reports that standalone output is unsupported:
node --cpu-prof --cpu-prof-dir=./.perf-profiles .next/standalone/server.jsChrome DevTools:
Open DevTools and go to the Performance tab.
Record the scenario you want to inspect.
Stop recording and save the result as a
.cpuprofileexport.
Related Perfonext Tools
perfonext-render-mcp — React render analysis for Next.js apps
perfonext-build-mcp — Next.js bundle/build analysis
Development
npm install
npm run build
npm testThe repository already includes sample fixtures under tests/fixtures/ for local validation.
License
MIT
Available Tools
9 toolscompare_profilesCompare ProfilesA
Compare two loaded CPU profiles side-by-side. Shows functions that got slower/faster and new/removed hotspots.
Inputs: baseProfileId (required), compareProfileId (required), limit.
explain_functionExplain FunctionA
Returns detailed timing info for a specific function: self-time, total-time, callers, and callees. Use this to understand why a function is slow.
Inputs: profileId (required), functionName (required), contextLines, includeSource.
get_hotspotsGet HotspotsA
Returns the top N functions by self-time (CPU time spent directly in the function, not its callees). Use this to find performance bottlenecks.
Inputs: profileId (required), limit.
get_package_costsGet Package CostsA
Aggregate CPU self-time by npm package. Identifies which third-party dependencies are consuming the most CPU, by parsing node_modules paths from the profile. Useful for deciding which packages to replace, lazy-load, or avoid. Scoped packages (e.g. @babel/core) are handled correctly.
Inputs: profileId (required), limit.
get_profile_summaryGet Profile SummaryA
Returns an overview of a loaded profile: duration, sample count, top-level call tree (filtered to functions >0.1% of total time), and idle time percentage. For large profiles, the call tree is limited to depth 2 and top 20 children per node to keep output manageable. Also lists all loaded profiles if no ID is given.
Inputs: profileId, treeDepth.
how_to_collectHow To Collect a CPU ProfileA
Returns a ready-to-run command and step-by-step recipe for capturing a V8 CPU profile, then loading it with load_profile. Use this when you do not yet have a .cpuprofile file. Choose the scenario that matches how the code runs.
Inputs: scenario.
load_profileLoad CPU ProfileA
Parse and load a V8/Chrome CPU profile from disk. Supports both .cpuprofile files and Chrome DevTools Trace JSON exports. Returns a profile ID for use with other tools.
Inputs: filePath (required).
read_source_contextRead Source ContextA
Read the actual source code for a hot function and annotate each line with sampled tick counts from positionTicks. The returned window is sized to cover the function's actual hot lines, not just the area around its declaration; if any ticks still fall outside it, a warning field reports how many and suggests a larger contextLines. Only reads files within the project root.
Inputs: profileId (required), functionName (required), contextLines.
suggest_optimizationsSuggest OptimizationsA
Analyzes the profile and returns structured optimization suggestions for the hottest functions. Detects high fan-in, recursion, dominant callers, V8-specific patterns, always reports CPU self-time cost for expensive functions, and deduplicates functions split across multiple call sites.
Inputs: profileId (required), limit.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Each tool maps to a distinct part of the profiling workflow: loading, summarizing, hotspot analysis, per-function detail, comparison, optimization, source inspection, package aggregation, and collection guidance. There is no meaningful overlap that would make an agent choose the wrong tool.
Most tools follow a clear snake_case verb_noun pattern such as load_profile, get_hotspots, and compare_profiles. A few names like explain_function and how_to_collect deviate slightly from the predominant get_ style, but the naming is still predictable and readable.
Nine tools is an ideal size for a profiler-analysis server: each tool serves a distinct analytical purpose and the set is neither bloated nor thin. The count feels appropriately scoped to the domain.
The tool surface covers the full workflow from capturing/loading profiles to summarizing, exploring hotspots, comparing profiles, reading source context, and identifying expensive packages. There are no obvious dead ends or missing operations that would prevent an agent from completing a typical profiling analysis.
Maintenance
Related MCP Connectors
Errors, logs and AI-call costs for apps on Node.js, Next.js, Cloudflare Workers or the browser. Ask your AI what’s broken, why, and how to fix it, right inside Cursor or Claude.
Find what slows your website down. Run a free check in Claude Code, Cursor or ChatGPT. No account needed to try it. Save your result with a free Nimo account, then check again after your fixes. No card needed. Learn more: https://heynimo.com/for/coding-assistants
Production telemetry for NestJS apps: traces, errors, regressions, jobs and alerts.
- Costory FinOps MCPDeprecatedio.costory
FinOps harness MCP: allocated cloud, data and LLM bills. Build on it or switch. Cloud read-only.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceMCP server for Polar Signals Cloud continuous profiling platform, enabling AI assistants to analyze CPU performance, memory usage, and identify optimization opportunities in production systems.9-
- AlicenseNot gradedqualityDmaintenanceProvides real-time debugging, code quality monitoring, and performance insights for React/Next.js applications with features including Chrome DevTools integration, breakpoint management, complexity analysis, and live error streaming.1MIT
- AlicenseAqualityDmaintenanceLive .NET runtime diagnostics for AI assistants. Ask Claude to diagnose memory leaks, GC pressure, LOH fragmentation, and thread starvation in any running .NET process — no code changes required.72MIT
- FlicenseNot gradedqualityDmaintenanceStreams live React profiler data to AI agents, enabling them to analyze performance and suggest specific, actionable fixes for slow components.3-