check_package_updates
Check for updates to a specific Dart/Flutter package or compare versions to maintain current dependencies.
Instructions
Check for updates to a specific package or compare versions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| packageName | Yes | Name of the package to check for updates | |
| currentVersion | No | Current version to compare against (optional) |
Implementation Reference
- src/pubdev-mcp.js:232-264 (handler)Main handler function that checks for package updates by fetching the latest version from pub.dev API, comparing it to the current version if provided, calculating if an update is available and versions behind, then returning a JSON-formatted status.async checkPackageUpdates(packageName, currentVersion) { const url = `https://pub.dev/api/packages/${packageName}`; const data = await this.fetchWithCache(url, `package-${packageName}`); const latestVersion = data.latest.version; const latestPublished = data.latest.published; let updateStatus = { packageName, currentVersion: currentVersion || 'unknown', latestVersion, latestPublished, updateAvailable: false, versionsBehind: 0 }; if (currentVersion) { updateStatus.updateAvailable = this.compareVersions(currentVersion, latestVersion) < 0; // Get version history to count versions behind const versionsUrl = `https://pub.dev/api/packages/${packageName}/versions`; const versionsData = await this.fetchWithCache(versionsUrl, `versions-${packageName}`); const currentIndex = versionsData.versions.findIndex((v) => v.version === currentVersion); const latestIndex = versionsData.versions.findIndex((v) => v.version === latestVersion); if (currentIndex > -1 && latestIndex > -1) { updateStatus.versionsBehind = currentIndex - latestIndex; } } return { content: [ { type: "text", text: JSON.stringify(updateStatus, null, 2) } ] }; }
- src/pubdev-mcp.js:39-56 (schema)Input schema definition for the check_package_updates tool, specifying packageName as required string and optional currentVersion string.{ name: "check_package_updates", description: "Check for updates to a specific package or compare versions", inputSchema: { type: "object", properties: { packageName: { type: "string", description: "Name of the package to check for updates" }, currentVersion: { type: "string", description: "Current version to compare against (optional)" } }, required: ["packageName"] } },
- src/pubdev-mcp.js:156-157 (registration)Registration in the tool dispatch switch statement, mapping the tool name to the checkPackageUpdates handler method.case "check_package_updates": return await this.checkPackageUpdates(args.packageName, args.currentVersion);
- src/pubdev-mcp.js:424-436 (helper)Helper function to compare two semantic version strings, used to determine if currentVersion is behind latestVersion.compareVersions(version1, version2) { const v1Parts = version1.split('.').map(Number); const v2Parts = version2.split('.').map(Number); for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) { const v1Part = v1Parts[i] || 0; const v2Part = v2Parts[i] || 0; if (v1Part < v2Part) return -1; if (v1Part > v2Part) return 1; } return 0; }
- src/pubdev-mcp.js:182-200 (helper)Caching helper for API fetches to pub.dev, used by the handler to retrieve package and versions data.async fetchWithCache(url, cacheKey) { const cached = this.packageCache.get(cacheKey); const now = Date.now(); if (cached && (now - cached.timestamp) < this.CACHE_DURATION) { return cached.data; } const response = await fetch(url, { headers: { 'User-Agent': 'MCP-PubDev-Server/1.0.0', 'Accept': 'application/json' } }); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } const data = await response.json(); this.packageCache.set(cacheKey, { data, timestamp: now }); return data; }