Skip to content

Commit b5450b0

Browse files
authored
[mcp] Update prompts (#33084)
Some tweaks to the prompt to provide more context on how to use them. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33084). * #33085 * __->__ #33084 * #33083
1 parent f150c04 commit b5450b0

File tree

1 file changed

+26
-7
lines changed
  • compiler/packages/react-mcp-server/src

1 file changed

+26
-7
lines changed

compiler/packages/react-mcp-server/src/index.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const server = new McpServer({
2929

3030
server.tool(
3131
'query-react-dev-docs',
32-
'Search/look up official docs from react.dev',
32+
'This tool lets you search for official docs from react.dev. This always has the most up to date information on React. You can look for documentation on APIs such as <ViewTransition>, <Activity>, and hooks like useOptimistic, useSyncExternalStore, useTransition, and more. Whenever you think hard about React, please use this tool to get more information before proceeding.',
3333
{
3434
query: z.string(),
3535
},
@@ -72,7 +72,7 @@ server.tool(
7272

7373
server.tool(
7474
'compile',
75-
'Compile code with React Compiler. Optionally, for debugging provide a pass name like "HIR" to see more information.',
75+
'Compile code with React Compiler. This tool will return the compiled output, which is automatically memoized React components and hooks, written in JavaScript or TypeScript. You can run this tool whenever you want to check if some React code will compile successfully. You can also run this tool every time you make a suggestion to code, to see how it affects the compiled output. If the compiler returns a diagnostic message, you should read the diagnostic message and try to fix the code and run the compiler again to verify.',
7676
{
7777
text: z.string(),
7878
passName: z.enum(['HIR', 'ReactiveFunction', 'All', '@DEBUG']).optional(),
@@ -356,13 +356,34 @@ Server Components - Shift data-heavy logic to the server whenever possible. Brea
356356

357357
server.tool(
358358
'review-react-runtime',
359-
`
360-
Run this tool every time you propose a performance related change to verify if your suggestion actually improves performance.
361-
359+
`Run this tool every time you propose a performance related change to verify if your suggestion actually improves performance.
360+
<requirements>
362361
This tool has some requirements on the code input:
363362
- The react code that is passed into this tool MUST contain an App functional component without arrow function.
364363
- DO NOT export anything since we can't parse export syntax with this tool.
365364
- Only import React from 'react' and use all hooks and imports using the React. prefix like React.useState and React.useEffect
365+
</requirements>
366+
367+
<goals>
368+
- LCP - loading speed: good ≤ 2.5 s, needs-improvement 2.5-4 s, poor > 4 s
369+
- INP - input responsiveness: good ≤ 200 ms, needs-improvement 200-500 ms, poor > 500 ms
370+
- CLS - visual stability: good ≤ 0.10, needs-improvement 0.10-0.25, poor > 0.25
371+
- (Optional: FCP ≤ 1.8 s, TTFB ≤ 0.8 s)
372+
</goals>
373+
374+
<evaluation>
375+
Classify each metric with the thresholds above. Identify the worst category in the order poor > needs-improvement > good.
376+
</evaluation>
377+
378+
<iterate>
379+
(repeat until every metric is good or two consecutive cycles show no gain)
380+
- Apply one focused change based on the failing metric plus React-specific guidance:
381+
- LCP: lazy-load off-screen images, inline critical CSS, preconnect, use React.lazy + Suspense for below-the-fold modules. if the user requests for it, use React Server Components for static content (Server Components).
382+
- INP: wrap non-critical updates in useTransition, avoid calling setState inside useEffect.
383+
- CLS: reserve space via explicit width/height or aspect-ratio, keep stable list keys, use fixed-size skeleton loaders, animate only transform/opacity, avoid inserting ads or banners without placeholders.
384+
385+
Stop when every metric is classified as good. Return the final metric table and the list of applied changes.
386+
</iterate>
366387
`,
367388
{
368389
text: z.string(),
@@ -432,8 +453,6 @@ ${perfData.renderTime / iterations}ms
432453
- Base Duration: ${perfData.reactProfilerMetrics.baseDuration / iterations}ms
433454
- Start Time: ${perfData.reactProfilerMetrics.startTime / iterations}ms
434455
- Commit Time: ${perfData.reactProfilerMetrics.commitTime / iterations}ms
435-
436-
These metrics can help you evaluate the performance of your React component. Lower values generally indicate better performance.
437456
`;
438457

439458
return {

0 commit comments

Comments
 (0)