[compiler] Add explain-compiler-diagnostic MCP tool#36879
Open
AnandSundar wants to merge 1 commit into
Open
Conversation
Adds a new MCP tool that explains React Compiler diagnostics in plain English. Ships with 5 hand-curated entries (set-state-in-render, preserve-manual-memoization, immutability, purity, refs) keyed by the stable ErrorCategory rule name, plus a Jest unit test suite. The tool falls back to a generic guidance string when no curated entry matches the formatted message returned by the existing compile tool.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When the existing
compiletool returns a diagnostic, the LLM receives a cryptic formatted message with no explanation of what the rule means or how to fix it. The LLM has to guess based on the message text alone.This PR adds a new
explain-compiler-diagnostictool toreact-mcp-serverthat takes a diagnostic and returns a structured plain-English explanation: title, summary, category, why-it-happens, how-to-fix, an optional before/after code example, severity, and links to the relevant React docs. The tool is registered alongside the existingcompiletool so a model can chain the two:compile-> on failure,explain-compiler-diagnostic.This is the first time the MCP server ships a hand-curated knowledge base alongside its tools. The catalog is keyed by the stable
ErrorCategoryrule name frombabel-plugin-react-compiler, so it survives compiler message-wording changes across versions. Adding a new entry is a single map-insert.What is in the catalog (v1)
5 hand-curated entries covering the most common compiler diagnostics:
set-state-in-renderpreserve-manual-memoizationimmutabilitypurityrefsAll five are in the
Recommendedlint preset. The catalog supports incremental growth -- future entries can be added asMapinserts without changing the tool code.How the matching works
{ message, codeContext?, rule? }.ruleis supplied, the tool does an exact lookup against the catalog (fast path).messagePatterns: RegExp[]againstmessage(case-insensitive) and returns the first match.ErrorCategoryenum source, and how to file an issue.Files changed
src/diagnostics/catalog.ts(new, 279 lines) -- the catalog.src/tools/explainCompilerDiagnostic.ts(new, 112 lines) -- the lookup function.src/index.ts(+45 lines) -- register the new tool.jest.config.js(new),src/tools/__tests__/explainCompilerDiagnostic-test.ts(new, 173 lines),package.json-- bootstrap Jest for the package (the existing test script wasecho "no tests").README.md(+16 lines) -- document the new tool alongside the existing ones.How I tested
yarn workspace react-mcp-server test-> 17/17 tests pass in 4.55s.yarn workspace react-mcp-server build-> tsup produces a 1.72 MB CJS bundle.tsc --strict-> clean.I did not run the MCP inspector manually. The new tool is wired into
server.tool(...)following the same pattern as the existingcompiletool.Future work (out of scope for this PR)
compiletool currently only exposes{message, loc}to the LLM, no structuredcategoryfield. Today the new tool works around this with regex matching + an optional direct rule-name lookup. A follow-up could exposecategoryon the diagnostic so the matcher becomes a simple hash lookup with no regex cost.