Repository navigation
Conversation
clients/mcp/ is a second client over api/, the arrangement packages/cli/CONTRIBUTING.md already describes as the point of the api/clients split: "the CLI is one consumer of it". Tool surface is the SAME two tools the hosted server ships (search + get, meta#2513), so this re-binds an already-shipped contract to a new data source rather than proposing a new tool surface. State the history accurately, because it cuts both ways: meta#2306 was won by CLI + search (9.6/10) and by no MCP variant, and its "What We're Shipping" section recommended the SIX-tool server (meta#2228) that meta#5134 also asks for. What followed went the other way -- meta#2228 was closed unmerged and meta#2513 shipped the two-tool hybrid (9.3/10), which on tokens was the dearer of the two (35K vs 17K). Two tools is what exists, not what was crowned. What is actually new is where answers come from. The hosted server reads registries frozen into its bundle at deploy time and never touches the caller's filesystem, so it answers for the version the docsite shipped with. This resolves through api/ against the caller's cwd and reports the installed core version, wired theme and configured integrations via the MCP `instructions` field, so no third tool is needed. No new dependency. MCP over stdio is newline-delimited JSON-RPC 2.0, so the transport is written here: @modelcontextprotocol/sdk 1.29 pulls express, hono, cors, jose and ajv to serve HTTP and OAuth, none of which a stdio server speaks, and @astryxdesign/cli is published, so every consumer would inherit them (the workspace already carries a @hono/node-server security override because of that chain). Protocol details that are easy to get wrong, each pinned by a test: batches are answered with one array, since 2024-11-05 and 2025-03-26 require them and this server advertises both; an unparseable line is answered with the id OMITTED, because JSON-RPC prescribes id:null but MCP's schema has no null member and a compliant client discards the frame; responses keep wire order. Three defects found and fixed along the way: - component() and hook() are both lenient, so get("spacing") answered with the Stack COMPONENT. Domain now comes from search(), which tags every hit; only docs() and template() were ever strict. - The setup nudge fired on every session. It is machine mode like --json, and serving a project that never ran `init` is the supported case, not a mistake. - The instructions promised answers would "fall back to the CLI bundled docs" without core installed. They do not: api/search throws first, so both tools hard-fail. It now says so. stdout purity is the load-bearing invariant and is proved by spawning the real binary. A mutation writing one banner line to stdout failed all the e2e tests. Out of scope, per the issue's own sequencing: init writing the client config, working-with-ai doc updates, and project-aware/side-effecting tools (upgrade, init) that wait on their api/ extractions.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size SummaryNo component packages changed. Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
…eta#5134) A JSON-RPC batch member that is null or a primitive now answers as an invalid request inside the batch reply. It used to crash the whole session: isNotification(null) threw, and the catch itself threw again reading message.id, so one bad frame ended the process mid-session and primitives were silently swallowed instead of answered. get now fetches by the search hit's canonical name. The name match is case-insensitive, but template() resolves by exact dirName, so get("AI-CHAT") answered "Unknown template" for a template search had just confirmed exists. search forwards limit: 0 to the api's own positive-integer validation instead of silently serving the default 20. 14 new tests close the review's edge-case gaps: batch member validation, the template domain through get (by id and by casing), a final message with no trailing newline, CRLF endings, blank lines, top-level primitive lines, a non-string method, a malformed core package.json, the closest-matches suffix, a doc section end to end, and get's missing-name guard.
This branch was successfully deployed
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.
What this does
Adds
astryx mcp, a Model Context Protocol server that runs locally over stdio. An AI assistant working inside a project can ask Astryx questions and get answers about the version of Astryx that project actually has installed.Why
The hosted server at
astryx.atmeta.com/mcpreads registries baked into its bundle when the docs site deploys. It imports nonode:fsand never readsprocess.cwd(), so it answers for whatever version was deployed and has no way to see the caller's theme or integration packages. A project pinned to an older release gets answers about a release it does not have.Read this first: this is deliberately not the shape the issue proposed
Issue #5134 proposes six tools, one per CLI command. This ships two,
searchandget, the same pair the hosted server already exposes.The reason is deference to what shipped, and the history deserves stating accurately because it cuts both ways:
So two tools is what exists today, not what the bake-off crowned. This PR matches the shipped contract so that it does not smuggle in a new tool surface, but a maintainer preferring the six-tool shape has #2306 on their side, not against them.
Two further things to weigh before this goes anywhere:
packages/cli/CONTRIBUTING.md.The argument #2306 did not test is cold-start discovery: MCP tools appear in an assistant's tool list on every request, instead of depending on it remembering to shell out. That is the open question, and it is why this is a draft.
What changed
packages/cli/clients/mcp/is a second client overapi/, which is the arrangementCONTRIBUTING.mdalready describes as the point of the api/clients split ("the CLI is one consumer of it").api/still imports nothing fromclients/.@modelcontextprotocol/[email protected]pullsexpress,hono,cors,joseandajvto serve HTTP and OAuth, none of which a stdio server speaks, and@astryxdesign/cliis published, so every consumer would inherit them. The workspace already carries a@hono/node-serversecurity override because of that chain.zodwas not an option either: it is sealed out ofpackages/cli/clients/**by eslint.instructionsfield (installed core version, doctor's theme finding, configured integrations), so project-awareness needed no third tool.eslint.config.js: the.mjsun-ignore and the two CLI rule blocks namedclients/cli/**, so a second client would have shipped with no lint, no copyright header and no@astryx/no-raw-console-cliguarding the protocol channel. ESLint's own words on the unfixed config:all of the files matching the glob pattern packages/cli/clients/mcp are ignored. Widened toclients/**.mcpis exempt from the setup nudge, for the same reason--jsonis. A client launches the server, so the nudge landed on stderr on every session, and it contradicted the feature: serving a project that never ranastryx initis the supported case.mcpis deliberately not inJSON_SUPPORTED, soastryx mcp --jsonis refused withERR_INVALID_OPTIONbefore any side effect. stdout carries the protocol, not an envelope.Three bugs worth calling out
component()andhook()share one resolver that fuzzy-matches, socomponent('spacing')returns the Stack component. Resolvinggetby trying each API in turn therefore answered a doc-topic request with a confidently wrong artifact.getnow dispatches on the domainsearch()tags every hit with. There is a named regression test.A self-review round caught two more of the same species, both living in untested seams. A batch member like
nullcrashed the whole session —isNotification(null)threw, and the recovery path threw again reading.idoff it, so one bad frame from a client ended the server; a non-object member now answers as an invalid request inside the batch reply. Andgetmatched names case-insensitively but fetched with the caller's casing, whiletemplate()resolves by exact id — soget("AI-CHAT")answered "Unknown template" for a templatesearchhad just found; every fetch now uses the hit's canonical name. Both fixes landed test-first, with 14 new edge-case tests alongside them (junk batch members, CRLF endings, an unterminated final line, blank lines, primitive lines, a non-string method, a malformed core package.json, doc sections end to end).One rough edge is deliberate: a template id that exists as both a page and a block surfaces the api's "narrow it with --type" message, which names flags an MCP caller does not have. The model's recourse is
search; a dedicated disambiguation shape can wait for a real collision.How to see it
Real output from this branch, trimmed:
The
notifications/initializedline correctly produces no reply.Verification
packages/clihad 9 failing tests across 4 files on untouchedupstream/main551a8de before this branch: two from a case-insensitive filesystem, two needing built theme dists, five from a relativepackages/core/srcpath. After this change the same 9 fail and 2781 pass, up from 2707.typecheck:strictreports 10 errors, verified identical to a stashed-pristine run (allTS2307for unbuilt@astryxdesign/lab/charts, the conditionCONTRIBUTING.mddocuments).typecheck:json-apiclean.CI=trueeslint clean across all 12 new files.check:repo8/8.cli-json-smoke-test11/11.api-cli-parity-test335 cases, 0 failures. README regenerated viapnpm readme.stdout purity is the load-bearing invariant, so it is proved by spawning the real binary rather than by inspection. It was mutation-verified too: writing a single banner line to stdout fails all four end-to-end tests.
Not in this PR
Following the issue's own sequencing:
initwriting the MCP client config,working-with-aidoc updates, and project-aware or side-effecting tools (upgrade,init) that wait on theirapi/extractions. No change to the hosted server.Refs #5134