Skip to main content
Glama
apolosan

Design Patterns MCP Server

by apolosan

get_pattern_details

Retrieve comprehensive information about specific design patterns to understand implementation details, use cases, and structural components for software development.

Instructions

Get detailed information about a specific pattern

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternIdYesPattern ID to get details for

Implementation Reference

  • Main handler function that executes the get_pattern_details tool: queries database for pattern by ID, handles not found with similar search, fetches implementations, parses examples, formats detailed markdown response with description, benefits, code examples etc.
    private async handleGetPatternDetails(args: any): Promise<any> { const pattern = this.db.queryOne( ` SELECT id, name, category, description, when_to_use, benefits, drawbacks, use_cases, complexity, tags, examples, created_at FROM patterns WHERE id = ? `, [args.patternId] ); if (!pattern) { // Try to find similar patterns using semantic search const similarPatterns = await this.semanticSearch.search({ text: args.patternId, options: { limit: 3, includeMetadata: true, }, }); if (similarPatterns.length > 0) { return { content: [ { type: 'text', text: `Pattern "${args.patternId}" not found. Here are similar patterns:\n\n${similarPatterns .map( (p, i) => `${i + 1}. **${p.pattern.name}** (${p.pattern.category})\n ${p.pattern.description}\n Score: ${(p.score * 100).toFixed(1)}%` ) .join('\n\n')}`, }, ], }; } else { return { content: [ { type: 'text', text: `Pattern "${args.patternId}" not found and no similar patterns were found.`, }, ], }; } } const implementations = this.db.query( ` SELECT language, code, explanation FROM pattern_implementations WHERE pattern_id = ? LIMIT 3 `, [args.patternId] ); // Parse code examples if available let examplesText = ''; if (pattern.examples) { try { const examples = JSON.parse(pattern.examples); const exampleKeys = Object.keys(examples); if (exampleKeys.length > 0) { examplesText = '\n\n**Code Examples:**\n'; exampleKeys.forEach(lang => { const example = examples[lang]; examplesText += `\n### ${lang.charAt(0).toUpperCase() + lang.slice(1)}\n`; if (example.description) { examplesText += `${example.description}\n\n`; } examplesText += `\`\`\`${lang}\n${example.code}\n\`\`\`\n`; }); } } catch (e) { // If parsing fails, skip examples } } return { content: [ { type: 'text', text: `# ${pattern.name} (${pattern.category})\n\n` + `**Description:** ${pattern.description}\n\n` + `**When to Use:** ${parseArrayProperty(pattern.when_to_use).join(', ')}\n\n` + `**Benefits:** ${parseArrayProperty(pattern.benefits).join(', ')}\n\n` + `**Drawbacks:** ${parseArrayProperty(pattern.drawbacks).join(', ')}\n\n` + `**Use Cases:** ${parseArrayProperty(pattern.use_cases).join(', ')}\n\n` + `**Complexity:** ${pattern.complexity}\n\n` + `**Tags:** ${parseTags(pattern.tags).join(', ')}\n` + examplesText + (implementations.length > 0 ? `\n\n**Implementations:**\n` + implementations .map( impl => `\n### ${impl.language}\n\`\`\`${impl.language.toLowerCase()}\n${impl.code}\n\`\`\`\n${impl.explanation}` ) .join('\n') : ''), }, ], }; }
  • Tool registration in the ListToolsRequestSchema handler, defining the tool name, description, and input schema requiring patternId.
    { name: 'get_pattern_details', description: 'Get detailed information about a specific pattern', inputSchema: { type: 'object', properties: { patternId: { type: 'string', description: 'Pattern ID to get details for', }, }, required: ['patternId'], }, },
  • Input validation schema and sanitizer specifically for get_pattern_details tool arguments, validating patternId format and throwing MCP error if invalid.
    * Validates all inputs for get_pattern_details tool */ static validateGetPatternDetailsArgs(args: any): { patternId: string; } { const patternIdResult = this.validatePatternId(args.patternId); this.throwIfInvalid(patternIdResult); return { patternId: patternIdResult.sanitized, }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/apolosan/design_patterns_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server