Skip to main content
Glama
MausRundung

Project Explorer MCP Server

by MausRundung

check_outdated

Check for outdated npm packages in a project's package.json. Analyzes dependencies to show available newer versions, with configurable options for dev dependencies and output format (detailed, summary, raw). Requires npm installed.

Instructions

Check for outdated npm packages in package.json using 'npm outdated'. Analyzes the current project's dependencies and shows which packages have newer versions available. Requires npm to be installed and accessible from the command line.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectPathNoPath to the directory containing package.json. Defaults to the first allowed directory if not specified.
includeDevDependenciesNoWhether to include dev dependencies in the check
outputFormatNoFormat of the output: detailed (full info), summary (counts only), or raw (npm command output)detailed

Implementation Reference

  • src/index.ts:41-42 (registration)
    Registration of the check_outdated tool in the tools list
      checkOutdatedTool
    ]
  • src/index.ts:68-69 (registration)
    Routing for the check_outdated tool name to its handler
    case "check_outdated":
      return await handleCheckOutdated(args, ALLOWED_DIRECTORIES);
  • Tool definition with name 'check_outdated', description, and input schema
    export const checkOutdatedTool = {
      name: "check_outdated",
      description: "Check for outdated npm packages in package.json using 'npm outdated'. Analyzes the current project's dependencies and shows which packages have newer versions available. Requires npm to be installed and accessible from the command line.",
      inputSchema: {
        type: "object",
        properties: {
          projectPath: {
            type: "string",
            description: "Path to the directory containing package.json. Defaults to the first allowed directory if not specified."
          },
          includeDevDependencies: {
            type: "boolean",
            description: "Whether to include dev dependencies in the check",
            default: true
          },
          outputFormat: {
            type: "string",
            enum: ["detailed", "summary", "raw"],
            description: "Format of the output: detailed (full info), summary (counts only), or raw (npm command output)",
            default: "detailed"
          }
        },
        additionalProperties: false
      }
    };
  • Main handler that executes npm outdated --json, parses results, and returns formatted output
    export async function handleCheckOutdated(args: any, allowedDirectories: string[]) {
      const { 
        projectPath = allowedDirectories[0], 
        includeDevDependencies = true,
        outputFormat = "detailed"
      } = args;
    
      if (!projectPath) {
        throw new McpError(ErrorCode.InvalidParams, "No project path specified and no allowed directories available");
      }
    
      // Resolve to absolute path
      const resolvedPath = path.resolve(projectPath);
    
      // Check if path is within allowed directories
      const isPathAllowed = allowedDirectories.some(dir => {
        const normalizedDir = path.resolve(dir).replace(/\\/g, '/');
        const normalizedPath = resolvedPath.replace(/\\/g, '/');
        return normalizedPath === normalizedDir || normalizedPath.startsWith(normalizedDir + '/');
      });
    
      if (!isPathAllowed) {
        throw new McpError(ErrorCode.InvalidParams, `Path "${resolvedPath}" is not within allowed directories`);
      }
    
      // Check if package.json exists
      const packageJsonPath = path.join(resolvedPath, 'package.json');
      if (!fs.existsSync(packageJsonPath)) {
        throw new McpError(ErrorCode.InvalidParams, `package.json not found in "${resolvedPath}"`);
      }
    
      try {
        // Build npm outdated command
        let command = 'npm outdated --json';
        if (!includeDevDependencies) {
          command += ' --prod';
        }
    
        // Execute npm outdated command
        const { stdout, stderr } = await execAsync(command, { 
          cwd: resolvedPath,
          timeout: 10000 // 10 second timeout
        });
    
        let outdatedData: any = {};
        let rawOutput = stdout || stderr;
    
        // npm outdated returns exit code 1 when packages are outdated, so we need to handle both stdout and stderr
        if (stdout && stdout.trim()) {
          try {
            outdatedData = JSON.parse(stdout);
          } catch (parseError) {
            // If JSON parsing fails, treat as no outdated packages
            outdatedData = {};
          }
        } else if (stderr && stderr.includes('{')) {
          try {
            // Sometimes npm outputs to stderr
            outdatedData = JSON.parse(stderr);
          } catch (parseError) {
            outdatedData = {};
          }
        }
    
        // Parse the outdated packages
        const outdatedPackages: OutdatedPackage[] = [];
        
        for (const [packageName, info] of Object.entries(outdatedData)) {
          if (typeof info === 'object' && info !== null) {
            const packageInfo = info as any;
            outdatedPackages.push({
              package: packageName,
              current: packageInfo.current || 'unknown',
              wanted: packageInfo.wanted || 'unknown', 
              latest: packageInfo.latest || 'unknown',
              location: packageInfo.location || resolvedPath,
              type: packageInfo.type || 'dependencies'
            });
          }
        }
    
        const totalOutdated = outdatedPackages.length;
        const hasOutdated = totalOutdated > 0;
    
        let message: string;
        if (!hasOutdated) {
          message = "All packages are up to date! 🎉";
        } else {
          message = `Found ${totalOutdated} outdated package${totalOutdated === 1 ? '' : 's'}`;
          
          if (outputFormat === "detailed") {
            message += ":\n\n";
            outdatedPackages.forEach(pkg => {
              message += `📦 ${pkg.package}\n`;
              message += `   Current: ${pkg.current}\n`;
              message += `   Wanted:  ${pkg.wanted}\n`;
              message += `   Latest:  ${pkg.latest}\n`;
              message += `   Type:    ${pkg.type}\n\n`;
            });
            message += "Run 'npm update' to update to wanted versions or 'npm install <package>@latest' for latest versions.";
          } else if (outputFormat === "summary") {
            const depTypes = outdatedPackages.reduce((acc, pkg) => {
              acc[pkg.type] = (acc[pkg.type] || 0) + 1;
              return acc;
            }, {} as Record<string, number>);
            
            message += "\n\nBreakdown by type:\n";
            Object.entries(depTypes).forEach(([type, count]) => {
              message += `- ${type}: ${count}\n`;
            });
          }
        }
    
        let result = `# NPM Outdated Check Results\n\n**Project:** ${packageJsonPath}\n**Total Packages Checked:** ${Object.keys(outdatedData).length}\n\n`;
        
        if (outputFormat === "raw") {
          result += `**Raw Output:**\n\`\`\`\n${rawOutput}\n\`\`\`\n\n`;
        }
        
        result += message;
        
        return {
          content: [
            {
              type: "text",
              text: result
            }
          ]
        };
    
      } catch (error: any) {
        // npm outdated exits with code 1 when packages are outdated, this is normal
        if (error.code === 1) {
          // This is the normal case - packages are outdated
          let outdatedData: any = {};
          let rawOutput = error.stdout || error.stderr || '';
    
          // Try to parse JSON from stdout or stderr
          const outputToParse = error.stdout || error.stderr || '';
          if (outputToParse && outputToParse.trim()) {
            try {
              outdatedData = JSON.parse(outputToParse);
            } catch (parseError) {
              // If JSON parsing fails, treat as no outdated packages
              outdatedData = {};
            }
          }
    
          // Parse the outdated packages
          const outdatedPackages: OutdatedPackage[] = [];
          
          for (const [packageName, info] of Object.entries(outdatedData)) {
            if (typeof info === 'object' && info !== null) {
              const packageInfo = info as any;
              outdatedPackages.push({
                package: packageName,
                current: packageInfo.current || 'unknown',
                wanted: packageInfo.wanted || 'unknown', 
                latest: packageInfo.latest || 'unknown',
                location: packageInfo.location || resolvedPath,
                type: packageInfo.type || 'dependencies'
              });
            }
          }
    
          const totalOutdated = outdatedPackages.length;
          const hasOutdated = totalOutdated > 0;
    
          let message: string;
          if (!hasOutdated) {
            message = "All packages are up to date! 🎉";
          } else {
            message = `Found ${totalOutdated} outdated package${totalOutdated === 1 ? '' : 's'}`;
            
            if (outputFormat === "detailed") {
              message += ":\n\n";
              outdatedPackages.forEach(pkg => {
                message += `📦 ${pkg.package}\n`;
                message += `   Current: ${pkg.current}\n`;
                message += `   Wanted:  ${pkg.wanted}\n`;
                message += `   Latest:  ${pkg.latest}\n`;
                message += `   Type:    ${pkg.type}\n\n`;
              });
              message += "Run 'npm update' to update to wanted versions or 'npm install <package>@latest' for latest versions.";
            } else if (outputFormat === "summary") {
              const depTypes = outdatedPackages.reduce((acc, pkg) => {
                acc[pkg.type] = (acc[pkg.type] || 0) + 1;
                return acc;
              }, {} as Record<string, number>);
              
              message += "\n\nBreakdown by type:\n";
              Object.entries(depTypes).forEach(([type, count]) => {
                message += `- ${type}: ${count}\n`;
              });
            }
          }
    
          let result = `# NPM Outdated Check Results\n\n**Project:** ${packageJsonPath}\n**Total Packages Checked:** ${Object.keys(outdatedData).length}\n\n`;
          
          if (outputFormat === "raw") {
            result += `**Raw Output:**\n\`\`\`\n${rawOutput}\n\`\`\`\n\n`;
          }
          
          result += message;
          
          return {
            content: [
              {
                type: "text",
                text: result
              }
            ]
          };
        }
    
        let errorMessage = `Failed to check outdated packages: ${error.message}`;
        
        if (error.code === 'ENOENT') {
          errorMessage = "npm command not found. Please ensure npm is installed and available in your PATH.";
        } else if (error.message.includes('timeout')) {
          errorMessage = "npm outdated command timed out. The operation took too long to complete.";
        } else if (error.message.includes('ENOTDIR') || error.message.includes('ENOENT')) {
          errorMessage = `Invalid project directory: "${resolvedPath}"`;
        }
    
        throw new McpError(ErrorCode.InternalError, errorMessage);
      }
    }
  • TypeScript interfaces for OutdatedPackage and OutdatedResult
    export interface OutdatedPackage {
      package: string;
      current: string;
      wanted: string;
      latest: string;
      location: string;
      type: 'dependencies' | 'devDependencies' | 'peerDependencies' | 'optionalDependencies';
    }
Behavior4/5

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

No annotations are provided, so the description carries full burden. It states the tool uses 'npm outdated', implying a read-only operation, and mentions prerequisites. It does not disclose error handling or performance, but the behavior is adequately transparent.

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 concise with two sentences. The first sentence clearly states the action, and the second adds prerequisite and scope. No unnecessary words.

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

Completeness4/5

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

Given three parameters and no output schema, the description covers the tool's purpose, prerequisite, and implied output. It could mention output format details, but the outputFormat parameter already addresses that. Adequate for the complexity.

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 coverage is 100% with parameter descriptions. The description adds context about overall purpose but does not provide additional meaning beyond what the schema already offers. Baseline 3 is appropriate.

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 checks for outdated npm packages using 'npm outdated', specifying the resource (package.json) and action. It distinguishes itself from sibling tools which are file operations and project exploration.

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

Usage Guidelines4/5

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

The description includes a prerequisite (npm installed) and implies the tool is for dependency analysis. It does not explicitly state when to use or not use, but the context is clear enough.

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/MausRundung/mcp-explorer'

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