Skip to main content
Glama
nahmanmate

Code Research MCP Server

by nahmanmate

search_npm

Search the npm registry for JavaScript packages to find dependencies and libraries for development projects.

Instructions

Search npm registry for JavaScript packages

Input Schema

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

Implementation Reference

  • The core handler function that searches the npm registry API for packages matching the query, caches the results, formats them with name, version, description, downloads, and link, and returns the formatted string.
    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:379-397 (registration)
    Registers the 'search_npm' tool in the MCP server's list of tools, including its 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']
      }
    },
  • Defines the input schema for the search_npm tool, specifying query (required string) and optional limit (number 1-10).
    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']
    }
  • The dispatch handler in the CallToolRequestSchema that extracts arguments, calls the searchNpm function, and returns the result as MCP text 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
          }
        ]
      };
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but offers minimal information. It doesn't mention whether this is a read-only operation, what authentication might be required, rate limits, network behavior, or what format results will be returned in. For a search tool with zero annotation coverage, this represents a significant transparency gap.

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 concise at just one sentence with zero wasted words. It's front-loaded with the core purpose and contains no unnecessary information. Every word earns its place in this minimal but complete statement of function.

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?

For a search tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what information will be returned, how results are structured, whether there's pagination, or any behavioral characteristics. The agent would need to guess about the tool's operation and output format based solely on this brief description.

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 description adds no parameter-specific information beyond what's already in the schema, which has 100% coverage with clear descriptions for both 'query' and 'limit' parameters. Since the schema does the heavy lifting, the baseline score of 3 is appropriate - the description doesn't add value but doesn't need to compensate for schema deficiencies either.

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's purpose: searching the npm registry for JavaScript packages. It specifies both the action ('search') and the target resource ('npm registry for JavaScript packages'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from sibling tools like search_pypi or search_github, which is why it doesn't earn a perfect score.

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. With sibling tools like search_pypi, search_github, and search_all available, there's no indication of when npm-specific searching is appropriate or when other search tools might be better suited. This lack of comparative context leaves the agent without usage direction.

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

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