mcp

package
v0.11.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2026 License: GPL-3.0 Imports: 23 Imported by: 0

README

CEM MCP Server

An MCP (Model Context Protocol) server that provides AI assistants with intelligent access to Custom Elements Manifest data for generating accurate HTML with web components.

What It Does

The CEM MCP Server helps AI assistants understand your custom elements and generate correct HTML by providing:

  • Component discovery: Find available custom elements in your project
  • Attribute validation: Get accurate attribute names, types, and values
  • HTML generation: Generate valid HTML with proper component usage
  • Documentation access: Access component descriptions and usage guidelines

Setup

  1. Install CEM: First make sure you have the CEM CLI installed

    npm install -g @pwrs/cem
    
  2. Generate manifests: Run CEM in your project to generate Custom Elements Manifests

    cem analyze
    
  3. Start the MCP server: Run the CEM MCP server in your project directory

    cem mcp
    
  4. Connect to AI assistant: Configure your AI assistant (Claude Desktop, etc.) to use the MCP server

Usage Examples

Discovering Components

Ask your AI assistant about available components:

"What custom elements are available in this project?"

The MCP server will provide a list of all custom elements found in your manifests.

Getting Component Information

Ask for details about specific components:

"Tell me about the my-button component"

You'll get information about:

  • Available attributes and their types
  • Slots for content projection
  • CSS custom properties for styling
  • Events the component fires
  • CSS parts for external styling
Generating HTML

Ask the AI to generate HTML using your components:

"Create a form with my-input and my-button components"

The AI will generate valid HTML with correct attribute names and values based on your component definitions.

Description Limits

For security and optimal AI performance, the MCP server enforces a 2000 character limit on component description fields. Descriptions exceeding this limit are automatically truncated with "..." appended.

This ensures:

  • Fast processing - AI can quickly parse component information
  • Security - Prevents abuse through extremely long descriptions
  • Quality focus - Encourages concise, actionable documentation

Best Practice: Keep descriptions concise and focused. Most effective descriptions are 200-400 characters.

You can customize this limit via configuration file or command line flag:

cem mcp --max-description-length 5000

Configuration

Claude Desktop

Add to your Claude Desktop MCP configuration:

{
  "mcpServers": {
    "cem": {
      "command": "cem",
      "args": ["mcp"]
    }
  }
}
Other AI Assistants

The CEM MCP server follows the standard MCP protocol and should work with any MCP-compatible AI assistant.

What You Get

Accurate Component Usage

The AI assistant will have access to:

  • Exact attribute names and types from your component definitions
  • Slot information for proper content placement
  • CSS custom properties for theme-aware styling
  • Event details for interactive components
Smart HTML Generation

Instead of guessing, the AI can generate HTML like:

<!-- AI knows the correct attributes and their types -->
<my-button variant="primary" size="large">
  Click me
</my-button>

<!-- AI understands slot usage -->
<my-card>
  <h2 slot="title">Card Title</h2>
  <p>Card content goes in the default slot</p>
  <button slot="action">Learn More</button>
</my-card>
Design System Integration

The AI can help with styling using your component's CSS API:

my-button {
  --button-background: var(--primary-color);
  --button-radius: var(--border-radius-md);
}

Benefits

  • No more guessing - AI uses your actual component definitions
  • Consistent usage - Components are used according to their documented API
  • Better DX - Less time looking up component documentation
  • Design system compliance - Automatic adherence to your design tokens

Documentation

Overview

Copyright © 2025 Benny Powers <web@bennypowers.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Benny Powers <web@bennypowers.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMCPContextAdapter

func NewMCPContextAdapter(context *MCPContext) MCPTypes.MCPContext

NewMCPContextAdapter creates an adapter that implements the tools interface

Types

type MCPContext

type MCPContext struct {
	// contains filtered or unexported fields
}

MCPContext manages custom elements manifests for MCP context This is a lightweight wrapper around the LSP registry for reuse

func NewMCPContext

func NewMCPContext(workspace types.WorkspaceContext, fsys platform.FileSystem) (*MCPContext, error)

NewMCPContext creates a new MCP context. If fsys is nil, it defaults to platform.NewOSFileSystem().

func (*MCPContext) AllCSSProperties

func (ctx *MCPContext) AllCSSProperties() []string

AllCSSProperties returns all CSS custom properties across elements (lazy-computed and cached)

func (*MCPContext) CommonPrefixes

func (ctx *MCPContext) CommonPrefixes() []string

CommonPrefixes returns common element tag name prefixes (lazy-computed and cached)

func (*MCPContext) Config added in v0.11.0

func (ctx *MCPContext) Config() (*IC.CemConfig, error)

func (*MCPContext) ConfigFile added in v0.11.0

func (ctx *MCPContext) ConfigFile() string

func (*MCPContext) ConfigSchemaJSON added in v0.11.0

func (ctx *MCPContext) ConfigSchemaJSON() []byte

func (*MCPContext) DocumentManager

func (ctx *MCPContext) DocumentManager() lspTypes.DocumentManager

DocumentManager returns the shared document manager for validation

func (*MCPContext) FileSystem added in v0.11.0

func (ctx *MCPContext) FileSystem() platform.FileSystem

func (*MCPContext) GetAllElements

func (ctx *MCPContext) GetAllElements() map[string]MCPTypes.ElementInfo

GetAllElements returns all available elements

func (*MCPContext) GetElementInfo

func (ctx *MCPContext) GetElementInfo(tagName string) (MCPTypes.ElementInfo, error)

GetElementInfo returns enhanced element information for MCP context

func (*MCPContext) GetManifestSchema

func (ctx *MCPContext) GetManifestSchema() (map[string]any, error)

GetManifestSchema returns the JSON schema for custom elements manifests

func (*MCPContext) GetManifestSchemaVersions

func (ctx *MCPContext) GetManifestSchemaVersions() []string

GetManifestSchemaVersions returns all unique schema versions found in loaded manifests

func (*MCPContext) InvalidateConfig added in v0.11.0

func (ctx *MCPContext) InvalidateConfig()

func (*MCPContext) LSPRegistry added in v0.9.3

func (ctx *MCPContext) LSPRegistry() *LSP.Registry

LSPRegistry returns the underlying LSP registry for additional package loading

func (*MCPContext) LoadManifests

func (ctx *MCPContext) LoadManifests() error

LoadManifests loads all available manifests

func (*MCPContext) RelationshipsFor added in v0.9.2

func (ctx *MCPContext) RelationshipsFor(tagName string) []relationships.Relationship

RelationshipsFor returns relationships for the given element. Always returns an empty slice instead of nil to avoid null in JSON/UI.

func (*MCPContext) Root added in v0.11.0

func (ctx *MCPContext) Root() string

type MCPContextAdapter

type MCPContextAdapter struct {
	*MCPContext
}

MCPContextAdapter implements MCPTypes.MCPContext interface for tools package

func (*MCPContextAdapter) AllElements

func (ctx *MCPContextAdapter) AllElements() map[string]MCPTypes.ElementInfo

AllElements implements MCPTypes.MCPContext interface

func (*MCPContextAdapter) Config added in v0.11.0

func (ctx *MCPContextAdapter) Config() (*IC.CemConfig, error)

func (*MCPContextAdapter) ConfigFile added in v0.11.0

func (ctx *MCPContextAdapter) ConfigFile() string

func (*MCPContextAdapter) ConfigSchemaJSON added in v0.11.0

func (ctx *MCPContextAdapter) ConfigSchemaJSON() []byte

func (*MCPContextAdapter) DocumentManager

func (ctx *MCPContextAdapter) DocumentManager() lspTypes.DocumentManager

DocumentManager implements MCPTypes.MCPContext interface

func (*MCPContextAdapter) ElementInfo

func (ctx *MCPContextAdapter) ElementInfo(tagName string) (MCPTypes.ElementInfo, error)

ElementInfo implements MCPTypes.MCPContext interface

func (*MCPContextAdapter) FileSystem added in v0.11.0

func (ctx *MCPContextAdapter) FileSystem() platform.FileSystem

func (*MCPContextAdapter) GetManifestSchemaVersions

func (ctx *MCPContextAdapter) GetManifestSchemaVersions() []string

GetManifestSchemaVersions implements MCPTypes.MCPContext interface

func (*MCPContextAdapter) Root added in v0.11.0

func (ctx *MCPContextAdapter) Root() string

type MCPCustomElementDeclaration

type MCPCustomElementDeclaration struct {
	*M.RenderableCustomElementDeclaration
	Guidelines  []string `json:"guidelines,omitempty"`
	CacheKey    string   `json:"cacheKey,omitempty"`
	ModulePath  string   `json:"modulePath,omitempty"`
	PackageName string   `json:"packageName,omitempty"`
}

MCPCustomElementDeclaration embeds manifest types with MCP-specific data

func NewMCPCustomElementDeclaration

func NewMCPCustomElementDeclaration(element *M.CustomElement, tagName string) *MCPCustomElementDeclaration

NewMCPCustomElementDeclaration creates a new MCP custom element declaration from a manifest element

type MCPElementInfoAdapter

type MCPElementInfoAdapter struct {
	*MCPCustomElementDeclaration
	// contains filtered or unexported fields
}

ElementInfoAdapter implements MCPTypes.ElementInfo interface MCPElementInfoAdapter implements MCPTypes.ElementInfo interface for MCP-specific behavior

func (*MCPElementInfoAdapter) Attributes

func (e *MCPElementInfoAdapter) Attributes() []M.Attribute

Member accessors returning manifest types directly

func (*MCPElementInfoAdapter) CssParts

func (e *MCPElementInfoAdapter) CssParts() []M.CssPart

func (*MCPElementInfoAdapter) CssProperties

func (e *MCPElementInfoAdapter) CssProperties() []M.CssCustomProperty

func (*MCPElementInfoAdapter) CssStates

func (e *MCPElementInfoAdapter) CssStates() []M.CssCustomState

func (*MCPElementInfoAdapter) Declaration

Declaration returns the underlying manifest declaration

func (*MCPElementInfoAdapter) Description

func (e *MCPElementInfoAdapter) Description() string

func (*MCPElementInfoAdapter) Element

Template-friendly access

func (*MCPElementInfoAdapter) Events

func (e *MCPElementInfoAdapter) Events() []M.Event

func (*MCPElementInfoAdapter) Examples

func (e *MCPElementInfoAdapter) Examples() []MCPTypes.Example

func (*MCPElementInfoAdapter) Guidelines

func (e *MCPElementInfoAdapter) Guidelines() []string

MCP-specific behavior

func (*MCPElementInfoAdapter) Module

func (e *MCPElementInfoAdapter) Module() string

func (*MCPElementInfoAdapter) Name

func (e *MCPElementInfoAdapter) Name() string

func (*MCPElementInfoAdapter) Package

func (e *MCPElementInfoAdapter) Package() string

func (*MCPElementInfoAdapter) Relationships added in v0.9.2

func (e *MCPElementInfoAdapter) Relationships() []relationships.Relationship

func (*MCPElementInfoAdapter) Slots

func (e *MCPElementInfoAdapter) Slots() []M.Slot

func (*MCPElementInfoAdapter) Summary

func (e *MCPElementInfoAdapter) Summary() string

func (*MCPElementInfoAdapter) TagName

func (e *MCPElementInfoAdapter) TagName() string

Convenience accessors that delegate to embedded manifest types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server implements an MCP server for custom elements

func NewServer

func NewServer(workspace types.WorkspaceContext) (*Server, error)

NewServer creates a new CEM MCP server with default configuration

func NewServerWithConfig

func NewServerWithConfig(workspace types.WorkspaceContext, config ServerConfig) (*Server, error)

NewServerWithConfig creates a new CEM MCP server with custom configuration

func (*Server) GetInfo

func (s *Server) GetInfo() ServerInfo

GetInfo returns server information

func (*Server) Registry added in v0.7.3

func (s *Server) Registry() *MCPContext

Registry returns the MCP registry for testing This is used by tests to verify stdout cleanliness

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run starts the MCP server with stdio transport

type ServerConfig

type ServerConfig struct {
	MaxDescriptionLength int
	// Additional packages to load manifests from (URLs, npm:, or jsr: specifiers)
	AdditionalPackages []string
	// FileSystem to use for filesystem operations. If nil, defaults to OSFileSystem.
	FileSystem platform.FileSystem
}

ServerConfig contains configuration options for the MCP server

type ServerInfo

type ServerInfo struct {
	Name        string `json:"name"`
	Version     string `json:"version"`
	Description string `json:"description"`
}

ServerInfo represents basic server information

Directories

Path Synopsis
Package chunking provides semantic-aware text chunking for MCP context management.
Package chunking provides semantic-aware text chunking for MCP context management.
Package relationships provides element relationship detection for MCP context.
Package relationships provides element relationship detection for MCP context.
gen-adapters command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL