Skip to main content
Glama

ai_search_npm

Search NPM packages and documentation by entering package names or keywords. This tool generates search URLs for accessing comprehensive package information through web fetching.

Instructions

📦 NPM包搜索 - 搜索NPM包和相关文档

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes包名或关键词
sizeNo返回结果数量,默认10

Implementation Reference

  • Handler for 'ai_search_npm' tool: validates input, generates NPM web and registry search URLs, creates detailed markdown with WebFetch prompts and search tips, saves to file, returns response.
    case 'ai_search_npm': {
      const rawQuery = normalizeString(args.query);
      const resolvedSize = clampNumber(args.size, 1, 100, 10);
    
      if (!rawQuery) {
        throw new Error('搜索关键词不能为空');
      }
    
      const searchUrl = `https://www.npmjs.com/search?q=${encodeURIComponent(rawQuery)}`;
      const registryUrl = `https://registry.npmjs.org/-/v1/search?text=${encodeURIComponent(rawQuery)}&size=${resolvedSize}`;
    
      // NPM 搜索技巧
      const tips = [
        `精确包名: ${rawQuery} (使用完整包名)`,
        `关键词搜索: keywords:${rawQuery}`,
        `作者搜索: author:${rawQuery}`,
        `维护者: maintainer:${rawQuery}`,
        `作用域包: @scope/${rawQuery}`,
        `特定版本: ${rawQuery}@latest`
      ];
    
      // 相关搜索建议
      const relatedSearches = [
        `${rawQuery} typescript`,
        `${rawQuery} cli`,
        `${rawQuery} plugin`,
        `@types/${rawQuery}`
      ];
    
      // 热门类别推荐
      const categories = [
        'react', 'vue', 'express', 'webpack',
        'babel', 'eslint', 'testing', 'cli-tools'
      ];
    
      const detailsContent = `📦 NPM 包搜索\n\n` +
        `**搜索关键词**: ${rawQuery}\n` +
        `**期望结果数**: ${resolvedSize} 个\n\n` +
        `---\n\n` +
        `🔗 **网页搜索**: ${searchUrl}\n` +
        `🔗 **API搜索**: ${registryUrl}\n\n` +
        `⚠️ **请使用 WebFetch 工具获取搜索结果**:\n` +
        `\`\`\`javascript\n` +
        `// 方式1: 网页搜索\n` +
        `WebFetch({\n` +
        `  url: "${searchUrl}",\n` +
        `  prompt: "提取前${resolvedSize}个包的:包名、描述、版本号、周下载量、最后更新时间"\n` +
        `})\n\n` +
        `// 方式2: API搜索 (推荐,结构化数据)\n` +
        `WebFetch({\n` +
        `  url: "${registryUrl}",\n` +
        `  prompt: "解析JSON数据,提取包的名称、描述、版本、作者和下载统计"\n` +
        `})\n` +
        `\`\`\`\n\n` +
        `---\n\n` +
        `💡 **NPM 搜索技巧**:\n` +
        tips.map(tip => `• ${tip}`).join('\n') +
        `\n\n📌 **相关搜索建议**:\n` +
        relatedSearches.map(s => `• ${s}`).join('\n') +
        `\n\n🏷️ **热门包分类**:\n` +
        categories.map(cat => `• ${cat}`).join(' ') +
        `\n\n📚 **直接访问包详情**: https://www.npmjs.com/package/${rawQuery}`;
    
      const filepath = await saveSearchResult('npm-search', rawQuery, detailsContent);
    
      return makeTextResponse(
        `📦 **NPM包搜索**\n\n` +
        `**关键词**: ${rawQuery}\n` +
        `**搜索链接**: ${searchUrl}\n\n` +
        `✅ 详细信息已保存至: ${filepath || '保存失败'}\n` +
        `💡 使用 WebFetch 工具访问搜索链接获取结果`
      );
    }
  • Registration of 'ai_search_npm' tool in AI_TOOLS array: includes name, description, and input schema definition.
    {
      name: 'ai_search_npm',
      description: '📦 NPM包搜索 - 搜索NPM包和相关文档\n\n【重要】此工具会返回NPM搜索URL,Claude Code应该使用WebFetch工具访问该URL以获取真实搜索结果。',
      inputSchema: {
        type: 'object',
        properties: {
          query: { type: 'string', description: '包名或关键词' },
          size: { type: 'number', description: '返回结果数量,默认10', default: 10 }
        },
        required: ['query']
      }
    },
  • Input schema for 'ai_search_npm' tool defining query (required string) and optional size (number).
      inputSchema: {
        type: 'object',
        properties: {
          query: { type: 'string', description: '包名或关键词' },
          size: { type: 'number', description: '返回结果数量,默认10', default: 10 }
        },
        required: ['query']
      }
    },
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing key behavioral traits: it returns NPM search URLs rather than direct results, and requires a secondary WebFetch call to get actual data. This is valuable information about the tool's output format and workflow requirements.

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

Conciseness5/5

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

The description is extremely efficient - two sentences with zero waste. The first sentence states purpose, the second provides critical behavioral guidance. Both sentences earn their place by adding essential information.

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

Completeness4/5

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

For a search tool with no annotations and no output schema, the description provides good completeness by explaining the tool's workflow (returns URLs requiring WebFetch). It covers the essential behavioral context needed to use the tool effectively, though it could mention typical use cases or limitations.

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%, providing good documentation for both parameters. The description doesn't add any parameter-specific information beyond what's in the schema, so it meets the baseline expectation when schema does the heavy lifting.

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 for NPM packages and related documentation with a specific verb ('搜索' - search) and resource ('NPM包' - NPM packages). It distinguishes from siblings by specifying NPM as the target, but doesn't explicitly contrast with other search tools beyond the domain difference.

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

Usage Guidelines4/5

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

The description provides clear context about when to use this tool (for NPM package searches) and explicitly states that Claude Code should use WebFetch tool to access the returned URLs. However, it doesn't specify when NOT to use it or mention alternatives among the sibling search tools.

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