Skip to main content
Glama

packageSearch

Read-onlyIdempotent

Find NPM and Python packages with their repository URLs to locate code sources and research dependencies from imports or configuration files.

Instructions

Find NPM/Python packages & their repository URLs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queriesYesResearch queries for packageSearch (1-3 queries per call for optimal resource management). Review schema before use for optimal results

Implementation Reference

  • Core execution logic for packageSearch tool: processes bulk queries, calls searchPackage API, handles errors, enriches results with repo info and deprecation status, generates contextual hints.
    async function searchPackages(
      queries: PackageSearchQuery[]
    ): Promise<CallToolResult> {
      return executeBulkOperation(
        queries,
        async (query: PackageSearchQuery, _index: number) => {
          try {
            const apiResult = await searchPackage(query);
    
            if (isPackageSearchError(apiResult)) {
              return createErrorResult(apiResult.error, query);
            }
    
            const packages = (apiResult.packages as PackageResult[]).map(pkg => {
              const repoUrl = getPackageRepo(pkg);
              const { owner, repo } = parseRepoInfo(repoUrl);
              if (owner && repo) {
                return { ...pkg, owner, repo };
              }
              return pkg;
            });
    
            const result = {
              packages,
              totalFound: apiResult.totalFound,
            };
    
            const hasContent = result.packages.length > 0;
    
            let deprecationInfo: DeprecationInfo | null = null;
            if (hasContent && query.ecosystem === 'npm' && result.packages[0]) {
              deprecationInfo = await checkNpmDeprecation(
                getPackageName(result.packages[0])
              );
            }
    
            // Generate context-specific hints for package search
            const extraHints = hasContent
              ? generateSuccessHints(result, query.ecosystem, deprecationInfo)
              : generateEmptyHints(query);
    
            // Use unified pattern with extraHints for package-specific guidance
            return createSuccessResult(
              query,
              result,
              hasContent,
              TOOL_NAMES.PACKAGE_SEARCH,
              { extraHints }
            );
          } catch (error) {
            return handleCatchError(error, query);
          }
        },
        {
          toolName: TOOL_NAMES.PACKAGE_SEARCH,
          keysPriority: ['packages', 'totalFound', 'error'],
        }
      );
    }
  • Registers the 'packageSearch' tool (TOOL_NAMES.PACKAGE_SEARCH) with MCP server, including input schema, description, annotations, and security-wrapped handler.
    export async function registerPackageSearchTool(
      server: McpServer,
      callback?: ToolInvocationCallback
    ): Promise<RegisteredTool | null> {
      const npmAvailable = await checkNpmAvailability(10000);
      if (!npmAvailable) {
        return null;
      }
    
      return server.registerTool(
        TOOL_NAMES.PACKAGE_SEARCH,
        {
          description: DESCRIPTIONS[TOOL_NAMES.PACKAGE_SEARCH],
          // Type assertion needed: Zod discriminatedUnion types don't fully align with MCP SDK's expected schema type
          inputSchema: PackageSearchBulkQuerySchema as Parameters<
            typeof server.registerTool
          >[1]['inputSchema'],
          annotations: {
            title: 'Package Search',
            readOnlyHint: true,
            destructiveHint: false,
            idempotentHint: true,
            openWorldHint: true,
          },
        },
        withSecurityValidation(
          TOOL_NAMES.PACKAGE_SEARCH,
          async (
            args: {
              queries: PackageSearchQuery[];
            },
            _authInfo,
            _sessionId
          ): Promise<CallToolResult> => {
            const queries = args.queries || [];
    
            await invokeCallbackSafely(
              callback,
              TOOL_NAMES.PACKAGE_SEARCH,
              queries
            );
    
            return searchPackages(queries);
          }
        )
      );
    }
  • Zod input schema: discriminated union for npm/python package queries (name, searchLimit, ecosystem-specific options), plus bulk query schema used in registration.
    export const PackageSearchQuerySchema = z.discriminatedUnion('ecosystem', [
      NpmPackageQuerySchema,
      PythonPackageQuerySchema,
    ]);
    
    export type NpmPackageQuery = z.infer<typeof NpmPackageQuerySchema>;
    export type PythonPackageQuery = z.infer<typeof PythonPackageQuerySchema>;
    export type PackageSearchQuery = NpmPackageQuery | PythonPackageQuery;
    export type PackageSearchBulkParams = {
      queries: PackageSearchQuery[];
    };
    
    export const PackageSearchBulkQuerySchema = createBulkQuerySchema(
      TOOL_NAMES.PACKAGE_SEARCH,
      PackageSearchQuerySchema
    );
  • ToolConfig entry that wires registerPackageSearchTool into the ALL_TOOLS array for automatic registration via toolsManager.
    export const PACKAGE_SEARCH: ToolConfig = {
      name: TOOL_NAMES.PACKAGE_SEARCH,
      description: getDescription(TOOL_NAMES.PACKAGE_SEARCH),
      isDefault: true,
      isLocal: false,
      type: 'search',
      fn: registerPackageSearchTool,
    };
  • Generic registration loop in registerTools() that invokes each tool's fn (including packageSearch via toolConfig), with filtering based on config.
    for (const tool of ALL_TOOLS) {
      // Step 1: Check if tool should be enabled
      if (!isToolEnabled(tool, localEnabled, filterConfig)) {
        continue;
      }
    
      // Step 2: Check if tool exists in metadata
      try {
        if (!isToolInMetadata(tool.name)) {
          await logSessionError(
            tool.name,
            TOOL_METADATA_ERRORS.INVALID_FORMAT.code
          );
          continue;
        }
      } catch {
        await logSessionError(
          tool.name,
          TOOL_METADATA_ERRORS.INVALID_API_RESPONSE.code
        );
        continue;
      }
    
      // Step 3: Register the tool
      try {
        const result = await tool.fn(server, callback);
        if (result !== null) {
          successCount++;
        }
      } catch {
        failedTools.push(tool.name);
      }
    }
Behavior4/5

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

While annotations already declare readOnlyHint=true, idempotentHint=true, and destructiveHint=false, the description adds valuable behavioral context beyond annotations. It explains ecosystem-specific limitations (Python always returns 1 result regardless of searchLimit due to PyPI limitation), field naming differences (Python returns 'repository' field instead of 'repoUrl'), and naming conventions (underscores vs dashes). However, it doesn't mention rate limits or authentication requirements, which would be useful additional context.

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 uses a structured format with clear sections (<when>, <fromTool>, <gotchas>, <examples>) that makes information easy to parse. While somewhat lengthy, every section adds value and the information is well-organized. The front-loaded purpose statement is clear, though the structured format adds some verbosity that could potentially be streamlined.

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

Completeness5/5

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

Given the tool's complexity (supporting multiple ecosystems with different behaviors) and the absence of an output schema, the description provides comprehensive context. It covers purpose, usage scenarios, behavioral differences between ecosystems, warnings, examples, and integration with sibling tools. This level of detail compensates well for the lack of output schema and provides the agent with sufficient information to use the tool effectively.

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?

With 100% schema description coverage, the schema already documents all parameters thoroughly. The description adds some semantic context about parameter usage (e.g., 'Use searchLimit=1 if name known | searchLimit=5 for searching alternatives'), but most parameter meaning is already captured in the schema. The baseline of 3 is appropriate when the schema does the heavy lifting for parameter documentation.

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

Purpose5/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: 'Find NPM/Python packages & their repository URLs' with specific verbs ('find', 'lookup') and resources ('packages', 'repository URLs'). It distinguishes from sibling tools by explicitly warning against using githubSearchCode or githubSearchRepositories for package discovery when this tool is available, establishing clear differentiation.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool through the <when> section ('Fast lookup of package repository...', 'Researching libraries | Finding dependencies'), when not to use it (<gotchas> section warns against using github tools for package discovery), and alternatives (<fromTool> section mentions comparing alternatives and trying semantic variants). This comprehensive guidance helps the agent make correct tool selection decisions.

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/bgauryy/octocode-mcp'

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