@perfonext/render-mcp 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,32 +2,81 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@perfonext/render-mcp)](https://www.npmjs.com/package/@perfonext/render-mcp)
4
4
 
5
- `perfonext-render-mcp` is an MCP server for loading and analyzing React DevTools Profiler exports captured from Next.js apps. It gives GitHub Copilot and other MCP clients structured render data they can reason over instead of forcing the model to inspect raw profiler JSON.
5
+ `perfonext-render-mcp` is an MCP server for analyzing React render behavior in Next.js apps and applying fixes
6
+ in the editor. It is the **agent companion** to React DevTools Profiler and `react-scan` — best at
7
+ machine-readable summaries, exact rerender-cause attribution, source-aware follow-up, and diffing.
8
+
9
+ The loop is **collect → analyze → fix**, all locally:
10
+
11
+ - **collect** — choose live capture (react-scan/lite streams events in real time) or manual DevTools export
12
+ - **analyze** — the MCP returns structured, machine-readable evidence: component costs, rerender causes, commit breakdowns, and regressions
13
+ - **fix** — Copilot uses that evidence to propose and apply concrete code changes
14
+
15
+ > **Note:** while a live capture session is active, React DevTools Timeline Profiler will not receive events
16
+ > (react-scan/lite takes over the profiling channel). Calling `stop_render_capture` restores it.
6
17
 
7
18
  ## What It Does
8
19
 
9
- - loads exported React Profiler JSON files from Next.js apps
20
+ - **live capture** streams per-commit fiber events from a running React app directly into the MCP over a local HTTP endpoint; no manual export required
21
+ - **manual export** — loads exported React DevTools Profiler JSON files as an alternative input path
10
22
  - summarizes commits, the most expensive components, and detected render issues in one call
11
23
  - ranks the hottest commits and shows the top components inside each spike
12
24
  - identifies the slowest components by total render cost
13
25
  - highlights components with repeated rerenders using deterministic heuristics, evidence signals, and confidence levels
14
26
  - compares two render profiles to surface regressions and improvements
15
- - keeps the loaded profiles in memory so an MCP client can iterate without re-reading the file
27
+ - keeps profiles in memory so Copilot can iterate without re-loading
16
28
 
17
29
  ## Tools
18
30
 
31
+ ### Entry point
32
+
19
33
  | Tool | Description |
20
34
  |------|-------------|
21
- | `load_render_profile` | Parse and load an exported React Profiler JSON file from disk |
22
- | `get_render_summary` | Summarize a loaded profile: top components by render cost, hottest commits, and detected render issues (rerender storms, commit spikes) |
35
+ | `begin_render_analysis` | Entry point. Accepts `approach: "live" \| "manual"`. For `live`: starts a capture session and returns the instrumentation snippet. For `manual`: returns React DevTools Profiler export steps. |
36
+
37
+ ### Live capture
38
+
39
+ | Tool | Description |
40
+ |------|-------------|
41
+ | `run_render_capture` | Called after instrumentation is wired up. Accepts `method: "manual-interaction" \| "test-suite"`. Returns focused instructions for whichever method the user picks. |
42
+ | `stop_render_capture` | Stop the session, finalize buffered events into a profile, and return a `profileId` for analysis |
43
+ | `get_captured_renders` | Optional diagnostic: peek at session progress without stopping (commit count, unknown events). Only call if something seems wrong. |
44
+
45
+ ### Analysis
46
+
47
+ | Tool | Description |
48
+ |------|-------------|
49
+ | `load_render_profile` | Parse and load an exported React DevTools Profiler JSON file from disk (manual path entry point) |
50
+ | `get_render_summary` | Summarize a loaded profile: top components by render cost, hottest commits, and detected render issues |
23
51
  | `get_hot_commits` | Rank the most expensive commits and show the top components inside each spike |
24
52
  | `get_slow_components` | Rank the slowest components by total actual render time |
25
- | `get_rerender_causes` | Explain likely rerender causes using profile-derived heuristics, evidence, confidence, and a documented score |
53
+ | `get_rerender_causes` | Explain rerender causes with evidence, confidence, and a risk score |
26
54
  | `compare_renders` | Diff two loaded render profiles and rank regressions, improvements, additions, and removals |
27
55
 
28
- `get_rerender_causes` is heuristic by design. It works from structural signals in the profiler export — update frequency, nested update propagation, commit spread, and self-intensive renders. When you record with **"Record why each component rendered"** enabled in React DevTools Profiler settings, the export includes richer `changeDescriptions` data; future versions of this tool will parse that field to surface exact prop/state/context diffs natively.
56
+ ## Quickstart
57
+
58
+ Ask Copilot: *"Run a render analysis on my app."*
59
+
60
+ Copilot calls `begin_render_analysis` and asks you to choose:
61
+
62
+ **Option A — Live capture (recommended)**
63
+
64
+ Copilot will:
65
+ 1. Start a capture session (ingest server on `127.0.0.1:7721`)
66
+ 2. Install `react-scan` as a devDependency if not present
67
+ 3. Write `instrumentation-client.js` at your project root with the session snippet
68
+ 4. Import it from your app's client-side entry point
69
+ 5. Ask whether you want to interact manually or run a test suite (`run_render_capture`)
70
+ 6. Stop the session and run analysis
29
71
 
30
- `get_render_summary` includes an `issues` field with up to 5 detected render issues (commit spikes and rerender storms) so you get actionable findings in the same call as the summary.
72
+ The ingest server runs on a **fixed port (7721)**. Only the `sessionId` line in `instrumentation-client.js` changes between sessions the file does not need to be re-wired each time.
73
+
74
+ **Option B — Manual DevTools export**
75
+
76
+ 1. Open React DevTools in the browser → Profiler tab → Record
77
+ 2. Interact with the app
78
+ 3. Export the JSON and share the file path
79
+ 4. Copilot calls `load_render_profile({ filePath: "..." })`
31
80
 
32
81
  ## Rerender Score Contract
33
82
 
@@ -44,17 +93,19 @@
44
93
  - `high`: three or more independent signals
45
94
  - `evidence[]`: machine-readable signals such as repeated updates, nested-update propagation, wide commit spread, or high actual-vs-self duration ratio
46
95
 
47
- Current score inputs are:
96
+ The score ranks investigation order, not exact root cause.
48
97
 
49
- - repeated update-phase renders
50
- - nested update propagation
51
- - appearance across many commits
52
- - high actual-vs-self duration ratio
98
+ ## Example Copilot Prompts
53
99
 
54
- The score is meant to help rank investigation order, not to claim exact root cause. Enable **"Record why each component rendered"** in React DevTools Profiler settings before recording to capture richer change metadata in the export.
100
+ - "Run a render analysis on my app."
101
+ - "Stop the capture and show me the slowest components."
102
+ - "Which components are re-rendering the most and why?"
103
+ - "Compare this run to the profile I captured before the refactor."
104
+ - "I already have a React DevTools export — load it and tell me what's slow."
55
105
 
56
106
  ## Install
57
107
 
108
+
58
109
  Run directly with `npx`:
59
110
 
60
111
  ```bash
@@ -71,7 +122,7 @@ The executable command remains `perfonext-render-mcp` after installation.
71
122
 
72
123
  ## MCP Configuration
73
124
 
74
- Add this server to VS Code settings:
125
+ Add to your VS Code `settings.json`:
75
126
 
76
127
  ```json
77
128
  {
@@ -86,15 +137,14 @@ Add this server to VS Code settings:
86
137
  }
87
138
  ```
88
139
 
89
- Local workspace MCP config is also included in `.vscode/mcp.json` for development.
90
-
91
140
  ## Example Copilot Prompts
92
141
 
93
- - "Load the React Profiler export at `./profile.json` and summarize the hottest components."
94
- - "Show me the hottest commits in `./profile.json` and which components dominated each spike."
95
- - "Compare `before.json` and `after.json` and tell me which components regressed."
96
- - "Which components are consuming the most render time in this Next.js profile?"
97
- - "Show me the likely rerender causes for the slowest components, including evidence and confidence."
142
+ - "Run a render analysis on my app."
143
+ - "Stop the capture and show me the slowest components."
144
+ - "Which components are re-rendering the most and why?"
145
+ - "Compare this run to the profile I captured before the refactor."
146
+ - "I already have a React DevTools export load it and tell me what's slow."
147
+ - "Show me the hottest commits and which components dominated each spike."
98
148
 
99
149
  ## Development
100
150
 
@@ -104,7 +154,7 @@ npm run build
104
154
  npm test
105
155
  ```
106
156
 
107
- Sample fixtures for local validation live under `tests/fixtures/`.
157
+ Sample fixtures live under `tests/fixtures/`.
108
158
 
109
159
  ## License
110
160
 
package/dist/index.js CHANGED
@@ -7,9 +7,13 @@ import { registerGetRenderSummary } from './tools/get-render-summary.js';
7
7
  import { registerGetHotCommits } from './tools/get-hot-commits.js';
8
8
  import { registerGetSlowComponents } from './tools/get-slow-components.js';
9
9
  import { registerGetRerenderCauses } from './tools/get-rerender-causes.js';
10
+ import { registerBeginRenderAnalysis } from './tools/begin-render-analysis.js';
11
+ import { registerRunRenderCapture } from './tools/run-render-capture.js';
12
+ import { registerStopRenderCapture } from './tools/stop-render-capture.js';
13
+ import { registerGetCapturedRenders } from './tools/get-captured-renders.js';
10
14
  const server = new McpServer({
11
15
  name: 'perfonext-render-mcp',
12
- version: '0.2.0',
16
+ version: '0.3.0',
13
17
  });
14
18
  registerLoadRenderProfile(server);
15
19
  registerCompareRenders(server);
@@ -17,6 +21,10 @@ registerGetRenderSummary(server);
17
21
  registerGetHotCommits(server);
18
22
  registerGetSlowComponents(server);
19
23
  registerGetRerenderCauses(server);
24
+ registerBeginRenderAnalysis(server);
25
+ registerRunRenderCapture(server);
26
+ registerStopRenderCapture(server);
27
+ registerGetCapturedRenders(server);
20
28
  const transport = new StdioServerTransport();
21
29
  await server.connect(transport);
22
30
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IAC3B,IAAI,EAAE,sBAAsB;IAC5B,OAAO,EAAE,OAAO;CACjB,CAAC,CAAC;AAEH,yBAAyB,CAAC,MAAM,CAAC,CAAC;AAClC,sBAAsB,CAAC,MAAM,CAAC,CAAC;AAC/B,wBAAwB,CAAC,MAAM,CAAC,CAAC;AACjC,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAC9B,yBAAyB,CAAC,MAAM,CAAC,CAAC;AAClC,yBAAyB,CAAC,MAAM,CAAC,CAAC;AAElC,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;AAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.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AC,OAAO,CAAC,SAAS,CAAC,CAAC"}
@@ -0,0 +1,53 @@
1
+ export interface ReactScanChangeDescription {
2
+ props?: string[] | null;
3
+ state?: string[] | null;
4
+ context?: string[] | null;
5
+ hooks?: string[] | null;
6
+ isFirstMount?: boolean;
7
+ }
8
+ export interface ReactScanSource {
9
+ fileName: string;
10
+ lineNumber: number;
11
+ columnNumber: number;
12
+ }
13
+ export interface ReactScanFiberEvent {
14
+ fiberId: number;
15
+ name: string;
16
+ depth: number;
17
+ actualDuration: number;
18
+ selfDuration?: number;
19
+ changeDescription?: ReactScanChangeDescription | null;
20
+ source?: ReactScanSource | null;
21
+ parentId?: number | null;
22
+ }
23
+ export interface ReactScanCommitEvent {
24
+ type: 'commit';
25
+ sessionId: string;
26
+ commitIndex: number;
27
+ rootId: number;
28
+ duration: number;
29
+ timestamp: number;
30
+ priorityName?: string;
31
+ laneLabels?: string[];
32
+ updaterNames?: string[];
33
+ fibers: ReactScanFiberEvent[];
34
+ }
35
+ export interface CaptureSession {
36
+ sessionId: string;
37
+ endpoint: string;
38
+ status: 'active' | 'stopped';
39
+ commits: ReactScanCommitEvent[];
40
+ profilingAvailable: boolean | null;
41
+ startTime: number;
42
+ /** Count of POST bodies that had no recognizable react-scan/lite `message` field.
43
+ * A non-zero value with zero commits usually means the instrumentation snippet
44
+ * is not wired correctly (e.g. the import path is wrong or the file runs server-side). */
45
+ unknownEvents: number;
46
+ }
47
+ export declare function createCaptureSession(): Promise<CaptureSession>;
48
+ export declare function getCaptureSession(sessionId: string): CaptureSession | undefined;
49
+ export declare function stopCaptureSession(sessionId: string): CaptureSession | undefined;
50
+ /** Remove a session from memory once its profile has been stored. */
51
+ export declare function deleteCaptureSession(sessionId: string): void;
52
+ export declare function getServerPort(): number | null;
53
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/ingest/server.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,0BA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,OAAO,EAAE,oBAAoB,EAAE,CAAC;IAChC,kBAAkB,EAAE,OAAO,GAAG,IAAI,CAAC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB;;+FAE2F;IAC3F,aAAa,EAAE,MAAM,CAAC;CACvB;AAuID,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,cAAc,CAAC,CAoBpE;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAE/E;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAKhF;AAED,qEAAqE;AACrE,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAE5D;AAED,wBAAgB,aAAa,IAAI,MAAM,GAAG,IAAI,CAE7C"}
@@ -0,0 +1,211 @@
1
+ import { createServer } from 'node:http';
2
+ import { randomUUID } from 'node:crypto';
3
+ function normalizeFiber(raw) {
4
+ const cd = raw.changeDescription ?? null;
5
+ return {
6
+ fiberId: typeof raw.fiberId === 'number' ? raw.fiberId : 0,
7
+ name: (typeof raw.name === 'string' && raw.name.trim()) ? raw.name.trim() : '(anonymous)',
8
+ depth: typeof raw.depth === 'number' ? raw.depth : 0,
9
+ actualDuration: typeof raw.actualDuration === 'number' ? raw.actualDuration : 0,
10
+ selfDuration: typeof raw.selfBaseDuration === 'number' ? raw.selfBaseDuration : 0,
11
+ changeDescription: cd != null ? {
12
+ isFirstMount: cd.isFirstMount ?? false,
13
+ props: cd.props ?? null,
14
+ state: cd.state ? ['state'] : null,
15
+ context: cd.context ? ['context'] : null,
16
+ hooks: cd.hooks?.map((i) => `hook[${i}]`) ?? null,
17
+ } : null,
18
+ source: (raw.source && typeof raw.source === 'object') ? raw.source : null,
19
+ parentId: null,
20
+ };
21
+ }
22
+ function parseOneEvent(raw, commitIndex, urlSessionId) {
23
+ if (!raw || typeof raw !== 'object')
24
+ return null;
25
+ const r = raw;
26
+ // ── Native react-scan/lite endpoint format ────────────────────────────────
27
+ // Body: { message: LiteEventKind, data: {...}, sessionId, timestamp }
28
+ if (typeof r.message === 'string') {
29
+ const data = (r.data && typeof r.data === 'object') ? r.data : {};
30
+ const ts = typeof r.timestamp === 'number' ? r.timestamp : Date.now();
31
+ if (r.message === 'commit') {
32
+ const tree = Array.isArray(data.tree) ? data.tree : [];
33
+ const fibers = tree.map(normalizeFiber);
34
+ // Use root-depth fiber's actualDuration as commit duration; fall back to sum.
35
+ const rootFiber = fibers.find(f => f.depth === 0);
36
+ const duration = rootFiber?.actualDuration ?? fibers.reduce((s, f) => s + f.actualDuration, 0);
37
+ return {
38
+ kind: 'commit',
39
+ event: {
40
+ type: 'commit',
41
+ sessionId: urlSessionId, // always use URL sessionId — never trust the body
42
+ commitIndex,
43
+ rootId: typeof data.rendererId === 'number' ? data.rendererId : 1,
44
+ duration,
45
+ timestamp: ts,
46
+ priorityName: typeof data.priorityName === 'string' ? data.priorityName : undefined,
47
+ laneLabels: Array.isArray(data.laneLabels) ? data.laneLabels : undefined,
48
+ updaterNames: [],
49
+ fibers,
50
+ },
51
+ };
52
+ }
53
+ if (r.message === 'profiling-hooks-status') {
54
+ return { kind: 'status', available: data.available === true };
55
+ }
56
+ return null; // other event kinds (render-start, post-commit, fiber-unmount, etc.) — expected noise
57
+ }
58
+ return null; // no `message` field — not a react-scan/lite payload
59
+ }
60
+ // ---------------------------------------------------------------------------
61
+ // Singleton HTTP server state
62
+ // ---------------------------------------------------------------------------
63
+ const sessions = new Map();
64
+ let httpServer = null;
65
+ let serverPort = null;
66
+ // ---------------------------------------------------------------------------
67
+ // Internal helpers
68
+ // ---------------------------------------------------------------------------
69
+ function readBody(req) {
70
+ return new Promise((resolve, reject) => {
71
+ const chunks = [];
72
+ req.on('data', (chunk) => chunks.push(chunk));
73
+ req.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')));
74
+ req.on('error', reject);
75
+ });
76
+ }
77
+ function handleRequest(req, res) {
78
+ res.setHeader('Access-Control-Allow-Origin', '*');
79
+ res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
80
+ res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
81
+ if (req.method === 'OPTIONS') {
82
+ res.writeHead(204);
83
+ res.end();
84
+ return;
85
+ }
86
+ const url = req.url ?? '';
87
+ const match = url.match(/^\/ingest\/([^/]+)$/);
88
+ if (!match || req.method !== 'POST') {
89
+ res.writeHead(404);
90
+ res.end(JSON.stringify({ error: 'not found' }));
91
+ return;
92
+ }
93
+ const sessionId = decodeURIComponent(match[1]);
94
+ const session = sessions.get(sessionId);
95
+ if (!session) {
96
+ res.writeHead(404);
97
+ res.end(JSON.stringify({ error: 'session not found' }));
98
+ return;
99
+ }
100
+ if (session.status !== 'active') {
101
+ res.writeHead(410);
102
+ res.end(JSON.stringify({ error: 'session already stopped' }));
103
+ return;
104
+ }
105
+ readBody(req)
106
+ .then(body => {
107
+ let rawEvents;
108
+ try {
109
+ const parsed = JSON.parse(body);
110
+ rawEvents = Array.isArray(parsed) ? parsed : [parsed];
111
+ }
112
+ catch {
113
+ res.writeHead(400);
114
+ res.end(JSON.stringify({ error: 'invalid JSON' }));
115
+ return;
116
+ }
117
+ let received = 0;
118
+ for (const raw of rawEvents) {
119
+ const normalized = parseOneEvent(raw, session.commits.length, sessionId);
120
+ if (!normalized) {
121
+ if (raw && typeof raw === 'object' && !('message' in raw)) {
122
+ session.unknownEvents++;
123
+ }
124
+ continue;
125
+ }
126
+ received++;
127
+ if (normalized.kind === 'commit') {
128
+ session.commits.push(normalized.event);
129
+ }
130
+ else if (normalized.kind === 'status') {
131
+ session.profilingAvailable = normalized.available;
132
+ }
133
+ }
134
+ res.writeHead(200);
135
+ res.end(JSON.stringify({ ok: true, received }));
136
+ })
137
+ .catch(() => {
138
+ res.writeHead(500);
139
+ res.end(JSON.stringify({ error: 'internal error' }));
140
+ });
141
+ }
142
+ // Default port 7721; override with PERFONEXT_INGEST_PORT.
143
+ const _rawPort = parseInt(process.env.PERFONEXT_INGEST_PORT ?? '7721', 10);
144
+ if (!Number.isFinite(_rawPort) || _rawPort < 1 || _rawPort > 65535) {
145
+ throw new Error(`PERFONEXT_INGEST_PORT must be a number between 1 and 65535 (got: "${process.env.PERFONEXT_INGEST_PORT}")`);
146
+ }
147
+ const INGEST_PORT = _rawPort;
148
+ function startHttpServer() {
149
+ return new Promise((resolve, reject) => {
150
+ const server = createServer(handleRequest);
151
+ // Bind to loopback only — no external exposure.
152
+ server.listen(INGEST_PORT, '127.0.0.1', () => {
153
+ const addr = server.address();
154
+ if (!addr || typeof addr === 'string') {
155
+ reject(new Error('Unexpected server address'));
156
+ return;
157
+ }
158
+ httpServer = server;
159
+ serverPort = addr.port;
160
+ resolve(addr.port);
161
+ });
162
+ server.on('error', (err) => {
163
+ if (err.code === 'EADDRINUSE') {
164
+ reject(new Error(`Ingest server port ${INGEST_PORT} is already in use. ` +
165
+ 'Free the port or set PERFONEXT_INGEST_PORT to a different value.'));
166
+ }
167
+ else {
168
+ reject(err);
169
+ }
170
+ });
171
+ });
172
+ }
173
+ // ---------------------------------------------------------------------------
174
+ // Public API
175
+ // ---------------------------------------------------------------------------
176
+ export async function createCaptureSession() {
177
+ if (!httpServer) {
178
+ await startHttpServer();
179
+ }
180
+ const sessionId = randomUUID();
181
+ const endpoint = `http://127.0.0.1:${serverPort}/ingest/${sessionId}`;
182
+ const session = {
183
+ sessionId,
184
+ endpoint,
185
+ status: 'active',
186
+ commits: [],
187
+ profilingAvailable: null,
188
+ startTime: Date.now(),
189
+ unknownEvents: 0,
190
+ };
191
+ sessions.set(sessionId, session);
192
+ return session;
193
+ }
194
+ export function getCaptureSession(sessionId) {
195
+ return sessions.get(sessionId);
196
+ }
197
+ export function stopCaptureSession(sessionId) {
198
+ const session = sessions.get(sessionId);
199
+ if (!session)
200
+ return undefined;
201
+ session.status = 'stopped';
202
+ return session;
203
+ }
204
+ /** Remove a session from memory once its profile has been stored. */
205
+ export function deleteCaptureSession(sessionId) {
206
+ sessions.delete(sessionId);
207
+ }
208
+ export function getServerPort() {
209
+ return serverPort;
210
+ }
211
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/ingest/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAC;AACjG,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAsEzC,SAAS,cAAc,CAAC,GAAa;IACnC,MAAM,EAAE,GAAG,GAAG,CAAC,iBAAiB,IAAI,IAAI,CAAC;IACzC,OAAO;QACL,OAAO,EAAE,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC1D,IAAI,EAAE,CAAC,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,aAAa;QACzF,KAAK,EAAE,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACpD,cAAc,EAAE,OAAO,GAAG,CAAC,cAAc,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;QAC/E,YAAY,EAAE,OAAO,GAAG,CAAC,gBAAgB,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;QACjF,iBAAiB,EAAE,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC;YAC9B,YAAY,EAAE,EAAE,CAAC,YAAY,IAAI,KAAK;YACtC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI;YACvB,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC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+ import type { ParsedRenderProfile } from './types.js';
3
+ /**
4
+ * Convert an array of raw react-scan/lite commit events into the internal
5
+ * ParsedRenderProfile model used by all analysis tools.
6
+ */
7
+ export declare function adaptReactScanEvents(rawCommits: ReactScanCommitEvent[], sessionId: string): ParsedRenderProfile;
8
+ //# sourceMappingURL=react-scan-lite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-scan-lite.d.ts","sourceRoot":"","sources":["../../src/parser/react-scan-lite.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAuB,MAAM,qBAAqB,CAAC;AACrF,OAAO,KAAK,EAGV,mBAAmB,EAGpB,MAAM,YAAY,CAAC;AAoFpB;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,oBAAoB,EAAE,EAClC,SAAS,EAAE,MAAM,GAChB,mBAAmB,CA+CrB"}
@@ -0,0 +1,114 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ // ---------------------------------------------------------------------------
3
+ // Internal helpers
4
+ // ---------------------------------------------------------------------------
5
+ function buildMeasurements(fibers, rootId, commitIndex, commitTime) {
6
+ return fibers.map(fiber => ({
7
+ fiberId: fiber.fiberId,
8
+ rootId,
9
+ componentName: fiber.name?.trim() || `(fiber:${fiber.fiberId})`,
10
+ phase: fiber.changeDescription?.isFirstMount === true ? 'mount' : 'update',
11
+ actualDuration: fiber.actualDuration ?? 0,
12
+ selfDuration: fiber.selfDuration ?? 0,
13
+ startTime: commitTime,
14
+ commitTime,
15
+ renderCount: 1,
16
+ commitIndex,
17
+ isNestedUpdate: false,
18
+ }));
19
+ }
20
+ function buildFiberNodes(fibers, rootId) {
21
+ // Wire format has no explicit parent IDs; parentFiberId and childFiberIds are always null/empty.
22
+ return fibers.map(fiber => ({
23
+ fiberId: fiber.fiberId,
24
+ rootId,
25
+ componentName: fiber.name?.trim() || `(fiber:${fiber.fiberId})`,
26
+ parentFiberId: null,
27
+ childFiberIds: [],
28
+ }));
29
+ }
30
+ function buildComponentStats(commits) {
31
+ const statsMap = new Map();
32
+ for (const commit of commits) {
33
+ for (const m of commit.measurements) {
34
+ let stats = statsMap.get(m.componentName);
35
+ if (!stats) {
36
+ stats = {
37
+ componentName: m.componentName,
38
+ renderCount: 0,
39
+ mountCount: 0,
40
+ updateCount: 0,
41
+ nestedUpdateCount: 0,
42
+ totalActualDuration: 0,
43
+ totalSelfDuration: 0,
44
+ maxActualDuration: 0,
45
+ commitIndices: [],
46
+ };
47
+ statsMap.set(m.componentName, stats);
48
+ }
49
+ stats.renderCount++;
50
+ if (m.phase === 'mount') {
51
+ stats.mountCount++;
52
+ }
53
+ else {
54
+ stats.updateCount++;
55
+ }
56
+ if (m.isNestedUpdate)
57
+ stats.nestedUpdateCount++;
58
+ stats.totalActualDuration += m.actualDuration;
59
+ stats.totalSelfDuration += m.selfDuration;
60
+ if (m.actualDuration > stats.maxActualDuration) {
61
+ stats.maxActualDuration = m.actualDuration;
62
+ }
63
+ if (!stats.commitIndices.includes(m.commitIndex)) {
64
+ stats.commitIndices.push(m.commitIndex);
65
+ }
66
+ }
67
+ }
68
+ return Array.from(statsMap.values());
69
+ }
70
+ // ---------------------------------------------------------------------------
71
+ // Public adapter
72
+ // ---------------------------------------------------------------------------
73
+ /**
74
+ * Convert an array of raw react-scan/lite commit events into the internal
75
+ * ParsedRenderProfile model used by all analysis tools.
76
+ */
77
+ export function adaptReactScanEvents(rawCommits, sessionId) {
78
+ const commits = rawCommits.map((raw, idx) => ({
79
+ index: idx,
80
+ rootId: raw.rootId ?? 1,
81
+ duration: raw.duration ?? 0,
82
+ timestamp: raw.timestamp ?? 0,
83
+ priorityLevel: raw.priorityName ?? null,
84
+ measurements: buildMeasurements(raw.fibers ?? [], raw.rootId ?? 1, idx, raw.timestamp ?? 0),
85
+ updaterComponentNames: raw.updaterNames ?? [],
86
+ }));
87
+ // Deduplicate fibers across commits by fiberId (use first occurrence).
88
+ const seenFiberIds = new Set();
89
+ const fiberNodes = [];
90
+ for (const raw of rawCommits) {
91
+ const rootId = raw.rootId ?? 1;
92
+ for (const fe of raw.fibers ?? []) {
93
+ if (!seenFiberIds.has(fe.fiberId)) {
94
+ seenFiberIds.add(fe.fiberId);
95
+ fiberNodes.push(...buildFiberNodes([fe], rootId));
96
+ }
97
+ }
98
+ }
99
+ const components = buildComponentStats(commits);
100
+ const totalCommitDuration = commits.reduce((sum, c) => sum + c.duration, 0);
101
+ const totalRenderDuration = commits.reduce((sum, c) => sum + c.measurements.reduce((ms, m) => ms + m.actualDuration, 0), 0);
102
+ return {
103
+ id: randomUUID(),
104
+ filename: `react-scan-session:${sessionId}`,
105
+ version: '5',
106
+ rendererId: null,
107
+ commits,
108
+ fiberNodes,
109
+ components,
110
+ totalCommitDuration,
111
+ totalRenderDuration,
112
+ };
113
+ }
114
+ //# sourceMappingURL=react-scan-lite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-scan-lite.js","sourceRoot":"","sources":["../../src/parser/react-scan-lite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAWzC,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,SAAS,iBAAiB,CACxB,MAA6B,EAC7B,MAAc,EACd,WAAmB,EACnB,UAAkB;IAElB,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC1B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,MAAM;QACN,aAAa,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,UAAU,KAAK,CAAC,OAAO,GAAG;QAC/D,KAAK,EAAE,KAAK,CAAC,iBAAiB,EAAE,YAAY,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ;QAC1E,cAAc,EAAE,KAAK,CAAC,cAAc,IAAI,CAAC;QACzC,YAAY,EAAE,KAAK,CAAC,YAAY,IAAI,CAAC;QACrC,SAAS,EAAE,UA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O,EAAE,GAAG;QACZ,UAAU,EAAE,IAAI;QAChB,OAAO;QACP,UAAU;QACV,UAAU;QACV,mBAAmB;QACnB,mBAAmB;KACpB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ export declare function registerBeginRenderAnalysis(server: McpServer): void;
3
+ //# sourceMappingURL=begin-render-analysis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"begin-render-analysis.d.ts","sourceRoot":"","sources":["../../src/tools/begin-render-analysis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKpE,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAyEnE"}
@@ -0,0 +1,69 @@
1
+ import { z } from 'zod';
2
+ import { createCaptureSession } from '../ingest/server.js';
3
+ export function registerBeginRenderAnalysis(server) {
4
+ server.registerTool('begin_render_analysis', {
5
+ title: 'Begin Render Analysis',
6
+ description: 'Entry point for render profiling. Choose an approach:\n' +
7
+ ' live — react-scan/lite streams events in real time; exact rerender causes, source locations, changeDescription.\n' +
8
+ ' manual — no install needed; user exports a JSON from the React DevTools Profiler tab and shares the file path.\n' +
9
+ 'Ask the user which approach they prefer before calling this tool.',
10
+ inputSchema: {
11
+ approach: z
12
+ .enum(['live', 'manual'])
13
+ .describe('"live": react-scan/lite live capture (richer data, needs npm install). ' +
14
+ '"manual": React DevTools Profiler JSON export (no install, less detailed).'),
15
+ },
16
+ }, async ({ approach }) => {
17
+ if (approach === 'live') {
18
+ const session = await createCaptureSession();
19
+ const snippet = [
20
+ `import { instrument } from "react-scan/lite";`,
21
+ `instrument({`,
22
+ ` endpoint: "${session.endpoint}",`,
23
+ ` sessionId: "${session.sessionId}",`,
24
+ ` recordChangeDescriptions: true,`,
25
+ ` includeFiberSource: true,`,
26
+ ` includeFiberIdentity: true,`,
27
+ `});`,
28
+ ].join('\n');
29
+ const result = {
30
+ approach: 'live',
31
+ sessionId: session.sessionId,
32
+ endpoint: session.endpoint,
33
+ snippet,
34
+ snippetFile: 'instrumentation-client.js',
35
+ setup: [
36
+ '1. npm install --save-dev react-scan',
37
+ '2. Create (or overwrite) instrumentation-client.js at your project root with the content in `snippet`.',
38
+ ' The ingest server runs on a fixed port (7721 by default), so only the sessionId line changes between runs.',
39
+ '3. Import it from your app\'s client-side entry point (e.g. _app.tsx, root layout, main.tsx)',
40
+ ' — inspect the project structure to find the right file.',
41
+ ' The import must run on the client (add "use client" if the entry is a Server Component).',
42
+ ].join('\n'),
43
+ nextStep: `run_render_capture({ sessionId: "${session.sessionId}", method: <ask the user> })`,
44
+ };
45
+ return {
46
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
47
+ };
48
+ }
49
+ // manual path — no session created
50
+ const result = {
51
+ approach: 'manual',
52
+ setup: [
53
+ '1. Install the React DevTools browser extension if not already (Chrome/Firefox/Edge).',
54
+ '2. Run your app (next dev or next start).',
55
+ '3. Open browser DevTools → React DevTools panel → "Profiler" tab.',
56
+ '4. Click the Record button (filled circle ●) to start profiling.',
57
+ '5. Interact with your app — navigate pages, trigger state changes, etc.',
58
+ '6. Click the Stop button (■) to end the recording.',
59
+ '7. Click the Export icon (download arrow ↓ in the top-right of the Profiler panel) and save the JSON file.',
60
+ '8. Share the saved file path — Copilot will call load_render_profile to load it.',
61
+ ].join('\n'),
62
+ nextStep: 'load_render_profile({ filePath: "<path-to-exported-json>" })',
63
+ };
64
+ return {
65
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
66
+ };
67
+ });
68
+ }
69
+ //# sourceMappingURL=begin-render-analysis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"begin-render-analysis.js","sourceRoot":"","sources":["../../src/tools/begin-render-analysis.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB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AE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;aAC5E,CAAC;QACJ,CAAC;QAED,mCAAmC;QACnC,MAAM,MAAM,GAAG;YACb,QAAQ,EAAE,QAAQ;YAClB,KAAK,EAAE;gBACL,uFAAuF;gBACvF,2CAA2C;gBAC3C,mEAAmE;gBACnE,kEAAkE;gBAClE,yEAAyE;gBACzE,oDAAoD;gBACpD,4GAA4G;gBAC5G,kFAAkF;aACnF,CAAC,IAAI,CAAC,IAAI,CAAC;YACZ,QAAQ,EAAE,8DAA8D;SACzE,CAAC;QAEF,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;SAC5E,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ export declare function registerGetCapturedRenders(server: McpServer): void;
3
+ //# sourceMappingURL=get-captured-renders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-captured-renders.d.ts","sourceRoot":"","sources":["../../src/tools/get-captured-renders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKpE,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA+ElE"}
@@ -0,0 +1,77 @@
1
+ import { z } from 'zod';
2
+ import { getCaptureSession } from '../ingest/server.js';
3
+ export function registerGetCapturedRenders(server) {
4
+ server.registerTool('get_captured_renders', {
5
+ title: 'Get Captured Renders',
6
+ description: 'Optional diagnostic: peek at the live progress of a render-capture session without stopping it. ' +
7
+ 'Returns commit count, components seen, whether actualDuration is populating, and an unknownEvents ' +
8
+ 'count (non-zero = instrumentation may not be wired correctly). ' +
9
+ 'Only call this if something seems wrong — it is not a required step before stop_render_capture.',
10
+ inputSchema: {
11
+ sessionId: z.string().describe('The sessionId returned by start_render_capture'),
12
+ },
13
+ }, async ({ sessionId }) => {
14
+ const session = getCaptureSession(sessionId);
15
+ if (!session) {
16
+ return {
17
+ content: [{ type: 'text', text: JSON.stringify({ error: `Session "${sessionId}" not found` }, null, 2) }],
18
+ isError: true,
19
+ };
20
+ }
21
+ const commitCount = session.commits.length;
22
+ const unknownEvents = session.unknownEvents;
23
+ const componentsSeen = new Set();
24
+ let hasActualDuration = false;
25
+ for (const commit of session.commits) {
26
+ for (const fiber of commit.fibers ?? []) {
27
+ if (fiber.name)
28
+ componentsSeen.add(fiber.name);
29
+ if ((fiber.actualDuration ?? 0) > 0)
30
+ hasActualDuration = true;
31
+ }
32
+ }
33
+ // Summarize the top components by total actualDuration so the agent can
34
+ // see which components are hot without stopping the session.
35
+ const durationByComponent = new Map();
36
+ for (const commit of session.commits) {
37
+ for (const fiber of commit.fibers ?? []) {
38
+ const name = fiber.name ?? `(fiber:${fiber.fiberId})`;
39
+ durationByComponent.set(name, (durationByComponent.get(name) ?? 0) + (fiber.actualDuration ?? 0));
40
+ }
41
+ }
42
+ const topComponents = Array.from(durationByComponent.entries())
43
+ .sort((a, b) => b[1] - a[1])
44
+ .slice(0, 10)
45
+ .map(([componentName, totalActualDuration]) => ({ componentName, totalActualDuration }));
46
+ let profilingStatus;
47
+ if (session.profilingAvailable === null) {
48
+ profilingStatus = 'unknown (no profiling-hooks-status event received yet)';
49
+ }
50
+ else if (session.profilingAvailable) {
51
+ profilingStatus = 'available';
52
+ }
53
+ else {
54
+ profilingStatus = 'unavailable — app may be running a production build; switch to `next dev`';
55
+ }
56
+ const diagnosis = unknownEvents > 0 && commitCount === 0
57
+ ? `${unknownEvents} unrecognized POST(s) received — the instrumentation snippet may not be imported correctly, or it is running server-side. Check that the import is in a client-side entry point and the file path is correct.`
58
+ : null;
59
+ const result = {
60
+ sessionId,
61
+ status: session.status,
62
+ commitCount,
63
+ componentCount: componentsSeen.size,
64
+ hasActualDuration,
65
+ profilingStatus,
66
+ ...(diagnosis ? { diagnosis } : {}),
67
+ topComponents,
68
+ nextStep: session.status === 'active'
69
+ ? `call stop_render_capture({ sessionId: "${sessionId}" }) when you are done`
70
+ : `session is stopped — call stop_render_capture({ sessionId: "${sessionId}" }) to finalize`,
71
+ };
72
+ return {
73
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
74
+ };
75
+ });
76
+ }
77
+ //# sourceMappingURL=get-captured-renders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-captured-renders.js","sourceRoot":"","sources":["../../src/tools/get-captured-renders.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,UAAU,0BAA0B,CAAC,MAAiB;IAC1D,MAAM,CAAC,YAAY,CAAC,sBAAsB,EAAE;QAC1C,KAAK,EAAE,sBAAsB;QAC7B,WAAW,EACT,kGAAkG;YAClG,oGAAoG;YACpG,iEAAiE;YACjE,iGAAiG;QACnG,WAAW,EAAE;YACX,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,gDAAgD,CAAC;SACjF;KACF,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE;QACzB,MAAM,OAAO,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAE7C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,YAAY,SAAS,aAAa,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;gBAClH,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;QAED,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;QAC3C,MAAM,aAAa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AyC,CAAC;AAOpE,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA2BjE"}
1
+ {"version":3,"file":"load-render-profile.d.ts","sourceRoot":"","sources":["../../src/tools/load-render-profile.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAOpE,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA6BjE"}
@@ -7,7 +7,9 @@ import { storeRenderProfile } from '../store.js';
7
7
  export function registerLoadRenderProfile(server) {
8
8
  server.registerTool('load_render_profile', {
9
9
  title: 'Load Render Profile',
10
- description: 'Parse and load a React DevTools profiler export captured from a Next.js app. Returns a profile ID for use with the other render analysis tools.',
10
+ description: 'Load a React DevTools Profiler JSON export. ' +
11
+ 'This is the entry point for the manual profiling path: open React DevTools in the browser → Profiler tab → Record → interact → Stop → Export JSON → share the file path here. ' +
12
+ 'Returns a profileId for use with get_render_summary, get_slow_components, get_rerender_causes, and the other analysis tools.',
11
13
  inputSchema: {
12
14
  filePath: z.string().describe('Absolute or relative path to the exported React Profiler JSON file'),
13
15
  },
@@ -1 +1 @@
1
- {"version":3,"file":"load-render-profile.js","sourceRoot":"","sources":["../../src/tools/load-render-profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,UAAU,yBAAyB,CAAC,MAAiB;IACzD,MAAM,CAAC,YAAY,CAAC,qBAAqB,EAAE;QACzC,KAAK,EAAE,qBAAqB;QAC5B,WAAW,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E,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,UAAU,yBAAyB,CAAC,MAAiB;IACzD,MAAM,CAAC,YAAY,CAAC,qBAAqB,EAAE;QACzC,KAAK,EAAE,qBAAqB;QAC5B,WAAW,EAAE,8CAA8C;YACzD,gLAAgL;YAChL,8HAA8H;QAChI,WAAW,EAAE;YACX,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,oEAAoE,CAAC;SACpG;KACF,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;QACxB,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QAClC,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACjD,MAAM,OAAO,GAAG,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACrD,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAE5B,OAAO;YACL,OAAO,EAAE,CAAC;oBACR,IAAI,EAAE,MAAe;oBACrB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;wBACnB,SAAS,EAAE,OAAO,CAAC,EAAE;wBACrB,QAAQ,EAAE,OAAO,CAAC,QAAQ;wBAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;wBACxB,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM;wBACnC,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,MAAM;wBACzC,mBAAmB,EAAE,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC;qBAC3D,EAAE,IAAI,EAAE,CAAC,CAAC;iBACZ,CAAC;SACH,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ export declare function registerRunRenderCapture(server: McpServer): void;
3
+ //# sourceMappingURL=run-render-capture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-render-capture.d.ts","sourceRoot":"","sources":["../../src/tools/run-render-capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKpE,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA4DhE"}
@@ -0,0 +1,59 @@
1
+ import { z } from 'zod';
2
+ import { getCaptureSession } from '../ingest/server.js';
3
+ export function registerRunRenderCapture(server) {
4
+ server.registerTool('run_render_capture', {
5
+ title: 'Run Render Capture',
6
+ description: 'Called after instrumentation is wired up (steps 1–3 of begin_render_analysis). ' +
7
+ 'Ask the user how they want to generate renders before calling this tool:\n' +
8
+ ' manual-interaction — start the dev server and the user clicks through the app.\n' +
9
+ ' test-suite — run an existing automated test suite against the running app.',
10
+ inputSchema: {
11
+ sessionId: z.string().describe('The sessionId returned by begin_render_analysis.'),
12
+ method: z
13
+ .enum(['manual-interaction', 'test-suite'])
14
+ .describe('"manual-interaction": user navigates the app manually (fast, focused). ' +
15
+ '"test-suite": run an existing test suite (automated; scope to one file/feature to keep payload manageable).'),
16
+ },
17
+ }, async ({ sessionId, method }) => {
18
+ const session = getCaptureSession(sessionId);
19
+ if (!session || session.status !== 'active') {
20
+ return {
21
+ content: [{
22
+ type: 'text',
23
+ text: JSON.stringify({ error: `No active session for sessionId "${sessionId}". Call begin_render_analysis first.` }, null, 2),
24
+ }],
25
+ isError: true,
26
+ };
27
+ }
28
+ if (method === 'manual-interaction') {
29
+ const result = {
30
+ method,
31
+ sessionId,
32
+ instructions: [
33
+ '1. Start the dev server (e.g. `npm run dev`).',
34
+ '2. Open the app in your browser and interact with the pages/flows you want to profile.',
35
+ '3. When done, call stop_render_capture to end the session.',
36
+ ].join('\n'),
37
+ nextStep: `stop_render_capture({ sessionId: "${sessionId}" })`,
38
+ };
39
+ return {
40
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
41
+ };
42
+ }
43
+ // test-suite
44
+ const result = {
45
+ method,
46
+ sessionId,
47
+ instructions: [
48
+ '1. Start the dev server if not already running (e.g. `npm run dev`).',
49
+ '2. Run your test suite. Scope to a single test file or feature to keep the payload manageable.',
50
+ '3. When the run finishes, call stop_render_capture to end the session.',
51
+ ].join('\n'),
52
+ nextStep: `stop_render_capture({ sessionId: "${sessionId}" })`,
53
+ };
54
+ return {
55
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
56
+ };
57
+ });
58
+ }
59
+ //# sourceMappingURL=run-render-capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-render-capture.js","sourceRoot":"","sources":["../../src/tools/run-render-capture.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,UAAU,wBAAwB,CAAC,MAAiB;IACxD,MAAM,CAAC,YAAY,CAAC,oBAAoB,EAAE;QACxC,KAAK,EAAE,oBAAoB;QAC3B,WAAW,EACT,iFAAiF;YACjF,4EAA4E;YAC5E,oFAAoF;YACpF,sFAAsF;QACxF,WAAW,EAAE;YACX,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,kDAAkD,CAAC;YAClF,MAAM,EAAE,CAAC;iBACN,IAAI,CAAC,CAAC,oBAAoB,EAAE,YAAY,CAAC,CAAC;iBAC1C,QAAQ,CACP,yEAAyE;gBACzE,6GAA6G,CAC9G;SACJ;KACF,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE;QACjC,MAAM,OAAO,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC5C,OAAO;gBACL,OAAO,EAAE,CAAC;wBACR,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,oCAAoC,SAAS,sCAAsC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;qBAC9H,CAAC;gBACF,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;QAED,IAAI,MAAM,KAAK,oBAAoB,EAAE,CAAC;YACpC,MAAM,MAAM,GAAG;gBACb,MAAM;gBACN,SAAS;gBACT,YAAY,EAAE;oBACZ,+CAA+C;oBAC/C,wFAAwF;oBACxF,4DAA4D;iBAC7D,CAAC,IAAI,CAAC,IAAI,CAAC;gBACZ,QAAQ,EAAE,qCAAqC,SAAS,MAAM;aAC/D,CAAC;YACF,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;aAC5E,CAAC;QACJ,CAAC;QAED,aAAa;QACb,MAAM,MAAM,GAAG;YACb,MAAM;YACN,SAAS;YACT,YAAY,EAAE;gBACZ,sEAAsE;gBACtE,gGAAgG;gBAChG,wEAAwE;aACzE,CAAC,IAAI,CAAC,IAAI,CAAC;YACZ,QAAQ,EAAE,qCAAqC,SAAS,MAAM;SAC/D,CAAC;QACF,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;SAC5E,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ export declare function registerStopRenderCapture(server: McpServer): void;
3
+ //# sourceMappingURL=stop-render-capture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stop-render-capture.d.ts","sourceRoot":"","sources":["../../src/tools/stop-render-capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAQpE,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAiEjE"}
@@ -0,0 +1,61 @@
1
+ import { z } from 'zod';
2
+ import { deleteCaptureSession, getCaptureSession, stopCaptureSession } from '../ingest/server.js';
3
+ import { adaptReactScanEvents } from '../parser/react-scan-lite.js';
4
+ import { storeRenderProfile } from '../store.js';
5
+ import { formatMs } from '../format.js';
6
+ export function registerStopRenderCapture(server) {
7
+ server.registerTool('stop_render_capture', {
8
+ title: 'Stop Render Capture',
9
+ description: 'Stop a live render-capture session, finalize the buffered events into a render profile, ' +
10
+ 'and return a profileId you can use with get_render_summary, get_slow_components, ' +
11
+ 'get_rerender_causes, and compare_renders.',
12
+ inputSchema: {
13
+ sessionId: z.string().describe('The sessionId returned by start_render_capture'),
14
+ },
15
+ }, async ({ sessionId }) => {
16
+ const session = getCaptureSession(sessionId);
17
+ if (!session) {
18
+ return {
19
+ content: [{ type: 'text', text: JSON.stringify({ error: `Session "${sessionId}" not found` }, null, 2) }],
20
+ isError: true,
21
+ };
22
+ }
23
+ if (session.status === 'stopped') {
24
+ return {
25
+ content: [{ type: 'text', text: JSON.stringify({ error: `Session "${sessionId}" is already stopped` }, null, 2) }],
26
+ isError: true,
27
+ };
28
+ }
29
+ // Mark stopped before processing so no new events are accepted.
30
+ stopCaptureSession(sessionId);
31
+ const commitCount = session.commits.length;
32
+ if (commitCount === 0) {
33
+ const warning = session.profilingAvailable === false
34
+ ? 'No commits captured. The app reported profiling-hooks-status: false — ' +
35
+ 'this usually means the app is running a production build. ' +
36
+ 'Switch to `next dev` or alias react-dom to react-dom/profiling.'
37
+ : 'No commits captured. Make sure the instrumentation snippet was loaded ' +
38
+ 'and you interacted with the app while the session was active.';
39
+ return {
40
+ content: [{ type: 'text', text: JSON.stringify({ warning, sessionId, commitCount: 0 }, null, 2) }],
41
+ };
42
+ }
43
+ const profile = adaptReactScanEvents(session.commits, sessionId);
44
+ storeRenderProfile(profile);
45
+ // Session data is no longer needed — free memory.
46
+ deleteCaptureSession(sessionId);
47
+ const result = {
48
+ profileId: profile.id,
49
+ sessionId,
50
+ commitCount: profile.commits.length,
51
+ componentCount: profile.components.length,
52
+ totalCommitDuration: formatMs(profile.totalCommitDuration),
53
+ profilingAvailable: session.profilingAvailable,
54
+ nextStep: `call get_render_summary with profileId "${profile.id}"`,
55
+ };
56
+ return {
57
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
58
+ };
59
+ });
60
+ }
61
+ //# sourceMappingURL=stop-render-capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stop-render-capture.js","sourceRoot":"","sources":["../../src/tools/stop-render-capture.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAClG,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,MAAM,UAAU,yBAAyB,CAAC,MAAiB;IACzD,MAAM,CAAC,YAAY,CAAC,qBAAqB,EAAE;QACzC,KAAK,EAAE,qBAAqB;QAC5B,WAAW,EACT,0FAA0F;YAC1F,mFAAmF;YACnF,2CAA2C;QAC7C,WAAW,EAAE;YACX,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,gDAAgD,CAAC;SACjF;KACF,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE;QACzB,MAAM,OAAO,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAE7C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAA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,OAAO,CAAC,OAAO,CAAC,MAAM;YACnC,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,MAAM;YACzC,mBAAmB,EAAE,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC;YAC1D,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;YAC9C,QAAQ,EAAE,2CAA2C,OAAO,CAAC,EAAE,GAAG;SACnE,CAAC;QAEF,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;SAC5E,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perfonext/render-mcp",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "MCP server for analyzing Next.js React Profiler exports: render summaries, rerender causes, hot commits, and profile diffing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",