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)
          }
        ]
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool will 'show differences', implying a read-only operation, but doesn't specify what types of differences (e.g., code changes, dependency updates, metadata), the format of the output, or any limitations like rate limits or authentication needs. This leaves significant gaps in understanding how the tool behaves.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is front-loaded with the core action ('compare') and resource, making it easy to parse. Every part of the sentence earns its place by conveying essential information concisely.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of comparing package versions (which could involve detailed diff outputs) and the lack of annotations and output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., a summary, detailed changes, or error messages), nor does it cover behavioral aspects like performance or constraints. For a tool with no structured output documentation, this leaves the agent with insufficient context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, clearly documenting each parameter's purpose. The description adds no additional semantic context beyond what the schema provides, such as examples of package names or version formats. Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'compare' and the resource 'two versions of a package', specifying the action and target. It distinguishes from siblings like 'get_package_info' or 'get_package_versions' by focusing on version differences rather than general info or listing versions. However, it doesn't explicitly differentiate from 'get_documentation_changes', which might also involve version comparisons.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'check_package_updates' or 'get_documentation_changes'. It lacks context about prerequisites, such as needing valid package names or version formats, and doesn't mention any exclusions or specific scenarios where this tool is preferred over others.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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