ai_search_github
Search GitHub repositories, code, issues, and users with programming language filters and sorting options to find relevant technical resources and projects.
Instructions
🐙 GitHub搜索 - 搜索GitHub仓库、代码、问题和用户
【重要】此工具会返回GitHub搜索URL,Claude Code应该使用WebFetch工具访问该URL以获取真实搜索结果。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| language | No | 编程语言筛选(可选) | |
| query | Yes | 搜索关键词 | |
| sort | No | 排序方式,默认stars | stars |
| type | No | 搜索类型,默认repositories | repositories |
Input Schema (JSON Schema)
{
"properties": {
"language": {
"description": "编程语言筛选(可选)",
"type": "string"
},
"query": {
"description": "搜索关键词",
"type": "string"
},
"sort": {
"default": "stars",
"description": "排序方式,默认stars",
"enum": [
"stars",
"forks",
"updated"
],
"type": "string"
},
"type": {
"default": "repositories",
"description": "搜索类型,默认repositories",
"enum": [
"repositories",
"code",
"issues",
"users"
],
"type": "string"
}
},
"required": [
"query"
],
"type": "object"
}
Implementation Reference
- mcp_server_node.js:90-102 (registration)Tool registration in AI_TOOLS array, including name, description, and input schema for 'ai_search_github'.{ name: 'ai_search_github', description: '🐙 GitHub搜索 - 搜索GitHub仓库、代码、问题和用户\n\n【重要】此工具会返回GitHub搜索URL,Claude Code应该使用WebFetch工具访问该URL以获取真实搜索结果。', inputSchema: { type: 'object', properties: { query: { type: 'string', description: '搜索关键词' }, type: { type: 'string', enum: ['repositories', 'code', 'issues', 'users'], description: '搜索类型,默认repositories', default: 'repositories' }, language: { type: 'string', description: '编程语言筛选(可选)' }, sort: { type: 'string', enum: ['stars', 'forks', 'updated'], description: '排序方式,默认stars', default: 'stars' } }, required: ['query'] }
- mcp_server_node.js:93-101 (schema)Input schema definition for the 'ai_search_github' tool, defining parameters like query, type, language, and sort.inputSchema: { type: 'object', properties: { query: { type: 'string', description: '搜索关键词' }, type: { type: 'string', enum: ['repositories', 'code', 'issues', 'users'], description: '搜索类型,默认repositories', default: 'repositories' }, language: { type: 'string', description: '编程语言筛选(可选)' }, sort: { type: 'string', enum: ['stars', 'forks', 'updated'], description: '排序方式,默认stars', default: 'stars' } }, required: ['query']
- mcp_server_node.js:338-436 (handler)The execution handler for 'ai_search_github' tool. Normalizes inputs, constructs GitHub search URL, generates detailed response with tips, saves results, and instructs to use WebFetch for actual results.case 'ai_search_github': { const rawQuery = normalizeString(args.query); const languageFilter = normalizeString(args.language); const requestedType = normalizeString(args.type).toLowerCase(); const requestedSort = normalizeString(args.sort).toLowerCase(); if (!rawQuery) { throw new Error('搜索关键词不能为空'); } const typeNames = { repositories: '仓库', code: '代码', issues: '问题', users: '用户' }; const sortNames = { stars: 'Star数', forks: 'Fork数', updated: '更新时间' }; const typeKey = pickKey(typeNames, requestedType, 'repositories'); const sortKey = pickKey(sortNames, requestedSort, 'stars'); // 构建搜索URL let searchUrl = `https://github.com/search?q=${encodeURIComponent(rawQuery)}`; if (languageFilter) searchUrl += `+language:${encodeURIComponent(languageFilter)}`; searchUrl += `&type=${typeKey}&s=${sortKey}&o=desc`; // GitHub 搜索技巧 const tips = [ `Stars数量: ${rawQuery} stars:>1000`, `Fork数量: ${rawQuery} forks:>100`, `特定语言: ${rawQuery} language:javascript`, `最近更新: ${rawQuery} pushed:>2024-01-01`, `主题标签: ${rawQuery} topic:react`, `组织仓库: ${rawQuery} org:facebook`, `仓库大小: ${rawQuery} size:>10000` ]; // 相关搜索建议 const relatedSearches = []; if (typeKey === 'repositories') { relatedSearches.push( `${rawQuery} stars:>1000`, `${rawQuery} language:${languageFilter || 'javascript'}`, `awesome ${rawQuery}` ); } else if (typeKey === 'code') { relatedSearches.push( `${rawQuery} extension:js`, `${rawQuery} path:src`, `${rawQuery} filename:README` ); } const detailsContent = `🐙 GitHub 搜索\n\n` + `**搜索关键词**: ${rawQuery}\n` + `**搜索类型**: ${typeNames[typeKey]}\n` + `**编程语言**: ${languageFilter || '全部语言'}\n` + `**排序方式**: ${sortNames[sortKey]}\n\n` + `---\n\n` + `🔗 **搜索链接**: ${searchUrl}\n\n` + `⚠️ **请使用 WebFetch 工具获取搜索结果**:\n` + `\`\`\`javascript\n` + `WebFetch({\n` + ` url: "${searchUrl}",\n` + ` prompt: "提取前10个${typeNames[typeKey]}的名称、描述、${typeKey === 'repositories' ? 'Star数、Fork数' : '相关信息'}和链接"\n` + `})\n` + `\`\`\`\n\n` + `---\n\n` + `💡 **GitHub 高级搜索技巧**:\n` + tips.map(tip => `• ${tip}`).join('\n') + (relatedSearches.length > 0 ? `\n\n📌 **相关搜索建议**:\n` + relatedSearches.map(s => `• ${s}`).join('\n') : '') + `\n\n📚 **更多搜索类型**:\n` + Object.keys(typeNames) .filter(t => t !== typeKey) .map((t) => { let altUrl = `https://github.com/search?q=${encodeURIComponent(rawQuery)}`; if (languageFilter) altUrl += `+language:${encodeURIComponent(languageFilter)}`; altUrl += `&type=${t}&s=${sortKey}&o=desc`; return `• ${typeNames[t]}: ${altUrl}`; }) .join('\n'); const filepath = await saveSearchResult('github-search', rawQuery, detailsContent); return makeTextResponse( `🐙 **GitHub搜索**\n\n` + `**关键词**: ${rawQuery}\n` + `**搜索链接**: ${searchUrl}\n\n` + `✅ 详细信息已保存至: ${filepath || '保存失败'}\n` + `💡 使用 WebFetch 工具访问搜索链接获取结果` ); }
- mcp_server_node.js:54-71 (helper)Helper function to save search results to a markdown file in .search-results directory, used by ai_search_github handler.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; } };