search_flet_ecosystem
Search the open-source Flet ecosystem for third-party packages that add features not available in the core library.
Instructions
Search the open-source community for third-party Flet packages and components. Use this when the user wants to add a feature (e.g., 'calendar', 'table', 'auth') that might not be in the core Flet library.
Args: query: The keyword to search for (e.g., 'calendar').
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/flet_mcp/services/packages.py:79-102 (handler)Core implementation in FletPackageFetcher class: searches GitHub repositories matching 'flet {query} language:python', fetches up to 15 results sorted by stars, verifies each is a real PyPI package depending on 'flet' via _is_true_flet_package, and returns name/description/stars/url/verified status.
async def search_flet_ecosystem(self, query: str) -> list[dict]: """Searches GitHub for third-party Flet packages and verifies them.""" search_query = f"flet {query} language:python" url = f"https://api.github.com/search/repositories?q={search_query}&sort=stars&order=desc&per_page=15" data = await self._fetch_json(url, headers=self.github_headers) if not data or "items" not in data: return [] results = [] for item in data["items"]: # Check if this GitHub repo is actually a published PyPI package depending on flet repo_name = item["name"] is_verified = await self._is_true_flet_package(repo_name) results.append({ "name": repo_name, "full_name": item["full_name"], "description": item["description"], "stars": item["stargazers_count"], "url": item["html_url"], "is_verified_flet_package": is_verified }) return results - src/flet_mcp/server.py:52-62 (registration)MCP tool registration via @mcp.tool() decorator. The server delegates to pkg_fetcher.search_flet_ecosystem().
@mcp.tool() async def search_flet_ecosystem(query: str) -> list[dict]: """ Search the open-source community for third-party Flet packages and components. Use this when the user wants to add a feature (e.g., 'calendar', 'table', 'auth') that might not be in the core Flet library. Args: query: The keyword to search for (e.g., 'calendar'). """ return await pkg_fetcher.search_flet_ecosystem(query) - Helper used by search: queries PyPI JSON API to check if a package's requires_dist includes 'flet' as a dependency, filtering out non-Flet repositories.
async def _is_true_flet_package(self, package_name: str) -> bool: """Verifies PyPI metadata to ensure the package actually depends on flet.""" url = f"https://pypi.org/pypi/{package_name}/json" data = await self._fetch_json(url) if not data or "info" not in data: return False requires_dist = data["info"].get("requires_dist") if not requires_dist: # Some packages might be Flet related but not strictly depend on 'flet' in metadata # but for a 'strict' check we require it. return False for req in requires_dist: # Clean up requirement string (e.g. 'flet (>=0.1.1) ; extra == "all"') dep_name = req.split(";")[0].split(" ")[0].split(">")[0].split("=")[0].split("<")[0] base_name = dep_name.split("[")[0].strip().lower() if base_name == "flet": return True return False - Low-level HTTP helper with diskcache support (24h TTL), used by search_flet_ecosystem to fetch GitHub search results.
async def _fetch_json(self, url: str, headers: dict | None = None) -> dict | None: if url in cache: return cache[url] try: response = await self.client.get(url, headers=headers) if response.status_code == 200: data = response.json() cache.set(url, data, expire=86400) return data except Exception: pass return None