search_packages
Discover Dart and Flutter packages on pub.dev by searching with queries, applying filters, and sorting results. Supports pagination for efficient package discovery and analysis.
Instructions
Search for packages on pub.dev with filters
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | Page number for pagination (default: 1) | |
| query | Yes | Search query | |
| sort | No | Sort order for results |
Input Schema (JSON Schema)
{
"properties": {
"page": {
"description": "Page number for pagination (default: 1)",
"type": "number"
},
"query": {
"description": "Search query",
"type": "string"
},
"sort": {
"description": "Sort order for results",
"enum": [
"top",
"text",
"created",
"updated",
"popularity",
"points",
"likes"
],
"type": "string"
}
},
"required": [
"query"
],
"type": "object"
}
Implementation Reference
- src/pubdev-mcp.ts:493-527 (handler)The core handler function implementing the search_packages tool logic: constructs pub.dev search URL, fetches and caches results, formats package information, and returns standardized MCP response.private async searchPackages(query: string, sort: string = 'top', page: number = 1) { const params = new URLSearchParams({ q: query, sort: sort, page: page.toString() }); const url = `https://pub.dev/api/search?${params}`; const data = await this.fetchWithCache<any>(url, `search-${query}-${sort}-${page}`); const results = { query, sort, page, totalResults: data.count, packages: data.packages.map((pkg: any) => ({ name: pkg.package, version: pkg.latest.version, description: pkg.latest.pubspec?.description, points: pkg.points, likes: pkg.likes, popularity: pkg.popularity, publishedAt: pkg.latest.published })) }; return { content: [ { type: "text", text: JSON.stringify(results, null, 2) } ] }; }
- src/pubdev-mcp.ts:162-179 (schema)Input schema defining parameters for the search_packages tool: query (required), sort (enum options), and page (optional).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"] }
- src/pubdev-mcp.ts:224-229 (registration)Registration in the tool dispatch switch statement: maps tool call to the searchPackages handler method.case "search_packages": return await this.searchPackages( args.query as string, args.sort as string, args.page as number );
- src/pubdev-mcp.ts:159-180 (registration)Tool registration object including name, description, and schema, added to the tools list for MCP tools/list endpoint.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"] } }