Design-Pattern-MCP

Design-Pattern-MCP

Provides design pattern templates and anti-pattern guidance to AI coding agents for correct pattern implementation.

Category
访问服务器

README

<p align="center"> <img src="assets/Design-Pattern-MCP-Banner.jpg" alt="Design-Pattern-MCP" width="1280"> </p>

Design-Pattern-MCP

An MCP (Model Context Protocol) server that provides design pattern structural constraints and anti-patterns to AI coding agents. Agents call this server during code generation to ensure they implement patterns correctly.

This server is not for human use. It is called by AI coding agents (Claude Code, Cursor, Copilot, etc.).

Tools

suggest_pattern

Map a problem description to pattern name(s).

Input: { description: string, category?: "creational"|"structural"|"behavioral"|"modern"|"architectural" }

Output: Up to 3 PatternSuggestion[]{ name, category, rationale, confidence }

Token cost: ~50–100 tokens

get_template

Get structural constraints and anti-patterns for a specific pattern in a specific language.

Input: { pattern: string, language: "go"|"java"|"python"|"rust"|"typescript"|"generic" }

Output: Compact plain text with COMPONENTS, CONSTRAINTS, ANTI-PATTERNS, language-specific notes, example structure

Token cost: ~300–500 tokens

Installation

git clone git@github.com:sirius-zuo/design-pattern-mcp.git
cd design-pattern-mcp
npm install
npm run build

Register with Claude Code

Add to ~/.claude/settings.json:

{
  "mcpServers": {
    "design-pattern-templates": {
      "command": "node",
      "args": ["/absolute/path/to/design-pattern-mcp/dist/index.js"]
    }
  }
}

Register with Cursor

Add to .cursor/mcp.json (project) or ~/.cursor/mcp.json (global):

{
  "mcpServers": {
    "design-pattern-templates": {
      "command": "node",
      "args": ["/absolute/path/to/design-pattern-mcp/dist/index.js"]
    }
  }
}

Register with Windsurf

Add to ~/.codeium/windsurf/mcp_config.json:

{
  "mcpServers": {
    "design-pattern-templates": {
      "command": "node",
      "args": ["/absolute/path/to/design-pattern-mcp/dist/index.js"]
    }
  }
}

Register with GitHub Copilot (VS Code)

Add to .vscode/mcp.json (project) or user settings:

{
  "servers": {
    "design-pattern-templates": {
      "type": "stdio",
      "command": "node",
      "args": ["/absolute/path/to/design-pattern-mcp/dist/index.js"]
    }
  }
}

Usage in Claude Desktop

Once registered, you can ask Claude to use the tools directly in conversation. The typical workflow is: suggest a pattern first, then fetch the full template for the one you want to implement.


Example 1 — Find the right pattern

You ask Claude:

I need to support multiple payment methods like credit card, PayPal, and crypto that can be swapped at runtime. What pattern should I use?

Claude calls suggest_pattern and returns:

[
  {
    "name": "Strategy",
    "category": "behavioral",
    "rationale": "multiple interchangeable algorithms",
    "confidence": 0.67
  },
  {
    "name": "Decorator",
    "category": "structural",
    "rationale": "add responsibilities dynamically without subclassing",
    "confidence": 0.50
  },
  {
    "name": "Saga",
    "category": "modern",
    "rationale": "long-running distributed transaction",
    "confidence": 0.33
  }
]

Strategy is the strongest match. You then ask for the full template.


Example 2 — Get the full template for your language

You ask Claude:

Give me the Strategy pattern template for TypeScript.

Claude calls get_template with { pattern: "strategy", language: "typescript" } and returns:

Pattern: Strategy
Language: typescript

COMPONENTS:
- **Context**: Holds a reference to a Strategy. Delegates algorithm execution to it. Contains NO algorithm logic itself.

CONSTRAINTS:
- Context must NOT contain algorithm logic; all logic lives in ConcreteStrategy.

ANTI-PATTERNS:
- Embedding the if/else or switch selection logic inside Context (defeats the purpose).

TYPESCRIPT-SPECIFIC NOTES:
- Define single-method stateless strategies as function types: `type SortStrategy = (data: number[]) => number[]` — no interface or class needed.
- Multi-method or stateful strategies: use an `interface` with structural typing — no `implements` declaration required.
- Inject via constructor (`constructor(private strategy: SortStrategy)`) for immutability; use a setter only when runtime switching is required.
- `Context` holds a field typed to the function type or interface; calling it is `this.strategy(params)` or `this.strategy.execute(params)`.

EXAMPLE STRUCTURE:
```typescript
type Sorter = (data: number[]) => number[];

class SortContext {
  constructor(private strategy: Sorter) {}
  setStrategy(s: Sorter): void { this.strategy = s; }
  run(data: number[]): number[] { return this.strategy(data); }
}

// Usage — any function with the right signature is a valid strategy
const ctx = new SortContext(data => [...data].sort((a, b) => a - b));
ctx.run([3, 1, 2]); // [1, 2, 3]

// Interface-based for stateful strategies
interface PricingStrategy { calculate(basePrice: number): number; }
class DiscountStrategy implements PricingStrategy {
  constructor(private pct: number) {}
  calculate(base: number): number { return base * (1 - this.pct); }
}

Claude then uses this output as grounding constraints when writing your actual payment service code — ensuring the context doesn't embed algorithm logic, strategies are injected via constructor, and the TypeScript-idiomatic function-type approach is used.

Pattern Coverage

38 patterns across 5 categories:

  • Creational (5): Abstract Factory, Builder, Factory Method, Prototype, Singleton
  • Structural (7): Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy
  • Behavioral (11): Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor
  • Modern (8): Circuit Breaker, CQRS, Dependency Injection, Event Sourcing, Pub/Sub, Repository, Retry with Backoff, Saga
  • Architectural (7): Clean Architecture, Event-Driven Architecture, Hexagonal Architecture, Layered Architecture, Microservices, MVC/MVP/MVVM, Pipe and Filter

Development

npm test         # run tests
npm run build    # compile TypeScript to dist/
npm start        # run the MCP server

推荐服务器

Baidu Map

Baidu Map

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

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

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

官方
精选
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

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

官方
精选
本地
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

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

官方
精选
本地
TypeScript
VeyraX

VeyraX

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

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

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

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

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

官方
精选
TypeScript
Exa MCP Server

Exa MCP Server

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

官方
精选
mcp-server-qdrant

mcp-server-qdrant

这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。

官方
精选
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选