fetch_data
Retrieve public datasets from the Israeli government's open data portal by specifying a dataset name, with options to limit results and paginate through records.
Instructions
Fetch data from public API based on a dataset name query
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dataset_name | Yes | ||
| limit | No | ||
| offset | No |
Implementation Reference
- server.py:130-161 (handler)The main handler function for the 'fetch_data' tool. It is decorated with @mcp.tool() for registration in the FastMCP server. The function finds the resource ID for the given dataset_name using package_show API, then fetches records from datastore_search API with optional limit and offset.@mcp.tool() def fetch_data(dataset_name: str, limit: int = 100, offset: int = 0): """Fetch data from public API based on a dataset name query""" def find_resource_id(dataset_name): dataset_url = f"{BASE_URL}/action/package_show?id={dataset_name}" response = requests.get(dataset_url) if response.status_code == 200: dataset_data = response.json() resources = dataset_data['result']['resources'] if resources: return resources[0]['id'] return None resource_id = find_resource_id(dataset_name) if not resource_id: return {"error": f"No dataset found matching '{dataset_name}'"} base_url = f"{BASE_URL}/action/datastore_search" params = { "resource_id": resource_id, "limit": limit, "offset": offset } response = requests.get(base_url, params=params) response.raise_for_status() api_data = response.json() if api_data.get("success"): return api_data["result"]["records"] else: raise Exception(api_data.get("error", "Unknown error occurred"))