Skip to content

feat(cli): astryx mcp, an MCP server that answers for the installed version - #5138

Closed
AKnassa wants to merge 2 commits into
meta:mainfrom
AKnassa:ak-5134-cli-mcp
Closed

AKnassa wants to merge 2 commits into
meta:mainfrom
AKnassa:ak-5134-cli-mcp

Conversation

@AKnassa

@AKnassa AKnassa commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

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.

// .mcp.json / .cursor/mcp.json / claude_desktop_config.json
{"mcpServers": {"astryx": {"command": "npx", "args": ["@astryxdesign/cli", "mcp"]}}}

Why

The hosted server at astryx.atmeta.com/mcp reads registries baked into its bundle when the docs site deploys. It imports no node:fs and never reads process.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, search and get, 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:

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 over api/, which is the arrangement CONTRIBUTING.md already describes as the point of the api/clients split ("the CLI is one consumer of it"). api/ still imports nothing from clients/.
  • No new dependency. MCP over stdio is newline-delimited JSON-RPC 2.0, so the transport is written here. @modelcontextprotocol/[email protected] 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. zod was not an option either: it is sealed out of packages/cli/clients/** by eslint.
  • Project facts ride in the MCP instructions field (installed core version, doctor's theme finding, configured integrations), so project-awareness needed no third tool.
  • eslint.config.js: the .mjs un-ignore and the two CLI rule blocks named clients/cli/**, so a second client would have shipped with no lint, no copyright header and no @astryx/no-raw-console-cli guarding 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 to clients/**.
  • mcp is exempt from the setup nudge, for the same reason --json is. A client launches the server, so the nudge landed on stderr on every session, and it contradicted the feature: serving a project that never ran astryx init is the supported case.
  • mcp is deliberately not in JSON_SUPPORTED, so astryx mcp --json is refused with ERR_INVALID_OPTION before any side effect. stdout carries the protocol, not an envelope.

Three bugs worth calling out

component() and hook() share one resolver that fuzzy-matches, so component('spacing') returns the Stack component. Resolving get by trying each API in turn therefore answered a doc-topic request with a confidently wrong artifact. get now dispatches on the domain search() 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 null crashed the whole session — isNotification(null) threw, and the recovery path threw again reading .id off 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. And get matched names case-insensitively but fetched with the caller's casing, while template() resolves by exact id — so get("AI-CHAT") answered "Unknown template" for a template search had 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

git checkout ak-5134-cli-mcp && pnpm install
printf '%s\n' \
  '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"demo","version":"1"}}}' \
  '{"jsonrpc":"2.0","method":"notifications/initialized"}' \
  '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' \
| node packages/cli/clients/cli/bin/astryx.mjs mcp

Real output from this branch, trimmed:

initialize -> {"name":"astryx","version":"0.4.3"}  protocolVersion 2025-06-18
instructions ->
  Astryx design system, answering for THIS project rather than the latest published docs.
  Project: /path/to/your/project
  @astryxdesign/core: 0.4.3 (installed)
  Theme: No @astryxdesign/theme-* packages are installed.
tools/list -> ["search","get"]
stderr -> (empty)

The notifications/initialized line correctly produces no reply.

Verification

packages/cli had 9 failing tests across 4 files on untouched upstream/main 551a8de before this branch: two from a case-insensitive filesystem, two needing built theme dists, five from a relative packages/core/src path. After this change the same 9 fail and 2781 pass, up from 2707.

typecheck:strict reports 10 errors, verified identical to a stashed-pristine run (all TS2307 for unbuilt @astryxdesign/lab / charts, the condition CONTRIBUTING.md documents). typecheck:json-api clean. CI=true eslint clean across all 12 new files. check:repo 8/8. cli-json-smoke-test 11/11. api-cli-parity-test 335 cases, 0 failures. README regenerated via pnpm 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: init writing the MCP client config, working-with-ai doc updates, and project-aware or side-effecting tools (upgrade, init) that wait on their api/ extractions. No change to the hosted server.

Refs #5134

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.
@vercel

vercel Bot commented Aug 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 18, 2026 2:15am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 17, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Aug 17, 2026
@github-actions

github-actions Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 17, 2026
…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

1 active deployment
Preview — a911bb5d Deployed Aug 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants