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
| Name | Required | Description | Default |
|---|---|---|---|
| packageName | Yes | Name of the npm package (e.g., 'ember-source', '@glimmer/component') | |
| currentVersion | Yes | Current version being used (e.g., '4.12.0', '1.1.2') |
Implementation Reference
- index.js:406-466 (handler)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, }; } }
- index.js:151-166 (schema)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);
- lib/npm-service.js:116-135 (helper)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, }; }