Skip to main content
Glama

search

Search the npm registry for packages by query. Optionally limit results to get relevant packages quickly.

Instructions

Search npm registry for packages

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query
limitNoMax results (default 20)

Implementation Reference

  • src/index.ts:132-153 (registration)
    Registration of the 'search' tool on the McpServer using server.tool(), with name 'search' and description 'Search npm registry for packages'.
    // ── npm search ──
    server.tool(
      "search",
      "Search npm registry for packages",
      {
        query: z.string().describe("Search query"),
        limit: z.number().optional().describe("Max results (default 20)"),
      },
      async ({ query, limit }) => {
        const args = ["search", query, "--json"];
        if (limit) args.push("--limit", String(limit));
        try {
          const { stdout } = await run(args);
          return { content: [{ type: "text", text: stdout }] };
        } catch (e: any) {
          return {
            content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }],
            isError: true,
          };
        }
      },
    );
  • Input schema for the 'search' tool: 'query' (string, required) and 'limit' (number, optional) defined using Zod schemas.
    {
      query: z.string().describe("Search query"),
      limit: z.number().optional().describe("Max results (default 20)"),
    },
  • Handler/execution function for the 'search' tool. Runs 'npm search <query> --json' with optional limit, returns JSON output or an error.
    async ({ query, limit }) => {
      const args = ["search", query, "--json"];
      if (limit) args.push("--limit", String(limit));
      try {
        const { stdout } = await run(args);
        return { content: [{ type: "text", text: stdout }] };
      } catch (e: any) {
        return {
          content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }],
          isError: true,
        };
      }
    },
  • The 'run' helper function that wraps npm execFile calls, used by the search handler to execute 'npm search'.
    async function run(
      args: string[],
      cwd?: string,
    ): Promise<{ stdout: string; stderr: string }> {
      const fullArgs = [...args, ...npmrcArgs];
      const opts: { cwd?: string; timeout: number; env: NodeJS.ProcessEnv; maxBuffer: number } = {
        timeout: 120_000,
        maxBuffer: 10 * 1024 * 1024, // 10MB buffer for large outputs
        env: { ...process.env, NO_COLOR: "1" },
      };
      if (cwd) opts.cwd = cwd;
      return exec(NPM, fullArgs, opts);
    }
  • src/index.ts:1222-1225 (registration)
    Sandbox registration of the 'search' tool (no-op implementation for Smithery sandbox testing).
    sandbox.tool("search", "Search npm registry for packages", {
      query: z.string().describe("Search query"),
      limit: z.number().optional().describe("Max results"),
    }, noop);
Behavior2/5

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

With no annotations, the description must disclose behavior. It only states the action without revealing if it's read-only, required permissions, rate limits, or result format. This is insufficient for an agent to understand side effects or constraints.

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, front-loaded sentence that efficiently captures the core purpose. However, it could be structured with more details without losing conciseness.

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 simple search tool with two parameters and no output schema, the description lacks essential context such as search query syntax, default limit behavior, pagination, and expected return format. The agent cannot reliably use the tool based on this description alone.

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% coverage with descriptions for both parameters. The description adds no additional meaning beyond what the schema provides, so it meets the baseline but does not enhance understanding.

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 verb 'Search' and the resource 'npm registry for packages'. It distinguishes from many sibling tools by specifying the registry search function, though it does not explicitly differentiate from the sibling 'query' tool which may overlap in function.

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?

No guidance is provided on when to use this tool versus alternatives like 'view', 'dist-tag', or 'query'. The description lacks context for appropriate usage scenarios or exclusions.

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/mikusnuz/npm-mcp'

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