search
Perform web searches to find information online. Enter a query to retrieve relevant results from the web.
Instructions
Perform a web search query
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query | |
| num | No | Number of results (1-10) |
Implementation Reference
- src/index.ts:127-175 (handler)Executes the 'search' tool: validates input, queries Google Custom Search API, maps results to SearchResult format, returns JSON stringified results or error message.if (request.params.name === 'search') { if (!isValidSearchArgs(request.params.arguments)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid search arguments' ); } const { query, num = 5 } = request.params.arguments; try { const response = await this.axiosInstance.get('', { params: { q: query, num: Math.min(num, 10), }, }); const results: SearchResult[] = response.data.items.map((item: any) => ({ title: item.title, link: item.link, snippet: item.snippet, })); return { content: [ { type: 'text', text: JSON.stringify(results, null, 2), }, ], }; } catch (error) { if (axios.isAxiosError(error)) { return { content: [ { type: 'text', text: `Search API error: ${ error.response?.data?.error?.message ?? error.message }`, }, ], isError: true, }; } throw error; } } else if (request.params.name === 'read_webpage') {
- src/index.ts:89-108 (registration)Registers the 'search' tool in the MCP server's listTools response, providing name, description, and input schema.{ name: 'search', description: 'Perform a web search query', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query', }, num: { type: 'number', description: 'Number of results (1-10)', minimum: 1, maximum: 10, }, }, required: ['query'], }, },
- src/index.ts:92-107 (schema)JSON Schema definition for the 'search' tool input parameters: query (required string), optional num (1-10).inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query', }, num: { type: 'number', description: 'Number of results (1-10)', minimum: 1, maximum: 10, }, }, required: ['query'], },
- src/index.ts:36-42 (helper)Type guard helper function to validate 'search' tool arguments before execution.const isValidSearchArgs = ( args: any ): args is { query: string; num?: number } => typeof args === 'object' && args !== null && typeof args.query === 'string' && (args.num === undefined || typeof args.num === 'number');
- src/index.ts:24-28 (schema)TypeScript interface defining the structure of each search result used in the handler.interface SearchResult { title: string; link: string; snippet: string; }