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

Hong Kong Open Data MCP Server

Official

list_categories

Browse and filter available data categories from Hong Kong's open government data portal to organize and access relevant datasets.

Instructions

Get a list of data categories (groups)

Args: order_by: Field to sort by ('name' or 'packages') - deprecated, use sort instead sort: Sorting of results ('name asc', 'package_count desc', etc.) limit: Maximum number of categories to return offset: Offset for pagination all_fields: Return full group dictionaries instead of just names language: Language code (en, tc, sc)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
all_fieldsNo
languageNoen
limitNo
offsetNo
order_byNoname
sortNotitle asc

Implementation Reference

  • The handler function for the 'list_categories' tool. It is registered using the @mcp.tool decorator and implements the core logic by making an API request to the data.gov.hk /group_list endpoint with the provided parameters, returning the list of categories or raising an error if the API call fails.
    @mcp.tool async def list_categories( order_by: str = "name", sort: str = "title asc", limit: Optional[int] = None, offset: Optional[int] = None, all_fields: bool = False, language: str = "en", ) -> Any: """ Get a list of data categories (groups) Args: order_by: Field to sort by ('name' or 'packages') - deprecated, use sort instead sort: Sorting of results ('name asc', 'package_count desc', etc.) limit: Maximum number of categories to return offset: Offset for pagination all_fields: Return full group dictionaries instead of just names language: Language code (en, tc, sc) """ base_url = BASE_URLS.get(language, BASE_URLS["en"]) url = f"{base_url}/group_list" params = {"sort": sort, "all_fields": str(all_fields).lower()} if order_by != "name": # Only add if not default params["order_by"] = order_by if limit is not None: params["limit"] = str(limit) if offset is not None: params["offset"] = str(offset) result = await make_api_request(url, params) if result.get("success"): return result["result"] else: raise Exception(f"API Error: {result.get('error', 'Unknown error')}")
  • The @mcp.tool decorator registers the list_categories function as an MCP tool on the FastMCP server instance.
    @mcp.tool
  • Helper function used by list_categories (and other tools) to perform HTTP GET requests to the data.gov.hk API, including debugging prints and error handling.
    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