@maschinenlesbar.org/dwd-mcp 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -69,15 +69,25 @@ For scripts and shared configs, pin a release and its digest from the
69
69
 
70
70
  | Tool | What it answers |
71
71
  |---|---|
72
- | `getWarningBriefing` | The active warnings of the nowcast, Gemeinde and coast feeds in one list, most severe first, each with DWD's own level (1 to 4: Wetterwarnung to extreme Unwetterwarnung; the feeds' number is that + 1); for a place (lat/lon), only the warnings whose area contains it. Identical warnings over several areas counted once; advance information apart; a stale feed named. |
73
- | `getWarningAreas` | The warning areas as a GeoJSON FeatureCollection, one feature per area, most severe first, a page at a time. |
74
- | `getStationForecast` | A DWD station's forecast in real units, hour by hour from now and day by day (sunshine summed from the series), with the station's warnings; an unknown station id is named as missing. |
72
+ | `getWarningBriefing` | The active warnings of the nowcast, Gemeinde and coast feeds in one list, most severe first, each with DWD's own level (1 to 4: Wetterwarnung to extreme Unwetterwarnung; the feeds' number is that + 1); for a place (lat/lon), only the warnings whose area contains it, with the coast and lake warnings (which have no area) apart, so a point at sea is never called calm while one is out, and a point outside Germany and its coastal waters said to be outside. Identical warnings over several areas counted once; a warning that begins later marked (`startsLater`) and counted (`startingLater`); advance information apart; a stale feed named, and a feed that could not be read named while the others are answered. |
73
+ | `getWarningAreas` | The warning areas as a GeoJSON FeatureCollection, one feature per area, most severe first, a page at a time. An outline over 300 positions is simplified to 300 (marked `simplified`, with a note), so every area fits an answer; `geometry: "full"` gives the outlines as delivered. |
74
+ | `getStationForecast` | A DWD station's forecast in real units, hour by hour from now and day by day (sunshine summed from the series), with the station's warnings; an unknown station id is named as missing. Stations in the order asked; over the size cap the last ones move to the next page (`offset`). |
75
75
  | `checkCrowdReports` | Crowd reports of the WarnWetter app near a place or a point, per category, with photos and likes as corroboration, optionally against the official warnings there; a place name matching towns far apart is reported as ambiguous. Positions rounded to about 10 km, times to the hour. |
76
76
  | `getWarningFeed` | One warning feed as DWD sends it, without the areas, a page at a time. |
77
77
  | `getStationOverview` | One station's overview as the web service sends it, decoded to real units. |
78
78
 
79
79
  Every tool only reads. An answer is JSON (`structuredContent` and the same as text), with the
80
- `source` it came from and the data licence. A failure is a tool error that says what to change.
80
+ `source` it came from (whole, never cut like the data; a call that reads several feeds names
81
+ each feed's URL, separated by ", "; an answer a redirect fetched from another
82
+ host says so there: "… (answered by https://other.example after a redirect)", and a WARN record
83
+ names both) and the data licence. A text over 2000 characters is cut and ends in `…[cut, N
84
+ characters in all]`, and the answer says `truncated`. An answer over `--max-result-chars` first
85
+ loses entries from the end of its page (then `nextOffset` says where to go on), then has its longest
86
+ texts cut further (each with that mark) or, when that isn't enough, its other lists shortened
87
+ (`reason` names them); a list keeps its first entry, `notes` stay whole, and the answer says
88
+ `truncated`. One that can't be cut down so far is a tool error that says to ask for less. A failure
89
+ is a tool error that says what to change (one over 5000 characters loses its middle, never its end,
90
+ where the reason is).
81
91
 
82
92
  ## Options
83
93
 
@@ -87,35 +97,49 @@ Every tool only reads. An answer is JSON (`structuredContent` and the same as te
87
97
  --port <n> HTTP: the port (default 3000)
88
98
  --allowed-hosts <list> HTTP: Host header names to answer (default localhost,127.0.0.1,[::1])
89
99
  --allowed-origins <list> HTTP: browser origins allowed to call, exactly (https://app.example.org); none by default
100
+ --auth-token-file <path> HTTP: a file with the bearer token every request must send (mode 600, 32+ characters)
90
101
  --base-url <url> API base URL (default https://app-prod-ws.warnwetter.de): a mirror
91
- of both hosts (its /v30 and /v16 under one base); without it, each
92
- host is its default
102
+ of both hosts (its /v30 and /v16 under one base); without it, or
103
+ with the default in any spelling, each host is its default
93
104
  --timeout <ms> per upstream request (default 30000)
94
105
  --call-timeout <ms> per tool call, retries included (default 45000)
95
106
  --max-result-chars <n> cap on one tool result's JSON (default 25000)
96
107
  --max-pages <n> pages a tool reads per list and call (default 10)
97
- --user-agent <ua> User-Agent header value
108
+ --user-agent <ua> User-Agent header value (Latin-1, one line)
98
109
  --log-format <text|jsonl> the log records on stderr (default text)
99
110
  ```
100
111
 
101
112
  ## What it does and doesn't do
102
113
 
103
114
  - **Read-only.** No tool changes anything, here or upstream.
104
- - **No authentication** on HTTP. It listens on loopback by default; it checks the `Host` header
105
- and, from a browser, the `Origin` (only the origins given with `--allowed-origins`, matched
106
- exactly) against DNS rebinding and other web pages. Exposed beyond localhost (it logs a warning then), it
107
- belongs behind a proxy that authenticates.
115
+ - **No authentication** on HTTP unless you give one. It listens on loopback by default; it checks
116
+ the `Host` header and, from a browser, the `Origin` (only the origins given with
117
+ `--allowed-origins`, matched exactly) against DNS rebinding and other web pages; a page on one of
118
+ those origins gets CORS (its preflight answered, the answers readable). With `--auth-token-file
119
+ <path>` every request must send `Authorization: Bearer <token>` (the file holds one token of at
120
+ least 32 characters, mode 600, owned by the user the server runs as, a regular file (a FIFO is
121
+ refused at once, never waited on); read once at start; `(umask 077; openssl rand -hex 32 >
122
+ mcp-token)` makes one); anything else is answered 401. Exposed beyond localhost (it logs a warning
123
+ then), it belongs behind a proxy that authenticates or at least terminates TLS.
108
124
  - **Gentle with the upstream.** One server process sends at most 2 requests at a time and 120 a
109
- minute to the API, pauses on HTTP 429, and stops a tool call after its deadline.
110
- - **Results are data.** Text from the API is cleaned (control, bidi and zero-width characters
111
- removed), but it is still other people's text: a model can be told things in it. The server
112
- can't act on that (it has no tool that writes), but other tools in the same session could.
113
- - **Stops cleanly.** On `docker stop` (SIGTERM) or Ctrl-C the HTTP server takes no new
114
- connection and lets calls in flight answer for up to 5 s, then exits 143 (130); a second signal
115
- ends it at once. On stdio it ends at once, and when stdin ends.
125
+ minute to the API, pauses the requests to a host that answers HTTP 429 (as long as its Retry-After
126
+ asks, at most 30 s; those to another host go on), and stops a tool call after its deadline (a tool
127
+ that has read part of its answer by then may answer with that part, and says so). A request those
128
+ limits would hold longer than it or its call may wait is not sent: the call fails at once, naming
129
+ the limit and when to ask again (and the log says so).
130
+ - **Results are data.** Text from the API, keys included, is cleaned (control, bidi, zero-width, tag
131
+ and other invisible characters removed, but an emoji keeps its joiners; a key that cleaning makes
132
+ equal to another stays, as `name~2`), but it is still other people's text: a model can be told
133
+ things in it. The server can't act on that (it has no tool that writes), but other tools in the
134
+ same session could.
135
+ - **Stops cleanly.** On `docker stop` (SIGTERM) or Ctrl-C the HTTP server takes no new connection
136
+ and lets calls in flight answer for up to 5 s, then exits 143 (130); a second signal ends it at
137
+ once. On stdio a signal ends it at once; when stdin ends, it first answers the requests it has
138
+ read (each within its call deadline), then exits.
116
139
  - **In a container** it needs at least 12 processes and threads (`--pids-limit`) and about
117
140
  256 MB of memory.
118
- - **Logs** go to stderr, one record per line; stdout carries only the protocol.
141
+ - **Logs** go to stderr, one record per line; stdout carries only the protocol. A call that fails
142
+ upstream or reaches its deadline leaves a WARN record naming the tool.
119
143
  - **Never installs anything.**
120
144
 
121
145
  ## Licence
@@ -9,7 +9,7 @@ export type { QueryParams, QueryValue } from "./query.js";
9
9
  export { assertValid, baseUrlProblem, headerValueProblem, langProblem, listProblem, nonBlankProblem, normalizeStationIds, normalizeToken, serviceBaseUrlProblem, splitList, stationIdProblem, tokenProblem, } from "./validate.js";
10
10
  export type { Problem } from "./validate.js";
11
11
  export { DwdError, DwdApiError, DwdNetworkError, DwdParseError, DwdValidationError, redactUrl, credentialsIn, quoteValue, redactCredentials, } from "./errors.js";
12
- export { berlinTime, checkCrowdReports, containsPoint, CROWD_CATEGORIES, distanceKm, DWD_LEVELS, dwdLevelOf, FORECAST_UNITS, getStationForecast, getWarningAreas, getWarningBriefing, regionGeometry, WARNING_FEEDS, } from "./operations.js";
12
+ export { berlinTime, checkCrowdReports, containsPoint, CROWD_CATEGORIES, distanceKm, DWD_LEVELS, DWD_WARNING_AREA, dwdLevelOf, FORECAST_UNITS, getStationForecast, getWarningAreas, getWarningBriefing, positionCount, regionGeometry, simplifyGeometry, WARNING_FEEDS, } from "./operations.js";
13
13
  export type { AreaGeometry, BriefedWarning, CrowdCheck, CrowdCheckInput, CrowdReport, FeedState, ForecastDay, ForecastHour, StationForecast, StationForecastInput, StationForecasts, WarningArea, WarningAreas, WarningAreasInput, WarningBriefing, WarningBriefingInput, WarningFeedName, } from "./operations.js";
14
14
  export * from "./enums.js";
15
15
  export * from "./types.js";
@@ -5,6 +5,6 @@ export { MAX_TIMEOUT_MS, nodeHttpTransport } from "./http.js";
5
5
  export { buildQueryString } from "./query.js";
6
6
  export { assertValid, baseUrlProblem, headerValueProblem, langProblem, listProblem, nonBlankProblem, normalizeStationIds, normalizeToken, serviceBaseUrlProblem, splitList, stationIdProblem, tokenProblem, } from "./validate.js";
7
7
  export { DwdError, DwdApiError, DwdNetworkError, DwdParseError, DwdValidationError, redactUrl, credentialsIn, quoteValue, redactCredentials, } from "./errors.js";
8
- export { berlinTime, checkCrowdReports, containsPoint, CROWD_CATEGORIES, distanceKm, DWD_LEVELS, dwdLevelOf, FORECAST_UNITS, getStationForecast, getWarningAreas, getWarningBriefing, regionGeometry, WARNING_FEEDS, } from "./operations.js";
8
+ export { berlinTime, checkCrowdReports, containsPoint, CROWD_CATEGORIES, distanceKm, DWD_LEVELS, DWD_WARNING_AREA, dwdLevelOf, FORECAST_UNITS, getStationForecast, getWarningAreas, getWarningBriefing, positionCount, regionGeometry, simplifyGeometry, WARNING_FEEDS, } from "./operations.js";
9
9
  export * from "./enums.js";
10
10
  export * from "./types.js";
@@ -21,6 +21,15 @@ export interface AreaGeometry {
21
21
  * each pair swapped. `triangles` is a rendering index, never geometry. Undefined when neither is usable.
22
22
  */
23
23
  export declare function regionGeometry(region: unknown): AreaGeometry | undefined;
24
+ /** How many positions a geometry has, over all its rings. */
25
+ export declare function positionCount(geometry: AreaGeometry): number;
26
+ /**
27
+ * `geometry` with at most about `maxPoints` positions: each ring keeps its share of them (at least
28
+ * 4, a closed triangle), evenly spaced along it, its first position and the closing one kept. A
29
+ * geometry within `maxPoints` comes back as it is. For a map of warning areas (an outline of
30
+ * thousands of positions is over a result's size), not for exact borders.
31
+ */
32
+ export declare function simplifyGeometry(geometry: AreaGeometry, maxPoints: number): AreaGeometry;
24
33
  /** True when `[lat, lon]` lies in the polygon (in its outer ring, not in a hole) or in one of the multipolygon's. */
25
34
  export declare function containsPoint(geometry: AreaGeometry, point: [number, number]): boolean;
26
35
  /**
@@ -31,11 +40,11 @@ export declare function containsPoint(geometry: AreaGeometry, point: [number, nu
31
40
  export declare function dwdLevelOf(warning: JsonObject): number | undefined;
32
41
  /** The input of {@link getWarningBriefing}. */
33
42
  export interface WarningBriefingInput {
34
- /** The feeds to read (default all three; with a point nowcast and Gemeinde, the coast feed has no areas). */
43
+ /** The feeds to read (default all three). */
35
44
  feeds?: readonly WarningFeedName[] | undefined;
36
45
  /** de (default) or en: in en the feeds translate event and texts, and state DWD's level. */
37
46
  lang?: Lang | undefined;
38
- /** Only the warnings whose area contains this point (nowcast and Gemeinde; coast and lake warnings have no area). */
47
+ /** Only the warnings whose area contains this point (nowcast and Gemeinde); coast and lake warnings have no area and come apart, in `unlocated`. */
39
48
  lat?: number | undefined;
40
49
  lon?: number | undefined;
41
50
  /** At most this many warnings listed, most severe first (1–100, default 25); the rest are counted. */
@@ -63,12 +72,17 @@ export interface BriefedWarning {
63
72
  count: number;
64
73
  /** Coastal zone or lake ids (coast and lake warnings have no area and no end). */
65
74
  zones?: string[];
75
+ /** True when the warning begins after now: issued, not yet in force. */
76
+ startsLater?: true;
66
77
  }
67
- /** A feed's age and whether it is stale. */
78
+ /** A feed's age and whether it is stale, or that it could not be read (`unavailable`, `problem` says why). */
68
79
  export interface FeedState {
69
80
  feed: WarningFeedName;
70
- published: string;
81
+ /** When the feed was published; absent for a feed that could not be read. */
82
+ published?: string;
71
83
  stale: boolean;
84
+ /** True when the feed could not be read: its warnings are missing from the answer. */
85
+ unavailable?: true;
72
86
  problem?: string;
73
87
  }
74
88
  /** The answer of {@link getWarningBriefing}. */
@@ -82,8 +96,10 @@ export interface WarningBriefing {
82
96
  };
83
97
  /** One line: the count and the worst level, or why there is nothing. */
84
98
  verdict: string;
85
- /** Active warnings (identical ones counted once). */
99
+ /** Active warnings (identical ones counted once): in force now, or issued for later. */
86
100
  active: number;
101
+ /** How many of them begin later (not yet in force); absent when none does. */
102
+ startingLater?: number;
87
103
  /** The worst DWD level among them. */
88
104
  worstDwdLevel?: number;
89
105
  /** Active warnings per event. */
@@ -93,10 +109,25 @@ export interface WarningBriefing {
93
109
  advance: BriefedWarning[];
94
110
  /** Entries left out past `limit`. */
95
111
  more?: number;
112
+ /**
113
+ * With a point: the active coast and inland-lake warnings, which have no area to test the point
114
+ * against (their zone ids name the sea area or lake); they apply when the point is at sea or on a lake.
115
+ */
116
+ unlocated?: BriefedWarning[];
96
117
  feeds: FeedState[];
97
118
  reason?: string;
98
119
  notes: string[];
99
120
  }
121
+ /**
122
+ * The area DWD warns for, as a box: Germany (47.2–55.1° N, 5.8–15.1° E) and its coastal waters
123
+ * (the German Bight and the western Baltic). A point outside it has no DWD warning, whatever the feeds say.
124
+ */
125
+ export declare const DWD_WARNING_AREA: Readonly<{
126
+ south: 47;
127
+ north: 56;
128
+ west: 3;
129
+ east: 15.5;
130
+ }>;
100
131
  /**
101
132
  * The official warnings of the nowcast, Gemeinde and coast feeds in one ranked list: expired items
102
133
  * dropped, advance information (`isVorabinfo`) apart, identical warnings (same feed, event, level,
@@ -105,7 +136,10 @@ export interface WarningBriefing {
105
136
  * coast and nowcast (short-fuse) before Gemeinde. Each states DWD's level (1–4) and its name, never
106
137
  * the feed's number as "level N". A stale feed (published more than an hour ago) is named, and an
107
138
  * empty answer with a stale feed says so instead of "calm". With a point, only the nowcast and
108
- * Gemeinde warnings whose area contains it (coast and lake warnings have no area).
139
+ * Gemeinde warnings whose area contains it; the coast and lake warnings, which have no area, come
140
+ * apart in `unlocated` (they apply at sea or on the lake), so a point at sea never reads as calm
141
+ * while a coast warning is out. A point outside {@link DWD_WARNING_AREA} is said to be outside,
142
+ * without a request.
109
143
  */
110
144
  export declare function getWarningBriefing(client: DwdClient, input?: WarningBriefingInput): Promise<WarningBriefing>;
111
145
  /** The input of {@link getWarningAreas}. */
@@ -115,6 +149,8 @@ export interface WarningAreasInput {
115
149
  lang?: Lang | undefined;
116
150
  /** Only warnings of at least this DWD level (1–4). */
117
151
  minDwdLevel?: number | undefined;
152
+ /** An area outline with more positions than this (20–100000) is simplified to about this many (simplifyGeometry); default as delivered. */
153
+ maxPoints?: number | undefined;
118
154
  /** The clock, epoch ms (default now). */
119
155
  now?: number | undefined;
120
156
  }
@@ -133,6 +169,8 @@ export interface WarningArea {
133
169
  start?: string;
134
170
  end?: string;
135
171
  isVorabinfo: boolean;
172
+ /** True when the outline was simplified (maxPoints): fine for a map, not for exact borders. */
173
+ simplified?: true;
136
174
  };
137
175
  }
138
176
  /** The answer of {@link getWarningAreas}: a FeatureCollection, most severe first. */
@@ -145,10 +183,12 @@ export interface WarningAreas {
145
183
  minDwdLevel?: number;
146
184
  };
147
185
  features: WarningArea[];
148
- /** Regions without a usable geometry, left out. */
186
+ /** Regions without a usable geometry, and warnings without regions, left out. */
149
187
  skipped: number;
150
188
  feeds: FeedState[];
151
189
  reason?: string;
190
+ /** What the feeds' items didn't fit (a field missing): only when there is something to say. */
191
+ notes?: string[];
152
192
  }
153
193
  /**
154
194
  * The active warnings of the nowcast and Gemeinde feeds as GeoJSON features, one per region (a
@@ -247,6 +287,8 @@ export interface StationForecasts {
247
287
  /** Ids the API has no data for (it answers an unknown id with nothing, not an error). */
248
288
  missing: string[];
249
289
  reason?: string;
290
+ /** What the answer leaves out and why (fewer hours than asked for). */
291
+ notes: string[];
250
292
  }
251
293
  /**
252
294
  * The forecast of one or more DWD stations in real units (°C, mm, %, hPa, km/h, minutes of sun):
@@ -256,24 +298,25 @@ export interface StationForecasts {
256
298
  * summed from the series, since the API's daily `sunshine` is often 0 on sunny days. A value the
257
299
  * API marks missing (32767) is null, never 0 or 3276.7; a series the station lacks is named in
258
300
  * `notProvided`. An unknown id is in `missing` (the API answers it with nothing, not an error).
301
+ * The stations come in the order asked, each once.
259
302
  */
260
303
  export declare function getStationForecast(client: DwdClient, input: StationForecastInput): Promise<StationForecasts>;
261
- /** Crowd report categories seen in the feed (others may come); BEWOELKUNG, cloud cover, is the feed's noise. */
262
- export declare const CROWD_CATEGORIES: readonly ["REGEN", "GEWITTER", "BLITZE", "HAGEL", "WIND", "NEBEL", "GLAETTE", "BEWOELKUNG"];
304
+ /** Crowd report categories seen in the feed (others may come: a category the feed has is one too); BEWOELKUNG, cloud cover, is the feed's noise. */
305
+ export declare const CROWD_CATEGORIES: readonly ["REGEN", "GEWITTER", "BLITZE", "HAGEL", "WIND", "NEBEL", "GLAETTE", "SCHNEEFALL", "SCHNEEDECKE", "BEWOELKUNG"];
263
306
  /** The input of {@link checkCrowdReports}. */
264
307
  export interface CrowdCheckInput {
265
- /** A place name, or part of it (`Mainz`, `Lauingen`): an exact name wins over partial matches. */
308
+ /** A place name, or part of it (`Mainz`, `Lauingen`): an exact name wins over partial matches; case, ß/ss and the umlauts spelled out (Muenchen) don't matter. */
266
309
  place?: string | undefined;
267
310
  /** A point, with radiusKm: the reports within that distance. */
268
311
  lat?: number | undefined;
269
312
  lon?: number | undefined;
270
313
  /** 1–200 km, default 25. */
271
314
  radiusKm?: number | undefined;
272
- /** Only these categories, e.g. HAGEL, BLITZE (default every category but BEWOELKUNG, cloud cover, the feed's noise). */
315
+ /** Only these categories, e.g. HAGEL, BLITZE (default every category but BEWOELKUNG, cloud cover, the feed's noise); case and umlauts don't matter (Glätte is GLAETTE). One that is neither in CROWD_CATEGORIES nor in the feed is named in the reason or a note, never answered as "nobody reported it". */
273
316
  categories?: readonly string[] | undefined;
274
317
  /** Reports from the last this many minutes before the feed's end (5–1440, default 60). */
275
318
  sinceMinutes?: number | undefined;
276
- /** Also the official warnings at the point (given, or the matching reports' mean position). */
319
+ /** Also the official warnings at the point (given, or the matching reports' mean position, rounded to 0.1°). */
277
320
  withWarnings?: boolean | undefined;
278
321
  /** The clock, epoch ms (default now), for the warnings' expiry and the feeds' age. */
279
322
  now?: number | undefined;