search_best_practices
Find specific development guidance by searching best practice guides for topics like validation, security, performance optimization, or error handling.
Instructions
Search across all best practice guides for specific terms, patterns, or concepts. Use this when you need guidance on specific topics like validation, security, performance optimization, error handling, or any development pattern. Perfect for finding relevant best practices without reading entire guides.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search term or concept (e.g., 'validation', 'security', 'performance'). Use single words for best results as the API does not support complex queries. |
Implementation Reference
- The handler configuration for the 'search_best_practices' tool. Defines validation (requires 'query' string), defaults, execution (delegates to SFCCBestPracticesClient.searchBestPractices), and logging.search_best_practices: { defaults: (args: ToolArguments) => args, validate: (args: ToolArguments, toolName: string) => { ValidationHelpers.validateArguments(args, CommonValidations.requiredString('query'), toolName); }, exec: async (args: ToolArguments, context: ToolExecutionContext) => { const client = context.bestPracticesClient as SFCCBestPracticesClient; return client.searchBestPractices(args.query as string); }, logMessage: (args: ToolArguments) => `Search best practices ${args.query}`, },
- The core implementation of the search logic in SFCCBestPracticesClient.searchBestPractices. Loads all guides, searches line-by-line for query matches with section context, caches results, and returns structured matches.async searchBestPractices(query: string): Promise<Array<{ guide: string; title: string; matches: Array<{section: string; content: string}>; }>> { const cacheKey = `best-practices:search:${query.toLowerCase()}`; const cached = this.cache.getSearchResults(cacheKey); if (cached) {return cached;} const guides = await this.getAvailableGuides(); const results = []; for (const guide of guides) { const guideContent = await this.getBestPracticeGuide(guide.name); if (!guideContent) {continue;} const matches = []; const lines = guideContent.content.split('\n'); let currentSection = ''; for (let i = 0; i < lines.length; i++) { const line = lines[i]; if (line.startsWith('##')) { currentSection = line.replace('##', '').trim(); } if (line.toLowerCase().includes(query.toLowerCase())) { // Get context around the match const start = Math.max(0, i - 2); const end = Math.min(lines.length, i + 3); const context = lines.slice(start, end).join('\n'); matches.push({ section: currentSection || 'Introduction', content: context, }); } } if (matches.length > 0) { results.push({ guide: guide.name, title: guide.title, matches, }); } } this.cache.setSearchResults(cacheKey, results); return results; }
- src/core/tool-definitions.ts:133-146 (schema)The tool schema definition in BEST_PRACTICES_TOOLS array, specifying name, description, and inputSchema with required 'query' string parameter.{ name: 'search_best_practices', description: 'Search across all best practice guides for specific terms, patterns, or concepts. Use this when you need guidance on specific topics like validation, security, performance optimization, error handling, or any development pattern. Perfect for finding relevant best practices without reading entire guides.', inputSchema: { type: 'object', properties: { query: { type: 'string', description: "Search term or concept (e.g., 'validation', 'security', 'performance'). Use single words for best results as the API does not support complex queries.", }, }, required: ['query'], }, },
- src/core/server.ts:119-119 (registration)Registration of BEST_PRACTICES_TOOLS (including search_best_practices schema) into the MCP server's listTools response.tools.push(...BEST_PRACTICES_TOOLS);
- src/core/server.ts:102-102 (registration)Instantiation and registration of BestPracticesToolHandler which handles execution for best practices tools including search_best_practices.new BestPracticesToolHandler(context, 'BestPractices'),