query_dwr_api
Query Colorado Division of Water Resources REST API endpoints to access surface water stations, streamflow data, water rights, well permits, and administrative calls.
Instructions
Generic tool to query any Colorado DWR REST API endpoint
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| endpoint | Yes | API endpoint path (e.g., 'surfacewater/surfacewaterstations') | |
| params | No | Query parameters |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"endpoint": {
"description": "API endpoint path (e.g., 'surfacewater/surfacewaterstations')",
"type": "string"
},
"params": {
"additionalProperties": {},
"description": "Query parameters",
"type": "object"
}
},
"required": [
"endpoint"
],
"type": "object"
}
Implementation Reference
- src/index.ts:115-124 (registration)Registration of the "query_dwr_api" tool in the ListTools response, including name, description, and Zod-based input schema.{ name: "query_dwr_api", description: "Generic tool to query any Colorado DWR REST API endpoint", inputSchema: zodToJsonSchema( z.object({ endpoint: z.string().describe("API endpoint path (e.g., 'surfacewater/surfacewaterstations')"), params: z.record(z.any()).optional().describe("Query parameters"), }) ), },
- src/index.ts:156-159 (handler)Handler logic for the "query_dwr_api" tool within the CallToolRequestHandler switch statement, which extracts endpoint and params from arguments and delegates to the shared handleApiCall method.case "query_dwr_api": { const args = request.params.arguments as any; return await this.handleApiCall(args.endpoint, args.params || {}); }
- src/index.ts:118-123 (schema)Zod schema definition for the tool's input parameters: endpoint (required string) and optional params (record). Converted to JSON schema for MCP.inputSchema: zodToJsonSchema( z.object({ endpoint: z.string().describe("API endpoint path (e.g., 'surfacewater/surfacewaterstations')"), params: z.record(z.any()).optional().describe("Query parameters"), }) ),
- src/index.ts:184-217 (handler)Shared handleApiCall method that performs the actual HTTP GET request to the DWR API using axios, handles API key addition (as query param), formats parameters, logs the request, and returns the JSON response as text content.public async handleApiCall(endpoint: string, params: any) { const url = `${BASE_URL}/${endpoint}`; const headers: Record<string, string> = {}; if (this.apiKey) { headers["Authorization"] = this.apiKey; // Or however DWR expects it, docs say 'Token: ...' or query param } // DWR docs say: "Token: B9xxxxx-xxxx-4D47-y" in header OR apiKey query param // I'll use query param if apiKey is present to be safe/easy, or header if I can confirm. // Docs: "Request Header: ... Token: ..." // Let's stick to query params for simplicity if header format is custom. // Actually, let's use the params object. const finalParams = formatParams(params); if (this.apiKey) { finalParams["apiKey"] = this.apiKey; } console.error(`Fetching ${url} with params ${JSON.stringify(finalParams)}`); const response = await axios.get(url, { params: finalParams, headers, }); return { content: [ { type: "text", text: JSON.stringify(response.data, null, 2), }, ], }; }
- src/index.ts:14-22 (helper)Utility function formatParams used by handleApiCall to remove undefined/null values from query parameters before sending the API request.const formatParams = (params: Record<string, any>) => { const formatted: Record<string, any> = {}; for (const [key, value] of Object.entries(params)) { if (value !== undefined && value !== null) { formatted[key] = value; } } return formatted; };