Skip to main content
Glama

compare_npm_versions

Check if an npm package needs updating by comparing your current version with the latest available version. Provides version details to help with dependency management.

Instructions

Compare a current package version with the latest available version on npm. Shows if an update is needed and provides version details to help with dependency upgrades.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packageNameYesName of the npm package (e.g., 'ember-source', '@glimmer/component')
currentVersionYesCurrent version being used (e.g., '4.12.0', '1.1.2')

Implementation Reference

  • Main handler function for the compare_npm_versions tool. Destructures args, calls NpmService.getVersionComparison, formats the comparison result into a markdown response, handles errors.
    async handleCompareNpmVersions(args) { const { packageName, currentVersion } = args; try { const comparison = await this.npmService.getVersionComparison(packageName, currentVersion); let text = `# Version Comparison: ${comparison.packageName}\n\n`; text += `**Current Version:** ${comparison.currentVersion}\n`; text += `**Latest Version:** ${comparison.latestVersion}\n\n`; if (comparison.isLatest) { text += `✅ **Status:** You are using the latest version!\n\n`; } else { text += `⚠️ **Status:** An update is available.\n\n`; } // Dist tags if (Object.keys(comparison.distTags).length > 0) { text += `**Available Tags:**\n`; for (const [tag, version] of Object.entries(comparison.distTags)) { const isCurrent = version === comparison.currentVersion ? ' (current)' : ''; text += ` - ${tag}: ${version}${isCurrent}\n`; } text += `\n`; } // Release dates if (comparison.currentVersionReleaseDate) { text += `**Current Version Released:** ${new Date(comparison.currentVersionReleaseDate).toLocaleDateString()}\n`; } if (comparison.releaseDate) { text += `**Latest Version Released:** ${new Date(comparison.releaseDate).toLocaleDateString()}\n`; } text += `\n**Total Available Versions:** ${comparison.availableVersionsCount}\n`; if (comparison.needsUpdate) { text += `\n**Recommendation:** Consider updating to version ${comparison.latestVersion}. `; text += `Use \`get_npm_package_info\` to see more details about the latest version.`; } return { content: [ { type: "text", text: text, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error comparing versions: ${error.message}`, }, ], isError: true, }; } }
  • Input schema definition for the compare_npm_versions tool, specifying packageName and currentVersion as required string parameters.
    inputSchema: { type: "object", properties: { packageName: { type: "string", description: "Name of the npm package (e.g., 'ember-source', '@glimmer/component')", }, currentVersion: { type: "string", description: "Current version being used (e.g., '4.12.0', '1.1.2')", }, }, required: ["packageName", "currentVersion"], },
  • index.js:147-167 (registration)
    Tool registration in ListToolsRequestHandler, including name, description, and input schema.
    { name: "compare_npm_versions", description: "Compare a current package version with the latest available version on npm. Shows if an update is needed and provides version details to help with dependency upgrades.", inputSchema: { type: "object", properties: { packageName: { type: "string", description: "Name of the npm package (e.g., 'ember-source', '@glimmer/component')", }, currentVersion: { type: "string", description: "Current version being used (e.g., '4.12.0', '1.1.2')", }, }, required: ["packageName", "currentVersion"], }, },
  • index.js:194-195 (registration)
    Dispatch case in CallToolRequestHandler switch statement that routes to the handler.
    case "compare_npm_versions": return await this.handleCompareNpmVersions(args);
  • Core helper method in NpmService that fetches package info from npm registry, compares current version against latest, and returns structured comparison data used by the handler.
    async getVersionComparison(packageName, currentVersion) { const packageInfo = await this.getPackageInfo(packageName); const latestVersion = packageInfo['dist-tags']?.latest; const distTags = packageInfo['dist-tags'] || {}; const isLatest = currentVersion === latestVersion; const availableVersions = Object.keys(packageInfo.versions || {}); return { packageName, currentVersion, latestVersion, isLatest, distTags, needsUpdate: !isLatest, availableVersionsCount: availableVersions.length, releaseDate: packageInfo.time?.[latestVersion] || null, currentVersionReleaseDate: packageInfo.time?.[currentVersion] || null, }; }

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/NullVoxPopuli/ember-mcp'

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