Labsco
carlospalacin logo

Spartan Ng Mcp

โ˜… 8

from carlospalacin

MCP server that gives AI assistants full access to the Spartan Angular UI ecosystem โ€” component discovery, Brain/Helm APIs, source code, installation commands, and project context detection.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeAdvanced setup

spartan-ng-mcp

An MCP (Model Context Protocol) server that exposes the Spartan Angular UI ecosystem as intelligent tools for AI-powered IDEs and assistants. Discover components, browse Brain/Helm APIs, fetch source code, generate install commands, detect project context, and use page-level building blocks โ€” all through the MCP protocol.

Why

Spartan's dual-layer architecture (Brain for headless logic + Helm for styled components) is powerful but has a learning curve. AI assistants need structured access to component APIs, source code, and installation patterns to generate correct Angular code. This MCP server bridges that gap โ€” turning the entire Spartan ecosystem into a queryable, context-aware tool surface.

Features

  • 56 components with full Brain/Helm API details (directives, inputs, outputs, signal models)
  • 17 page-level blocks (sidebar, login, signup, calendar variants)
  • Fuzzy search across components, blocks, and documentation
  • TypeScript source code fetching from GitHub with intelligent caching
  • Project context detection โ€” Angular version, Nx workspace, Tailwind config, zoneless mode
  • Installation command generation โ€” nx generate or npm install with peer dependency resolution
  • Post-install audit โ€” verification checklist for Tailwind preset, Brain/Helm pairing, OnPush
  • Runtime registry refresh โ€” pick up new Spartan components without an MCP update
  • Skills installer โ€” deploy spartan-ng-skills to any Angular project

Tools

Discovery

ToolDescription
spartan_listList all components and blocks. Filter by type or block category.
spartan_searchFuzzy search across components, blocks, and docs. Ranked results with scores.
spartan_viewDetailed component view: Brain directives, Helm components, inputs/outputs, examples, install snippets.
spartan_dependenciesComponent dependency graph with direct, transitive, and reverse dependencies.

Source Code

ToolDescription
spartan_sourceFetch Brain/Helm TypeScript source code from GitHub.
spartan_block_sourceFetch block source code with shared utilities and extracted imports.

Documentation

ToolDescription
spartan_docsFetch documentation topics: installation, CLI, theming, dark-mode, typography, figma, changelog.

Installation

ToolDescription
spartan_install_commandGenerate nx generate @spartan-ng/cli:ui or npm install commands. Auto-detects package manager.
spartan_auditPost-installation checklist: Angular project, Tailwind, Spartan preset, Brain/Helm pairing, OnPush.
spartan_install_skillsInstall spartan-ng-skills into a project's .claude/skills/spartan/ directory.

Project Context

ToolDescription
spartan_project_infoDetect Angular/Nx config, Tailwind version, installed packages, package manager, zoneless mode.
spartan_project_componentsList installed Brain/Helm packages with missing pair detection.

Cache & Registry

ToolDescription
spartan_cacheCache status, clear, or rebuild. Shows memory + file stats and GitHub rate limit.
spartan_registry_refreshRefresh registry from live Spartan Analog API. Reports added/updated/removed components.

Resources

MCP resources provide direct data access via the spartan:// URI scheme:

URIDescription
spartan://components/listAll components with Brain/Helm availability
spartan://blocks/listAll blocks grouped by category
spartan://project/infoRegistry metadata
spartan://component/{name}/apiBrain & Helm API specs for a component
spartan://component/{name}/examplesCode examples for a component

Prompts

Pre-built workflow templates for common tasks:

PromptDescription
spartan-get-startedInstallation + API overview + basic usage for any component
spartan-compare-layersSide-by-side Brain vs Helm API comparison
spartan-implementStep-by-step feature implementation guide
spartan-use-blockBlock integration guide with source fetching
spartan-migrateVersion migration guide with Nx generators

Architecture

src/
โ”œโ”€โ”€ index.ts                  # Entry point โ€” stdio transport
โ”œโ”€โ”€ server.ts                 # McpServer factory + tool registration
โ”œโ”€โ”€ tools/                    # 14 MCP tools (one file per group)
โ”‚   โ”œโ”€โ”€ discovery.ts          # list, search, view, dependencies
โ”‚   โ”œโ”€โ”€ source.ts             # component + block source
โ”‚   โ”œโ”€โ”€ docs.ts               # documentation topics
โ”‚   โ”œโ”€โ”€ install.ts            # CLI commands + audit
โ”‚   โ”œโ”€โ”€ context.ts            # project detection
โ”‚   โ”œโ”€โ”€ cache.ts              # cache + registry refresh
โ”‚   โ”œโ”€โ”€ dependencies.ts       # dependency graph
โ”‚   โ””โ”€โ”€ skills.ts             # skills installer
โ”œโ”€โ”€ data/                     # API clients
โ”‚   โ”œโ”€โ”€ analog-api.ts         # Spartan Analog API (primary data source)
โ”‚   โ”œโ”€โ”€ github.ts             # GitHub API (source code)
โ”‚   โ””โ”€โ”€ types.ts              # Shared TypeScript types
โ”œโ”€โ”€ registry/                 # Hybrid component registry
โ”‚   โ”œโ”€โ”€ registry.ts           # Loader + search + runtime refresh
โ”‚   โ”œโ”€โ”€ schema.ts             # Zod validation schemas
โ”‚   โ””โ”€โ”€ registry.json         # Static registry (56 components, 17 blocks)
โ”œโ”€โ”€ cache/                    # Multi-layer caching
โ”‚   โ”œโ”€โ”€ memory-cache.ts       # LRU with TTL (5 min)
โ”‚   โ”œโ”€โ”€ file-cache.ts         # Versioned file cache (24h)
โ”‚   โ””โ”€โ”€ cache-manager.ts      # Orchestrator: memory โ†’ file โ†’ network
โ”œโ”€โ”€ project/                  # Project scanner
โ”‚   โ”œโ”€โ”€ detector.ts           # Angular/Nx/Tailwind/zoneless detection
โ”‚   โ””โ”€โ”€ types.ts              # SpartanProjectContext type
โ”œโ”€โ”€ search/fuzzy.ts           # fuzzysort wrapper
โ”œโ”€โ”€ errors/errors.ts          # SpartanError + 17 error codes
โ”œโ”€โ”€ resources/spartan.ts      # spartan:// URI handlers
โ”œโ”€โ”€ prompts/workflows.ts      # 5 workflow templates
โ””โ”€โ”€ utils/                    # Pure utilities
    โ”œโ”€โ”€ constants.ts           # URLs, timeouts, allowed hosts
    โ”œโ”€โ”€ fetch.ts               # HTTP client with SSRF protection
    โ”œโ”€โ”€ html.ts                # HTML parsing + extraction
    โ””โ”€โ”€ imports.ts             # TypeScript import/export extraction

Data Resolution (3-tier)

Discovery (list, search)    โ†’  Static Registry (instant, offline)
Details (view, examples)    โ†’  Memory Cache โ†’ File Cache โ†’ Analog API
Source code (source, block) โ†’  Memory Cache โ†’ File Cache โ†’ GitHub API
  1. Static Registry (registry.json) โ€” committed per release, zero latency
  2. Analog API โ€” structured JSON from spartan.ng, cached 30min (memory) + 24h (file)
  3. GitHub API โ€” TypeScript source code, cached 24h, rate-limited

Spartan UI Concepts

Components have two API layers:

  • Brain โ€” headless, logic-only primitives. Attribute selectors like [brnDialogTrigger]. Provides ARIA, keyboard handling, and focus management.
  • Helm โ€” styled wrappers using hostDirectives to compose Brain. Mixed selectors: [hlmBtn], hlm-dialog-content, [hlmCard],hlm-card. Uses CVA (Class Variance Authority) for variants and Tailwind for styling.

Some Helm components wrap @angular/cdk directly instead of Brain (DropdownMenu, ContextMenu, Menubar).

Blocks are page-level building blocks โ€” complete Angular components combining multiple Spartan components (sidebar layouts, login forms, calendar views).

Skills

This MCP server is designed to work alongside spartan-ng-skills โ€” Claude Code skills that teach AI assistants how to correctly compose Spartan components.

MCP provides the knowledge: what components exist, their APIs, source code. Skills provide the wisdom: how to use them correctly, composition rules, styling conventions.

Install skills into any project:

# Via MCP tool
spartan_install_skills(cwd="/path/to/your-angular-project")

# Or manually
cp -r /path/to/spartan-ng-skills/.claude /path/to/your-angular-project/

The skills include 6 rule files with correct/incorrect Angular code pairs covering:

  • Brain vs Helm selection and hostDirectives
  • Component composition (Dialog, Card, Tabs, forms)
  • Styling with hlm(), classes(), CVA variants, semantic tokens
  • Angular Reactive Forms with HlmField system
  • Icon patterns with ng-icon
  • Angular directives: signals, @if/@for, inject(), OnPush

Development

npm run dev          # TypeScript watch mode
npm run typecheck    # Type-check without emitting
npm run build        # Compile to dist/
npm test             # Run tests
npm run lint         # ESLint