get_package_info
Retrieve detailed information about Dart and Flutter packages from pub.dev, including version, dependencies, and documentation, using a specific package name.
Instructions
Get detailed information about a Dart/Flutter package from pub.dev
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| packageName | Yes | Name of the package to retrieve information for |
Input Schema (JSON Schema)
{
"properties": {
"packageName": {
"description": "Name of the package to retrieve information for",
"type": "string"
}
},
"required": [
"packageName"
],
"type": "object"
}
Implementation Reference
- src/pubdev-mcp.ts:271-303 (handler)The main handler function that fetches package data from pub.dev API using caching, extracts relevant information, 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) } ] }; }
- src/pubdev-mcp.ts:64-76 (registration)Tool registration in the listTools handler, including name, description, and input schema definition.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"] } },
- src/pubdev-mcp.ts:15-23 (schema)TypeScript interface defining the structure of package information used in the handler.name: string; version: string; description?: string; homepage?: string; repository?: string; publishedAt: string; dependencies?: Record<string, string>; devDependencies?: Record<string, string>; }
- src/pubdev-mcp.ts:195-196 (registration)Dispatcher case in the CallToolRequestSchema handler that routes to the getPackageInfo method.case "get_package_info": return await this.getPackageInfo(args.packageName as string);
- src/pubdev-mcp.ts:247-269 (helper)Caching utility function used by getPackageInfo to fetch and cache API responses.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; }