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
访问服务器

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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选