Skip to main content
Glama

Get Package Dependencies

get_package_dependencies

Retrieve dependencies, devDependencies, and peerDependencies for any npm package to understand its required components and development setup.

Instructions

Get dependencies, devDependencies, and peerDependencies for a package

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packageNameYes
versionNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
versionYes
dependenciesYes
devDependenciesYes
peerDependenciesYes

Implementation Reference

  • The main handler function that fetches package data from npm registry, validates it using PackageDependenciesSchema, formats the dependencies (regular, dev, peer), and returns both text summary and structured output.
    async ({ packageName, version }) => {
      try {
        const rawData = await fetchPackageData(packageName, version);
        const parseResult = PackageDependenciesSchema.safeParse(rawData);
    
        if (!parseResult.success) {
          throw new Error(
            `Invalid package dependencies structure: ${parseResult.error.message}`
          );
        }
    
        const data = parseResult.data;
    
        const formatDeps = (deps: Record<string, string> | undefined) => {
          if (!deps) return "None";
          return Object.entries(deps)
            .map(([name, version]) => `  ${name}: ${version}`)
            .join("\n");
        };
    
        const output = {
          name: data.name,
          version: data.version,
          dependencies: data.dependencies || {},
          devDependencies: data.devDependencies || {},
          peerDependencies: data.peerDependencies || {},
        };
    
        return {
          content: [
            {
              type: "text",
              text: `Package: ${data.name}\nVersion: ${
                data.version
              }\n\nDependencies:\n${formatDeps(
                data.dependencies
              )}\n\nDev Dependencies:\n${formatDeps(
                data.devDependencies
              )}\n\nPeer Dependencies:\n${formatDeps(data.peerDependencies)}`,
            },
          ],
          structuredContent: output,
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error fetching package dependencies: ${
                error instanceof Error ? error.message : "Unknown error"
              }`,
            },
          ],
          isError: true,
        };
      }
    }
  • src/index.ts:442-517 (registration)
    Registers the 'get_package_dependencies' tool with the MCP server, including title, description, input/output schemas using Zod, and the handler function.
    server.registerTool(
      "get_package_dependencies",
      {
        title: "Get Package Dependencies",
        description:
          "Get dependencies, devDependencies, and peerDependencies for a package",
        inputSchema: {
          packageName: z.string(),
          version: z.string().optional(),
        },
        outputSchema: {
          name: z.string(),
          version: z.string(),
          dependencies: z.record(z.string(), z.string()),
          devDependencies: z.record(z.string(), z.string()),
          peerDependencies: z.record(z.string(), z.string()),
        },
      },
      async ({ packageName, version }) => {
        try {
          const rawData = await fetchPackageData(packageName, version);
          const parseResult = PackageDependenciesSchema.safeParse(rawData);
    
          if (!parseResult.success) {
            throw new Error(
              `Invalid package dependencies structure: ${parseResult.error.message}`
            );
          }
    
          const data = parseResult.data;
    
          const formatDeps = (deps: Record<string, string> | undefined) => {
            if (!deps) return "None";
            return Object.entries(deps)
              .map(([name, version]) => `  ${name}: ${version}`)
              .join("\n");
          };
    
          const output = {
            name: data.name,
            version: data.version,
            dependencies: data.dependencies || {},
            devDependencies: data.devDependencies || {},
            peerDependencies: data.peerDependencies || {},
          };
    
          return {
            content: [
              {
                type: "text",
                text: `Package: ${data.name}\nVersion: ${
                  data.version
                }\n\nDependencies:\n${formatDeps(
                  data.dependencies
                )}\n\nDev Dependencies:\n${formatDeps(
                  data.devDependencies
                )}\n\nPeer Dependencies:\n${formatDeps(data.peerDependencies)}`,
              },
            ],
            structuredContent: output,
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error fetching package dependencies: ${
                  error instanceof Error ? error.message : "Unknown error"
                }`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • Zod schema used to validate and parse the npm package data specifically for dependencies, devDependencies, and peerDependencies.
    const PackageDependenciesSchema = z.object({
      name: z.string(),
      version: z.string(),
      dependencies: z.record(z.string(), z.string()).optional(),
      devDependencies: z.record(z.string(), z.string()).optional(),
      peerDependencies: z.record(z.string(), z.string()).optional(),
    });
  • Helper function that fetches raw package data (including dependencies) from the npm registry API for a given package name and optional version.
    async function fetchPackageData(
      packageName: string,
      version?: string
    ): Promise<any> {
      const versionPath = version || "latest";
      const encodedPackageName = encodeURIComponent(packageName);
      const response = await fetch(
        `https://registry.npmjs.org/${encodedPackageName}/${versionPath}`
      );
    
      if (!response.ok) {
        throw new Error(
          `Failed to fetch package ${packageName}: ${response.statusText}`
        );
      }
    
      return await response.json();
    }
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 states the tool retrieves dependencies but doesn't mention any behavioral traits like whether it's read-only, if it requires authentication, rate limits, or what happens with invalid inputs. This leaves significant gaps for a tool with no annotation coverage.

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 a single, efficient sentence that directly states the tool's function without any unnecessary words. It's appropriately sized and front-loaded, making it easy to understand at a glance.

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

Completeness3/5

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

Given that there's an output schema (which handles return values), no annotations, and low complexity, the description covers the basic purpose but lacks details on usage, parameters, and behavior. It's minimally adequate but has clear gaps, especially with 0% schema coverage and no annotations to compensate.

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?

Schema description coverage is 0%, so the schema provides no parameter details. The description mentions 'for a package', which implies the 'packageName' parameter, but doesn't explain what 'version' does or provide any additional meaning beyond the basic schema. With 0% coverage, this adds minimal value, resulting in a baseline score.

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 action ('Get') and the resource ('dependencies, devDependencies, and peerDependencies for a package'), making the purpose specific and understandable. However, it doesn't explicitly distinguish this tool from siblings like 'get_package_info' or 'get_package_versions', which might also provide dependency-related information, so it doesn't reach the highest 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 siblings such as 'get_package_info' that might include dependencies, there's no indication of when this specific tool is preferred or what its unique context is, leaving usage unclear.

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/JuanSebastianGB/npm-context-agent-mcp'

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