compare_package_versions
Compare two versions of a Dart or Flutter package to identify differences. Analyze changes in functionality, dependencies, or documentation between specified versions for informed decision-making.
Instructions
Compare two versions of a package and show differences
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fromVersion | Yes | Source version to compare from | |
| packageName | Yes | Name of the package to compare | |
| toVersion | Yes | Target version to compare to |
Implementation Reference
- src/pubdev-mcp.js:354-391 (handler)The core handler function for the 'compare_package_versions' tool. It fetches package versions from pub.dev API, retrieves pubspec data for the from and to versions, computes dependency changes using helper, and returns a JSON-structured comparison including versions, publish dates, dependencies, and changes.async comparePackageVersions(packageName, fromVersion, toVersion) { const versionsUrl = `https://pub.dev/api/packages/${packageName}/versions`; const data = await this.fetchWithCache(versionsUrl, `versions-${packageName}`); const fromVersionData = data.versions.find((v) => v.version === fromVersion); const toVersionData = data.versions.find((v) => v.version === toVersion); if (!fromVersionData || !toVersionData) { throw new Error('One or both versions not found'); } const comparison = { packageName, comparison: { from: { version: fromVersion, published: fromVersionData.published, dependencies: fromVersionData.pubspec?.dependencies || {}, devDependencies: fromVersionData.pubspec?.dev_dependencies || {} }, to: { version: toVersion, published: toVersionData.published, dependencies: toVersionData.pubspec?.dependencies || {}, devDependencies: toVersionData.pubspec?.dev_dependencies || {} } }, changes: { dependencyChanges: this.compareDependencies(fromVersionData.pubspec?.dependencies || {}, toVersionData.pubspec?.dependencies || {}), devDependencyChanges: this.compareDependencies(fromVersionData.pubspec?.dev_dependencies || {}, toVersionData.pubspec?.dev_dependencies || {}) } }; return { content: [ { type: "text", text: JSON.stringify(comparison, null, 2) } ] }; }
- src/pubdev-mcp.js:99-119 (schema)The input schema and metadata for the tool, defining required string parameters: packageName, fromVersion, toVersion.name: "compare_package_versions", description: "Compare two versions of a package and show differences", inputSchema: { type: "object", properties: { packageName: { type: "string", description: "Name of the package to compare" }, fromVersion: { type: "string", description: "Source version to compare from" }, toVersion: { type: "string", description: "Target version to compare to" } }, required: ["packageName", "fromVersion", "toVersion"] } },
- src/pubdev-mcp.js:162-163 (registration)Registration in the request handler switch statement, dispatching calls to the comparePackageVersions method.case "compare_package_versions": return await this.comparePackageVersions(args.packageName, args.fromVersion, args.toVersion);
- src/pubdev-mcp.js:437-462 (helper)Helper function used by the handler to compute differences in dependencies: added, removed, updated between old and new sets.compareDependencies(oldDeps, newDeps) { const changes = { added: [], removed: [], updated: [] }; // Find added dependencies for (const [pkg, version] of Object.entries(newDeps)) { if (!(pkg in oldDeps)) { changes.added.push(`${pkg}: ${version}`); } } // Find removed and updated dependencies for (const [pkg, oldVersion] of Object.entries(oldDeps)) { if (!(pkg in newDeps)) { changes.removed.push(`${pkg}: ${oldVersion}`); } else if (newDeps[pkg] !== oldVersion) { changes.updated.push({ package: pkg, from: oldVersion, to: newDeps[pkg] }); } } return changes;
- src/pubdev-mcp.js:84-144 (registration)Tool registration in the MCP server's tools list, including name, description, and schema. (Approximate lines based on context; exact tool entry 99-119)}, version: { type: "string", description: "Specific version (optional, defaults to latest)" }, docType: { type: "string", enum: ["readme", "changelog", "example", "api_docs"], description: "Type of documentation to retrieve" } }, required: ["packageName"] } }, { name: "compare_package_versions", description: "Compare two versions of a package and show differences", inputSchema: { type: "object", properties: { packageName: { type: "string", description: "Name of the package to compare" }, fromVersion: { type: "string", description: "Source version to compare from" }, toVersion: { type: "string", description: "Target version to compare to" } }, required: ["packageName", "fromVersion", "toVersion"] } }, { name: "search_packages", description: "Search for packages on pub.dev with filters", inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query" }, sort: { type: "string", enum: ["top", "text", "created", "updated", "popularity", "points", "likes"], description: "Sort order for results" }, page: { type: "number", description: "Page number for pagination (default: 1)" } }, required: ["query"] } } ] };