perfonext-build-mcp
Summary: perfonext-build-mcp is a stdio MCP server that turns Next.js .next build artifacts into structured bundle analysis — heavy routes, shared chunks, duplicate packages, and bundle-growth explanations — for MCP clients like Copilot, Claude Desktop, and Claude Code.
Load a build snapshot (
load_build_stats) — parse a.nextdirectory into in-memory route/chunk footprint data, optionally with capturednext buildoutput for build duration.Rank heavy routes (
get_largest_routes) — the largest user-facing routes by emitted chunk bytes.Rank shared chunks (
get_shared_chunks) — heaviest shared chunks and which routes depend on them.Compare two builds (
compare_builds) — which routes and chunks grew or shrank, matching chunks across content-hashed filenames.Explain growth (
explain_growth) — severity-ranked route findings and top growing chunks between a baseline and current build.Get stats-collection instructions (
how_to_collect_stats) — a manual recipe or an automatic action plan for generating.next/stats.json(webpack; says so if the app uses Turbopack).Load webpack stats (
load_webpack_stats) — parse.next/stats.jsonand link it to a loaded build, unlocking the attribution tools.Trace an import (
trace_import) — explain why a module or npm package is bundled by walking its import chain to the entry.Find duplicates (
find_duplicates) — npm packages emitted into more than one chunk, ranked by wasted bytes.Explain shared chunks (
explain_shared_chunks) — which packages and app code dominate the chunks loaded by many routes.Suggest optimizations (
suggest_optimizations) — aggregate route, chunk, and stats evidence into severity-ranked, evidence-backed fixes sized in emitted on-disk bytes; works on manifests alone but is enriched once webpack stats are loaded.Setup flexibility — runs via
npx -y @perfonext/build-mcp(or a localnode dist/index.js); manifest tools need zero setup, while import-level attribution needs the optional stats file and degrades gracefully without it.
Analyzes Next.js build artifacts to rank heaviest routes, identify shared chunks, compare builds for bundle growth, trace import chains, and suggest evidence-backed optimizations.
perfonext-build-mcp
Analyze Next.js build artifacts to find heavy routes, shared chunks, and bundle growth.
perfonext-build-mcp is a Model Context Protocol (MCP) server that gives GitHub Copilot, Claude Desktop,
Claude Code, and other MCP clients structured bundle analysis for Next.js performance work. It loads .next
build artifacts and turns them into route-size rankings, shared-chunk and duplication findings, and
severity-ranked fix suggestions — evidence agents can reason over instead of inspecting raw .next manifests.
Quick Start
perfonext-build-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/build-mcpOr install globally:
npm install -g @perfonext/build-mcpThe executable command remains perfonext-build-mcp after installation.
VS Code
Add the server to .vscode/mcp.json (the workspace MCP configuration file):
{
"servers": {
"perfonext-build": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@perfonext/build-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-build": {
"command": "npx",
"args": ["-y", "@perfonext/build-mcp"]
}
}
}Restart Claude Desktop to pick up the new server.
Claude Code
Add the server with the CLI:
claude mcp add perfonext-build -- npx -y @perfonext/build-mcpOr add it directly to .mcp.json:
{
"mcpServers": {
"perfonext-build": {
"command": "npx",
"args": ["-y", "@perfonext/build-mcp"]
}
}
}Other MCP clients
Any client that supports stdio MCP servers can launch the same command/args pair:
command: npx, args: ["-y", "@perfonext/build-mcp"]. Consult your client's docs for where its MCP
server configuration file lives.
For a locally-built checkout, point command/args at node and the repo's dist/index.js instead,
in any of the configurations above.
Then ask your assistant: "Load the Next.js build in ./.next and show me the largest routes."
Related MCP server: @registry/mcp
Troubleshooting
spawn npx ENOENT / spawn node ENOENT on macOS with nvm
If the server fails to start with spawn npx ENOENT (or spawn node ENOENT), your editor/app was
likely launched from the Dock/Finder and cannot see nvm. GUI apps on macOS do not load shell config
(.zshrc/.bashrc), so npx/node installed via nvm are not on PATH. This applies to VS Code,
Claude Desktop, and any other GUI MCP client on macOS.
Fix it by giving the MCP config an absolute npx path and a PATH that includes the same Node bin
directory (dirname $(which npx)):
{
"command": "/Users/YOU/.nvm/versions/node/v<version>/bin/npx",
"args": ["-y", "@perfonext/build-mcp"],
"env": {
"PATH": "/Users/YOU/.nvm/versions/node/v<version>/bin:/usr/bin:/bin"
}
}Merge the command/args/env fields above into your client's server entry (e.g. under servers
for VS Code or mcpServers for Claude Desktop/Code).
What It Does
loads Next.js build artifacts from a
.nextdirectoryranks the largest user-facing routes by emitted bundle footprint
identifies the heaviest shared chunks that affect multiple routes
compares two builds and explains which routes and chunks drove bundle growth, with severity-ranked, evidence-backed fix suggestions
matches chunks across builds even though Next.js fingerprints filenames with content hashes
traces why a given module or npm package is bundled (import chain entry → module) when an optional webpack stats file is collected
finds npm packages duplicated across chunks and explains what dominates shared chunks
aggregates all of the above into severity-ranked, evidence-backed optimization suggestions tied to concrete Next.js actions
keeps loaded build snapshots in memory so an MCP client can inspect them without re-reading the same build
Tools
Tool | Description |
| Parse a Next.js |
| Rank the heaviest user-facing routes by total emitted chunk bytes |
| Rank shared chunks by size and show which routes depend on them |
| Compare a baseline and current build snapshot to show which routes and chunks grew or shrank |
| Severity-rank which routes and chunks drove bundle growth between two builds, with evidence-backed fix suggestions |
| Return the recipe (manual) or an action plan (automatic) to generate |
| Parse |
| Explain why a module or npm package is bundled by walking its import chain to the entry |
| Rank npm packages whose code is emitted into more than one chunk, by wasted bytes |
| Show which packages and app code dominate the shared chunks loaded by many routes |
| Aggregate route, chunk, and webpack-stats evidence into severity-ranked, evidence-backed fix suggestions |
The output stays machine-readable and includes raw byte counts so your MCP client can explain regressions, prioritise fixes, and suggest concrete dependency or import-level follow-up.
Every suggest_optimizations finding is sized in emittedBytes — actual on-disk chunk bytes — so suggestions of different kinds rank on one scale. Unminified webpack module sizes appear only where they are named as such (moduleSizeBytes, shareOfChunkModuleBytes).
Because Next.js content-hashes emitted filenames (framework-<hash>.js, and CSS files named purely by hash), compare_builds and explain_growth match chunks across builds by a hash-normalized identity. This prevents a rehashed-but-unchanged chunk from being misreported as removed-and-recreated, while still flagging genuinely new chunks.
Inputs
The core tools read build artifacts developers already have after running next build:
.next/build-manifest.json.next/prerender-manifest.jsonwhen present.next/app-build-manifest.jsonwhen present.next/app-path-routes-manifest.jsonwhen present — maps App Router manifest keys (/gallery/page) to the real paths (/gallery) the prerender manifest is keyed by, so routetype,isPrerendered, andprerenderBlockedReasonare read from the build rather than guessed from the pathoptional captured
next buildoutput text to derive build duration
Import-level attribution (trace_import, find_duplicates, explain_shared_chunks) and the
stats-enriched suggestions from suggest_optimizations additionally need a webpack module-stats file
at .next/stats.json. A stock next build does not emit one; how_to_collect_stats returns the
recipe to generate it. The manifest tools above never read it, so they work with or without it.
Deep bundle attribution (optional)
The manifest tools work with zero setup. To answer "why is this package bundled?", collect a webpack stats file first:
Call
how_to_collect_stats({ method: 'manual' | 'automatic' })and apply the returned steps — it addswebpack-stats-pluginandcross-env, gates anext.confighook behindANALYZE=true && !isServer, and rebuilds withcross-env ANALYZE=true next build --webpack. Turbopack builds will not produce.next/stats.json.Call
load_build_stats({ buildDir })to get abuildId.Call
load_webpack_stats({ buildId })to parse the generated.next/stats.json.Call
trace_import({ buildId, moduleName })to see the import chain that pulls a module in.Call
find_duplicates({ buildId })to find packages bundled into more than one chunk, andexplain_shared_chunks({ buildId })to see what dominates the chunks loaded by many routes.Call
suggest_optimizations({ buildId })for severity-ranked, evidence-backed recommendations. It works on manifests alone and is enriched with dedupe, shared-chunk, and package-import findings once stats are loaded. Code-split advice is tailored for Next.js framework routes (/404,/500,/_error,/_app,/_document) — these are flagged to be slimmed down by trimming imports rather than split withnext/dynamic, which does not apply to them.
If the app builds with Turbopack there is no webpack module graph, so how_to_collect_stats says so
and points back to the manifest-only tools. The attribution tools degrade gracefully with a
breadcrumb when no stats file is loaded — it is never an error.
Example Prompts
"Load the Next.js build in
./.nextand show me the largest routes.""Which shared chunks are affecting the most routes in this build?"
"Summarize the build footprint and tell me which routes ship the most JavaScript."
"Compare my baseline and current
.nextbuilds and show me which routes or shared chunks grew the most.""Explain what grew between my baseline and current
.nextbuilds and what I should fix first.""Set up webpack stats collection so I can see why a package is bundled."
"Why is
axiosin my bundle? Trace its import chain.""Which npm packages are duplicated across chunks and how many bytes are wasted?"
"What's dominating my shared chunks?"
"Suggest the highest-impact bundle optimizations for this build."
Related Perfonext Tools
perfonext-profiler-mcp — CPU profiling (V8/Chrome) for Next.js servers
perfonext-render-mcp — React render analysis for Next.js apps
Development
npm install
npm run build
npm testSample fixtures for local validation live under tests/fixtures/.
License
MIT
Available Tools
11 toolscompare_buildsCompare BuildsA
Compare two loaded Next.js builds and show which routes and chunks grew or shrank the most.
Inputs: limit, currentBuildId, baselineBuildId.
explain_growthExplain GrowthA
Identify which routes and chunks are responsible for bundle size growth between two loaded builds. Returns severity-ranked route findings, the top growing chunks, and an overall regression summary.
Inputs: limit, currentBuildId, baselineBuildId.
find_duplicatesFind Duplicate PackagesA
Find npm packages whose code is bundled into more than one chunk, wasting bytes, ranked by wasted bytes. Requires load_webpack_stats first.
Inputs: buildId (required), limit.
get_largest_routesGet Largest RoutesA
Rank the heaviest user-facing routes in a loaded Next.js build by emitted chunk bytes.
Inputs: limit, buildId.
how_to_collect_statsHow To Collect Webpack StatsA
Explain how to generate the webpack stats file (.next/stats.json) required by the bundle attribution tools. Choose manual (a recipe you apply yourself) or automatic (an action plan Copilot executes).
Inputs: method (required), scenario.
load_build_statsLoad Build StatsA
Parse a Next.js .next directory and load route and chunk footprint data for later analysis.
Inputs: buildDir (required), buildOutputPath.
load_webpack_statsLoad Webpack StatsA
Parse the webpack module stats file (.next/stats.json) and link it to a build loaded with load_build_stats. Unlocks the stats-powered tools: suggest_optimizations (enriched), find_duplicates, explain_shared_chunks, and trace_import.
Inputs: buildId (required).
suggest_optimizationsSuggest OptimizationsA
Aggregate route, chunk, and (when loaded) webpack-stats evidence into severity-ranked, evidence-backed bundle optimizations tied to concrete Next.js actions. Every suggestion is sized in emitted on-disk bytes. Works on manifests alone; load_webpack_stats first for dedupe, shared-chunk, and package-import suggestions.
Inputs: buildId (required), limit.
trace_importTrace ImportA
Explain why a module is bundled by tracing its import chain from an entry point to the module. moduleSizeBytes is the unminified webpack module size, not emitted chunk size. Requires load_webpack_stats first.
Inputs: buildId (required), moduleName (required), limit.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 11 tools
Most tools have clearly distinct purposes, but compare_builds and explain_growth overlap in analyzing build differences, and get_shared_chunks vs explain_shared_chunks could be confused at first glance. The descriptions and dependency notes help disambiguate, so it is mostly clear.
Tool names largely follow a verb_noun snake_case pattern, with load_, get_, compare_, explain_, and suggest_ prefixes. The one outlier is how_to_collect_stats, which uses a non-standard how_to_ prefix but remains readable and understandable.
With 11 tools, the server is well-scoped for its purpose of Next.js bundle analysis. Each tool contributes to a distinct part of the workflow: data collection, loading stats, analysis, comparison, and optimization recommendations.
The tool set covers the full analysis lifecycle: collecting stats, loading build and webpack data, identifying large routes and shared chunks, finding duplicates, tracing imports, comparing builds, explaining growth, and suggesting optimizations. No significant gaps are apparent for the stated domain.
Maintenance
Related MCP Connectors
Bundlephobia MCP — npm bundle-size analysis
MCP server for progressive tool usage at any scale (see https://klavis.ai)
The official MCP Server for the Mux API
Related MCP Servers
- AlicenseAqualityDmaintenanceA comprehensive MCP server for frontend analysis. It provides Google Lighthouse audits, code quality checks, SEO metadata verification, accessibility analysis, and bundle optimization for React and Next.js projects.83MIT
- AlicenseNot gradedqualityDmaintenanceUnified MCP server for searching, analyzing, and managing packages across npm, JSR, Deno, and multiple CDN providers with auto-detection.MIT
- AlicenseNot gradedqualityDmaintenanceCreates and manages an MCP server integrated with build tools (Rollup, Vite, Webpack, etc.) to enable AI assistants to analyze, inspect, and control the build process.31MIT
- AlicenseNot gradedqualityCmaintenanceEnables MCP-compatible clients to inspect Next.js codebases, analyze App Router and Pages Router structure, discover API routes, and audit build performance through controlled tools.MIT