Skip to main content
Glama
btwiuse

npm-search-mcp-server

by btwiuse

search_npm_packages

Find and retrieve npm packages by entering specific search queries to streamline package discovery and integration in your projects.

Instructions

Search for npm packages

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query

Implementation Reference

  • index.ts:65-114 (handler)
    Handler for CallToolRequestSchema that specifically handles 'search_npm_packages' by validating arguments, executing 'npm search' command, and returning stdout as text content or appropriate errors.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => { if (request.params.name !== 'search_npm_packages') { throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}` ); } if (!isValidSearchArgs(request.params.arguments)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid search arguments' ); } const query = request.params.arguments.query; try { const { stdout, stderr } = await execPromise(`npm search ${query}`); if (stderr) { throw new McpError( ErrorCode.InternalError, `npm search error: ${stderr}` ); } return { content: [ { type: 'text', text: stdout, }, ], }; } catch (error) { if (error instanceof McpError) { throw error; } if (error instanceof Error) { throw new McpError( ErrorCode.InternalError, `Unexpected error: ${error.message}` ); } throw new McpError( ErrorCode.InternalError, 'Unexpected error occurred' ); } });
  • JSON Schema defining the input parameters for the search_npm_packages tool: an object with a required 'query' string property.
    inputSchema: { // JSON Schema for parameters type: 'object', properties: { query: { type: 'string', description: 'Search query', }, }, required: ['query'], // Array of required property names },
  • index.ts:47-61 (registration)
    Tool registration in the ListTools response, including name, description, and inputSchema for search_npm_packages.
    { name: 'search_npm_packages', // Unique identifier description: 'Search for npm packages', // Human-readable description inputSchema: { // JSON Schema for parameters type: 'object', properties: { query: { type: 'string', description: 'Search query', }, }, required: ['query'], // Array of required property names }, },
  • Helper type guard function to validate that tool arguments contain a valid 'query' string.
    const isValidSearchArgs = (args: any): args is { query: string } => typeof args === 'object' && args !== null && typeof args.query === 'string';

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/btwiuse/npm-search-mcp-server'

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