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
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search 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' ); } });
- index.ts:50-60 (schema)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 }, },
- index.ts:15-16 (helper)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';