search_docs
Search documentation using Elasticsearch queries to find specific information in codebases or repositories. Use keywords with ES syntax like "install AND guide" for precise results.
Instructions
Search documentation using the probe search engine.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Elasticsearch query string. Focus on keywords and use ES syntax (e.g., "install AND guide", "configure OR setup", "api NOT internal"). | |
| page | No | Optional page number for pagination of results (e.g., 1, 2, 3...). Default is 1. |
Implementation Reference
- src/index.js:178-203 (handler)The primary handler function that performs the actual documentation search by calling the 'search' function from '@probelabs/probe' with the query and data directory.async executeDocsSearch(args) { try { // Always use the configured data directory const searchPath = config.dataDir; // Create a clean options object const options = { path: searchPath, query: args.query, maxTokens: 10000 // Set default maxTokens // Removed filesOnly, maxResults, session }; console.error("Executing search with options:", JSON.stringify(options, null, 2)); // Call search with the options object const result = await search(options); return result; } catch (error) { console.error('Error executing docs search:', error); throw new McpError( ErrorCode.MethodNotFound, `Error executing docs search: ${error.message || String(error)}` ); } }
- src/index.js:102-116 (schema)Defines the JSON schema for the tool's input parameters: required 'query' string and optional 'page' number.inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Elasticsearch query string. Focus on keywords and use ES syntax (e.g., "install AND guide", "configure OR setup", "api NOT internal").', }, page: { type: 'number', description: 'Optional page number for pagination of results (e.g., 1, 2, 3...). Default is 1.', default: 1, // Set a default value } }, required: ['query'] // 'page' is optional },
- src/index.js:97-119 (registration)Registers the 'search_docs' tool (using config.toolName) with its description and schema in the MCP ListToolsRequestSchema handler.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: config.toolName, // Use configured tool name description: config.toolDescription, // Use configured description inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Elasticsearch query string. Focus on keywords and use ES syntax (e.g., "install AND guide", "configure OR setup", "api NOT internal").', }, page: { type: 'number', description: 'Optional page number for pagination of results (e.g., 1, 2, 3...). Default is 1.', default: 1, // Set a default value } }, required: ['query'] // 'page' is optional }, }, ], }));
- src/index.js:121-170 (registration)Handles MCP CallToolRequestSchema, validates tool name matches 'search_docs', and invokes the executeDocsSearch handler.this.server.setRequestHandler(CallToolRequestSchema, async (request) => { // Check against the configured tool name if (request.params.name !== config.toolName) { throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}. Expected: ${config.toolName}` ); } try { // Log the incoming request for debugging console.error(`Received request for tool: ${request.params.name}`); console.error(`Request arguments: ${JSON.stringify(request.params.arguments)}`); // Ensure arguments is an object if (!request.params.arguments || typeof request.params.arguments !== 'object') { throw new Error("Arguments must be an object"); } const args = request.params.arguments; // Validate required fields if (!args.query) { throw new Error("Query is required in arguments"); } const result = await this.executeDocsSearch(args); return { content: [ { type: 'text', text: result, }, ], }; } catch (error) { console.error(`Error executing ${request.params.name}:`, error); return { content: [ { type: 'text', text: `Error executing ${request.params.name}: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }); }
- src/config.js:27-30 (helper)Default configuration for the tool name and description, loaded and used throughout the server.// MCP Tool configuration toolName: 'search_docs', toolDescription: 'Search documentation using the probe search engine.',