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
| Name | Required | Description | Default |
|---|---|---|---|
| categories | No | Optional: Pattern categories to search in | |
| maxResults | No | Maximum number of recommendations to return | |
| programmingLanguage | No | Target programming language for implementation examples | |
| query | Yes | Natural language description of the problem or requirements |
Implementation Reference
- src/mcp-server.ts:319-348 (handler)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'), }, ], }; }
- src/mcp-server.ts:156-184 (registration)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'], }, },
- src/mcp-server.ts:161-182 (schema)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; } }