loading…
Search for a command to run...
loading…
Provides design pattern templates and anti-pattern guidance to AI coding agents for correct pattern implementation.
Provides design pattern templates and anti-pattern guidance to AI coding agents for correct pattern implementation.
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.).
suggest_patternMap 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_templateGet 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
git clone [email protected]:sirius-zuo/design-pattern-mcp.git
cd design-pattern-mcp
npm install
npm run build
Add to ~/.claude/settings.json:
{
"mcpServers": {
"design-pattern-templates": {
"command": "node",
"args": ["/absolute/path/to/design-pattern-mcp/dist/index.js"]
}
}
}
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"]
}
}
}
Add to ~/.codeium/windsurf/mcp_config.json:
{
"mcpServers": {
"design-pattern-templates": {
"command": "node",
"args": ["/absolute/path/to/design-pattern-mcp/dist/index.js"]
}
}
}
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"]
}
}
}
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.
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.
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.
38 patterns across 5 categories:
npm test # run tests
npm run build # compile TypeScript to dist/
npm start # run the MCP server
Run in your terminal:
claude mcp add design-pattern-mcp -- npx Security
Low riskAutomated heuristic from public metadata — not a security guarantee.