Introducing a new way to review your PRs.

Read the announcement

spartan-ng / spartan

Cutting-edge tools powering Angular full-stack development.

View on GitHub

18 documents · Updated Nov 23, 2026

docs / mcp-server

MCP server integration

The MCP server gives AI assistants a structured way to use Spartan UI documentation, components, blocks, and health guidance. It runs as a local Model Context Protocol process, reads public content from spartan.ng, and returns focused data through tools, resources, and prompts.

System purpose

MCP server boundary

@spartan-ng/mcp is the product boundary between an MCP client and the Spartan UI knowledge base. The server accepts requests over standard input and output, then exposes discovery, documentation, analysis, cache, and health capabilities without requiring the client to know the site structure. libs/…/server.ts• L15-38

The published package can run on demand through npx, or through its spartan-mcp command after a global install. This keeps the client setup small while the server owns access to current Spartan content. libs/…/README.md• L23-71 libs/…/package.json• L25-34

References: libs/…/server.ts• L15-38 libs/…/package.json• L25-34 libs/…/README.md• L23-71

Content model

Spartan content sources

The server treats the public Spartan site as its source of truth. It can address three related content types:

  • Components are individual UI building blocks with Brain and Helm API descriptions and examples. The known component catalog includes chart as a data-display component.
  • Blocks are larger UI patterns made from several components.
  • Documentation topics explain workspace setup, the CLI, themes, dark mode, typography, health checks, updates, MCP use, and skills.

The server keeps known names for these content types so clients can discover valid routes instead of guessing URLs. The same component names also support the categorized component prompt. libs/…/utils.ts• L3-5 libs/…/utils.ts• L12-106 libs/…/prompts.ts• L282-343

Brain is the unstyled and accessible primitive layer. Helm is the pre-styled component layer built for use in an application. The MCP responses preserve this distinction so an assistant can guide a user toward the right level of control. See Brain primitives, Helm components, registry and theming, and the documentation application for the related UI model and its published content.

References: libs/…/utils.ts• L3-5 libs/…/utils.ts• L12-106 libs/…/prompts.ts• L282-343 libs/…/resources.ts• L83-92

Tool surface

Component tools

Component tools support the main discovery path for an assistant. A client first lists known components, then requests one component with either code examples or structured API data. Separate analysis tools explain dependencies and accessibility concerns. libs/…/components.ts• L35-66 libs/…/components.ts• L68-157 libs/…/analysis.ts• L5-98

The component response can include the source URL, the selected version, cache state, API data, and examples. This gives an assistant both the facts needed to answer a question and a path back to the full page.

References: libs/…/components.ts• L35-157 libs/…/analysis.ts• L5-98

Documentation and metadata tools

spartan_docs_get returns an official documentation topic as HTML or text. It can also return only code blocks, headings, or links when the client needs a narrow answer. spartan_meta supplies the known topics, components, and blocks with URLs for autocomplete and discovery. libs/…/docs.ts• L6-95 libs/…/meta.ts• L11-60

The documentation tool also supports an external dark-mode article. That topic is not part of the versioned Spartan documentation set, so it is fetched directly rather than stored in the disk cache. libs/…/docs.ts• L44-72

References: libs/…/docs.ts• L6-95 libs/…/meta.ts• L11-60

Analysis tools

Analysis tools turn component pages into decision support. Dependency analysis identifies package, Angular CDK, peer component, import, setup, and optional transitive dependency information. Accessibility analysis looks for ARIA, keyboard, screen reader, and WCAG guidance and returns recommendations. libs/…/analysis.ts• L101-189 libs/…/analysis.ts• L191-256

These tools describe what the public page states. Their output is guidance for an assistant and is not a runtime check of the user's application.

References: libs/…/analysis.ts• L101-256

Block tools

Block tools expose complete UI patterns as a higher-level alternative to selecting components one at a time. A client can list blocks, fetch a block as HTML or text, and inspect the Spartan, npm, and Angular CDK dependencies found in its examples. libs/…/blocks.ts• L13-121 libs/…/blocks.ts• L123-217

Blocks connect the component catalog to common application flows. Their dependency view helps an assistant explain how a pattern relates to the lower-level components it uses.

References: libs/…/blocks.ts• L13-217

Cache tools

Cache tools let an MCP client inspect and control stored content. The surface includes status, clear, rebuild, version switch, and version listing operations. Rebuild can target selected components or blocks and can include the standard documentation topics. libs/…/cache-tools.ts• L7-205

These tools are operational controls rather than content lookup tools. They let an engineer choose between quick reuse of known content and a deliberate refresh from the public site.

References: libs/…/cache-tools.ts• L7-205

Health tools

Health tools cover two different checks. spartan_health_check tests whether selected public documentation and component pages respond. The other two tools provide the Spartan CLI health-check instructions and build the exact Angular CLI or Nx command for a user's workspace. libs/…/health.ts• L5-87 libs/…/health.ts• L89-133

The page check measures the remote documentation service. It does not inspect the local Angular or Nx workspace; the CLI commands are the separate path for that task.

References: libs/…/health.ts• L5-133

Resources and prompts

Component resources

Resources provide stable URI-shaped entry points for clients that want direct context instead of an action-oriented tool call. The list resource describes all components. Per-component resources expose API data, examples, or a combined full view. libs/…/resources.ts• L5-42 libs/…/resources.ts• L44-101 libs/…/resources.ts• L103-230

The resource forms are:

  • spartan://components/list
  • spartan://component/{name}/api
  • spartan://component/{name}/examples
  • spartan://component/{name}/full

The API resource separates Brain and Helm specifications. The examples resource focuses on working code. The full resource combines both views with fetch metadata.

References: libs/…/resources.ts• L5-42 libs/…/resources.ts• L44-101 libs/…/resources.ts• L103-230

Workflow prompts

Prompts package common assistant workflows around the same component knowledge. They help a user get started, compare Brain and Helm, implement a feature, troubleshoot a component, or list components by category. The category view places chart with other data-display components. libs/…/prompts.ts• L5-92 libs/…/prompts.ts• L94-203 libs/…/prompts.ts• L205-375

Prompts return a prepared conversation with documentation context and a suggested next step. They complement tools and resources: prompts shape the task, while tools and resources supply reusable facts.

References: libs/…/prompts.ts• L5-92 libs/…/prompts.ts• L94-203 libs/…/prompts.ts• L205-375

Retrieval and cache lifecycle

Content retrieval path

The retrieval path combines a short-lived in-memory fetch cache with a longer-lived versioned disk cache. Component, documentation, and block lookup tools use the disk cache when allowed. Resource, prompt, and analysis paths use the shared fetch layer, which can reuse recent responses in the running process. libs/…/utils.ts• L128-176 libs/…/components.ts• L99-137 libs/…/docs.ts• L44-72

The normal flow is:

flowchart LR
    Client[MCP client] --> Server[MCP server]
    Server --> Surface[Tool, resource, or prompt]
    Surface --> Memory[In-memory fetch cache]
    Surface --> Disk[Versioned disk cache]
    Memory --> Site[Public Spartan site]
    Disk --> Site
    Site --> Result[Structured response with source context]
    Memory --> Result
    Disk --> Result

An explicit cache bypass sends the request to the public site. A normal miss fetches fresh content and stores it for later requests when that surface supports disk caching.

References: libs/…/utils.ts• L128-176 libs/…/components.ts• L99-137 libs/…/docs.ts• L44-72 libs/…/blocks.ts• L72-106

Versioned disk cache

The disk cache keeps component, documentation, and block data under a separate directory for each Spartan version. The active version defaults to latest, while a request or a cache switch can select another valid version. Each version has metadata that records cached item counts, timestamps, and sizes. libs/…/cache.ts• L23-30 libs/…/cache.ts• L102-151 libs/…/cache.ts• L392-463

Disk entries become stale after the configured disk-cache lifetime. A stale entry is refreshed by the content tool rather than returned as current data. Version separation prevents content for one Spartan release from silently answering a request for another release. libs/…/cache.ts• L159-210 libs/…/cache.ts• L238-264 libs/…/cache.ts• L287-314

The cache directory can be set explicitly. Otherwise the server uses the XDG cache location and then the user's home cache directory, which keeps cache data outside the installed package. libs/…/cache.ts• L6-20

References: libs/…/cache.ts• L6-20 libs/…/cache.ts• L23-30 libs/…/cache.ts• L102-151 libs/…/cache.ts• L159-210 libs/…/cache.ts• L238-264 libs/…/cache.ts• L287-314 libs/…/cache.ts• L392-463

Cache warm-up

Warm-up builds a complete snapshot for the active version. It fetches the known components first, then the known blocks, and then the standard documentation topics. Each group reports successful and failed items and the total duration. libs/…/cache-warmup.ts• L15-28 libs/…/cache-warmup.ts• L85-161

The rebuild tool clears the active version before warm-up. This makes rebuild a replacement operation, not an incremental merge with old entries. A failed item is recorded in the result so an engineer can see whether the snapshot is complete. libs/…/cache-tools.ts• L77-147

References: libs/…/cache-warmup.ts• L15-28 libs/…/cache-warmup.ts• L30-83 libs/…/cache-warmup.ts• L85-172 libs/…/cache-tools.ts• L77-147

Cache timing controls

Two time limits control different layers. SPARTAN_CACHE_TTL_MS controls reuse of a response in the running process and defaults to five minutes. SPARTAN_CACHE_TTL_HOURS controls when a disk entry becomes stale and defaults to 24 hours. SPARTAN_MCP_CACHE_DIR changes the disk-cache location. libs/…/README.md• L134-143 libs/…/utils.ts• L139-175 libs/…/cache.ts• L171-176

These settings let a client balance freshness against remote requests. They do not change the public source URLs or the set of known content names.

References: libs/…/README.md• L134-143 libs/…/utils.ts• L139-175 libs/…/cache.ts• L171-176

Client integration

MCP client connection

An MCP client starts the server as a child process and communicates through standard input and output. The client configuration names the server and points to either the on-demand package command or the installed binary. libs/…/server.ts• L36-38 libs/…/README.md• L25-54

The server has no separate web service to deploy for the normal use case. Its network dependency is the public Spartan site, while its local state is the optional disk cache.

References: libs/…/server.ts• L36-38 libs/…/README.md• L23-71 libs/…/package.json• L25-34

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the known component, block, and documentation lists aligned with the URLs exposed by tools, metadata, resources, prompts, and warm-up.
  • Keep the version and cache-key rules aligned between direct lookups, rebuilds, and cache status. A mismatch can make warm content invisible to a lookup.
  • Keep the Brain and Helm names consistent across API extraction, component resources, prompts, and related UI documentation.
  • Keep the health topic set aligned with the topics accepted by documentation lookup. A health check can otherwise report a route that the docs tool cannot fetch.
  • Keep the disk-cache TTL and in-memory TTL separate when changing freshness behavior. They protect different request paths.

Important failure modes

TriggerConsequenceGuard
A component, block, or topic is not in the known-name listThe related lookup or analysis rejects the request even if a public page existsUpdate the shared content lists and every discovery surface together
The public Spartan page is unavailable or times outA live fetch, refresh, or warm-up item fails and may return an error instead of current contentUse cache status to inspect existing data and use warm-up results to find failed items
A disk entry is staleContent tools fetch the public page again instead of treating old data as currentRebuild or adjust SPARTAN_CACHE_TTL_HOURS when the freshness window changes
The active cache version differs from the requested Spartan versionA client receives data from a different version or misses an otherwise valid cache entryInitialize or switch the cache version before version-specific retrieval
The cache directory is not writableCache writes and cache control operations fail even though the public site may be reachableSet SPARTAN_MCP_CACHE_DIR to a writable directory
A client treats spartan_health_check as a local workspace checkThe client checks the remote docs site but misses local Angular or Nx problemsUse the health instructions or generated command for the workspace check

Key files

FileWhy to read it
libs/…/server.tsShows the MCP server boundary and the complete registration of tools, resources, and prompts.
libs/…/README.mdGives the client setup, public MCP surface, cache settings, and usage model.
libs/…/package.jsonDefines the published package identity and the spartan-mcp command used to start the server.
libs/…/components.tsExplains the primary component discovery and documentation flow.
libs/…/docs.tsExplains topic lookup and focused documentation extraction.
libs/…/analysis.tsShows the dependency and accessibility guidance available to assistants.
libs/…/blocks.tsShows how higher-level UI patterns are exposed and related to components.
libs/…/resources.tsDefines the direct URI resources for component lists, APIs, examples, and full documentation.
libs/…/prompts.tsDefines the guided assistant workflows for common component tasks and their categories.
libs/…/health.tsSeparates remote page availability checks from local CLI health-check guidance.
libs/…/cache.tsDefines versioned cache state, disk location, staleness, and cache control behavior.
libs/…/cache-warmup.tsDescribes how a full version snapshot is built and how failures are reported.
libs/…/utils.tsDefines public source URLs, known content names, in-memory fetch reuse, and content extraction boundaries.