ai_search_web
Search the web using Google, Bing, Baidu, or Sogou to find information and generate search result URLs for further investigation.
Instructions
🔍 网络搜索 - 通用网络搜索(Google/Bing/百度/搜狗)
【重要】此工具会返回搜索URL,Claude Code应该使用WebFetch工具访问该URL以获取真实搜索结果。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | No | 期望的结果数量,默认10 | |
| engine | No | 搜索引擎,默认baidu | baidu |
| query | Yes | 搜索关键词 |
Implementation Reference
- mcp_server_node.js:262-336 (handler)The handler for the 'ai_search_web' tool. It processes the query, engine, and count parameters, constructs a search URL for the specified engine (Google, Bing, Baidu, or Sogou), generates search tips and related suggestions, saves detailed information to a file, and returns a text response with instructions to use WebFetch for actual content retrieval.case 'ai_search_web': { const rawQuery = normalizeString(args.query); const requestedEngine = normalizeString(args.engine).toLowerCase(); const resolvedCount = clampNumber(args.count, 1, 50, 10); if (!rawQuery) { throw new Error('搜索关键词不能为空'); } const searchUrls = { google: `https://www.google.com/search?q=${encodeURIComponent(rawQuery)}&num=${resolvedCount}`, bing: `https://www.bing.com/search?q=${encodeURIComponent(rawQuery)}&count=${resolvedCount}`, baidu: `https://www.baidu.com/s?wd=${encodeURIComponent(rawQuery)}&rn=${resolvedCount}`, sogou: `https://www.sogou.com/web?query=${encodeURIComponent(rawQuery)}&num=${resolvedCount}` }; const engineNames = { google: 'Google', bing: 'Bing (必应)', baidu: '百度', sogou: '搜狗' }; const resolvedEngine = pickKey(searchUrls, requestedEngine, 'baidu'); const searchUrl = searchUrls[resolvedEngine]; const tips = [ `精确匹配: "${rawQuery}"`, `排除关键词: ${rawQuery} -排除词`, `限定站点: site:github.com ${rawQuery}`, `文件类型: ${rawQuery} filetype:pdf`, `时间范围: ${rawQuery} after:2023`, ]; const relatedSearches = [ `${rawQuery} 教程`, `${rawQuery} 最佳实践`, `${rawQuery} 示例`, `${rawQuery} 文档` ]; const detailsContent = `🔍 网络搜索\n\n` + `**搜索关键词**: ${rawQuery}\n` + `**搜索引擎**: ${engineNames[resolvedEngine]}\n` + `**期望结果数**: ${resolvedCount} 条\n\n` + `---\n\n` + `🔗 **搜索链接**: ${searchUrl}\n\n` + `⚠️ **请使用 WebFetch 工具获取搜索结果**:\n` + `\`\`\`javascript\n` + `WebFetch({\n` + ` url: "${searchUrl}",\n` + ` prompt: "提取前${resolvedCount}条搜索结果,包括:标题、链接、摘要"\n` + `})\n` + `\`\`\`\n\n` + `---\n\n` + `💡 **高级搜索技巧**:\n` + tips.map(tip => `• ${tip}`).join('\n') + `\n\n📌 **相关搜索建议**:\n` + relatedSearches.map(s => `• ${s}`).join('\n') + `\n\n🌐 **其他搜索引擎**:\n` + Object.keys(searchUrls) .filter(e => e !== resolvedEngine) .map(e => `• ${engineNames[e]}: ${searchUrls[e]}`) .join('\n'); const filepath = await saveSearchResult('web-search', rawQuery, detailsContent); return makeTextResponse( `🔍 **网络搜索** (${engineNames[resolvedEngine]})\n\n` + `**关键词**: ${rawQuery}\n` + `**搜索链接**: ${searchUrl}\n\n` + `✅ 详细信息已保存至: ${filepath || '保存失败'}\n` + `💡 使用 WebFetch 工具访问搜索链接获取结果` ); }
- mcp_server_node.js:77-89 (schema)The tool schema definition for 'ai_search_web', including name, description, and inputSchema specifying parameters: query (required string), engine (enum with default 'baidu'), and count (number with default 10).{ name: 'ai_search_web', description: '🔍 网络搜索 - 通用网络搜索(Google/Bing/百度/搜狗)\n\n【重要】此工具会返回搜索URL,Claude Code应该使用WebFetch工具访问该URL以获取真实搜索结果。', inputSchema: { type: 'object', properties: { query: { type: 'string', description: '搜索关键词' }, engine: { type: 'string', enum: ['google', 'bing', 'baidu', 'sogou'], description: '搜索引擎,默认baidu', default: 'baidu' }, count: { type: 'number', description: '期望的结果数量,默认10', default: 10 } }, required: ['query'] } },
- mcp_server_node.js:252-254 (registration)Registration of all tools, including 'ai_search_web', via the ListToolsRequest handler that returns the AI_TOOLS array.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: AI_TOOLS, }));
- mcp_server_node.js:54-71 (helper)Helper function used by 'ai_search_web' and other tools to save detailed search results and tips to a markdown file in .search-results directory.const saveSearchResult = async (toolName, query, details) => { try { const resultsDir = join(process.cwd(), '.search-results'); if (!existsSync(resultsDir)) { await mkdir(resultsDir, { recursive: true }); } const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, -5); const filename = `${toolName}-${timestamp}.md`; const filepath = join(resultsDir, filename); await writeFile(filepath, details, 'utf-8'); return filepath; } catch (error) { console.error('Failed to save search result:', error); return null; } };
- mcp_server_node.js:25-32 (helper)Helper function to format the tool response as MCP content with text type.const makeTextResponse = (text) => ({ content: [ { type: 'text', text, }, ], });