Skip to main content
Glama
devqxi

Pub.dev MCP Server

by devqxi

get_package_info

Retrieve detailed information about Dart and Flutter packages from pub.dev, including version data, dependencies, and documentation for development analysis.

Instructions

Get detailed information about a Dart/Flutter package from pub.dev

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packageNameYesName of the package to retrieve information for

Implementation Reference

  • The primary handler function that implements the get_package_info tool. It fetches package data from pub.dev API using caching, extracts relevant information into a structured PackageInfo object, and returns formatted JSON response.
    private async getPackageInfo(packageName: string) {
      const url = `https://pub.dev/api/packages/${packageName}`;
      const data = await this.fetchWithCache<any>(url, `package-${packageName}`);
    
      const packageInfo: PackageInfo = {
        name: data.name,
        version: data.latest.version,
        description: data.latest.pubspec?.description,
        homepage: data.latest.pubspec?.homepage,
        repository: data.latest.pubspec?.repository,
        publishedAt: data.latest.published,
        dependencies: data.latest.pubspec?.dependencies,
        devDependencies: data.latest.pubspec?.dev_dependencies
      };
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify({
              package: packageInfo,
              stats: {
                likes: data.likes,
                points: data.points,
                popularity: data.popularity
              },
              publishers: data.publishers,
              uploaders: data.uploaders
            }, null, 2)
          }
        ]
      };
    }
  • Registration of the get_package_info tool in the ListToolsRequestHandler, including name, description, and input schema.
    {
      name: "get_package_info",
      description: "Get detailed information about a Dart/Flutter package from pub.dev",
      inputSchema: {
        type: "object",
        properties: {
          packageName: {
            type: "string",
            description: "Name of the package to retrieve information for"
          }
        },
        required: ["packageName"]
      }
    },
  • TypeScript interface defining the output structure for package information used in the handler.
    interface PackageInfo {
      name: string;
      version: string;
      description?: string;
      homepage?: string;
      repository?: string;
      publishedAt: string;
      dependencies?: Record<string, string>;
      devDependencies?: Record<string, string>;
    }
  • Dispatch case in the CallToolRequestHandler that routes calls to the getPackageInfo method.
    case "get_package_info":
      return await this.getPackageInfo(args.packageName as string);
  • Helper method for fetching data from pub.dev with caching, used by the getPackageInfo handler.
    private async fetchWithCache<T>(url: string, cacheKey: string): Promise<T> {
      const cached = this.packageCache.get(cacheKey);
      const now = Date.now();
    
      if (cached && (now - cached.timestamp) < this.CACHE_DURATION) {
        return cached.data as T;
      }
    
      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() as T;
      this.packageCache.set(cacheKey, { data, timestamp: now });
      return data;
    }

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