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 and use cases for solving programming problems.

Instructions

Get detailed information about a specific pattern

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternIdYesPattern ID to get details for

Implementation Reference

  • The main execution logic for the get_pattern_details tool. Validates input, queries the database for pattern details and related implementations, handles cases where the pattern is not found by suggesting similar patterns via semantic search, parses JSON examples, and constructs a formatted markdown response with all details.
    private async handleGetPatternDetails(args: unknown): Promise<CallToolResult> { const validatedArgs = InputValidator.validateGetPatternDetailsArgs(args); 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 = ? `, [validatedArgs.patternId] ); if (!pattern) { // Try to find similar patterns using semantic search const similarPatterns = await this.semanticSearch.search({ text: validatedArgs.patternId, options: { limit: 3, includeMetadata: true, }, }); if (similarPatterns.length > 0) { return { content: [ { type: 'text', text: `Pattern "${validatedArgs.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 "${validatedArgs.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 `, [validatedArgs.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 ListToolsRequest handler, defining the tool name, description, and input schema (requiring a patternId string).
    { 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 enforcement for get_pattern_details tool arguments, using patternId validator to ensure valid string format and throw MCP errors on invalid input.
    static validateGetPatternDetailsArgs(args: unknown): { patternId: string; } { if (typeof args !== 'object' || args === null) { throw new McpError(ErrorCode.InvalidParams, 'Invalid arguments: expected object'); } const obj = args as Record<string, unknown>; const patternIdResult = this.validatePatternId(obj.patternId); this.throwIfInvalid(patternIdResult); return { patternId: patternIdResult.sanitized as string, }; }

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