search_best_practices
Search across best practice guides to find specific guidance on validation, security, performance optimization, error handling, or development patterns. Avoid reading entire guides by pinpointing relevant information quickly.
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
- src/core/tool-definitions.ts:133-146 (schema)Input schema definition and description for the search_best_practices MCP tool, including required 'query' 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:98-107 (registration)Registration of tool handlers in the MCP server, including BestPracticesToolHandler which handles 'search_best_practices'.this.handlers = [ new LogToolHandler(context, 'Log'), new JobLogToolHandler(context, 'JobLog'), new DocsToolHandler(context, 'Docs'), new BestPracticesToolHandler(context, 'BestPractices'), new SFRAToolHandler(context, 'SFRA'), new SystemObjectToolHandler(context, 'SystemObjects'), new CodeVersionToolHandler(context, 'CodeVersions'), new CartridgeToolHandler(context, 'Cartridge'), ];
- src/core/server.ts:115-135 (registration)Tool list response handler that includes BEST_PRACTICES_TOOLS containing search_best_practices in the MCP tools list.const tools = []; // Always available tools tools.push(...SFCC_DOCUMENTATION_TOOLS); tools.push(...BEST_PRACTICES_TOOLS); tools.push(...SFRA_DOCUMENTATION_TOOLS); tools.push(...CARTRIDGE_GENERATION_TOOLS); // Conditional tools based on available capabilities if (this.capabilities.canAccessLogs) { tools.push(...LOG_TOOLS); tools.push(...JOB_LOG_TOOLS); } if (this.capabilities.canAccessOCAPI) { tools.push(...SYSTEM_OBJECT_TOOLS); tools.push(...CODE_VERSION_TOOLS); } return { tools }; });
- Handler specification for search_best_practices tool: validation for required 'query' arg, execution delegates to client.searchBestPractices.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}`, },
- Core searchBestPractices implementation: caches results, iterates over guides, searches line-by-line for query matches with context, returns guide titles and matching sections.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; }