Skip to main content
Glama

search_npm

Search the npm registry for JavaScript packages by query, with options to limit results. Helps developers find and integrate relevant npm packages efficiently.

Instructions

Search npm registry for JavaScript packages

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of results (default: 5)
queryYesSearch query

Implementation Reference

  • Core handler function that searches the npm registry API for packages matching the query, caches results, and formats the output with package details.
    private async searchNpm(query: string, limit: number = 5): Promise<string> { const cacheKey = `npm:${query}:${limit}`; const cached = cache.get<string>(cacheKey); if (cached) return cached; try { const response = await this.axiosInstance.get( `https://registry.npmjs.org/-/v1/search`, { params: { text: query, size: limit } } ); const results = response.data.objects.map((item: any, i: number) => { const pkg = item.package; return `${i + 1}. ${pkg.name} (v${pkg.version})\n` + ` ${pkg.description || 'No description'}\n` + ` Weekly Downloads: ${pkg.downloads}\n` + ` ${pkg.links.npm}\n`; }).join('\n'); cache.set(cacheKey, results); return results; } catch (error) { throw new McpError( ErrorCode.InternalError, `npm API error: ${error instanceof Error ? error.message : 'Unknown error'}` ); } }
  • src/index.ts:378-397 (registration)
    Registers the 'search_npm' tool in the MCP server's tool list, including name, description, and input schema.
    { name: 'search_npm', description: 'Search npm registry for JavaScript packages', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query' }, limit: { type: 'number', description: 'Maximum number of results (default: 5)', minimum: 1, maximum: 10 } }, required: ['query'] } },
  • Dispatcher case in CallToolRequestHandler that invokes the searchNpm handler and returns the formatted results as MCP content.
    case 'search_npm': { const { query, limit } = request.params.arguments as { query: string; limit?: number }; const results = await this.searchNpm(query, limit); return { content: [ { type: 'text', text: results } ] }; }
  • Helper call to searchNpm within the searchAll tool implementation.
    this.searchNpm(query, limit).catch(error =>

Other Tools

Related 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/nahmanmate/code-research-mcp-server'

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