Skip to main content
Glama

query_dwr_api

Query Colorado Division of Water Resources REST API endpoints to access water data including surface water stations, streamflow time series, water rights, well permits, and administrative calls.

Instructions

Generic tool to query any Colorado DWR REST API endpoint

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
endpointYesAPI endpoint path (e.g., 'surfacewater/surfacewaterstations')
paramsNoQuery parameters

Implementation Reference

  • Handler logic for the 'query_dwr_api' tool. Extracts arguments and delegates to the shared handleApiCall method with the specified endpoint and parameters.
    case "query_dwr_api": { const args = request.params.arguments as any; return await this.handleApiCall(args.endpoint, args.params || {}); }
  • Zod input schema for the query_dwr_api tool, defining 'endpoint' (required string) and 'params' (optional record). Converted to JSON schema for MCP registration.
    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:115-124 (registration)
    Tool registration in the ListTools response, including name, description, and inputSchema derived from Zod.
    { 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"), }) ), },
  • Shared helper method that performs the actual API request to the DWR REST API, handles parameters, API key, and formats the response for MCP.
    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), }, ], }; }
  • Utility function to filter out undefined and null values from query parameters before making the API call.
    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; };

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/EdgeworthHitbox/dwr-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server