designpattern
Apply design patterns to solve software architecture challenges, including modular architecture, API integration, state management, and security best practices.
Instructions
A tool for applying design patterns to software architecture and implementation. Supports various design patterns including:
Modular Architecture
API Integration Patterns
State Management
Asynchronous Processing
Scalability Considerations
Security Best Practices
Agentic Design Patterns
Each pattern provides a structured approach to solving common design challenges.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| patternName | Yes | ||
| context | Yes | ||
| implementation | No | ||
| benefits | No | ||
| tradeoffs | No | ||
| codeExample | No | ||
| languages | No |
Implementation Reference
- src/tools/designPatternServer.ts:64-93 (handler)The core handler function for the 'designpattern' tool. Validates input using DesignPatternData schema, formats a colored console output, logs it, and returns a structured JSON response with pattern details or error.public processPattern(input: unknown): { content: Array<{ type: string; text: string }>; isError?: boolean } { try { const validatedInput = this.validatePatternData(input); const formattedOutput = this.formatPatternOutput(validatedInput); console.error(formattedOutput); return { content: [{ type: "text", text: JSON.stringify({ patternName: validatedInput.patternName, status: 'success', hasImplementation: validatedInput.implementation.length > 0, hasCodeExample: !!validatedInput.codeExample }, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: JSON.stringify({ error: error instanceof Error ? error.message : String(error), status: 'failed' }, null, 2) }], isError: true }; } }
- src/index.ts:66-115 (schema)Tool definition including name, description, and inputSchema which serves as the schema for validation of 'designpattern' tool calls.const DESIGN_PATTERN_TOOL: Tool = { name: "designpattern", description: `A tool for applying design patterns to software architecture and implementation. Supports various design patterns including: - Modular Architecture - API Integration Patterns - State Management - Asynchronous Processing - Scalability Considerations - Security Best Practices - Agentic Design Patterns Each pattern provides a structured approach to solving common design challenges.`, inputSchema: { type: "object", properties: { patternName: { type: "string", enum: [ "modular_architecture", "api_integration", "state_management", "async_processing", "scalability", "security", "agentic_design", ], }, context: { type: "string" }, implementation: { type: "array", items: { type: "string" }, }, benefits: { type: "array", items: { type: "string" }, }, tradeoffs: { type: "array", items: { type: "string" }, }, codeExample: { type: "string" }, languages: { type: "array", items: { type: "string" }, }, }, required: ["patternName", "context"], }, };
- src/index.ts:1057-1069 (registration)Registration of the tool handler in the main CallToolRequestHandler switch statement, dispatching calls to designPatternServer.processPattern.case "designpattern": { const result = designPatternServer.processPattern( request.params.arguments ); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; }
- src/index.ts:1000-1000 (registration)Registers the DESIGN_PATTERN_TOOL schema in the MCP server capabilities.tools object.designpattern: DESIGN_PATTERN_TOOL,
- Helper function that validates and casts input to DesignPatternData interface, enforcing the tool schema.private validatePatternData(input: unknown): DesignPatternData { const data = input as Record<string, unknown>; if (!data.patternName || typeof data.patternName !== 'string') { throw new Error('Invalid patternName: must be a string'); } if (!data.context || typeof data.context !== 'string') { throw new Error('Invalid context: must be a string'); } return { patternName: data.patternName as string, context: data.context as string, implementation: Array.isArray(data.implementation) ? data.implementation.map(String) : [], benefits: Array.isArray(data.benefits) ? data.benefits.map(String) : [], tradeoffs: Array.isArray(data.tradeoffs) ? data.tradeoffs.map(String) : [], codeExample: typeof data.codeExample === 'string' ? data.codeExample as string : undefined, languages: Array.isArray(data.languages) ? data.languages.map(String) : undefined }; }