Clean Architecture MCP Server

Clean Architecture MCP Server

Enables scaffolding and managing Clean Architecture in Next.js projects, providing tools to initialize structure, create features with all layers, and validate architecture compliance.

Category
Visit Server

README

Clean Architecture MCP Server

Model Context Protocol Server for scaffolding and managing Clean Architecture in Next.js projects.

šŸŽÆ Features

This MCP Server provides 3 powerful tools:

  1. initialize_clean_architecture - Set up complete Clean Architecture structure
  2. create_feature - Generate new features with all layers
  3. validate_architecture - Check for architecture violations

šŸš€ Installation

Option 1: Global Installation (Recommended)

# From the mcp-server directory
cd mcp-server
npm install
npm run build
npm link

# Now available globally as 'clean-architecture-mcp'

Option 2: Local Installation

cd mcp-server
npm install
npm run build

āš™ļø Configuration

For Cursor/Claude Desktop

Add to your MCP configuration file:

Mac/Linux: ~/.config/cursor/mcp.json or ~/Library/Application Support/Claude/claude_desktop_config.json

Windows: %APPDATA%\Cursor\mcp.json or %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "clean-architecture": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-server/dist/index.js"]
    }
  }
}

Or if globally installed:

{
  "mcpServers": {
    "clean-architecture": {
      "command": "clean-architecture-mcp"
    }
  }
}

Restart Cursor/Claude

After configuration, restart Cursor or Claude Desktop to load the MCP server.

šŸ“š Usage

Tool 1: Initialize Architecture

Initialize Clean Architecture in your Next.js project:

In Cursor chat:

Use the clean-architecture MCP server to initialize the project structure

With parameters:

Use clean-architecture to initialize with features: products, orders, customers

What it does:

  • āœ… Creates complete directory structure
  • āœ… Adds .gitkeep files
  • āœ… Creates README.md in each layer
  • āœ… Updates tsconfig.json paths
  • āœ… Sets up domain/infra/components/tests folders

Tool 2: Create Feature

Generate a complete feature:

In Cursor chat:

Use clean-architecture to create a "products" feature

What it creates:

src/domain/products/
ā”œā”€ā”€ models/product.ts              # Zod schema
ā”œā”€ā”€ business-rules/                # Pure business logic
ā”œā”€ā”€ services/product-service.ts    # Use cases
└── ports/product-repository.ts    # Interface

src/infra/adapters/
└── product-repository.prisma.ts   # Implementation

src/app/api/products/
ā”œā”€ā”€ route.ts                       # GET, POST
└── [id]/route.ts                  # GET, DELETE

Tool 3: Validate Architecture

Check for architecture violations:

In Cursor chat:

Use clean-architecture to validate the project

What it checks:

  • āŒ Next.js imports in domain layer
  • āŒ React imports in domain layer
  • āŒ Direct Prisma imports in domain
  • āš ļø Missing ports/interfaces
  • āš ļø Missing tests

Output:

{
  "success": true,
  "score": 100,
  "issues": [],
  "warnings": [],
  "message": "āœ… Architecture validation passed!"
}

šŸŽØ Examples

Example 1: New Project Setup

User: Initialize Clean Architecture in this Next.js project with features: users, products, orders

AI: [Uses initialize_clean_architecture tool]

Result:
āœ… Created 45 directories
āœ… Created 6 README files
āœ… Updated tsconfig.json
āœ… Ready to develop!

Example 2: Create Feature

User: Create a "products" feature with fields: name, price, stock

AI: [Uses create_feature tool with featureName: "products"]

Result:
āœ… Created models/product.ts
āœ… Created business rules
āœ… Created service layer
āœ… Created repository port
āœ… Created Prisma adapter
āœ… Created API routes

Example 3: Validate

User: Check if my architecture follows Clean Architecture principles

AI: [Uses validate_architecture tool]

Result:
āŒ Found 2 issues:
  - src/domain/users/services/create-user.ts: Contains Next.js import
  - src/domain/products/models/product.ts: Direct Prisma import

Score: 60/100

šŸ› ļø Development

# Install dependencies
npm install

# Build
npm run build

# Watch mode (during development)
npm run dev

# Test the server
node dist/index.js

šŸ“‹ Tool Reference

initialize_clean_architecture

Parameters:

  • targetDir (optional): Target directory (default: current directory)
  • features (optional): Array of feature names (default: ['users', 'auth', 'payments'])

Returns:

{
  success: boolean;
  message: string;
  created: number;
  directories: string[];
  features: string[];
}

create_feature

Parameters:

  • featureName (required): Feature name in kebab-case
  • targetDir (optional): Target directory (default: current directory)
  • fields (optional): Custom model fields

Returns:

{
  success: boolean;
  message: string;
  feature: string;
  created: string[];
}

validate_architecture

Parameters:

  • targetDir (optional): Directory to validate (default: current directory)

Returns:

{
  success: boolean;
  score: number;
  issues: string[];
  warnings: string[];
  message: string;
}

šŸ”§ Troubleshooting

MCP Server not appearing in Cursor

  1. Check configuration file path
  2. Verify absolute path to dist/index.js
  3. Restart Cursor completely
  4. Check Cursor logs: Help > Show Logs

"Command not found" error

If globally installed:

npm link
# Verify
which clean-architecture-mcp

TypeScript errors

npm run build
# Check for compilation errors

Tool execution fails

Check that you're in a Next.js project directory with package.json.

šŸ“¦ Publishing

To publish to npm:

npm publish

Then users can install globally:

npm install -g clean-architecture-mcp-server

šŸ¤ Contributing

  1. Add new tools in src/index.ts
  2. Update tool schemas
  3. Test with npm run build && node dist/index.js
  4. Update this README

šŸ“„ License

MIT

šŸ”— Resources


Made with ā¤ļø for Clean Architecture enthusiasts

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured