Skip to main content
Glama

search_docs

Search across Laravel documentation files to find specific content and code examples for development tasks.

Instructions

Search for content across all documentation files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query

Implementation Reference

  • Complete implementation of the search_docs tool: registration, input schema definition, and the handler function that searches for content across all documentation files. The handler reads all markdown files, performs case-insensitive line-by-line search, limits results to 50 matches, and returns JSON with query, match count, and results array containing file path, line number, and matching content.
    // Register tool: Search documentation
    server.registerTool(
      'search_docs',
      {
        description: 'Search for content across all documentation files',
        inputSchema: {
          query: z.string().describe('Search query'),
        },
      },
      async ({ query }) => {
        const files = getDocFiles(DOCS_PATH);
        const queryLower = query.toLowerCase();
        const results = [];
    
        for (const file of files) {
          const content = fs.readFileSync(file.full_path, 'utf-8');
          const lines = content.split('\n');
    
          lines.forEach((line, index) => {
            if (line.toLowerCase().includes(queryLower)) {
              results.push({
                file: file.path,
                line: index + 1,
                content: line.trim(),
              });
            }
          });
    
          if (results.length >= 50) break;
        }
    
        return {
          content: [{
            type: 'text',
            text: JSON.stringify({
              query,
              matches: results.length,
              results: results.slice(0, 50),
            }, null, 2),
          }],
        };
      }
    );
  • Input schema for search_docs tool: defines the 'query' parameter as a required string using zod validation.
    inputSchema: {
      query: z.string().describe('Search query'),
    },
  • Helper function getDocFiles() recursively scans the documentation directory for all markdown files, skipping hidden directories and node_modules. Returns array of objects with file metadata including relative path, full path, and filename. Used by search_docs to get files to search through.
    // Helper function to get all markdown files recursively
    function getDocFiles(dir, basePath = dir) {
      const files = [];
    
      if (!fs.existsSync(dir)) {
        return files;
      }
    
      const entries = fs.readdirSync(dir, { withFileTypes: true });
    
      for (const entry of entries) {
        const fullPath = path.join(dir, entry.name);
        const relativePath = path.relative(basePath, fullPath);
    
        if (entry.isDirectory()) {
          // Skip node_modules and hidden directories
          if (!entry.name.startsWith('.') && entry.name !== 'node_modules') {
            files.push(...getDocFiles(fullPath, basePath));
          }
        } else if (entry.name.endsWith('.md')) {
          files.push({
            path: relativePath,
            full_path: fullPath,
            name: entry.name,
          });
        }
      }
    
      return files;
    }

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/pujandan/mcp-laravel'

If you have feedback or need assistance with the MCP directory API, please join our Discord server