fetch_data
Retrieve specific datasets from the Israeli government’s public API by querying dataset names, with options to set limits and offsets for results.
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-160 (handler)The handler function for the 'fetch_data' tool. It first finds the resource ID for the given dataset_name by calling the package_show API, then queries the datastore_search API to fetch the records with the specified 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"))