get_package_details
Retrieve PyPI details, current version, and installation instructions for a specified Flet package.
Instructions
Fetch PyPI details, current version, and installation instructions for a specific Flet package.
Args: package_name: The exact name of the package on PyPI (e.g., 'flet-audio').
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| package_name | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/flet_mcp/server.py:64-72 (handler)MCP tool handler that delegates to FletPackageFetcher.get_package_details(). This is the @mcp.tool()-decorated function invoked when the 'get_package_details' tool is called.
@mcp.tool() async def get_package_details(package_name: str) -> str: """ Fetch PyPI details, current version, and installation instructions for a specific Flet package. Args: package_name: The exact name of the package on PyPI (e.g., 'flet-audio'). """ return await pkg_fetcher.get_package_details(package_name) - Core implementation: fetches PyPI JSON data for a package, extracts version/summary, classifies the package type (UI Control, Service Integration, or Python Package), and returns formatted details with installation instructions.
async def get_package_details(self, package_name: str) -> str: """Fetches detailed package info and installation instructions from PyPI.""" url = f"https://pypi.org/pypi/{package_name}/json" data = await self._fetch_json(url) if not data or "info" not in data: return f"Package '{package_name}' not found on PyPI." info = data["info"] version = info.get("version", "Unknown") summary = info.get("summary", "No summary available.") # Smart Classification pkg_type = "Python Package" summary_lower = summary.lower() if "control" in summary_lower or "widget" in summary_lower or "ui" in summary_lower: pkg_type = "UI Control" elif "service" in summary_lower or "auth" in summary_lower or "database" in summary_lower: pkg_type = "Service Integration" details = ( f"Package: {package_name} (v{version})\n" f"Type: {pkg_type}\n" f"Summary: {summary}\n\n" f"Installation:\n```bash\n" f"uv add {package_name}\n```\n" ) return details - src/flet_mcp/server.py:64-65 (registration)The @mcp.tool() decorator on the get_package_details function registers it as an MCP tool in the FastMCP server instance named 'mcp'.
@mcp.tool() async def get_package_details(package_name: str) -> str: - src/flet_mcp/server.py:65-71 (schema)The tool's input schema is implicitly defined by the function signature (package_name: str). The docstring serves as the description for this parameter.
async def get_package_details(package_name: str) -> str: """ Fetch PyPI details, current version, and installation instructions for a specific Flet package. Args: package_name: The exact name of the package on PyPI (e.g., 'flet-audio'). """ - Helper method _fetch_json used by get_package_details to fetch and cache PyPI JSON responses with a 24-hour TTL.
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