query_dataset
Query Australian Bureau of Statistics datasets using the ABS MCP Server, enabling targeted data retrieval and analysis with optional filters for precise insights.
Instructions
Query a specific ABS dataset with optional filters
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| datasetId | Yes | ID of the dataset to query (e.g., C21_G01_LGA) |
Implementation Reference
- src/index.ts:50-82 (handler)The CallToolRequestSchema handler implements the execution logic for the "query_dataset" tool: validates the tool name and datasetId argument, constructs the API URL, fetches data from the Australian Bureau of Statistics (ABS) API using axios, handles errors, and returns the JSON response as text content.server.setRequestHandler(CallToolRequestSchema, async (request) => { try { const { name, arguments: args } = request.params; if (name !== "query_dataset") { throw new Error(`Unknown tool: ${name}`); } if (!args?.datasetId || typeof args.datasetId !== "string") { throw new Error("datasetId is required and must be a string"); } const url = `${ABS_API_BASE}/data/${args.datasetId}/all?format=json&dimensionAtObservation=AllDimensions`; try { const response = await axios.get(url); return { content: [{ type: "text", text: JSON.stringify(response.data, null, 2) }] }; } catch (error) { if (error instanceof AxiosError && error.response) { throw new Error(`ABS API Error: ${error.response.status} - ${JSON.stringify(error.response.data)}`); } throw error; } } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); throw new Error(`Error querying dataset: ${errorMessage}`); } });
- src/index.ts:29-48 (registration)Registers the "query_dataset" tool in the ListToolsRequestSchema handler, specifying its name, description, and input schema requiring a 'datasetId' string.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "query_dataset", description: "Query a specific ABS dataset with optional filters", inputSchema: { type: "object", required: ["datasetId"], properties: { datasetId: { type: "string", description: "ID of the dataset to query (e.g., C21_G01_LGA)" } } } } ] }; });
- src/index.ts:35-44 (schema)Defines the input schema for the "query_dataset" tool, requiring a 'datasetId' property of type string.inputSchema: { type: "object", required: ["datasetId"], properties: { datasetId: { type: "string", description: "ID of the dataset to query (e.g., C21_G01_LGA)" } } }