search_documentation
Search Cloudflare documentation to retrieve relevant content based on your query, with options to specify the maximum number of results returned.
Instructions
Searches Cloudflare documentation and returns relevant content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| maxResults | No | Maximum number of results to return | |
| query | Yes | Search query |
Implementation Reference
- src/server.ts:264-325 (handler)Implementation of the search_documentation tool handler. Validates input arguments, simulates a search of Cloudflare documentation using mock data, formats the results as markdown, and returns them as text content. Includes error handling./** * Handle the search_documentation tool */ private async handleSearchDocumentation(args: any) { // Validate arguments if (typeof args !== 'object' || args === null || typeof args.query !== 'string') { throw new McpError(ErrorCode.InvalidParams, 'Invalid arguments for search_documentation'); } const { query, maxResults = 3 } = args; try { // In a real implementation, you would: // 1. Use Cloudflare Browser Rendering to navigate to the docs // 2. Use the search functionality on the docs site // 3. Extract the search results // For this simulation, we'll return mock results const mockResults = [ { title: 'Browser Rendering API Overview', url: 'https://developers.cloudflare.com/browser-rendering/', snippet: 'Cloudflare Browser Rendering is a serverless headless browser service that allows execution of browser actions within Cloudflare Workers.', }, { title: 'REST API Reference', url: 'https://developers.cloudflare.com/browser-rendering/rest-api/', snippet: 'The REST API provides simple endpoints for common browser tasks like fetching content, taking screenshots, and generating PDFs.', }, { title: 'Workers Binding API Reference', url: 'https://developers.cloudflare.com/browser-rendering/workers-binding/', snippet: 'For more advanced use cases, you can use the Workers Binding API with Puppeteer to automate browser interactions.', }, ].slice(0, maxResults); // Format the results const formattedResults = mockResults.map(result => `## [${result.title}](${result.url})\n${result.snippet}\n` ).join('\n'); return { content: [ { type: 'text', text: `# Search Results for "${query}"\n\n${formattedResults}`, }, ], }; } catch (error) { console.error('[Error] Error searching documentation:', error); return { content: [ { type: 'text', text: `Error searching documentation: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }
- src/server.ts:91-107 (registration)Registration of the search_documentation tool in the listTools response, including name, description, and input schema definition.name: 'search_documentation', description: 'Searches Cloudflare documentation and returns relevant content', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query', }, maxResults: { type: 'number', description: 'Maximum number of results to return', }, }, required: ['query'], }, },
- src/server.ts:186-188 (handler)Dispatch logic in the CallToolRequestSchema handler that routes calls to the search_documentation tool to its handler function.case 'search_documentation': console.error(`[API] Searching documentation for: ${args?.query}`); return await this.handleSearchDocumentation(args);