diff --git a/compiler/packages/react-mcp-server/src/index.ts b/compiler/packages/react-mcp-server/src/index.ts index 6e0f561ab2..8ce2633d6e 100644 --- a/compiler/packages/react-mcp-server/src/index.ts +++ b/compiler/packages/react-mcp-server/src/index.ts @@ -5,10 +5,10 @@ * LICENSE file in the root directory of this source tree. */ -import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; -import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; -import { z } from 'zod'; -import { compile, type PrintedCompilerPipelineValue } from './compiler'; +import {McpServer} from '@modelcontextprotocol/sdk/server/mcp.js'; +import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js'; +import {z} from 'zod'; +import {compile, type PrintedCompilerPipelineValue} from './compiler'; import { CompilerPipelineValue, printReactiveFunctionWithOutlined, @@ -17,13 +17,15 @@ import { SourceLocation, } from 'babel-plugin-react-compiler/src'; import * as cheerio from 'cheerio'; -import { queryAlgolia } from './utils/algolia'; +import {queryAlgolia} from './utils/algolia'; import assertExhaustive from './utils/assertExhaustive'; -import { convert } from 'html-to-text'; -import { measurePerformance } from './tools/runtimePerf'; +import {convert} from 'html-to-text'; +import {measurePerformance} from './tools/runtimePerf'; function calculateMean(values: number[]): string { - return values.length > 0 ? (values.reduce((acc, curr) => acc + curr, 0) / values.length) + 'ms' : 'could not collect'; + return values.length > 0 + ? values.reduce((acc, curr) => acc + curr, 0) / values.length + 'ms' + : 'could not collect'; } const server = new McpServer({ @@ -37,12 +39,12 @@ server.tool( { query: z.string(), }, - async ({ query }) => { + async ({query}) => { try { const pages = await queryAlgolia(query); if (pages.length === 0) { return { - content: [{ type: 'text' as const, text: `No results` }], + content: [{type: 'text' as const, text: `No results`}], }; } const content = pages.map(html => { @@ -68,7 +70,7 @@ server.tool( } catch (err) { return { isError: true, - content: [{ type: 'text' as const, text: `Error: ${err.stack}` }], + content: [{type: 'text' as const, text: `Error: ${err.stack}`}], }; } }, @@ -89,7 +91,7 @@ server.tool( text: z.string(), passName: z.enum(['HIR', 'ReactiveFunction', 'All', '@DEBUG']).optional(), }, - async ({ text, passName }) => { + async ({text, passName}) => { const pipelinePasses = new Map< string, Array @@ -141,7 +143,7 @@ server.tool( } } }; - const errors: Array<{ message: string; loc: SourceLocation | null }> = []; + const errors: Array<{message: string; loc: SourceLocation | null}> = []; const compilerOptions: Partial = { panicThreshold: 'none', logger: { @@ -170,10 +172,10 @@ server.tool( if (result.code == null) { return { isError: true, - content: [{ type: 'text' as const, text: 'Error: Could not compile' }], + content: [{type: 'text' as const, text: 'Error: Could not compile'}], }; } - const requestedPasses: Array<{ type: 'text'; text: string }> = []; + const requestedPasses: Array<{type: 'text'; text: string}> = []; if (passName != null) { switch (passName) { case 'All': { @@ -274,14 +276,14 @@ server.tool( } return { content: [ - { type: 'text' as const, text: result.code }, + {type: 'text' as const, text: result.code}, ...requestedPasses, ], }; } catch (err) { return { isError: true, - content: [{ type: 'text' as const, text: `Error: ${err.stack}` }], + content: [{type: 'text' as const, text: `Error: ${err.stack}`}], }; } }, @@ -323,7 +325,7 @@ server.tool( text: z.string(), iterations: z.number().optional().default(2), }, - async ({ text, iterations }) => { + async ({text, iterations}) => { try { const results = await measurePerformance(text, iterations); const formattedResults = ` diff --git a/compiler/packages/react-mcp-server/src/tools/runtimePerf.ts b/compiler/packages/react-mcp-server/src/tools/runtimePerf.ts index 491bcf091b..242ab0aa75 100644 --- a/compiler/packages/react-mcp-server/src/tools/runtimePerf.ts +++ b/compiler/packages/react-mcp-server/src/tools/runtimePerf.ts @@ -27,7 +27,6 @@ type PerformanceResults = { error: Error | null; }; - type EvaluationResults = { renderTime: number | null; webVitals: { @@ -50,7 +49,7 @@ type EvaluationResults = { function delay(time: number) { return new Promise(function (resolve) { - setTimeout(resolve, time) + setTimeout(resolve, time); }); } @@ -95,7 +94,7 @@ export async function measurePerformance( const browser = await puppeteer.launch(); const page = await browser.newPage(); - await page.setViewport({ width: 1280, height: 720 }); + await page.setViewport({width: 1280, height: 720}); const html = buildHtml(transpiled); let performanceResults: PerformanceResults = { @@ -119,7 +118,7 @@ export async function measurePerformance( }; for (let ii = 0; ii < iterations; ii++) { - await page.setContent(html, { waitUntil: 'networkidle0' }); + await page.setContent(html, {waitUntil: 'networkidle0'}); await page.waitForFunction( 'window.__RESULT__ !== undefined && (window.__RESULT__.renderTime !== null || window.__RESULT__.error !== null)', ); @@ -127,7 +126,9 @@ export async function measurePerformance( // ui chaos monkey const selectors = await page.evaluate(() => { window.__INTERACTABLE_SELECTORS__ = []; - const elements = Array.from(document.querySelectorAll('a')).concat(Array.from(document.querySelectorAll('button'))); + const elements = Array.from(document.querySelectorAll('a')).concat( + Array.from(document.querySelectorAll('button')), + ); for (const el of elements) { window.__INTERACTABLE_SELECTORS__.push(el.tagName.toLowerCase()); } @@ -161,15 +162,24 @@ export async function measurePerformance( const webVitalMetrics = ['cls', 'lcp', 'inp', 'fid', 'ttfb'] as const; for (const metric of webVitalMetrics) { if (evaluationResult.webVitals[metric] !== null) { - performanceResults.webVitals[metric].push(evaluationResult.webVitals[metric]); + performanceResults.webVitals[metric].push( + evaluationResult.webVitals[metric], + ); } } - const profilerMetrics = ['id', 'phase', 'actualDuration', 'baseDuration', 'startTime', 'commitTime'] as const; + const profilerMetrics = [ + 'id', + 'phase', + 'actualDuration', + 'baseDuration', + 'startTime', + 'commitTime', + ] as const; for (const metric of profilerMetrics) { if (evaluationResult.reactProfiler[metric] !== null) { performanceResults.reactProfiler[metric].push( - evaluationResult.reactProfiler[metric] + evaluationResult.reactProfiler[metric], ); } }