Skip to main content
Glama

ai_search_github

Search GitHub repositories, code, issues, and users to find technical resources. Generates search URLs for accessing comprehensive results through web fetching tools.

Instructions

🐙 GitHub搜索 - 搜索GitHub仓库、代码、问题和用户

【重要】此工具会返回GitHub搜索URL,Claude Code应该使用WebFetch工具访问该URL以获取真实搜索结果。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes搜索关键词
typeNo搜索类型,默认repositoriesrepositories
languageNo编程语言筛选(可选)
sortNo排序方式,默认starsstars

Implementation Reference

  • Handler function for 'ai_search_github' tool. Normalizes input arguments (query, type, language, sort), constructs GitHub search URL with filters, generates comprehensive details including search tips, related searches, and WebFetch instructions, saves to file, and returns formatted text response.
    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 工具访问搜索链接获取结果`
      );
    }
  • Tool metadata definition including name 'ai_search_github', description, and inputSchema specifying parameters: query (required), type (repositories|code|issues|users), language, sort (stars|forks|updated). This is part of AI_TOOLS array used for tool listing.
    {
      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']
      }
  • Registers the list of tools (including ai_search_github) by handling ListToolsRequestSchema and returning the AI_TOOLS array.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: AI_TOOLS,
    }));
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It discloses that the tool returns GitHub search URLs rather than direct results, which is valuable behavioral information not evident from the schema. However, it doesn't mention rate limits, authentication requirements, or error handling for GitHub API constraints.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized with two sentences: one stating the purpose and scope, and another providing critical behavioral guidance about URL returns. The emoji and formatting are slightly decorative but don't detract from clarity. Every sentence adds value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description partially compensates by explaining the URL return behavior. However, for a search tool with 4 parameters and potential complexity (e.g., GitHub API limitations), it lacks details on result format, pagination, or error scenarios, leaving gaps in completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 4 parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema, maintaining the baseline score of 3 for adequate but not enhanced coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool searches GitHub repositories, code, issues, and users, providing a specific verb ('搜索' meaning 'search') and resource ('GitHub'). However, it doesn't explicitly differentiate from sibling tools like ai_search_web or ai_search_stackoverflow, which also perform searches but on different platforms.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by specifying GitHub as the search target, but doesn't provide explicit guidance on when to use this tool versus alternatives like ai_search_web for general web searches or other platform-specific search tools. The mention of using WebFetch for results is procedural rather than contextual guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/adminhuan/smart-search-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server