Skip to main content
Glama
starwind-ui

Starwind UI MCP Server

by starwind-ui

get_package_manager

Detect the package manager in a project directory to ensure correct dependency management commands are used.

Instructions

Detects and returns the current package manager information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cwdYesRoot directory to check for lock files
defaultManagerNoDefault package manager to use if detection fails (npm, yarn, pnpm)

Implementation Reference

  • The async handler function that executes the tool logic: logs args, checks for lockfiles, prepares options, calls detectPackageManager, and returns the package manager name and commands.
    handler: async (args: PackageManagerDetectionArgs) => {
      // Debug logging
      log("MCP Tool - get_package_manager called with args:", args);
      log("MCP Tool - Current working directory:", process.cwd());
    
      // Check for lock files directly in the handler
      const lockFiles = {
        pnpm: "pnpm-lock.yaml",
        yarn: "yarn.lock",
        npm: "package-lock.json",
      };
    
      // Log existence of each lock file
      Object.entries(lockFiles).forEach(([pm, file]) => {
        const lockPath = resolve(process.cwd(), file);
        log(`MCP Tool - ${pm} lock file (${file}) exists:`, existsSync(lockPath));
      });
    
      // Only include options that are actually provided
      const options: Record<string, any> = {
        cwd: args.cwd, // cwd is now required
      };
    
      if (args.defaultManager) {
        options.defaultManager = args.defaultManager;
      } else {
        // Set npm as default if not specified
        options.defaultManager = "npm";
      }
    
      log("MCP Tool - Calling detectPackageManager with options:", options);
      const pmInfo = detectPackageManager(options);
      log("MCP Tool - Detection result:", pmInfo);
    
      return {
        name: pmInfo.name,
        commands: {
          install: pmInfo.installCmd,
          add: pmInfo.addCmd,
          remove: pmInfo.removeCmd,
          run: pmInfo.runCmd,
        },
        // cwd: options.cwd,
      };
    },
  • The inputSchema defining the tool's parameters: cwd (required) and optional defaultManager.
    inputSchema: {
      type: "object",
      properties: {
        cwd: {
          type: "string",
          description: "Root directory to check for lock files",
        },
        defaultManager: {
          type: "string",
          description: "Default package manager to use if detection fails (npm, yarn, pnpm)",
          enum: ["npm", "yarn", "pnpm"],
        },
      },
      required: ["cwd"],
    },
  • Registers the packageManagerTool in the central tools Map by name, making it available for the MCP server.
    // Register package manager tool
    tools.set(packageManagerTool.name, packageManagerTool);
  • Core helper function detectPackageManager that checks for lockfiles in priority order (pnpm, yarn, npm) and returns PackageManagerInfo with name and commands.
    export function detectPackageManager(options: PackageManagerOptions = {}): PackageManagerInfo {
      const { cwd = process.cwd(), defaultManager = "npm" } = options;
    
      // Determine priorities for checking lock files
      const packageManagers: PackageManager[] = ["pnpm", "yarn", "npm"];
    
      // Detected package managers
      const detected: PackageManager[] = [];
    
      // Check for each lock file
      for (const pm of packageManagers) {
        const lockFile = LOCK_FILES[pm];
        const lockFilePath = resolve(cwd, lockFile);
    
        console.log(`Checking for ${lockFile} at ${lockFilePath}`);
    
        if (existsSync(lockFilePath)) {
          detected.push(pm);
          // Found a lock file, no need to check others
          break;
        }
      }
    
      // Return the first detected package manager or default
      const packageManager = detected.length > 0 ? detected[0] : defaultManager;
    
      return {
        name: packageManager,
        ...PACKAGE_MANAGER_COMMANDS[packageManager],
      };
    }
  • Type definition for the output structure returned by the tool.
    export interface PackageManagerInfo {
      /** The name of the detected package manager */
      name: PackageManager;
      /** The command to use for installing packages */
      installCmd: string;
      /** The command to use for adding a package */
      addCmd: string;
      /** The command to use for removing a package */
      removeCmd: string;
      /** The command to use for running scripts */
      runCmd: 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 states the tool 'detects and returns' information, implying a read-only operation, but doesn't clarify how detection works (e.g., checking lock files), potential side effects, error handling, or return format. 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 with zero waste. It's front-loaded with the core purpose ('detects and returns'), making it easy to parse. Every word earns its place without redundancy or unnecessary elaboration.

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 complexity (detection logic with fallback behavior) and lack of annotations/output schema, the description is incomplete. It doesn't explain what 'package manager information' includes (e.g., name, version), how detection prioritizes lock files, or what happens if 'cwd' is invalid. For a tool with no structured behavioral data, this leaves too many unknowns.

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 100%, so the schema already documents both parameters ('cwd' and 'defaultManager') with descriptions and enum values. The description adds no additional meaning beyond what the schema provides, such as explaining detection logic or parameter interactions. Baseline 3 is appropriate when the schema does the heavy lifting.

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 with a specific verb ('detects and returns') and resource ('package manager information'). It distinguishes itself from siblings like 'install_component' or 'update_component' by focusing on detection rather than installation or updates. However, it doesn't explicitly differentiate from all siblings (e.g., 'get_documentation' might also retrieve information).

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. It doesn't mention prerequisites (e.g., needing a project directory), exclusions, or comparisons with sibling tools like 'init_project' (which might also involve package manager setup). Usage is implied but not explicitly stated.

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/starwind-ui/starwind-ui-mcp'

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