{
  "markdown": "<div align=\"center\">\n  <h1>@cyanheads/usgs-water-mcp-server</h1>\n  <p><b>Query real-time and historical water data from ~8,000 USGS stream gages and groundwater wells via MCP. STDIO or Streamable HTTP.</b>\n  <div>7 Tools • 2 Resources</div>\n  </p>\n</div>\n\n<div align=\"center\">\n\n[![Version](https://img.shields.io/badge/Version-0.2.3-blue.svg?style=flat-square)](./CHANGELOG.md) [![License](https://img.shields.io/badge/License-Apache%202.0-orange.svg?style=flat-square)](./LICENSE) [![Docker](https://img.shields.io/badge/Docker-ghcr.io-2496ED?style=flat-square&logo=docker&logoColor=white)](https://github.com/users/cyanheads/packages/container/package/usgs-water-mcp-server) [![MCP SDK](https://img.shields.io/badge/MCP%20SDK-^2.0.0-green.svg?style=flat-square)](https://modelcontextprotocol.io/) [![npm](https://img.shields.io/npm/v/@cyanheads/usgs-water-mcp-server?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@cyanheads/usgs-water-mcp-server) [![TypeScript](https://img.shields.io/badge/TypeScript-^7.0.2-3178C6.svg?style=flat-square)](https://www.typescriptlang.org/) [![Bun](https://img.shields.io/badge/Bun-v1.4.0-blueviolet.svg?style=flat-square)](https://bun.sh/)\n\n</div>\n\n<div align=\"center\">\n\n[![Install in Claude Desktop](https://img.shields.io/badge/Install_in-Claude_Desktop-D97757?style=for-the-badge&logo=anthropic&logoColor=white)](https://github.com/cyanheads/usgs-water-mcp-server/releases/latest/download/usgs-water-mcp-server.mcpb) [![Install in Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en/install-mcp?name=usgs-water-mcp-server&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBjeWFuaGVhZHMvdXNncy13YXRlci1tY3Atc2VydmVyIl19) [![Install in VS Code](https://img.shields.io/badge/VS_Code-Install_Server-0098FF?style=for-the-badge&logo=visualstudiocode&logoColor=white)](https://vscode.dev/redirect?url=vscode:mcp/install?%7B%22name%22%3A%22usgs-water-mcp-server%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40cyanheads%2Fusgs-water-mcp-server%22%5D%7D)\n\n[![Framework](https://img.shields.io/badge/Built%20on-@cyanheads/mcp--ts--core-67E8F9?style=flat-square)](https://www.npmjs.com/package/@cyanheads/mcp-ts-core)\n\n</div>\n\n<div align=\"center\">\n\n**Public Hosted Server:** [https://usgs-water.caseyjhand.com/mcp](https://usgs-water.caseyjhand.com/mcp)\n\n</div>\n\n---\n\n## Tools\n\nFive tools for querying USGS water data, plus two for SQL analytics over the DuckDB-backed canvas dataframes that `water_get_series` and `water_find_sites` materialize:\n\n| Tool | Description |\n|:-----|:------------|\n| `water_list_parameters` | Static lookup of well-known USGS parameter codes with names, units, and domain. No network call. |\n| `water_find_sites` | Find USGS monitoring sites by bounding box, state, county, or HUC watershed. Filter by site type and parameter availability. Large match sets spill to DataCanvas. |\n| `water_get_readings` | Get the latest instantaneous values (~15 min real-time) for up to 100 USGS sites. |\n| `water_get_series` | Get a time series of daily or instantaneous values for a site over a date range. Large ranges spill to DataCanvas. |\n| `water_get_conditions` | Get current hydrologic conditions ranked against the full period-of-record percentile statistics. |\n| `water_dataframe_describe` | List tables and columns staged on a DataCanvas by `water_get_series` or `water_find_sites`. |\n| `water_dataframe_query` | Run a read-only SQL SELECT against the time-series and site tables staged by `water_get_series` and `water_find_sites`. |\n\n### `water_list_parameters`\n\nStatic lookup of well-known USGS parameter codes — no network call, instant response.\n\n- Discover that `00060` = Discharge (ft³/s), `00065` = Gage height (ft), `00010` = Temperature (°C), `72019` = Depth to water level (ft), and more\n- Filter by thematic domain: `streamflow`, `groundwater`, `temperature`, `meteorological`, `water-quality`, or `all`\n- Use this first — parameter codes are required by every other water tool\n\n---\n\n### `water_find_sites`\n\nDiscover USGS monitoring sites before calling data tools — all other tools require a site number.\n\n- Geographic scoping: bounding box (`\"west,south,east,north\"` decimal degrees), 2-letter state code, bare 5-digit FIPS county code (e.g. `51013`), or HUC watershed code — either a 2-digit major HUC (`02`) or an 8-digit minor HUC (`02070008`), the only two lengths NWIS accepts\n- Site type filtering: `ST` (stream), `GW` (groundwater well), `LK` (lake/reservoir), `SP` (spring), and more\n- Parameter filter: only return sites that have data for a specific parameter code — comma-separate to require several (e.g. `00060,00065`)\n- Data type filter: require sites with real-time (`iv`), daily (`dv`), or groundwater (`gw`) data\n- Returns site number, name, coordinates, type, state/county/HUC codes, and drainage area (expanded mode only) — altitude is included in both modes when USGS records it\n- Bounded result set: capped at 500 sites inline, with a `truncated` flag and `upstreamTotal` (the full upstream count) so an oversized query never overflows the response\n- **DataCanvas spillover:** when the result is truncated and `CANVAS_PROVIDER_TYPE=duckdb` is set, the full match set is staged to a DuckDB-backed canvas — the response includes `canvas_id` and `table_name` to retrieve every match past the 500 cap via `water_dataframe_query`. Without DataCanvas, narrow the query with additional filters (county, HUC, bbox, parameter, data type) to bring the result under the cap\n\n---\n\n### `water_get_readings`\n\nGet the latest instantaneous (~15 min) values for one or more USGS monitoring sites.\n\n- Batch up to 100 site numbers in a single call\n- Accepts any parameter code discoverable via `water_list_parameters`\n- Configurable lookback period via ISO 8601 duration (e.g. `PT2H` = last 2 hours, `P7D` = last 7 days)\n- Returns per-site, per-parameter records with timestamp, value, unit, and provisional/approved qualifier\n- Bounded by design: each series carries its 10 most recent records, with `totalValues` reporting how many the period actually held and `truncated` flagging the cap. Use `water_get_series` when you need the full series\n- Partial batches are explicit: requested sites NWIS returns no data for are named in `missingSites` rather than dropped silently\n- Groundwater depth available via `parameterCd=72019` (the legacy `gwlevels` endpoint was decommissioned November 2025 — use the IV service instead)\n\n---\n\n### `water_get_series`\n\nGet a historical time series for a site and parameter over a date range.\n\n- Daily values (DV service, one value per day) or instantaneous values (IV service, ~15 min resolution)\n- Returns site name, parameter name, unit code, and time-ordered value records with qualifiers\n- **DataCanvas spillover:** large date ranges (>500 records) automatically spill to a DuckDB-backed canvas when `CANVAS_PROVIDER_TYPE=duckdb` is set — response includes `canvas_id` and `table_name` for follow-up SQL via `water_dataframe_query`\n- Without DataCanvas, returns the most recent 500 records with a `truncated` flag and `totalRecords` count\n- Supports chaining: pass a prior `canvas_id` to append data to an existing canvas\n\n---\n\n### `water_get_conditions`\n\nGet current hydrologic conditions placed in full historical context.\n\n- Fetches the current IV reading and the full daily percentile table in parallel\n- Classifies the reading: `record-high` (≥ p95), `above-normal` (p75–p95), `normal` (p25–p75), `below-normal` (p10–p25), `low` (p05–p10), `record-low` (< p05)\n- Pairs each class with a `percentileLabel` spelling out the threshold — `record-high` and `record-low` mark percentile-of-record extremes, not verified all-time records, and the label says so where the class name does not\n- Ranks against the observation's own calendar day, so a reading near midnight is not compared against the neighboring day's percentiles\n- Discloses the granularity approximation in `comparisonBasis`: the reading is instantaneous while the percentiles are approved daily-mean values, so the class is a \"how unusual is this\" ranking — not a flood-stage or drought determination, which need authoritative thresholds this tool does not fetch\n- Validates `site` and `parameterCd` at the schema edge; a well-formed value NWIS still rejects surfaces as the typed `invalid_request` reason rather than an opaque upstream error\n- Gracefully degrades when historical context is missing: returns the current reading with `historicalContext: null` and a `historicalContextStatus` saying why — `no_record` (new/short record), `no_matching_day` (no row for the date), or `unavailable` (stat call failed — transient and retryable, kept distinct from a sparse record)\n\n---\n\n### `water_dataframe_describe` / `water_dataframe_query`\n\nIn-conversation SQL analytics over the dataframes that `water_get_series` and `water_find_sites` materialize on a DuckDB-backed canvas — time-series tables from the former, full site match sets from the latter.\n\n**Workflow:**\n1. Call `water_get_series` with a large date range, or `water_find_sites` with a query that matches more than 500 sites — when DataCanvas is enabled, the response includes `canvas_id` and `table_name`\n2. Call `water_dataframe_describe` with the `canvas_id` to confirm the table schema — series tables carry `date_time`, `value`, `qualifiers`, `site_number`, `parameter_cd`, `unit_code`; site tables carry `site_number`, `site_name`, `site_type`, `latitude`, `longitude`, `huc_cd`, and the expanded fields\n3. Call `water_dataframe_query` with the `canvas_id` and a SELECT statement to run aggregates, filter, or join\n\nRead-only by default — only SELECT statements are permitted. Results are capped at 10,000 rows; a query matching more comes back with `truncated: true`. Requires `CANVAS_PROVIDER_TYPE=duckdb` in the server environment.\n\n## Resources and prompts\n\n| Type | Name | Description |\n|:-----|:-----|:------------|\n| Resource | `usgs-water://site/{siteId}` | Site metadata: name, coordinates, type, HUC, state, county, drainage area, and altitude |\n| Resource | `usgs-water://parameters` | Full parameter code catalog (same data as `water_list_parameters`) |\n\nAll resource data is also reachable via tools. Use `water_find_sites` for geographic site discovery.\n\n## Features\n\nBuilt on [`@cyanheads/mcp-ts-core`](https://www.npmjs.com/package/@cyanheads/mcp-ts-core):\n\n- Declarative tool and resource definitions — single file per primitive, framework handles registration and validation\n- Unified error handling — handlers throw, framework catches, classifies, and formats\n- Pluggable auth: `none`, `jwt`, `oauth`\n- Swappable storage backends: `in-memory`, `filesystem`, `Supabase`, `Cloudflare KV/R2/D1`\n- Structured logging with optional OpenTelemetry tracing\n- STDIO and Streamable HTTP transports\n\nUSGS NWIS–specific:\n\n- Wraps NWIS IV (instantaneous), DV (daily), site, and stat endpoints — no API key required, fully public\n- Input formats checked at the edge against what NWIS actually accepts — site numbers, parameter codes, ISO 8601 periods, HUC, FIPS county, state, and bbox all carry a validated pattern that is advertised in each tool's JSON Schema, so malformed values fail with a pointed message instead of an opaque upstream 400\n- HTML error detection: NWIS returns 400 with an HTML body for bad inputs; the service layer extracts NWIS's own message — which names the field it rejected — and maps it to a typed failure\n- Multi-site batching: `water_get_readings` accepts up to 100 site numbers in one call\n- Provisional vs. approved data qualifiers surfaced on every reading — not hidden from callers\n- DataCanvas spillover: `water_get_series` (long date ranges) and `water_find_sites` (match sets past the 500-site cap) stage the full result as a DuckDB-backed table queryable via `water_dataframe_query`\n- Groundwater via the IV service using parameter `72019` — the legacy `gwlevels` endpoint was decommissioned November 2025\n\nAgent-friendly output:\n\n- Percentile classification on every conditions response — callers get a `percentileClass` string (`record-high`, `normal`, `record-low`, etc.) they can act on directly without parsing numeric thresholds, plus a `percentileLabel` stating the threshold in plain language so the `record-*` classes are not mistaken for verified all-time records\n- Partial success on conditions: when percentiles are missing, the current reading still returns with `historicalContext: null` and a `historicalContextStatus` that separates an empty stat table (`no_record` / `no_matching_day`) from a failed stat call (`unavailable`, transient), rather than collapsing both into an error\n- Partial success on batches: `water_get_readings` returns the series it got and names the rest in `missingSites`, so a silently dropped site never reads as a complete answer\n- Truncation signals: `water_get_series` reports `totalRecords` and `truncated`, `water_find_sites` reports `upstreamTotal` and `truncated`, and `water_get_readings` reports per-series `totalValues` plus `truncated`, so callers know when a preview is incomplete. `canvas_id` / `table_name` tell them exactly how to retrieve the rest\n- Structured content and rendered text agree: every cap and count a tool applies is reported identically in `structuredContent` and in the markdown, so neither class of client sees a different answer\n\n## Getting started\n\n### Public Hosted Instance\n\nA public instance is available at `https://usgs-water.caseyjhand.com/mcp` — no installation required. Point any MCP client at it via Streamable HTTP:\n\n```json\n{\n  \"mcpServers\": {\n    \"usgs-water-mcp-server\": {\n      \"type\": \"streamable-http\",\n      \"url\": \"https://usgs-water.caseyjhand.com/mcp\"\n    }\n  }\n}\n```\n\n### Self-Hosted / Local\n\nAdd the following to your MCP client configuration file.\n\n```json\n{\n  \"mcpServers\": {\n    \"usgs-water-mcp-server\": {\n      \"type\": \"stdio\",\n      \"command\": \"bunx\",\n      \"args\": [\"@cyanheads/usgs-water-mcp-server@latest\"],\n      \"env\": {\n        \"MCP_TRANSPORT_TYPE\": \"stdio\",\n        \"MCP_LOG_LEVEL\": \"info\"\n      }\n    }\n  }\n}\n```\n\nOr with npx (no Bun required):\n\n```json\n{\n  \"mcpServers\": {\n    \"usgs-water-mcp-server\": {\n      \"type\": \"stdio\",\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"@cyanheads/usgs-water-mcp-server@latest\"],\n      \"env\": {\n        \"MCP_TRANSPORT_TYPE\": \"stdio\",\n        \"MCP_LOG_LEVEL\": \"info\"\n      }\n    }\n  }\n}\n```\n\nOr with Docker:\n\n```json\n{\n  \"mcpServers\": {\n    \"usgs-water-mcp-server\": {\n      \"type\": \"stdio\",\n      \"command\": \"docker\",\n      \"args\": [\n        \"run\", \"-i\", \"--rm\",\n        \"-e\", \"MCP_TRANSPORT_TYPE=stdio\",\n        \"ghcr.io/cyanheads/usgs-water-mcp-server:latest\"\n      ]\n    }\n  }\n}\n```\n\nTo enable DataCanvas for SQL analytics over large result sets (time series and site match sets), add `CANVAS_PROVIDER_TYPE=duckdb` to the `env` block in any of the configs above.\n\nFor Streamable HTTP, set the transport and start the server:\n\n```sh\nMCP_TRANSPORT_TYPE=http MCP_HTTP_PORT=3010 bun run start:http\n# Server listens at http://localhost:3010/mcp\n```\n\n### Prerequisites\n\n- [Bun v1.4.0](https://bun.sh/) or higher (or Node.js v24+).\n- No API key required — USGS NWIS is a free, public API.\n\n### Installation\n\n1. **Clone the repository:**\n\n```sh\ngit clone https://github.com/cyanheads/usgs-water-mcp-server.git\n```\n\n2. **Navigate into the directory:**\n\n```sh\ncd usgs-water-mcp-server\n```\n\n3. **Install dependencies:**\n\n```sh\nbun install\n```\n\n4. **Configure environment:**\n\n```sh\ncp .env.example .env\n# Edit .env to set any optional overrides\n```\n\n## Configuration\n\n| Variable | Description | Default |\n|:---------|:------------|:--------|\n| `CANVAS_PROVIDER_TYPE` | Set to `duckdb` to enable DataCanvas spillover for large results from `water_get_series` and `water_find_sites`. | — |\n| `USGS_USER_AGENT` | Custom User-Agent string sent to USGS NWIS. USGS requests a descriptive User-Agent per their terms. | `usgs-water-mcp-server/0.2.3 (contact: https://github.com/cyanheads/usgs-water-mcp-server)` |\n| `USGS_REQUEST_TIMEOUT_MS` | HTTP request timeout in milliseconds for NWIS calls. | `30000` |\n| `MCP_TRANSPORT_TYPE` | Transport: `stdio` or `http`. | `stdio` |\n| `MCP_HTTP_PORT` | Port for HTTP server. | `3010` |\n| `MCP_SESSION_MODE` | HTTP session mode. This project's `.env.example` and Docker runtime use `stateless`; `auto` resolves to `stateful`. | `stateless` |\n| `MCP_AUTH_MODE` | Auth mode: `none`, `jwt`, or `oauth`. | `none` |\n| `MCP_LOG_LEVEL` | Log level (RFC 5424). | `info` |\n| `LOGS_DIR` | Directory for log files (Node.js only). | `<project-root>/logs` |\n| `OTEL_ENABLED` | Enable [OpenTelemetry instrumentation](https://github.com/cyanheads/mcp-ts-core/tree/main/docs/telemetry) (spans, metrics, completion logs). | `false` |\n\nSee [`.env.example`](./.env.example) for the full list of optional overrides.\n\n## Running the server\n\n### Local development\n\n- **Build and run:**\n\n  ```sh\n  # One-time build\n  bun run rebuild\n\n  # Run the built server\n  bun run start:stdio\n  # or\n  bun run start:http\n  ```\n\n- **Run checks and tests:**\n\n  ```sh\n  bun run devcheck   # Lint, format, typecheck, security\n  bun run test       # Vitest test suite\n  bun run lint:mcp   # Validate MCP definitions against spec\n  ```\n\n### Docker\n\n```sh\ndocker build -t usgs-water-mcp-server .\ndocker run --rm -p 3010:3010 usgs-water-mcp-server\n```\n\nThe Dockerfile defaults to HTTP transport, stateless session mode, and logs to `/var/log/usgs-water-mcp-server`. OpenTelemetry peer dependencies are installed by default — build with `--build-arg OTEL_ENABLED=false` to omit them.\n\n## Project structure\n\n| Directory | Purpose |\n|:----------|:--------|\n| `src/index.ts` | `createApp()` entry point — registers tools/resources and inits services. |\n| `src/config` | Server-specific environment variable parsing and validation with Zod. |\n| `src/mcp-server/tools` | Tool definitions (`*.tool.ts`). |\n| `src/mcp-server/resources` | Resource definitions (`*.resource.ts`). |\n| `src/services/nwis` | NWIS HTTP client — IV, DV, site, and stat endpoints with HTML error detection. |\n| `src/services/canvas` | DataCanvas accessor for DuckDB-backed spillover. |\n| `tests/` | Unit and integration tests mirroring `src/`. |\n\n## Development guide\n\nSee [`CLAUDE.md`](./CLAUDE.md) for development guidelines and architectural rules. The short version:\n\n- Handlers throw, framework catches — no `try/catch` in tool logic\n- Use `ctx.log` for request-scoped logging, `ctx.state` for tenant-scoped storage\n- Register new tools and resources via the barrels in `src/mcp-server/*/definitions/index.ts`\n- Wrap external API calls: validate raw → normalize to domain type → return output schema; never fabricate missing fields\n\n## Contributing\n\nIssues and pull requests are welcome. Run checks and tests before submitting:\n\n```sh\nbun run devcheck\nbun run test\n```\n\n## License\n\nApache-2.0 — see [LICENSE](LICENSE) for details.\n",
  "bytes": 18894,
  "sha": "1714c3668baf6fc0cb395b935cc4d9c834239f39c0ac855feafdb67293b3e963",
  "repo_slug": "cyanheads/usgs-water-mcp-server",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/mcp_io_github_cyanheads_usgs_water_mcp_serve_5e6680a0/readme"
}