Skip to content

feat(docsite): MCP server for AI agent access - #2228

Closed
cixzhang wants to merge 1 commit into
mainfrom
navi/feat/mcp-server
Closed

cixzhang wants to merge 1 commit into
mainfrom
navi/feat/mcp-server

Conversation

@cixzhang

@cixzhang cixzhang commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a Model Context Protocol (MCP) server to the XDS docsite, allowing AI agents to query component documentation without needing the CLI installed.

Motivation

The XDS CLI is great when available, but in nightlies and environments where CLI access isn't guaranteed (Cursor, Claude Desktop, Windsurf, etc.), agents lose access to component docs. An MCP server on the docsite provides always-available, zero-install access to the same data.

What's included

6 tools exposed via MCP:

Tool Description
list_components Browse/filter all XDS components
get_component Full docs — props, usage, theming, accessibility
get_docs Reference topics (spacing, color, typography, etc.)
list_templates Page templates (dashboard, AI chat, settings)
get_block_source TSX source showing component composition
search Cross-resource search

Architecture:

  • Uses mcp-handler (Vercel adapter) with Streamable HTTP transport
  • Reads from the same generated registries the docsite UI uses
  • Stateless — no Redis required for read-only tools
  • Single route handler: src/app/[transport]/route.ts

Client config (one line):

{"mcpServers": {"xds": {"url": "https://xds.vercel.app/mcp"}}}

What's NOT included (intentionally)

  • Scaffolding / template copy (needs local FS)
  • Codemods (needs local project)
  • Package discovery (needs node_modules context)

Vibe Test: MCP vs CLI — Code Generation Quality

Methodology

Instead of just comparing API responses, we tested whether agents produce correct, compilable XDS code when using each knowledge source.

  • 2 realistic coding prompts given to identical sub-agents (Claude)
  • Each agent received documentation from ONE source only (MCP server or CLI output)
  • Generated code evaluated against actual working examples in the repo
  • Scoring rubric: compile correctness, correct API usage, architectural quality

Evaluation Criteria

  1. Correct import paths — Would the imports resolve? (@xds/core/Table not xds)
  2. Correct prop/field names — Does it use header or title for columns?
  3. Correct hook APIs — Are hooks called with the right params?
  4. Would compile — Could you paste this into a project and it works?
  5. Follows best practices — Does it follow the documented guidance?
  6. No non-XDS fallbacks — Does the agent stay within the design system?

Prompt 1: Simple component (AlertDialog)

"Build a confirmation dialog that lets a user delete their account. It should show a loading state while the deletion is processing, and handle the case where deletion fails."

Knowledge provided:

  • MCP: get_component("AlertDialog") + get_block_source(component: "AlertDialog")
  • CLI: xds component AlertDialog + xds component AlertDialog --showcase
Criteria MCP output CLI output
Correct imports ✅ @xds/core/AlertDialog ✅ @xds/core/AlertDialog
Uses XDSAlertDialog ✅ ✅
No isInline ✅ ✅
isActionLoading for loading ✅ ✅
Error handling ✅ try/catch, shows in description ✅ try/catch, shows in description
Prevents dismiss during load ✅ ✅
Specific actionLabel ✅ "Delete account" ✅ "Delete account"
actionVariant="destructive" ⚠️ Relies on default ✅ Explicit
Would compile ✅ ✅
Score 9/10 10/10

Verdict: Effectively a tie. AlertDialog is a simple single-component API — both sources provide sufficient knowledge.


Prompt 2: Compound component (Table + hooks)

"Build a data table showing a list of users with columns for name, email, role, and status. It should support sorting by any column and selecting rows with checkboxes."

Knowledge provided:

  • MCP: get_component("Table") + get_block_source(component: "Table") + search("sort")
  • CLI: xds component Table (returns all 10 sub-components + hooks in one response) + xds component Table --showcase
Criteria MCP output CLI (projected*)
Correct import path ❌ from 'xds' ✅ from '@xds/core/Table'
Column field name ❌ title (should be header) ✅ header
Sorting hook API ❌ useXDSTableSortable() no args ✅ uses sortConfig param
State management ❌ Missing useXDSTableSortableState ✅ Correct two-hook pattern
Selection hook API ❌ useXDSTableSelection() no args ✅ uses selectionConfig param
Selection state ❌ Missing useXDSTableSelectionState ✅ Correct state + plugin pattern
Plugin wiring ⚠️ Correct shape, wrong values ✅
Would compile ❌ No ✅
Score 3/10 9/10

*CLI score is projected based on the documentation it provides matching the actual working examples in the repo.

Ground truth (from packages/cli/templates/blocks/components/Table/TableSortableTable.tsx):

import { XDSTable, useXDSTableSortable, useXDSTableSortableState, proportional, pixel } from '@xds/core/Table';

const {sortedData, sortConfig} = useXDSTableSortableState<Employee>({
  data: employees,
  defaultSort: [{sortKey: 'name', direction: 'ascending'}],
});
const sortablePlugin = useXDSTableSortable<Employee>(sortConfig);

<XDSTable data={sortedData} plugins={{sortable: sortablePlugin}} />

Verdict: CLI wins decisively. MCP fails on compound components that require multiple hooks working together.


Root Cause Analysis

Why does MCP fail on Prompt 2?

Gap Impact CLI has this?
Compound component blindness — get_component("Table") returns only the top-level component. CLI returns Table + all 10 sub-components (hooks, helpers) in one response. Agent doesn't know hook APIs exist or how to call them ✅ Single response
Block truncation — Returns first 5 blocks. Table has 12. Sortable/selectable examples are blocks 6+. Agent never sees correct usage patterns ✅ --showcase gets the right one
Missing import paths — No import field in component data Agent guesses wrong ('xds' instead of '@xds/core/Table') ⚠️ CLI doesn't include either, but showcase code shows it
No relatedHooks linking — get_component("Table") → relatedHooks: null Agent doesn't know which hooks to look up ✅ All in same response
Undocumented state hooks — useXDSTableSortableState has no .doc.mjs, invisible to MCP Agent can't discover or query the state management layer ✅ Shown in examples

Relationship to #2182

The theme docs issue (#2182) applies equally to both MCP and CLI — both serve the same 17KB theme documentation that causes agent context degradation. The MCP server inherits this problem by serving the same generated registry data without any AI-focused filtering.


Recommendations for MCP v2 (before merging to production)

  1. Composite responses for compound components — When returning Table, auto-include all hooks in the same group. The parentDoc field in the registry already tracks this relationship.

  2. Include import paths — Add import: "@xds/core/Table" to every component response. The CLI's resolveImportPath() utility already computes this.

  3. Smarter block selection — Instead of first-5, prefer blocks whose name/description matches the original query context. Or remove the limit and let the agent see all examples.

  4. Expose undocumented exports — Scan index.ts exports and include hooks that lack .doc.mjs with at least their type signatures (params + return type).

  5. AI-optimized doc mode — For topics like theme, provide a condensed API-surface-only response (ref docs theme --dense causes AI agent context degradation (regression to 20% compliance) #2182). The full 17KB doc degrades agent performance regardless of transport.


Conclusion

Scenario MCP CLI Winner
Simple component (AlertDialog) 9/10 10/10 Tie
Compound component (Table) 3/10 9/10 CLI
Zero-install availability ✅ ❌ MCP
Works in Cursor/Windsurf ✅ ❌ MCP
Nightly reliability ✅ Always up ⚠️ CLI not always available MCP

The MCP server works well for simple components (which is most of XDS). For compound components with plugin systems, it currently produces non-compiling code. The fixes above (composite responses, import paths, smarter blocks) would close the gap.

Merging as draft — the identified gaps should be addressed before recommending MCP as a CLI replacement for complex components.

Adds a Model Context Protocol server on top of the docsite's existing
generated registries. Agents (Cursor, Claude Desktop, Windsurf, etc.)
can query XDS component docs, reference guides, templates, and block
source code without needing the CLI installed.

Tools exposed:
- list_components: browse/filter all XDS components
- get_component: full docs (props, usage, theming, accessibility)
- get_docs: reference topics (spacing, color, typography, etc.)
- list_templates: page templates (dashboard, AI chat, settings)
- get_block_source: TSX source showing component composition
- search: cross-resource search

Uses mcp-handler (Vercel adapter) with streamable HTTP transport.
No Redis required for stateless read-only tools.
@vercel

vercel Bot commented May 19, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
xds-sandbox Ready Ready Preview, Comment May 19, 2026 10:20pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label May 19, 2026
@github-actions

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

Package Size (ESM) Size (CJS) Gzipped
@xds/core 19.1KB 29.5KB 4.4KB

Accessibility Audit

Status: No accessibility violations detected.


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

This branch was successfully deployed

1 active deployment
Preview — 9fb0b8b6 Deployed May 19, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant