Skip to content

Add MCP compile_route tool#92951

Draft
lukesandberg wants to merge 3 commits intoeviction_semantics_for_real_this_timefrom
followups
Draft

Add MCP compile_route tool#92951
lukesandberg wants to merge 3 commits intoeviction_semantics_for_real_this_timefrom
followups

Conversation

@lukesandberg
Copy link
Copy Markdown
Contributor

@lukesandberg lukesandberg commented Apr 17, 2026

What?

Adds a compile_route MCP tool that triggers on-demand compilation of a specific route (app or pages) without issuing an HTTP request, and returns any compilation issues.

Why?

Coding agents and benchmarking workflows need a way to warm the module graph or measure compile time for a route without standing up a live backend to satisfy the request. The existing path — hitting the URL — requires the route's runtime dependencies to be available and couples compile timing to request handling.

How?

  • New tool mcp/compile_route registered in get-or-create-mcp-server.ts, backed by a compileRoute({ page, clientOnly }) callback plumbed from both the Turbopack and webpack hot reloaders.
  • Reuses the dev server's existing on-demand entry path (ensurePage / handleRouteType), so the call path matches a first navigation.
  • Adds a subscribeToChanges opt-out on ensurePage and threads it through handleRouteType / handlePagesErrorRoute. One-shot MCP compilations skip HMR subscription wiring — without this, each call would leak a subscription that fires on every subsequent file change for the life of the dev server.
  • Telemetry: registers mcp/compile_route in the McpToolName union.
  • Error 1172 reserved for "compilation failed but no issues were recorded".
  • e2e test in test/development/mcp-server/mcp-server-compile-route.test.ts.

Copy link
Copy Markdown
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@lukesandberg lukesandberg changed the title compile route mcsp handler Add MCP compile_route tool Apr 17, 2026
@nextjs-bot
Copy link
Copy Markdown
Collaborator

nextjs-bot commented Apr 17, 2026

Tests Passed

Comment thread packages/next/src/server/dev/hot-reloader-turbopack.ts Outdated
Comment thread packages/next/src/server/dev/hot-reloader-webpack.ts Outdated
@nextjs-bot nextjs-bot added the Documentation Related to Next.js' official documentation. label Apr 18, 2026
@nextjs-bot
Copy link
Copy Markdown
Collaborator

Stats from current PR

🔴 1 regression

Metric Canary PR Change Trend
node_modules Size 494 MB 494 MB 🔴 +87.8 kB (+0%) ████▁
📊 All Metrics
📖 Metrics Glossary

Dev Server Metrics:

  • Listen = TCP port starts accepting connections
  • First Request = HTTP server returns successful response
  • Cold = Fresh build (no cache)
  • Warm = With cached build artifacts

Build Metrics:

  • Fresh = Clean build (no .next directory)
  • Cached = With existing .next directory

Change Thresholds:

  • Time: Changes < 50ms AND < 10%, OR < 2% are insignificant
  • Size: Changes < 1KB AND < 1% are insignificant
  • All other changes are flagged to catch regressions

⚡ Dev Server

Metric Canary PR Change Trend
Cold (Listen) 455ms 455ms ▁▁▅▅▅
Cold (Ready in log) 440ms 440ms ▇▂▅▅▆
Cold (First Request) 827ms 822ms ▁█▁█▁
Warm (Listen) 456ms 456ms ▅▅▅█▅
Warm (Ready in log) 439ms 439ms ▃▃▁▄▁
Warm (First Request) 340ms 338ms ▅▇▂▇▁
📦 Dev Server (Webpack) (Legacy)

📦 Dev Server (Webpack)

Metric Canary PR Change Trend
Cold (Listen) 456ms 456ms ▁▅▅▅▁
Cold (Ready in log) 438ms 438ms ▇▁▃▅▁
Cold (First Request) 1.867s 1.871s █▆▆█▆
Warm (Listen) 455ms 455ms █▁▅▅▅
Warm (Ready in log) 437ms 437ms ▆▂▃▅▂
Warm (First Request) 1.881s 1.856s ▇▆▆█▆

⚡ Production Builds

Metric Canary PR Change Trend
Fresh Build 4.006s 4.006s ▇▃▅▂█
Cached Build 4.002s 3.986s █▂▄▁█
📦 Production Builds (Webpack) (Legacy)

📦 Production Builds (Webpack)

Metric Canary PR Change Trend
Fresh Build 14.423s 14.409s █▂▃█▃
Cached Build 14.537s 14.520s █▄▁▆▁
node_modules Size 494 MB 494 MB 🔴 +87.8 kB (+0%) ████▁
📦 Bundle Sizes

Bundle Sizes

⚡ Turbopack

Client

Main Bundles
Canary PR Change
0_2mxpvrrod2f.js gzip 154 B N/A -
07rxhp_1_g4mu.js gzip 13.1 kB N/A -
08avva-dy02e7.js gzip 10.4 kB N/A -
09y82iy5lc0-z.js gzip 153 B N/A -
0bog1koyarlbh.js gzip 153 B N/A -
0cz1d0mv5g_q7.js gzip 39.4 kB 39.4 kB
0fli3_wppnim5.js gzip 12.9 kB N/A -
0k09jwjeb-tki.js gzip 13.8 kB N/A -
0kb7_ep3r1z0_.js gzip 10.1 kB N/A -
0kw8xgqdrilf6.js gzip 8.56 kB N/A -
0lgndkr1hands.js gzip 49.6 kB N/A -
0n2xjxbp1o-cf.js gzip 154 B N/A -
0ojkk2e654xsc.js gzip 8.59 kB N/A -
0tqzh3vdgxqs0.js gzip 155 B N/A -
0wxpyd8r-vipl.js gzip 1.47 kB N/A -
0xy2fhla48_rd.js gzip 9.24 kB N/A -
1-3n9-2yrca70.js gzip 156 B N/A -
10wqsvi2mgfmi.js gzip 9.82 kB N/A -
16lhqjoqbznyg.js gzip 220 B 220 B
16vepdkipri3r.js gzip 8.51 kB N/A -
17n96uu6y1pxq.js gzip 8.6 kB N/A -
18y4_8-9or0mn.js gzip 8.51 kB N/A -
1bzee7q1zyj1i.js gzip 169 B N/A -
1elt1qium-r2m.css gzip 115 B 115 B
1gq145j3kps-h.js gzip 8.62 kB N/A -
1nsh-mbn0e-se.js gzip 8.56 kB N/A -
1s-jybzia-ks5.js gzip 157 B N/A -
1tsrrp1tdngti.js gzip 13.3 kB N/A -
2__-e_ym8n788.js gzip 450 B N/A -
22o6xd9_ywdu6.js gzip 233 B N/A -
2is7z6q3dc_xy.js gzip 156 B N/A -
2kvj8yrfznmwx.js gzip 5.69 kB N/A -
2qv7m7xjnokgr.js gzip 8.58 kB N/A -
31gb7ha0076ao.js gzip 65.5 kB N/A -
342ijzvrpe53h.js gzip 2.29 kB N/A -
39rz5eajodm-i.js gzip 70.8 kB N/A -
3h-3_i35diwz_.js gzip 159 B N/A -
3qsufpzxbwkfg.js gzip 161 B N/A -
3tmsbs5k2j6h3.js gzip 155 B N/A -
3x0u96gydkgya.js gzip 154 B N/A -
44un3--wmqiyh.js gzip 7.61 kB N/A -
turbopack-0g..x5-a.js gzip 4.19 kB N/A -
turbopack-0j..k2mx.js gzip 4.19 kB N/A -
turbopack-0j..hh5a.js gzip 4.19 kB N/A -
turbopack-0r..9e-j.js gzip 4.19 kB N/A -
turbopack-0s..0s2z.js gzip 4.19 kB N/A -
turbopack-1b..3wfz.js gzip 4.19 kB N/A -
turbopack-23..fv87.js gzip 4.19 kB N/A -
turbopack-24.._76v.js gzip 4.19 kB N/A -
turbopack-2h..oi17.js gzip 4.17 kB N/A -
turbopack-2w..udhg.js gzip 4.19 kB N/A -
turbopack-3j.._sjy.js gzip 4.19 kB N/A -
turbopack-3k..tfg-.js gzip 4.19 kB N/A -
turbopack-43..qbh-.js gzip 4.2 kB N/A -
turbopack-43..70ze.js gzip 4.19 kB N/A -
02-ohkib1boio.js gzip N/A 155 B -
09t9i6o8nvir7.js gzip N/A 49.6 kB -
0arkbdqpxc37i.js gzip N/A 8.6 kB -
0bz-xifewa17d.js gzip N/A 8.63 kB -
0tvekitj587fh.js gzip N/A 8.51 kB -
0ug8gcgkteixz.js gzip N/A 154 B -
0yvk6-wi8e9wh.js gzip N/A 13.3 kB -
0z83a1om5rvtt.js gzip N/A 7.61 kB -
1-jqyfc89tixo.js gzip N/A 1.46 kB -
14t1kneseb8th.js gzip N/A 2.3 kB -
15sb1-dsqfk_j.js gzip N/A 8.59 kB -
1ab2xruymo-oj.js gzip N/A 449 B -
1dvuvo8jk3a6v.js gzip N/A 156 B -
1tu25qtsmfhar.js gzip N/A 9.82 kB -
1vein_gnv3mwr.js gzip N/A 8.56 kB -
1wzrm0xjjbzn5.js gzip N/A 10.1 kB -
1z3g0uaqtv9_3.js gzip N/A 8.56 kB -
2_2mij-bqvb21.js gzip N/A 157 B -
22w4zs_iimiwv.js gzip N/A 168 B -
23hbmknn7eyfs.js gzip N/A 155 B -
24gkrtv9a0_bk.js gzip N/A 160 B -
25a1yz7zua29z.js gzip N/A 13.8 kB -
26u4q6n2guyn5.js gzip N/A 154 B -
2bi5hx402juv-.js gzip N/A 8.58 kB -
2eleo8xxk7-8o.js gzip N/A 70.8 kB -
2hy56297fog9u.js gzip N/A 8.52 kB -
2m547nowcdwcx.js gzip N/A 157 B -
2oc_djlxina77.js gzip N/A 65.5 kB -
2ocku-vkz67rf.js gzip N/A 158 B -
2u_rpxq3tzytl.js gzip N/A 233 B -
311e8omf8_-ly.js gzip N/A 161 B -
368lim5wq0o0r.js gzip N/A 12.9 kB -
3d05m1jqni2og.js gzip N/A 157 B -
3drqjohogojbw.js gzip N/A 5.69 kB -
3g8l1m2-o-ewi.js gzip N/A 13.1 kB -
3jmkxsnxg0nrh.js gzip N/A 10.4 kB -
3wpp8nvyoj121.js gzip N/A 9.24 kB -
41o_vu8pnc-q8.js gzip N/A 153 B -
turbopack-06..gptw.js gzip N/A 4.19 kB -
turbopack-0f..4-x9.js gzip N/A 4.19 kB -
turbopack-0x..55ly.js gzip N/A 4.19 kB -
turbopack-0x..z2bu.js gzip N/A 4.19 kB -
turbopack-0z..f2r2.js gzip N/A 4.19 kB -
turbopack-1q..n6_k.js gzip N/A 4.19 kB -
turbopack-1t..fx3m.js gzip N/A 4.19 kB -
turbopack-22..aaoz.js gzip N/A 4.19 kB -
turbopack-2n..6mkj.js gzip N/A 4.19 kB -
turbopack-2u..8rul.js gzip N/A 4.17 kB -
turbopack-37..bmsx.js gzip N/A 4.19 kB -
turbopack-3h..ktv0.js gzip N/A 4.19 kB -
turbopack-3y..8yjt.js gzip N/A 4.2 kB -
turbopack-40..uisw.js gzip N/A 4.19 kB -
Total 465 kB 465 kB ⚠️ +57 B

Server

Middleware
Canary PR Change
middleware-b..fest.js gzip 717 B 718 B
Total 717 B 718 B ⚠️ +1 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 431 B 431 B
Total 431 B 431 B

📦 Webpack

Client

Main Bundles
Canary PR Change
2637-HASH.js gzip 4.63 kB N/A -
7724.HASH.js gzip 169 B N/A -
8274-HASH.js gzip 61.4 kB N/A -
8817-HASH.js gzip 5.59 kB N/A -
c3500254-HASH.js gzip 62.8 kB N/A -
framework-HASH.js gzip 59.7 kB 59.7 kB
main-app-HASH.js gzip 254 B 255 B
main-HASH.js gzip 39.4 kB 39.3 kB
webpack-HASH.js gzip 1.68 kB 1.68 kB
5887-HASH.js gzip N/A 5.61 kB -
6522-HASH.js gzip N/A 60.8 kB -
6779-HASH.js gzip N/A 4.63 kB -
8854.HASH.js gzip N/A 169 B -
eab920f9-HASH.js gzip N/A 62.8 kB -
Total 236 kB 235 kB ✅ -640 B
Polyfills
Canary PR Change
polyfills-HASH.js gzip 39.4 kB 39.4 kB
Total 39.4 kB 39.4 kB
Pages
Canary PR Change
_app-HASH.js gzip 193 B 193 B
_error-HASH.js gzip 182 B 182 B
css-HASH.js gzip 333 B 334 B
dynamic-HASH.js gzip 1.81 kB 1.8 kB
edge-ssr-HASH.js gzip 255 B 255 B
head-HASH.js gzip 353 B 349 B 🟢 4 B (-1%)
hooks-HASH.js gzip 384 B 382 B
image-HASH.js gzip 581 B 581 B
index-HASH.js gzip 260 B 259 B
link-HASH.js gzip 2.51 kB 2.51 kB
routerDirect..HASH.js gzip 316 B 318 B
script-HASH.js gzip 386 B 386 B
withRouter-HASH.js gzip 313 B 314 B
1afbb74e6ecf..834.css gzip 106 B 106 B
Total 7.98 kB 7.97 kB ✅ -10 B

Server

Edge SSR
Canary PR Change
edge-ssr.js gzip 126 kB 126 kB
page.js gzip 274 kB 273 kB
Total 399 kB 399 kB ✅ -404 B
Middleware
Canary PR Change
middleware-b..fest.js gzip 616 B 617 B
middleware-r..fest.js gzip 156 B 156 B
middleware.js gzip 44 kB 44.4 kB
edge-runtime..pack.js gzip 842 B 842 B
Total 45.6 kB 46 kB ⚠️ +383 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 721 B 720 B
Total 721 B 720 B ✅ -1 B
Build Cache
Canary PR Change
0.pack gzip 4.38 MB 4.38 MB
index.pack gzip 113 kB 114 kB
index.pack.old gzip 115 kB 115 kB
Total 4.61 MB 4.61 MB ⚠️ +2.72 kB

🔄 Shared (bundler-independent)

Runtimes
Canary PR Change
app-page-exp...dev.js gzip 347 kB 347 kB
app-page-exp..prod.js gzip 192 kB 192 kB
app-page-tur...dev.js gzip 347 kB 347 kB
app-page-tur..prod.js gzip 192 kB 192 kB
app-page-tur...dev.js gzip 343 kB 343 kB
app-page-tur..prod.js gzip 190 kB 190 kB
app-page.run...dev.js gzip 344 kB 344 kB
app-page.run..prod.js gzip 190 kB 190 kB
app-route-ex...dev.js gzip 77 kB 77 kB
app-route-ex..prod.js gzip 52.5 kB 52.5 kB
app-route-tu...dev.js gzip 77.1 kB 77.1 kB
app-route-tu..prod.js gzip 52.6 kB 52.6 kB
app-route-tu...dev.js gzip 76.7 kB 76.7 kB
app-route-tu..prod.js gzip 52.3 kB 52.3 kB
app-route.ru...dev.js gzip 76.6 kB 76.6 kB
app-route.ru..prod.js gzip 52.3 kB 52.3 kB
dist_client_...dev.js gzip 324 B 324 B
dist_client_...dev.js gzip 326 B 326 B
dist_client_...dev.js gzip 318 B 318 B
dist_client_...dev.js gzip 317 B 317 B
pages-api-tu...dev.js gzip 43.9 kB 43.9 kB
pages-api-tu..prod.js gzip 33.5 kB 33.5 kB
pages-api.ru...dev.js gzip 43.9 kB 43.9 kB
pages-api.ru..prod.js gzip 33.5 kB 33.5 kB
pages-turbo....dev.js gzip 53.3 kB 53.3 kB
pages-turbo...prod.js gzip 39.1 kB 39.1 kB
pages.runtim...dev.js gzip 53.3 kB 53.3 kB
pages.runtim..prod.js gzip 39.1 kB 39.1 kB
server.runti..prod.js gzip 63 kB 63 kB
Total 3.07 MB 3.07 MB ⚠️ +2 B
📎 Tarball URL
https://vercel-packages.vercel.app/next/commits/2c18328be3b24216906fa3685cddf39c186938c3/next

@lukesandberg lukesandberg marked this pull request as ready for review April 20, 2026 20:49
@lukesandberg lukesandberg marked this pull request as draft April 20, 2026 20:49
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 20, 2026

Merging this PR will degrade performance by 3.48%

❌ 2 regressed benchmarks
✅ 15 untouched benchmarks
⏩ 3 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation packages-bundle.js[full] 949.3 ms 982.2 ms -3.35%
Simulation app-page-turbo.runtime.prod.js[full] 621.2 ms 643.6 ms -3.48%

Comparing followups (ca35fb9) with eviction_semantics_for_real_this_time (bc661cd)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

let appOriginalName: string | undefined
for (const [name] of currentEntrypoints.app) {
if (normalizeAppPath(name) === page) {
appOriginalName = name
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be clearer to just create the definition here instead of having the ternary below

it could just be 'extraParams' and be unconditionally spread so all the comments are in one place

type HandleRouteTypeHooks = {
handleWrittenEndpoint: HandleWrittenEndpoint
subscribeToChanges: StartChangeSubscription
subscribeToChanges?: StartChangeSubscription
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of making this be optional would it be better to just pass a no-op subscribe function down?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

created-by: Turbopack team PRs by the Turbopack team. Documentation Related to Next.js' official documentation. tests type: next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants