search_patterns
Find coding patterns by searching across names, descriptions, technologies, use cases, and code content with a single query.
Instructions
Search for patterns based on a query across all fields
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The search query to match against pattern names, descriptions, technologies, use cases, and code content |
Implementation Reference
- src/index.ts:119-133 (handler)The searchPatterns method in the PatternsManager class implements the search logic. It loads the database and filters patterns by searching across all fields (name, category, description, use_cases, technologies, and code_examples) using case-insensitive matching.
async searchPatterns(query: string): Promise<PatternsDatabase> { const database = await this.loadDatabase(); const filteredPatterns = database.patterns.filter(p => p.name.toLowerCase().includes(query.toLowerCase()) || p.category.toLowerCase().includes(query.toLowerCase()) || p.description.toLowerCase().includes(query.toLowerCase()) || p.use_cases.some(uc => uc.toLowerCase().includes(query.toLowerCase())) || p.technologies.some(tech => tech.toLowerCase().includes(query.toLowerCase())) || Object.keys(p.code_examples).some(lang => lang.toLowerCase().includes(query.toLowerCase())) || Object.values(p.code_examples).some(code => code.toLowerCase().includes(query.toLowerCase())) ); return { patterns: filteredPatterns }; } - src/index.ts:270-279 (schema)The tool schema definition in the ListToolsRequestSchema handler. Defines the tool name as 'search_patterns', its description, and the input schema requiring a 'query' string parameter.
name: "search_patterns", description: "Search for patterns based on a query across all fields", inputSchema: { type: "object", properties: { query: { type: "string", description: "The search query to match against pattern names, descriptions, technologies, use cases, and code content" }, }, required: ["query"], }, }, - src/index.ts:319-320 (registration)The case handler in the CallToolRequestSchema that routes 'search_patterns' tool calls to the patternsManager.searchPatterns method, passing the query argument and formatting the result as JSON.
case "search_patterns": return { content: [{ type: "text", text: JSON.stringify(await patternsManager.searchPatterns(args.query as string), null, 2) }] }; - src/index.ts:24-35 (schema)TypeScript interface definitions for Pattern and PatternsDatabase that define the schema for pattern objects and the database structure used by the search_patterns tool.
interface Pattern { name: string; category: string; description: string; use_cases: string[]; technologies: string[]; code_examples: { [language: string]: string }; } interface PatternsDatabase { patterns: Pattern[]; }