Skip to main content
Glama
mcp-open-data-hk

Hong Kong Open Data MCP Server

Official

get_datasets_by_format

Filter Hong Kong government open datasets by file format to find CSV, JSON, or GeoJSON resources for data analysis and integration.

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
NameRequiredDescriptionDefault
file_formatYes
limitNo
languageNoen

Implementation Reference

  • The @mcp.tool decorated handler function that implements the get_datasets_by_format tool. It searches the data.gov.hk package_search API using a res_format filter query to find datasets available in the specified file format.
    @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')}")
  • The FastMCP decorator that registers the get_datasets_by_format tool.
    @mcp.tool
  • Helper function used by get_datasets_by_format to make HTTP requests to the data.gov.hk API.
    async def make_api_request( url: str, params: Optional[Dict[str, Any]] = None ) -> Dict[str, Any]: """Make an API request to data.gov.hk""" async with httpx.AsyncClient() as client: # Print the request for debugging print(f"Making request to {url} with params {params}") response = await client.get(url, params=params) print(f"Response status: {response.status_code}") response.raise_for_status() return response.json()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mcp-open-data-hk/mcp-open-data-hk'

If you have feedback or need assistance with the MCP directory API, please join our Discord server