Skip to main content
Glama
devqxi

Pub.dev MCP Server

by devqxi

compare_package_versions

Compare two versions of a Dart/Flutter package to identify changes and differences between them.

Instructions

Compare two versions of a package and show differences

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packageNameYesName of the package to compare
fromVersionYesSource version to compare from
toVersionYesTarget version to compare to

Implementation Reference

  • The main handler function that executes the 'compare_package_versions' tool. It fetches package versions from pub.dev API, finds the specified from and to versions, compares their pubspec dependencies and dev_dependencies, and returns a structured JSON with the comparison 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)
                }
            ]
        };
    }
  • Tool registration in the ListTools response, defining the tool name, description, and input schema for validation.
    {
        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"]
        }
    },
  • Input schema defining the parameters for the compare_package_versions tool: packageName, fromVersion, toVersion.
    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"]
  • Supporting helper function that computes dependency changes (added, removed, updated) between two dependency maps, used in the handler for both dependencies and devDependencies.
    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;
    }
  • TypeScript version of the main handler function, identical logic to JS version.
    private async comparePackageVersions(packageName: string, fromVersion: string, toVersion: string) {
      const versionsUrl = `https://pub.dev/api/packages/${packageName}/versions`;
      const data = await this.fetchWithCache<any>(versionsUrl, `versions-${packageName}`);
      
      const fromVersionData = data.versions.find((v: any) => v.version === fromVersion);
      const toVersionData = data.versions.find((v: any) => 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)
          }
        ]
      };
    }

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/devqxi/pubdev-mcp-server'

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