Skip to content

feat: add MCP servers for UI component libraries#141

Open
cabana8471-arch wants to merge 2 commits intoAutoForgeAI:masterfrom
cabana8471-arch:feature/ui-component-mcp-servers
Open

feat: add MCP servers for UI component libraries#141
cabana8471-arch wants to merge 2 commits intoAutoForgeAI:masterfrom
cabana8471-arch:feature/ui-component-mcp-servers

Conversation

@cabana8471-arch
Copy link
Contributor

@cabana8471-arch cabana8471-arch commented Jan 31, 2026

Summary

Add support for selecting UI component libraries during project creation, with MCP server integration for rapid component generation.

  • Phase 3b (UI Library): Users can choose shadcn/ui, Ark UI, Radix UI, or Custom
  • Phase 3c (Visual Style): Users can choose Modern, Neobrutalism, Glassmorphism, Retro, or Custom
  • MCP Integration: shadcn-ui and ark-ui get automatic MCP server configuration for component generation
  • Design Tokens: Non-default visual styles generate .autocoder/design-tokens.json

Changes

New Files

  • app_spec_parser.py - Shared parser for UI config from app_spec.txt
  • design_tokens.py - Design token generation with style presets
  • test_ui_config.py - 36 unit tests for UI configuration
  • ui/src/components/UILibrarySelector.tsx - React component for library selection
  • ui/src/components/VisualStyleSelector.tsx - React component for style selection
  • ui/public/previews/README.md - Guidelines for preview images

Modified Files

  • .claude/commands/create-spec.md - Added Phase 3b and 3c questions
  • .claude/templates/app_spec.template.txt - Added <ui_components> and <visual_style> sections
  • .claude/templates/coding_prompt.template.md - Added UI verification checklist
  • .claude/templates/initializer_prompt.template.md - Added UI library documentation
  • client.py - Added UI_MCP_TOOLS and dynamic MCP server configuration
  • server/services/spec_chat_session.py - Generate design tokens on spec completion
  • CLAUDE.md - Documented UI MCP servers and visual styles

Test Plan

  • All 36 new UI config tests pass
  • Existing security tests pass (48 passed)
  • UI builds without errors
  • Lint checks pass

Dependencies

This PR depends on #128 (Token Optimization) being merged first.


Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added UI component library selection during project setup (shadcn/ui, Ark UI, Radix UI, and custom options)
    • Introduced visual style customization with automatic design token generation (Neobrutalism, Glassmorphism, Retro)
    • Framework compatibility validation for selected libraries
    • MCP-enabled UI tooling integration for enhanced component generation
  • Documentation

    • Updated configuration guides for UI libraries and visual styles
  • Tests

    • Added comprehensive test coverage for UI configuration and design token generation

✏️ Tip: You can customize this high-level summary in your review settings.

Add support for UI component library selection during project creation:

- Add Phase 3b (UI library) and Phase 3c (visual style) to create-spec

- Add app_spec_parser.py for shared UI config parsing

- Add design_tokens.py with style presets (neobrutalism, glassmorphism, retro)

- Update client.py with UI_MCP_TOOLS and dynamic MCP server configuration

- Add UILibrarySelector and VisualStyleSelector React components

- Generate design tokens on spec creation completion

- Add 36 unit tests for UI configuration parsing

Supported libraries: shadcn-ui (React), ark-ui (multi-framework)

Libraries with MCP get rapid component generation via npx servers.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 31, 2026

Warning

Rate limit exceeded

@cabana8471-arch has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 11 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

This pull request introduces UI component library and visual style selection phases to the project specification flow. It adds parsing utilities to extract configuration from spec files, design token generation based on style preferences, MCP server integration for UI tools, and React components for selecting libraries and styles during project initialization.

Changes

Cohort / File(s) Summary
Specification Templates
.claude/commands/create-spec.md, .claude/templates/app_spec.template.txt, .claude/templates/coding_prompt.template.md, .claude/templates/initializer_prompt.template.md
Restructure project specification phases: Phase 3b renamed to "UI Component Library (OPTIONAL)" with MCP support, new Phase 3c "Visual Style (OPTIONAL)" for design aesthetics, and Phase 3d "Database Requirements (MANDATORY)" shifted. Templates now include ui_components and visual_style configuration blocks with detailed parsing guidance and UI component generation instructions.
UI Configuration Parsing
app_spec_parser.py, test_ui_config.py
New module provides utilities to parse app spec files and extract UI configuration (library, framework, MCP status, style, token path). Includes TypedDicts for config modeling, parsing functions with sensible defaults, and public constants for valid values. Comprehensive test coverage validates parsing logic, defaults, edge cases, and integration with spec files.
Design Tokens Generation
design_tokens.py
New module generates design tokens (JSON) based on visual style presets (neobrutalism, glassmorphism, retro). Provides preset retrieval, token generation to .autocoder/design-tokens.json, style validation, and integration with app spec parsing to drive conditional token creation.
MCP and Client Integration
client.py
Integrates UI MCP servers (shadcn-ui, ark-ui) with conditional tooling based on UI config. Adds platform-aware npx command resolution with Windows fallback, version pinning via environment variables, and dynamic MCP server registration when UI MCP is enabled and configured.
Specification Service
server/services/spec_chat_session.py
Extends spec chat session to generate design tokens after spec finalization via generate_design_tokens_from_spec(). Emits file written events and logs token file locations; gracefully handles generation errors.
UI Selection Components
ui/src/components/UILibrarySelector.tsx, ui/src/components/VisualStyleSelector.tsx
New React components provide grid-based selection interfaces for UI libraries and visual styles. UILibrarySelector displays library metadata, framework compatibility, MCP badges, and keyboard/accessibility support. VisualStyleSelector renders style cards with color swatches, preview images, and token generation indicators.
Documentation
CLAUDE.md, ui/public/previews/README.md
Updates project documentation with UI component MCP server configuration, environment variable setup, design tokens usage, and preview image guidelines for library/style previews.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant UI as React Form
    participant Spec as Spec Generator
    participant Parser as Config Parser
    participant Tokens as Token Generator
    participant MCP as MCP Client
    
    User->>UI: Select UI Library & Visual Style
    UI->>Spec: Send selections
    Spec->>Spec: Write app_spec.txt with config
    Spec->>Parser: Parse UI config from spec
    Parser-->>Spec: Return UIConfig
    Spec->>Tokens: generate_design_tokens_from_spec()
    alt Style is non-default
        Tokens->>Tokens: Load preset (neobrutalism/glassmorphism/retro)
        Tokens->>Tokens: Generate design-tokens.json
        Tokens-->>Spec: Return tokens file path
        Spec->>Spec: Emit file_written event
    else Default style
        Tokens-->>Spec: Return None (skip token generation)
    end
    Spec->>MCP: Initialize UI MCP servers
    alt has_mcp is true
        MCP->>MCP: Register shadcn-ui/ark-ui tools
        MCP->>MCP: Resolve npx command (platform-aware)
        MCP-->>Spec: UI tools ready
    else has_mcp is false
        MCP-->>Spec: No UI tools
    end
    Spec-->>User: Project initialized with config
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly Related PRs

Poem

🐰 A UI garden grows in phases,
With colors, tokens, styles and cases,
shadcn and Ark now hop along,
MCP tools make components strong,
Neobrutalism hops into view,
Design tokens fresh—hoorah, it's true! 🎨✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.30% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add MCP servers for UI component libraries' accurately summarizes the main change—integrating MCP servers for UI libraries like shadcn/ui and ark-ui. The title is concise, clear, and specific about the primary addition.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.claude/commands/create-spec.md (1)

294-296: ⚠️ Potential issue | 🟡 Minor

Incorrect phase reference.

Line 296 references "Phase 3b" for the database storage question, but this was renumbered to "Phase 3d" earlier in this PR (line 155).

📝 Suggested fix
 **MANDATORY: Infrastructure Features**
 
-If the app requires a database (Phase 3b answer was "Yes" or "Not sure"), you MUST include 5 Infrastructure features (indices 0-4):
+If the app requires a database (Phase 3d answer was "Yes" or "Not sure"), you MUST include 5 Infrastructure features (indices 0-4):
🤖 Fix all issues with AI agents
In `@client.py`:
- Around line 363-368: In create_client, avoid repeatedly calling
get_ui_config_from_spec(project_dir); call it once at the start of the function
(e.g., ui_config = get_ui_config_from_spec(project_dir)) and reuse that
ui_config when building allowed_tools, computing permissions, and reading MCP
server config (references: allowed_tools logic, permissions block, MCP server
config block); remove the extra get_ui_config_from_spec calls and use the cached
ui_config variable throughout create_client to prevent multiple disk
reads/parses.

In `@test_ui_config.py`:
- Around line 23-28: The test module is missing coverage for
generate_design_tokens_from_spec; import generate_design_tokens_from_spec into
test_ui_config.py and add an integration-style test that calls
generate_design_tokens_from_spec with a representative spec (or fixture used by
server/services/spec_chat_session.py) and asserts the returned tokens match
expected values or that keys/structure produced by generate_design_tokens,
get_style_preset, and validate_visual_style are present; reference the function
name generate_design_tokens_from_spec and the call site in spec_chat_session.py
to mirror the real input/usage so the end-to-end flow is validated.
🧹 Nitpick comments (9)
server/services/spec_chat_session.py (1)

24-27: Duplicate ROOT_DIR definition.

ROOT_DIR is defined twice - once at line 25 and again at line 63. Both compute the same value. Remove the duplicate to avoid confusion.

♻️ Suggested fix
 # Add root directory to path for imports
 ROOT_DIR = Path(__file__).parent.parent.parent
 if str(ROOT_DIR) not in sys.path:
     sys.path.insert(0, str(ROOT_DIR))

 # Load environment variables from .env file if present
 load_dotenv()

 logger = logging.getLogger(__name__)

 # ... (API_ENV_VARS definition)

 async def _make_multimodal_message(content_blocks: list[dict]) -> AsyncGenerator[dict, None]:
     # ...

-# Root directory of the project
-ROOT_DIR = Path(__file__).parent.parent.parent

Also applies to: 62-63

ui/src/components/VisualStyleSelector.tsx (1)

165-171: Consider removing unused hover state or wrapping in role="listbox".

Two observations on this segment:

  1. The hoveredId state (Lines 72, 169-171) is tracked but immediately suppressed with void _hovered. If hover preview effects are planned, add a TODO comment with the intent; otherwise, remove the unused state to reduce complexity.

  2. Each Card uses role="option" (Line 184), but there's no parent element with role="listbox". For complete ARIA semantics, wrap the grid in a container with role="listbox":

♻️ Suggested fix for ARIA listbox
   return (
-    <div className={cn('grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3', className)}>
+    <div
+      role="listbox"
+      aria-label="Visual style selection"
+      className={cn('grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3', className)}
+    >
       {VISUAL_STYLES.map((style) => {
ui/src/components/UILibrarySelector.tsx (2)

86-88: Redundant check in isCompatible.

The lib.id === 'none' check is redundant because the 'none' library (Lines 48-53) already includes all frameworks (['react', 'vue', 'solid', 'svelte', 'vanilla']) in its frameworks array. The first condition lib.frameworks.includes(framework) will always return true for 'none'.

♻️ Suggested simplification
   const isCompatible = (lib: UILibrary) => {
-    return lib.frameworks.includes(framework) || lib.id === 'none'
+    return lib.frameworks.includes(framework)
   }

90-91: Add role="listbox" to parent container for ARIA compliance.

Similar to VisualStyleSelector, each Card uses role="option" but there's no parent role="listbox" container.

♻️ Suggested fix
   return (
-    <div className={cn('grid grid-cols-1 gap-3 sm:grid-cols-2', className)}>
+    <div
+      role="listbox"
+      aria-label="UI library selection"
+      className={cn('grid grid-cols-1 gap-3 sm:grid-cols-2', className)}
+    >
       {UI_LIBRARIES.map((lib) => {
design_tokens.py (2)

174-178: Consider handling file write errors.

The tokens_path.write_text() call can raise OSError or PermissionError if the file cannot be written (disk full, permission denied, etc.). The caller (generate_design_tokens_from_spec) doesn't handle this, and an unhandled exception could interrupt the spec generation flow.

🛡️ Suggested defensive handling
     # Write design tokens
     tokens_path = autocoder_dir / "design-tokens.json"
-    tokens_path.write_text(json.dumps(preset, indent=2), encoding="utf-8")
-
-    return tokens_path
+    try:
+        tokens_path.write_text(json.dumps(preset, indent=2), encoding="utf-8")
+        return tokens_path
+    except OSError:
+        return None

163-164: Document why "custom" returns None.

The function returns None for both "default" and "custom" styles, but the reasoning differs:

  • "default" needs no tokens (uses library defaults)
  • "custom" expects user-provided tokens (shouldn't generate preset tokens)

Adding a brief comment would clarify this intent for future maintainers.

📝 Suggested documentation
+    # "default" uses library defaults; "custom" expects user-provided tokens
     if style == "default" or style == "custom":
         return None
client.py (1)

511-515: Avoid passing None for env in MCP server config.

Line 514 sets "env": None when ui_mcp_env is empty. Some SDK implementations may not handle None gracefully. Prefer omitting the key entirely or passing an empty dict.

🛡️ Suggested fix
-                    mcp_servers["ui_components"] = {
-                        "command": npx_cmd,
-                        "args": ui_mcp_args,
-                        "env": ui_mcp_env if ui_mcp_env else None,
-                    }
+                    ui_mcp_config = {
+                        "command": npx_cmd,
+                        "args": ui_mcp_args,
+                    }
+                    if ui_mcp_env:
+                        ui_mcp_config["env"] = ui_mcp_env
+                    mcp_servers["ui_components"] = ui_mcp_config
app_spec_parser.py (2)

66-69: Comment filtering is incomplete.

The check value.startswith("<!--") only catches XML comments at the very beginning of the value. Comments preceded by whitespace (after strip) or inline comments won't be filtered.

For example, this would still return "value ":

<tag>value <!-- comment --></tag>

Consider using regex to strip comments if this is a concern:

♻️ Suggested improvement
     if match:
         value = match.group(1).strip()
         # Filter out XML comments
-        if value and not value.startswith("<!--"):
+        # Remove XML comments and re-strip
+        value = re.sub(r"<!--.*?-->", "", value, flags=re.DOTALL).strip()
+        if value:
             return value
     return None

174-184: Consider moving constants to the top of the module.

Python convention typically places module-level constants near the top (after imports) for visibility. These constants (VALID_UI_LIBRARIES, MCP_SUPPORTED_LIBRARIES, VALID_VISUAL_STYLES, VALID_FRAMEWORKS) are referenced externally and would be easier to find at the top.

- Cache ui_config in client.py to avoid 3 redundant file reads
- Fix env:None in MCP config by omitting key when empty
- Add integration tests for generate_design_tokens_from_spec
- Fix Phase 3b → 3d reference in create-spec.md
- Remove duplicate ROOT_DIR in spec_chat_session.py
- Add ARIA listbox role to UILibrarySelector and VisualStyleSelector
- Remove redundant isCompatible check in UILibrarySelector
- Add OSError handling in design_tokens.py
- Move constants to top of app_spec_parser.py
- Improve XML comment filtering with regex pattern

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
rudiheydra added a commit to rudiheydra/AutoBuildr that referenced this pull request Feb 2, 2026
…atterns (Feature AutoForgeAI#141)

Replace all remaining 'forbidden_output' references with 'forbidden_patterns' to
match the validator registry in validators.py and the VALIDATOR_TYPES constant.

- api/dspy_signatures.py: Updated DSPy signature field descriptions
- api/static_spec_adapter.py: Updated create_validator() call
- tests/verify_feature_8.py: Updated test validator type list

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
rudiheydra added a commit to rudiheydra/AutoBuildr that referenced this pull request Feb 2, 2026
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant