UNPKG

@rsc-kit/mcp

Version:

An MCP server over what an rsc-kit build decided: the routes, why each one is static or not, and what it costs the browser.

182 lines (138 loc) • 7.18 kB
# Working with an AI agent > An MCP server that answers from your actual build, and the AGENTS.md written into every project. Every project ships with two things for an agent. `AGENTS.md` states the rules, and an MCP server answers questions from your actual build: ```text title="explain_route /locale" /locale — a stored shell, with the rest rendered per request (from the last build, 5 minutes ago) Rendered by app/locale/page. Ships 85 kB of javascript, gzipped. Why it is not stored whole: cookies(), headers() stream per request; the rest is stored ``` `AGENTS.md` is short on purpose: it sits in an agent's context on every turn. The MCP server holds everything that doesn't fit in that budget. ## Connecting the server The scaffold already did. Every project gets a `.mcp.json` at its root: ```json title=".mcp.json" { "mcpServers": { "rsc-kit": { "command": "bunx", "args": ["@rsc-kit/mcp"] } } } ``` On a Node project, a Laravel app on Node included, it is `"command": "npx", "args": ["-y", "@rsc-kit/mcp"]`: the same server, launched by the runtime the project has. The scaffold writes whichever fits. Claude Code reads that as project-scoped configuration and asks you to approve it the first time it starts the server. Nothing is installed until then, and your build and dev server don't change. Commit the file; it is the same for everyone on the project. ### In an older project `create-rsc-kit init` writes the file, and leaves one that is already there alone. Or add it by hand: ```sh claude mcp add rsc-kit -- bunx @rsc-kit/mcp # or: npx -y @rsc-kit/mcp ``` ### In another client Any MCP client takes the same entry — a stdio server, command `bunx` (or `npx`), argument `@rsc-kit/mcp` — in its own file: ```json title=".cursor/mcp.json" { "mcpServers": { "rsc-kit": { "command": "bunx", "args": ["@rsc-kit/mcp"] } } } ``` ```json title=".vscode/mcp.json" { "servers": { "rsc-kit": { "command": "bunx", "args": ["@rsc-kit/mcp"] } } } ``` If a client reports the server as unreachable, run the command by hand. `bunx @rsc-kit/mcp` waits on stdin for a client, and printing nothing is it working. ## Asking about your app Every build writes `build-report.json`: the same rows it printed, plus every server action and whether a client built it. These tools read it, so nothing runs a build or imports your code: | tool | answers | | --- | --- | | `list_routes` | every route, what happened to it, what it ships | | `explain_route` | why one url is stored or rendered per request | | `what_is_dynamic` | the routes that are not stored, with reasons | | `heaviest_routes` | what costs the browser most | The reason a page is dynamic is **recorded, not guessed** — the call that made it dynamic is in the answer above. Asked to "make this page faster", an agent without it guesses at a cause and edits something. **Every answer says how old it is.** It reports the last build, and your files may have changed since, so `(from the last build, 5 minutes ago)` is on every response. With no build at all it says to run one, rather than reporting that there are no routes. ## Asking about the framework | tool | answers | | --- | --- | | `rules` | the rules for this app, as the installed version writes them - read first | | `list_topics` | every topic it can explain | | `how_to` | the short answer: forms, prefetch, validation, the action client, data with TanStack Query or SWR, Suspense, offline, pwa, no-javascript, api routes, authorization, why a page is dynamic | | `list_guides` | every guide on this site, one line each | | `read_guide` | the full text of one, exactly as published here — bundled with the server, so it matches the version installed | | `search_guides` | every line in the guides mentioning a word, with the guide it is in | `how_to` is the opinionated summary an agent should read first; `read_guide` is for when the summary isn't enough. Both come from the same source, and the guides are copied in at build time, so what an agent reads is what this site says for the version it has. These exist because the patterns here differ from Next and plain React **in ways that compile either way**: a check written in the component instead of the action, a hand-parsed query string, `"use server"` at the top of a page. An agent that hasn't been told writes those confidently. ## The rules in AGENTS.md `bun create rsc-kit` writes an `AGENTS.md`, and `rsc-kit init` adds a section to the one you have. It opens with **Rules** - the things an agent gets wrong in ways that compile: - a change is not done without its test, and not until `check` passes; - every environment variable is declared in `env.ts` (and `.env.example`) - rsc-kit's own included; - pages paint at once: each read is an async component under its own `<Suspense>`, not a `loading.tsx`; - server components call the data function directly, never the app's own api; - live data is `refreshOn` with `changed()`, and polling only for what nothing can announce; - every action and query is built from the action client the scaffold writes (`src/server/client.ts`), with authorisation as its `.use()` middleware - or, with a Go or Laravel backend, in the backend's own guards; - links and redirects are typed template literals; metadata is `export const metadata`; - generated files are never edited; secrets are generated, never committed; - ask `how_to` before reaching for a pattern from another framework. A Laravel app gets the same rules from its Boost skill, in Laravel's terms. ## Keeping AGENTS.md current ```sh bunx rsc-kit agents # rewrites the rsc-kit section only; review it in git ``` The section is rsc-kit's - between `<!-- rsc-kit:start -->` and `<!-- rsc-kit:end -->`, stamped with the version that wrote it - and everything around it is yours. The dev server says when the section is older than the rsc-kit installed. An `AGENTS.md` from before the stamp needs `--host` and `--source-dir` once: ```sh bunx rsc-kit agents --host bun --source-dir src/app ``` One with no section at all is only rewritten with `--replace`. The `rules` tool answers the same rules for the installed version, so an agent that reads it first is never working from an outdated file. ## Reading the docs as markdown Every page on this site is also a markdown file at the same url with `index.md` added — `/guides/forms/index.md` — and [`/llms.txt`](/llms.txt) is an index of all of them, with [`/llms-full.txt`](/llms-full.txt) as one document. An agent without the MCP server, or one asked about a version other than the one installed, reads those. `read_guide` is the same text, offline, at the installed version. ## Checking the build report in CI `build-report.json` is an ordinary file. A CI step can assert on it — that nothing stopped being prerendered, that no route crossed a size budget — which is the check most likely to catch a regression nobody would otherwise see. ## Why it is read-only Nothing here edits, builds or deploys. Your agent already has a shell for those, and a server that can change a project is one that can change it while answering a question about it.