Skip to main content
Glama
apolosan

Design Patterns MCP Server

by apolosan

find_patterns

Identify design patterns for programming problems using semantic search. Describe your challenge in natural language to get pattern recommendations with implementation examples.

Instructions

Find design patterns matching a problem description using semantic search

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoriesNoOptional: Pattern categories to search in
maxResultsNoMaximum number of recommendations to return
programmingLanguageNoTarget programming language for implementation examples
queryYesNatural language description of the problem or requirements

Implementation Reference

  • The primary handler for the 'find_patterns' tool. Processes input arguments, invokes the PatternMatcher service, and formats the response with pattern recommendations including confidence scores and rationales.
    private async handleFindPatterns(args: any): Promise<any> { const request = { id: crypto.randomUUID(), query: args.query, categories: args.categories || [], maxResults: args.maxResults || 5, programmingLanguage: args.programmingLanguage, }; const recommendations = await this.patternMatcher.findMatchingPatterns(request); return { content: [ { type: 'text', text: `Found ${recommendations.length} pattern recommendations:\n\n` + recommendations .map( (rec, index) => `${index + 1}. **${rec.pattern.name}** (${rec.pattern.category})\n` + ` Confidence: ${(rec.confidence * 100).toFixed(1)}%\n` + ` Rationale: ${rec.justification.primaryReason}\n` + ` Benefits: ${rec.justification.benefits.join(', ')}\n` ) .join('\n'), }, ], }; }
  • Tool registration in the ListToolsRequest handler, defining the name, description, and input schema for 'find_patterns'.
    { name: 'find_patterns', description: 'Find design patterns matching a problem description using semantic search', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Natural language description of the problem or requirements', }, categories: { type: 'array', items: { type: 'string' }, description: 'Optional: Pattern categories to search in', }, maxResults: { type: 'number', description: 'Maximum number of recommendations to return', default: 5, }, programmingLanguage: { type: 'string', description: 'Target programming language for implementation examples', }, }, required: ['query'], }, },
  • Input schema definition for the 'find_patterns' tool, specifying parameters, types, descriptions, and requirements.
    type: 'object', properties: { query: { type: 'string', description: 'Natural language description of the problem or requirements', }, categories: { type: 'array', items: { type: 'string' }, description: 'Optional: Pattern categories to search in', }, maxResults: { type: 'number', description: 'Maximum number of recommendations to return', default: 5, }, programmingLanguage: { type: 'string', description: 'Target programming language for implementation examples', }, }, required: ['query'],
  • Core helper method implementing the pattern matching logic: caching, hybrid search (semantic + keyword), recommendation building, and result processing. Called directly by the tool handler.
    async findMatchingPatterns(request: PatternRequest): Promise<PatternRecommendation[]> { try { // Check cache first const cacheKey = `pattern_match:${request.query}:${JSON.stringify({ categories: request.categories?.sort(), maxResults: request.maxResults, programmingLanguage: request.programmingLanguage, })}`; const cachedResult = this.cache.get(cacheKey); if (cachedResult) { return cachedResult; } const matches = await this.performMatching(request); const recommendations = await this.buildRecommendations(matches, request); // Sort by confidence and limit results recommendations.sort((a, b) => b.confidence - a.confidence); const finalResults = recommendations.slice(0, request.maxResults || this.config.maxResults); // Cache the results for 30 minutes this.cache.set(cacheKey, finalResults, 1800000); return finalResults; } catch (error) { structuredLogger.error('pattern-matcher', 'Pattern matching failed', error as Error); throw error; } }

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