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';
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It only states the action ('Search for npm packages') without detailing traits like rate limits, authentication needs, pagination, or response format. This leaves significant gaps in understanding how the tool behaves in practice.

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 a single, efficient sentence with no wasted words, making it appropriately concise. However, it lacks front-loaded critical information and could benefit from more structure to enhance clarity, but it avoids unnecessary verbosity.

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

Completeness2/5

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

Given the tool's simplicity (1 parameter, no output schema, no annotations), the description is incomplete. It fails to address behavioral aspects like search result format, limitations, or error handling, which are essential for an agent to use the tool effectively despite the low complexity.

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?

The input schema has 100% description coverage, with the 'query' parameter documented as 'Search query'. The description does not add any meaning beyond this, such as examples or constraints on the query format. With high schema coverage, the baseline score of 3 is appropriate as the schema handles the parameter documentation adequately.

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

Purpose3/5

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

The description 'Search for npm packages' clearly states the verb (search) and resource (npm packages), making the basic purpose understandable. However, it lacks specificity about what kind of search this is (e.g., keyword search, advanced filtering) and doesn't differentiate from potential siblings since none exist, though it remains somewhat vague in scope.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or context for its application. With no sibling tools, this is less critical, but it still offers no usage instructions, leaving the agent to infer based on the tool name alone.

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

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