get_datasets_by_format
Find Hong Kong government datasets available in specific file formats like CSV, JSON, or GeoJSON to access open data resources that match your technical requirements.
Instructions
Get datasets that have resources in a specific file format.
Args: file_format: The file format to filter by (e.g., "CSV", "JSON", "GeoJSON") limit: Maximum number of datasets to return language: Language code (en, tc, sc)
Returns: A dictionary containing: - count: Total number of matching datasets - results: List of matching datasets
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_format | Yes | ||
| language | No | en | |
| limit | No |
Implementation Reference
- src/mcp_open_data_hk/server.py:269-305 (handler)The handler function for the 'get_datasets_by_format' tool. It uses the data.gov.hk package_search API with a 'res_format' filter to find datasets matching the specified file format. The @mcp.tool decorator registers this function as an MCP tool.@mcp.tool async def get_datasets_by_format( file_format: str, limit: int = 10, language: str = "en" ) -> Dict[str, Any]: """ Get datasets that have resources in a specific file format. Args: file_format: The file format to filter by (e.g., "CSV", "JSON", "GeoJSON") limit: Maximum number of datasets to return language: Language code (en, tc, sc) Returns: A dictionary containing: - count: Total number of matching datasets - results: List of matching datasets """ # Using package_search API with format filter base_url = BASE_URLS.get(language, BASE_URLS["en"]) url = f"{base_url}/package_search" # Create a query that filters by format query = f"res_format:{file_format}" params = {"q": query, "rows": min(limit, 1000), "start": 0} result = await make_api_request(url, params) if result.get("success"): search_result = result["result"] return { "count": search_result.get("count", 0), "results": search_result.get("results", []), } else: raise Exception(f"API Error: {result.get('error', 'Unknown error')}")