dwelldelta-mcp 0.7.0 → 0.8.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
@@ -17,9 +17,11 @@ Six read-only tools, and one that adds the user's own rent when they ask:
17
17
  | `contribute_rent` | adds the user's own rent, anonymously, to DwellDelta's suburb benchmarks - only when the user asks, and only after they have read and agreed to the consent wording (from 0.5.0) |
18
18
 
19
19
  It runs on your own machine over stdio. It records nothing and sends nothing about you unless you choose to add
20
- your rent. At start it fetches the week's indicators from tools.dwelldelta.com.au - one request for one public
21
- file; nothing about you or your questions is sent - and otherwise uses the copy it ships with. Set
22
- `DWELLDELTA_OFFLINE=1` and that fetch is not made. Nothing it says is a forecast, a valuation or advice.
20
+ your rent. At start it fetches DwellDelta's published files from tools.dwelldelta.com.au - the week's indicators,
21
+ the rents and sale prices it answers from, eight public files in all, the same for everyone; nothing about you or
22
+ your questions is sent - and otherwise uses the copies it ships with. Set `DWELLDELTA_OFFLINE=1` and none of those
23
+ eight files is fetched; adding a rent with `contribute_rent` still sends it, as you asked. Nothing it says is a
24
+ forecast, a valuation or advice.
23
25
 
24
26
  ## Adding a rent (from 0.5.0)
25
27
 
@@ -40,7 +42,9 @@ type, because a sale price without it answers nobody's question, and carries the
40
42
  its limits. DCJ reports a quarter when about 80% of its sales have been notified, so the counts are incomplete
41
43
  and the sales quarter runs behind the rents quarter. DCJ's own table has rows that a few very large sales, or
42
44
  many sales at one identical price, have set: the answer marks those lines UNUSUAL and says not to quote them as
43
- a going price. Prices in the structured result stay in DCJ's unit, thousands of dollars, and `unit` says so.
45
+ a going price. Where the published file notes that a total is mostly the sales of such a row (its
46
+ `unusual_part` field), releases from 0.8.0 say so on that total's line, and say only that its median and its
47
+ change may be moved by that row's sales. Prices in the structured result stay in DCJ's unit, thousands of dollars, and `unit` says so.
44
48
  The feed is public at <https://tools.dwelldelta.com.au/market/nsw-sales.json>.
45
49
 
46
50
  ## Use it
@@ -76,6 +80,25 @@ https://tools.dwelldelta.com.au/market/nsw-rents.json, `qld-rents.json` and `wa-
76
80
  at start the way it reads the indicators, and `DWELLDELTA_STATE_RENTS_DIR` points it at a folder of copies.
77
81
  Victoria, measured differently again, stays in `vic_rents`.
78
82
 
83
+ ### By dwelling type and bedrooms (from 0.8.0)
84
+
85
+ Give `area_rents` a `dwelling_type`, a number of `bedrooms`, or both, and for NSW and Queensland it answers with
86
+ the publisher's own figure for that kind of home - a two-bedroom unit, a three-bedroom house - under the
87
+ publisher's own label. One of the two is enough: a type gives every size the publisher reports for it, a size
88
+ every type. A combination with no published median is said to have none; it is never filled from the
89
+ all-dwellings figure, a neighbouring area or a wider group. Many of these figures rest on few bonds, and each
90
+ small sample is marked. The Residential Tenancies Authority does not define its labels: reading "Flat 2" as a
91
+ two-bedroom flat is DwellDelta's reading, and every Queensland answer says so. WA's bond records carry neither
92
+ dwelling type nor bedrooms, so WA has no such figures. DCJ's largest size is "4 or more Bedrooms": a number above
93
+ four is answered under that label, and the answer says it is not for that number alone. A number followed by a
94
+ plus means "or more", which only that one size has; anything else with a plus is refused, not answered as exactly
95
+ that many.
96
+
97
+ The two files (https://tools.dwelldelta.com.au/market/nsw-rents-by-type.json and `qld-rents-by-type.json`) are
98
+ large and are not bundled. The server asks for them once at start, without waiting for them, and never in
99
+ response to a question. Offline, put copies in the folder `DWELLDELTA_STATE_RENTS_DIR` names; without them a
100
+ by-type question fails with the next step, and every other answer is unaffected.
101
+
79
102
  It is listed in the MCP registry as `au.com.dwelldelta/dwelldelta`.
80
103
 
81
104
  ## What an agent gets back
@@ -11,6 +11,9 @@
11
11
  * else the published file (fetched once at start - one public file each; nothing about the user or their questions is
12
12
  * sent - and used if well formed, for the right state, and not older than the bundled copy), else the copy bundled at
13
13
  * pack time. DWELLDELTA_OFFLINE=1 never fetches. The data changes once a quarter, so every answer states its quarter.
14
+ *
15
+ * With dwelling_type or bedrooms (from 0.8.0) NSW and Queensland answer from their by-type
16
+ * files instead - see "by dwelling type and bedrooms" at the end of this file.
14
17
  */
15
18
  import { existsSync } from "node:fs";
16
19
  import { fileURLToPath } from "node:url";
@@ -71,7 +74,9 @@ export async function loadAllAreaRents(opts) {
71
74
 
72
75
  // Exported for sale-prices-tool.mjs (0.7.0), which matches names and words figures the same way.
73
76
  export const norm = (s) => String(s).trim().toLowerCase();
74
- export const dollars = (v) => `$${v.toLocaleString("en-AU")}`;
77
+ // Cents as two digits ($872.50, a WA median between two bonds), whole dollars as $650 - as the site prints them
78
+ // since tools #27 (2026-10-17).
79
+ export const dollars = (v) => { const n = Number(v); return `$${n.toLocaleString("en-AU", Number.isInteger(n) ? {} : { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`; };
75
80
  export const signed = (v) => `${v >= 0 ? "+" : ""}${v}%`;
76
81
 
77
82
  function line(r, name) {
@@ -110,8 +115,13 @@ export function nswPostcodes(wanted, suburbs, feed) {
110
115
  return found.slice(0, 5).map((m) => `${m[1]} is in postcode ${m[2]}`);
111
116
  }
112
117
 
113
- /** area_rents: one state; an area (postcode, suburb or locality), a council, or neither for the state's own row. */
114
- export function areaRentsResult({ state, area, council } = {}, feeds, now = new Date(), { nswSuburbs = [] } = {}) {
118
+ /**
119
+ * area_rents: one state; an area (postcode, suburb or locality), a council, or neither for the state's own row.
120
+ * With dwelling_type or bedrooms the answer comes from that state's by-type file instead (byType[state], loaded at
121
+ * start by loadAllRentsByType) - see byTypeResult below.
122
+ */
123
+ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms } = {}, feeds, now = new Date(),
124
+ { nswSuburbs = [], byType = {} } = {}) {
115
125
  const info = STATES[state];
116
126
  if (!info) {
117
127
  throw new ToolError(`No area rents for ${JSON.stringify(state)}.`,
@@ -143,6 +153,9 @@ export function areaRentsResult({ state, area, council } = {}, feeds, now = new
143
153
  }
144
154
  }
145
155
  const whole = !areas.length && !councils.length;
156
+ if (wantsByType({ dwelling_type, bedrooms })) {
157
+ return byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas, councils, file: byType[state] }, now);
158
+ }
146
159
  if (whole) regions = feed.regions;
147
160
  const dropped = [];
148
161
  for (const [label, rows] of [[kind, areas], ["council", councils]]) {
@@ -176,3 +189,246 @@ export function areaRentsResult({ state, area, council } = {}, feeds, now = new
176
189
  state_total: whole ? feed.state_total : null, regions, councils, areas,
177
190
  truncated: dropped.length > 0, limits: feed.limits, changes_made: feed.changes_made } };
178
191
  }
192
+
193
+ // --- by dwelling type and bedrooms --------------------------------------------------------------------------------
194
+ // Prepared 2026-10-10; NOT in 0.7.0, the version on npm. "What does a two-bedroom unit rent for there?" is the
195
+ // question people ask, and the feeds above answer only for all dwellings together. NSW and Queensland publish a
196
+ // companion file each (market/{nsw,qld}-rents-by-type.json); WA's bond records carry neither dwelling type nor
197
+ // bedrooms, so WA has none.
198
+ //
199
+ // The files are large (1.3 MB and 0.4 MB) and are not bundled: they load from DWELLDELTA_STATE_RENTS_DIR, the
200
+ // owner's live store, or the published address - asked for once, at start, like every other file and never in
201
+ // response to a question, so a request still says nothing about the user or what they asked. The server does not
202
+ // wait for them: the first by-type question does. Offline, with no folder of copies, a by-type question fails with
203
+ // the next step, and the all-dwellings answer is unaffected.
204
+ //
205
+ // Every figure is the publisher's cell under the publisher's own label. A combination the file does not list has NO
206
+ // published median - it is said, with the file's own words for what that means, and never filled from a
207
+ // neighbouring area, a wider group or the all-dwellings figure. The RTA does not define "Flat 2": reading it as a
208
+ // two-bedroom flat is DwellDelta's reading, and the answer carries the file's sentence saying so.
209
+ export const BY_TYPE = { NSW: "nsw-rents-by-type.json", QLD: "qld-rents-by-type.json" };
210
+ export const BY_TYPE_TIMEOUT_MS = 20000;
211
+ /** Places answered by type in one call: each can run to a dozen lines. */
212
+ export const MAX_TYPE_PLACES = 5;
213
+
214
+ export const wantsByType = ({ dwelling_type, bedrooms } = {}) =>
215
+ [dwelling_type, bedrooms].some((v) => v != null && String(v).trim() !== "");
216
+
217
+ const wellFormedByType = (f, state) => f && f.state === state && f.detail === "dwelling_type_and_bedrooms"
218
+ && quarterKey(f.quarter) > 0 && Array.isArray(f.areas) && f.areas.length > 0 && Array.isArray(f.councils)
219
+ && f.state_total && f.state_total.breakdown && Array.isArray(f.limits) && f.licence && f.attribution
220
+ && f.changes_made && f.absent_means && f.labels;
221
+
222
+ /** One state's by-type file and where it came from ("env", "live" or "published"); { feed: null } if none. */
223
+ export async function loadRentsByType(state, { env = process.env, fetchImpl = globalThis.fetch, liveDir = LIVE_DIR } = {}) {
224
+ const file = BY_TYPE[state];
225
+ const read = (path) => loadJson(path).then((f) => (wellFormedByType(f, state) ? f : null)).catch(() => null);
226
+ if (env.DWELLDELTA_STATE_RENTS_DIR) return { feed: await read(join(env.DWELLDELTA_STATE_RENTS_DIR, file)), origin: "env" };
227
+ if (existsSync(join(liveDir, file))) return { feed: await read(join(liveDir, file)), origin: "live" };
228
+ if (env.DWELLDELTA_OFFLINE !== "1" && typeof fetchImpl === "function") {
229
+ try {
230
+ const res = await fetchImpl(PUBLISHED_BASE + file, { signal: AbortSignal.timeout(BY_TYPE_TIMEOUT_MS) });
231
+ const got = res.ok ? await res.json() : null;
232
+ if (wellFormedByType(got, state)) return { feed: got, origin: "published" };
233
+ } catch {
234
+ // Offline, blocked or slow: there is no bundled copy, and a by-type question will say what to do.
235
+ }
236
+ }
237
+ return { feed: null, origin: null };
238
+ }
239
+
240
+ /** Both states' by-type files: { NSW: file-with-origin | null, QLD: ... }. It never rejects. */
241
+ export async function loadAllRentsByType(opts) {
242
+ const states = Object.keys(BY_TYPE);
243
+ const loaded = await Promise.all(states.map((s) => loadRentsByType(s, opts).catch(() => ({ feed: null }))));
244
+ return Object.fromEntries(states.map((s, i) => [s, loaded[i].feed ? { ...loaded[i].feed, origin: loaded[i].origin } : null]));
245
+ }
246
+
247
+ const NSW_TYPES = ["House", "Townhouse", "Flat/Unit", "Other", "Total"];
248
+ const NSW_SIZES = ["Bedsitter", "1 Bedroom", "2 Bedrooms", "3 Bedrooms", "4 or more Bedrooms", "Not Specified", "Total"];
249
+ // Words people use for the publishers' labels. Each maps to ONE label, and the answer always prints the label itself.
250
+ const TYPE_WORDS = { unit: "Flat/Unit", units: "Flat/Unit", flat: "Flat/Unit", flats: "Flat/Unit", apartment: "Flat/Unit",
251
+ apartments: "Flat/Unit", houses: "House", "town house": "Townhouse", townhouses: "Townhouse",
252
+ all: "Total", any: "Total", "all dwellings": "Total" };
253
+ const QLD_KINDS = { unit: "Flat", units: "Flat", flats: "Flat", apartment: "Flat", apartments: "Flat", houses: "House",
254
+ "town house": "Townhouse", townhouses: "Townhouse" };
255
+ const known = (present, order) => [...order.filter((l) => present.has(l)), ...[...present].filter((l) => !order.includes(l))];
256
+
257
+ /** The one label a word names: the label itself, a known word for it, or the only label containing it. */
258
+ function label(wanted, labels, words, what, state) {
259
+ const w = norm(wanted).replace(/\s+/g, " ");
260
+ const found = labels.find((l) => norm(l) === w) ?? (labels.includes(words[w]) ? words[w] : null);
261
+ if (found) return found;
262
+ const part = labels.filter((l) => norm(l).includes(w));
263
+ if (part.length === 1) return part[0];
264
+ throw new ToolError(`No ${STATES[state].name} ${what} matches ${JSON.stringify(wanted)}.`,
265
+ `The publisher's ${what} labels are: ${labels.join(", ")}. Call again with one of them.`);
266
+ }
267
+
268
+ /**
269
+ * A number of bedrooms as someone writes it - "2", "2 bed", "2br", "4+", "studio" - or null if it is not one.
270
+ * orMore is the plus: "that many or more" is a different question from "exactly that many", and is answered only
271
+ * where the publisher has a label that means it. (It used to be dropped, so "3+" was answered as three.)
272
+ */
273
+ function bedroomsAsked(wanted) {
274
+ const w = norm(wanted).replace(/\s+/g, " ");
275
+ if (["studio", "bedsit", "bedsitter"].includes(w)) return { n: 0, orMore: false };
276
+ const m = /^(\d{1,2})\s*(\+)?\s*(?:bed(?:room)?s?|br)?$/.exec(w);
277
+ return m ? { n: Number(m[1]), orMore: Boolean(m[2]) } : null;
278
+ }
279
+
280
+ /** NSW: which of DCJ's dwelling types and sizes were asked for (null = every one), as DCJ labels them. */
281
+ function nswAsked(file, dwelling_type, bedrooms) {
282
+ const cells = file.state_total.breakdown;
283
+ const types = known(new Set(Object.keys(cells)), NSW_TYPES);
284
+ const sizes = known(new Set(Object.values(cells).flatMap((c) => Object.keys(c))), NSW_SIZES);
285
+ const type = wantsByType({ dwelling_type }) ? label(dwelling_type, types, TYPE_WORDS, "dwelling type", "NSW") : null;
286
+ let size = null;
287
+ const notes = [];
288
+ if (wantsByType({ bedrooms })) {
289
+ const b = bedroomsAsked(bedrooms);
290
+ // DCJ's one "or more" size is "4 or more Bedrooms". Below that, "N or more" has no figure of its own.
291
+ if (b && b.orMore && b.n < 4) {
292
+ throw new ToolError(`DCJ reports no figure for ${b.n} or more bedrooms.`,
293
+ `Its sizes are: ${sizes.join(", ")}. Call again with bedrooms "${b.n}" for exactly that many, or "4+" for DCJ's ` +
294
+ `"4 or more Bedrooms".`);
295
+ }
296
+ const n = b ? b.n : null;
297
+ const counted = n === null ? null
298
+ : n === 0 ? "Bedsitter" : n >= 4 ? "4 or more Bedrooms" : sizes.find((s) => s.startsWith(`${n} Bedroom`));
299
+ size = counted && sizes.includes(counted) ? counted
300
+ : label(bedrooms, sizes, { all: "Total", any: "Total", "all sizes": "Total" }, "bedrooms", "NSW");
301
+ // Five, six or "5+" lie inside "4 or more Bedrooms", the only figure DCJ has for them - but it is the figure for
302
+ // every home of four or more, which is not what was asked. Answered, and said. (It used to be answered and not said.)
303
+ if (b && b.n > 4 && size === "4 or more Bedrooms") {
304
+ notes.push(`You asked for ${b.n}${b.orMore ? " or more" : ""} bedrooms. DCJ's largest size is "4 or more Bedrooms": the figures ` +
305
+ "here are for every home of four bedrooms or more together, and DCJ reports nothing narrower. Say so when you give them.");
306
+ }
307
+ }
308
+ const wanted = [];
309
+ for (const t of type ? [type] : types) {
310
+ for (const s of size ? [size] : sizes) {
311
+ // Total and Total is the all-dwellings figure: shown only when both were asked for by name.
312
+ if (t === "Total" && s === "Total" && !(type && size)) continue;
313
+ wanted.push({ dwelling_type: t, bedrooms: s, words: `${t === "Total" ? "All dwellings" : t}, ${s === "Total" ? "all sizes" : s}`,
314
+ cell: (group) => group?.breakdown?.[t]?.[s] ?? null });
315
+ }
316
+ }
317
+ return { wanted, asked: { dwelling_type: type, bedrooms: size }, notes };
318
+ }
319
+
320
+ /** Queensland: which of the RTA's labels ("Flat 2", "House 3") were asked for. */
321
+ function qldAsked(file, dwelling_type, bedrooms) {
322
+ const labels = Object.keys(file.state_total.breakdown).filter((l) => l !== "All dwellings");
323
+ const parsed = labels.map((l) => ({ l, m: /^([A-Za-z ]+?) (\d)$/.exec(l) })).filter((x) => x.m)
324
+ .map((x) => ({ label: x.l, kind: x.m[1], n: Number(x.m[2]) }));
325
+ const kinds = [...new Set(parsed.map((p) => p.kind))];
326
+ let chosen = parsed, kind = null, n = null, full = null;
327
+ if (wantsByType({ dwelling_type })) {
328
+ const whole = labels.find((l) => norm(l) === norm(dwelling_type)); // a label given in full: "Flat 2"
329
+ if (whole) {
330
+ // With its own number, where it has one: "Flat 2" and bedrooms "2" agree. (It used to carry none, so any
331
+ // bedrooms at all emptied the answer and the refusal said the RTA publishes no label for 2 bedrooms.)
332
+ full = parsed.find((p) => p.label === whole) ?? { label: whole, kind: whole, n: null };
333
+ chosen = [full];
334
+ } else {
335
+ kind = label(dwelling_type, kinds, QLD_KINDS, "dwelling type", "QLD");
336
+ chosen = chosen.filter((p) => p.kind === kind);
337
+ }
338
+ }
339
+ if (wantsByType({ bedrooms })) {
340
+ const b = bedroomsAsked(bedrooms);
341
+ if (b === null) {
342
+ throw new ToolError(`${JSON.stringify(bedrooms)} is not a number of bedrooms.`,
343
+ `The RTA's labels are: ${labels.join(", ")}. Give bedrooms as a number, or dwelling_type as one of the labels.`);
344
+ }
345
+ if (b.orMore) {
346
+ throw new ToolError(`The RTA publishes no "${b.n} or more" figure.`,
347
+ `Each of these labels carries one number, which DwellDelta reads as that many bedrooms: ` +
348
+ `${parsed.map((p) => p.label).join(", ")}. Call again with bedrooms as a plain number.`);
349
+ }
350
+ n = b.n;
351
+ if (full && full.n === null) {
352
+ throw new ToolError(`The RTA's label ${JSON.stringify(full.label)} carries no number of bedrooms.`,
353
+ `Call again without bedrooms: dwelling_type ${JSON.stringify(full.label)} is one figure.`);
354
+ }
355
+ if (full && full.n !== n) {
356
+ throw new ToolError(`${JSON.stringify(full.label)} is the label DwellDelta reads as ${full.n} bedroom${full.n === 1 ? "" : "s"}, ` +
357
+ `and bedrooms was given as ${n}.`,
358
+ `Give dwelling_type ${JSON.stringify(full.label)} on its own, or a dwelling type and bedrooms that agree. The RTA's ` +
359
+ `labels are: ${labels.join(", ")}.`);
360
+ }
361
+ chosen = chosen.filter((p) => p.n === n);
362
+ }
363
+ if (!chosen.length) {
364
+ const what = [kind, n === null ? null : `${n} bedroom${n === 1 ? "" : "s"}`].filter(Boolean).join(", ");
365
+ throw new ToolError(`The RTA publishes no label for ${what}.`, `Its labels are: ${labels.join(", ")}.`);
366
+ }
367
+ return { wanted: chosen.map((p) => ({ label: p.label, words: p.label, cell: (group) => group?.breakdown?.[p.label] ?? null })),
368
+ asked: { dwelling_type: kind, bedrooms: n, labels: chosen.map((p) => p.label) } };
369
+ }
370
+
371
+ /** area_rents with dwelling_type or bedrooms: the publisher's own cells for the places matched, and no others. */
372
+ function byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas, councils, file }, now) {
373
+ if (!BY_TYPE[state]) {
374
+ throw new ToolError(`${info.name} rents are not published by dwelling type or bedrooms.`,
375
+ "WA's bond records carry neither. Call area_rents for WA without dwelling_type and bedrooms: every WA figure " +
376
+ "is all dwellings together.");
377
+ }
378
+ if (!file) {
379
+ throw new ToolError(`The ${info.name} rents by dwelling type file is not on this machine.`,
380
+ `It is read once at start from ${PUBLISHED_BASE}${BY_TYPE[state]}. Offline, point DWELLDELTA_STATE_RENTS_DIR at ` +
381
+ "a folder holding a copy. Without dwelling_type and bedrooms, area_rents still answers for all dwellings together.");
382
+ }
383
+ if (file.quarter !== feed.quarter) {
384
+ throw new ToolError(`The ${info.name} by-type file is for ${file.quarter} and the rents feed for ${feed.quarter}.`,
385
+ "They are published together and must be the same quarter. Call area_rents without dwelling_type and bedrooms " +
386
+ "for the all-dwellings figure, and restart the server to read both again.");
387
+ }
388
+ const { wanted, asked, notes = [] } = state === "NSW" ? nswAsked(file, dwelling_type, bedrooms) : qldAsked(file, dwelling_type, bedrooms);
389
+ const kind = feed.area_kind;
390
+ const places = whole ? [{ name: `${info.name} (whole state)`, place: info.name, place_kind: "state", group: file.state_total }]
391
+ : [...councils.map((r) => ({ name: `${r.council} (council)`, place: r.council, place_kind: "council",
392
+ group: file.councils.find((g) => g.council === r.council) })),
393
+ ...areas.map((r) => ({ name: `${r.area} (${kind})`, place: r.area, place_kind: kind,
394
+ group: file.areas.find((g) => g.area === r.area) }))];
395
+ const shown = places.slice(0, MAX_TYPE_PLACES);
396
+ const lines = [], rows = [];
397
+ for (const p of shown) {
398
+ const absent = [];
399
+ for (const w of wanted) {
400
+ const cell = w.cell(p.group);
401
+ rows.push({ place: p.place, place_kind: p.place_kind,
402
+ ...(state === "NSW" ? { dwelling_type: w.dwelling_type, bedrooms: w.bedrooms } : { label: w.label }), figure: cell });
403
+ if (cell) lines.push(line(cell, `${p.name}, ${w.words}`));
404
+ else absent.push(w.words);
405
+ }
406
+ if (absent.length) lines.push(`${p.name}: no published median for ${absent.join("; ")}.`);
407
+ }
408
+ const truncated = places.length > shown.length;
409
+ if (truncated) lines.push(`${places.length - shown.length} more places match: narrow the name.`);
410
+ const env = envelope({ sources: [{ source: file.source, licence: file.licence, attribution: file.attribution }],
411
+ dataAsOf: file.quarter, origin: file.origin ?? null }, now);
412
+ const text = [
413
+ `${file.what}. Quarter: ${file.quarter}, against ${file.compared_with}.`,
414
+ "",
415
+ ...notes.flatMap((n) => [n, ""]),
416
+ ...lines,
417
+ "",
418
+ ...(rows.some((r) => !r.figure) ? [`Where there is no published median: ${file.absent_means}`,
419
+ "Do not fill a gap from a neighbouring area, a wider group, an earlier quarter or the all-dwellings figure " +
420
+ "without saying that you have.", ""] : []),
421
+ `Labels: ${file.labels}`,
422
+ "",
423
+ "Limits:",
424
+ ...file.limits.map((l) => "- " + l),
425
+ "",
426
+ `Source: ${file.attribution}`,
427
+ `What DwellDelta changed: ${file.changes_made}`,
428
+ FOOTER,
429
+ ].join("\n");
430
+ return { text, structured: { ...env, state, state_name: info.name, area_kind: kind, quarter: file.quarter,
431
+ compared_with: file.compared_with, detail: file.detail, asked, notes, rows, truncated,
432
+ absent_means: file.absent_means, labels: file.labels, limits: file.limits,
433
+ changes_made: file.changes_made } };
434
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dwelldelta-mcp",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Is an Australian rent fair? A rent check on the ABS rents index, rents by area for four states, NSW median sale prices, and sourced property and lending indicators, for AI agents.",
5
5
  "mcpName": "au.com.dwelldelta/dwelldelta",
6
6
  "license": "MIT",
@@ -9,6 +9,9 @@
9
9
  * non-strata (separate houses) and strata (units, town houses, villas), each labelled;
10
10
  * - DCJ's own table has rows that a few unusual sales set (postcode 2034, strata, March 2026: $8.954m, up 478%, from
11
11
  * 184 sales). The feed marks them `unusual_prices`; the answer says UNUSUAL in words, on that line, with the reason;
12
+ * a total the feed notes as mostly such a row's sales (`unusual_part`: Randwick council, 466 of 613) says so on its
13
+ * own line, and is said only to be possibly moved by them - never to have been set by them, nor not; a mark or a
14
+ * note this version does not know is shown as the file gives it, with nothing claimed about it;
12
15
  * - a gap is said with its reason and is never shown as zero.
13
16
  *
14
17
  * The feed keeps DCJ's unit (thousands of dollars) and so does the structured result, which says so; the text writes
@@ -31,6 +34,25 @@ const LIVE_DIR = join(HERE, "..", "..", "dwelldelta-data", "market");
31
34
  export const SALES_FILE = "nsw-sales.json";
32
35
  export const DWELLING_TYPES = ["total", "non_strata", "strata"];
33
36
  const LABEL = { total: "all dwellings", non_strata: "houses (non-strata)", strata: "units and town houses (strata)" };
37
+ /** The two reasons the builder writes in `unusual_prices`, word for word; anything else there - the same rule with
38
+ * another threshold included - is a mark this version does not know, and is not called UNUSUAL. */
39
+ const REASONS = ["the median equals a quartile: many sales at one identical price", "the third quartile is more than 3 times the median"];
40
+ /** `unusual_part` as the builder writes it: "its strata row is marked unusual_prices (...), and that row is 466 of this total's 613 sales". */
41
+ const KNOWN_PART = new RegExp(`^its (?:non-strata|strata) row is marked unusual_prices \\((?:${REASONS.join("|")})\\), and that row is (\\d+) of this total's (\\d+) sales$`);
42
+ const has = (v) => v != null && v !== false && v !== "";
43
+ const knownMark = (v) => REASONS.includes(v);
44
+ /** The builder's note, and its own numbers bear it out: the second is this row's sales and the first is more than half of it. */
45
+ function knownPart(r) {
46
+ const m = typeof r.unusual_part === "string" ? KNOWN_PART.exec(r.unusual_part) : null;
47
+ return m !== null && Number(m[2]) === r.sales && 2 * Number(m[1]) > Number(m[2]);
48
+ }
49
+ /** What a row carries, as this version can read it: a mark and a note, each "known", "unknown" or null. The note is
50
+ * known only as the builder writes it: on a total, with no mark of the total's own. */
51
+ function reads(r, type) {
52
+ const mark = !has(r.unusual_prices) ? null : knownMark(r.unusual_prices) ? "known" : "unknown";
53
+ const part = !has(r.unusual_part) ? null : type === "total" && mark === null && knownPart(r) ? "known" : "unknown";
54
+ return { mark, part };
55
+ }
34
56
  const HINT = "NSW sale prices are by four-digit postcode (area: \"2148\") or by council (council: \"Blacktown\").";
35
57
 
36
58
  const wellFormed = (f) => f && f.state === "NSW" && f.measure === "sale_price" && quarterKey(f.quarter) > 0
@@ -71,9 +93,18 @@ function line(r, name, type) {
71
93
  const change = r.change_pct == null ? "" : `, ${signed(r.change_pct)} on a year before`;
72
94
  const spread = r.first_quartile_k_aud == null || r.third_quartile_k_aud == null ? ""
73
95
  : `; half of sales between ${price(r.first_quartile_k_aud)} and ${price(r.third_quartile_k_aud)}`;
96
+ // UNUSUAL is the word the tool's description says means "set by a few very large sales", so only the two
97
+ // reasons that mean that are printed under it.
98
+ const carries = reads(r, type);
99
+ const mark = carries.mark === null ? ""
100
+ : (carries.mark === "known" ? ` UNUSUAL - ${r.unusual_prices}`
101
+ : ` MARKED (unusual_prices) - ${typeof r.unusual_prices === "string" ? r.unusual_prices : "a mark this version of the tool cannot put in words"}`) +
102
+ ": do not quote this as the going price of a home there.";
103
+ const part = carries.part === null ? ""
104
+ : carries.part === "known" ? ` MOSTLY A MARKED ROW - ${r.unusual_part}: its median and its change may be moved by that row's sales.`
105
+ : ` NOTE (unusual_part) - ${typeof r.unusual_part === "string" ? r.unusual_part : "a note this version of the tool cannot put in words"}.`;
74
106
  return `${label}: median ${price(r.median_price_k_aud)}${sales}${change}${spread}` +
75
- `${r.small_sample ? " (small sample: treat with caution)" : ""}.` +
76
- `${r.unusual_prices ? ` UNUSUAL - ${r.unusual_prices}: do not quote this as the going price of a home there.` : ""}`;
107
+ `${r.small_sample ? " (small sample: treat with caution)" : ""}.${mark}${part}`;
77
108
  }
78
109
 
79
110
  /** nsw_sale_prices: a postcode, a council, or neither for the state; optionally one dwelling type. */
@@ -114,7 +145,11 @@ export function salePricesResult({ area, council, dwelling_type } = {}, feed, no
114
145
  councils = councils.slice(0, MAX_ROWS);
115
146
  const shown = [...(whole ? [["New South Wales (whole state)", feed.state_total]] : []),
116
147
  ...councils.map((g) => [`${g.council} (council)`, g]), ...areas.map((g) => [`${g.area} (postcode)`, g])];
117
- const marked = shown.some(([, g]) => types.some((t) => g[t]?.unusual_prices));
148
+ // Only rows that are shown and have a median are spoken of: line() says nothing of a mark on any other.
149
+ const seen = shown.flatMap(([, g]) => types.filter((t) => g[t] && g[t].median_price_k_aud != null).map((t) => reads(g[t], t)));
150
+ const marked = seen.some((s) => s.mark !== null), noted = seen.some((s) => s.part !== null);
151
+ const setByAFew = seen.some((s) => s.mark === "known"), mostlyARow = seen.some((s) => s.part === "known");
152
+ const unknown = seen.some((s) => s.mark === "unknown" || s.part === "unknown");
118
153
  const env = envelope({ sources: [{ source: feed.source, licence: feed.licence, attribution: feed.attribution }],
119
154
  dataAsOf: feed.quarter, origin: feed.origin ?? null }, now);
120
155
  const text = [
@@ -125,8 +160,14 @@ export function salePricesResult({ area, council, dwelling_type } = {}, feed, no
125
160
  ...dropped,
126
161
  ...(whole ? ["", `${feed.areas.length.toLocaleString("en-AU")} postcode rows and ${feed.councils.length} councils ` +
127
162
  "are available: call again with area or council."] : []),
128
- ...(marked ? ["", "At least one row above is marked UNUSUAL: its figure is DCJ's own, and a few very large sales " +
163
+ ...(setByAFew ? ["", "At least one row above is marked UNUSUAL: its figure is DCJ's own, and a few very large sales " +
129
164
  "or many sales at one identical price have set it. Say so if you mention it."] : []),
165
+ ...(mostlyARow ? ["", "A total above is mostly the sales of a row marked UNUSUAL, by DCJ's own numbers of sales. The " +
166
+ "total's figure is DCJ's own and carries no UNUSUAL mark of its own, but its median and its change may be moved " +
167
+ "by that row's sales. Say so if you mention it."] : []),
168
+ ...(unknown ? ["", "At least one row above carries a mark or a note this version of the tool does not know; it is shown " +
169
+ "on its line as the file gives it. Its figure is DCJ's own. Do not quote that row as a going price, and read " +
170
+ "\"What DwellDelta changed\" below for what the file's marks mean."] : []),
130
171
  "",
131
172
  "Limits:",
132
173
  ...feed.limits.map((l) => "- " + l),
@@ -141,5 +182,6 @@ export function salePricesResult({ area, council, dwelling_type } = {}, feed, no
141
182
  dwelling_types: feed.dwelling_types ?? null,
142
183
  state_total: whole ? pick(feed.state_total) : null,
143
184
  councils: councils.map(pick), areas: areas.map(pick), any_unusual: marked,
185
+ any_unusual_part: noted,
144
186
  truncated: dropped.length > 0, limits: feed.limits, changes_made: feed.changes_made } };
145
187
  }
package/server.mjs CHANGED
@@ -5,7 +5,8 @@
5
5
  // (DWELLDELTA_OFFLINE=1 never fetches). Six read-only tools; the logic lives in tools.mjs, vic_rents
6
6
  // (Victorian rents by suburb group, 0.5.0) in vic-rents-tool.mjs, area_rents (NSW postcodes, Queensland suburbs
7
7
  // and WA localities, 0.6.0) in area-rents-tool.mjs, and nsw_sale_prices (NSW median sale prices by postcode, 0.7.0)
8
- // in sale-prices-tool.mjs, each feed loaded the same way. A seventh tool,
8
+ // in sale-prices-tool.mjs, each feed loaded the same way. area_rents also answers by dwelling type and bedrooms for
9
+ // NSW and Queensland (0.8.0), from two larger files that are not bundled. A seventh tool,
9
10
  // contribute_rent (contribute-tool.mjs), is connected from 0.5.0 (2026-10-03): it sends a rent only on a second call carrying the user's agreement.
10
11
  //
11
12
  // Every result carries text to quote and a structured result (the figures plus where they come from, under which
@@ -21,7 +22,7 @@ import {
21
22
  } from "./tools.mjs";
22
23
  import { makeContributeTool, INSTRUCTION } from "./contribute-tool.mjs";
23
24
  import { loadVicRents, vicRentsResult } from "./vic-rents-tool.mjs";
24
- import { loadAllAreaRents, areaRentsResult, STATES } from "./area-rents-tool.mjs";
25
+ import { loadAllAreaRents, loadAllRentsByType, wantsByType, areaRentsResult, STATES } from "./area-rents-tool.mjs";
25
26
  import { loadNswSales, salePricesResult, DWELLING_TYPES } from "./sale-prices-tool.mjs";
26
27
  import { HOME_TYPES, BEDROOMS, LEASE_KINDS, WHOSE } from "./vendor/contribute.mjs";
27
28
 
@@ -33,6 +34,10 @@ const snapshot = loaded.snapshot ? { ...loaded.snapshot, origin: loaded.origin }
33
34
  const vicLoaded = await loadVicRents();
34
35
  const vic = vicLoaded.feed ? { ...vicLoaded.feed, origin: vicLoaded.origin } : null;
35
36
  const areaRents = await loadAllAreaRents();
37
+ // The NSW and Queensland rents by dwelling type files are large and are not bundled. They are asked for here, once,
38
+ // at start - never in response to a question - and NOT awaited: the server is ready without them, and the first
39
+ // by-type question waits for this promise. It never rejects.
40
+ const rentsByType = loadAllRentsByType();
36
41
  const salesLoaded = await loadNswSales();
37
42
  const nswSales = salesLoaded.feed ? { ...salesLoaded.feed, origin: salesLoaded.origin } : null;
38
43
  const readOnly = { readOnlyHint: true, idempotentHint: true, openWorldHint: false, destructiveHint: false };
@@ -118,15 +123,29 @@ server.registerTool("area_rents", {
118
123
  "Communities and Justice), QLD by suburb or council (Residential Tenancies Authority), WA by locality " +
119
124
  "(calculated by DwellDelta from the Government of Western Australia's bond records). Each CC BY 4.0. With no " +
120
125
  "area or council it gives the state's own figure. New-bond medians, not advertised rents; never add or compare " +
121
- "the states as one series; quote the quarter, the source line and the limits. Victoria is in vic_rents.",
126
+ "the states as one series; quote the quarter, the source line and the limits. Victoria is in vic_rents. " +
127
+ "For NSW and QLD, give dwelling_type or bedrooms (or both) for the publisher's figure for that kind of home " +
128
+ "instead - a two-bedroom unit, a three-bedroom house. Only combinations the publisher reports are answered: " +
129
+ "one with no published median is said to have none, and must not be filled from another area or from the " +
130
+ "all-dwellings figure. Many such figures rest on few bonds. WA has no figures by dwelling type or bedrooms.",
122
131
  inputSchema: {
123
132
  state: z.enum(Object.keys(STATES)).describe("NSW, QLD or WA - one state per call"),
124
133
  area: z.string().optional().describe("NSW: a four-digit postcode (a suburb name returns its postcodes to try). " +
125
134
  "QLD: a suburb. WA: a locality. Part of a suburb or locality name works"),
126
135
  council: z.string().optional().describe("A council (NSW or QLD), or part of its name"),
136
+ dwelling_type: z.string().optional().describe("NSW and QLD only. NSW (DCJ's labels): House, Townhouse, " +
137
+ "Flat/Unit, Other. QLD (the RTA's): Flat, House, Townhouse. 'unit' and 'apartment' are read as flat/unit. " +
138
+ "Without bedrooms, every size the publisher reports for that type is given"),
139
+ bedrooms: z.string().optional().describe("NSW and QLD only: a number of bedrooms, as '2' or '2 bedrooms'. NSW " +
140
+ "also has Bedsitter, and 4 means DCJ's '4 or more Bedrooms'; a number above 4 is answered under that label " +
141
+ "too, and the answer says it is not for that number alone. QLD: the RTA publishes flats of 1 to 3, houses " +
142
+ "of 2 to 4 and town houses of 2 to 3, and does not define its labels - reading the number as bedrooms is " +
143
+ "DwellDelta's. A plus means 'or more', which only DCJ's 4 has: '3+', and any 'N+' for QLD, is refused, not " +
144
+ "answered as exactly N. Without dwelling_type, every type the publisher reports at that size is given"),
127
145
  },
128
146
  annotations: readOnly,
129
- }, guard((args) => areaRentsResult(args, areaRents, new Date(), { nswSuburbs: suburbs })));
147
+ }, guard(async (args) => areaRentsResult(args, areaRents, new Date(),
148
+ { nswSuburbs: suburbs, byType: wantsByType(args) ? await rentsByType : {} })));
130
149
 
131
150
  server.registerTool("nsw_sale_prices", {
132
151
  title: "NSW median sale prices by postcode or council",
@@ -135,7 +154,9 @@ server.registerTool("nsw_sale_prices", {
135
154
  "dwellings, non_strata (separate houses) and strata (units, town houses, villas). From the NSW Department of " +
136
155
  "Communities and Justice's Rent and Sales Report (CC BY 4.0). Medians of homes sold: not asking prices, not " +
137
156
  "valuations, and never what any one home sold for or is worth. A line marked UNUSUAL was set by a few very " +
138
- "large sales - say so, and do not quote it as a going price. Always name the dwelling type, the quarter and " +
157
+ "large sales - say so, and do not quote it as a going price. A total noted as mostly a marked row's sales may " +
158
+ "be moved by them - say that, and no more. A line with any other mark or note: do not quote it as a going " +
159
+ "price, and claim nothing about why. Always name the dwelling type, the quarter and " +
139
160
  "the source line, and repeat the limits. With no area or council it gives the state's own figures.",
140
161
  inputSchema: {
141
162
  area: z.string().optional().describe("A four-digit NSW postcode (a suburb name returns its postcodes to try)"),
package/tools.mjs CHANGED
@@ -62,7 +62,7 @@ export async function loadSnapshot({ env = process.env, fetchImpl = globalThis.f
62
62
  }
63
63
 
64
64
  export const FOOTER = "Information, not advice. From DwellDelta (dwelldelta.com.au), built on public data.";
65
- export const SERVER_VERSION = "0.7.0";
65
+ export const SERVER_VERSION = "0.8.0";
66
66
  // The indicators snapshot is rebuilt every Monday. Older than this and the answer says so, in words and in the
67
67
  // structured result, rather than serving a stale figure as current.
68
68
  export const STALE_DAYS = 10;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "publisher": "DwellDelta, a service of Xcelerent Pty Ltd",
3
- "built": "2026-10-10",
3
+ "built": "2026-10-12",
4
4
  "indicators": [
5
5
  {
6
6
  "id": "cash_rate",
@@ -397,14 +397,14 @@
397
397
  "id": "completions",
398
398
  "name": "Dwellings completed, seasonally adjusted",
399
399
  "geography": "NSW",
400
- "value": 10227.0,
400
+ "value": 13332.0,
401
401
  "unit": "dwellings per quarter",
402
- "period": "2026-03",
402
+ "period": "2026-06",
403
403
  "source": "ABS Building Activity, Australia (8752.0), Table 38: dwelling units completed by state, all types and sectors, quarterly, seasonally adjusted.",
404
404
  "licence": "CC BY 4.0",
405
405
  "attribution": "Based on Australian Bureau of Statistics data",
406
406
  "change": {
407
- "value": -4.8,
407
+ "value": 43.5,
408
408
  "unit": "percent",
409
409
  "over": "year"
410
410
  }
@@ -573,7 +573,7 @@
573
573
  ],
574
574
  "cannot_answer": [
575
575
  "What any individual home sold for, or what it rents for today: the NSW datasets that hold those are licensed for non-commercial use only.",
576
- "Rents for a suburb or a street outside Victoria: the ABS rents index is city-wide, and contributed NSW suburb rents are not yet collected. Victorian rents by suburb group are in https://tools.dwelldelta.com.au/market/vic-rents.json (Homes Victoria, CC BY 4.0).",
576
+ "Rents for a street, for a home of a given size, or for any area of South Australia, Tasmania, the ACT or the Northern Territory: the ABS rents index is city-wide. Median rents of new bonds, all dwellings together, are published by area for four states, each file with its own source, licence and limits and never to be pooled: Victoria by suburb group, https://tools.dwelldelta.com.au/market/vic-rents.json (Homes Victoria, CC BY 4.0); NSW by postcode, https://tools.dwelldelta.com.au/market/nsw-rents.json (NSW Department of Communities and Justice, CC BY 4.0); Queensland by suburb, https://tools.dwelldelta.com.au/market/qld-rents.json (Residential Tenancies Authority, CC BY 4.0); Western Australia by locality, https://tools.dwelldelta.com.au/market/wa-rents.json (calculated by DwellDelta from the Government of Western Australia's bond records, CC BY 4.0).",
577
577
  "Advice of any kind: every figure here is information, not financial or tenancy advice."
578
578
  ],
579
579
  "rules": "Every figure is observed data with its period and source; none is a forecast or advice."
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "publisher": "DwellDelta, a service of Xcelerent Pty Ltd",
3
- "built": "2026-10-10",
3
+ "built": "2026-10-13",
4
4
  "state": "QLD",
5
5
  "state_name": "Queensland",
6
6
  "area_kind": "suburb",
@@ -18,7 +18,7 @@
18
18
  "limits": [
19
19
  "Medians of NEW bonds lodged with the RTA in the quarter (new tenancies) - not advertised rents, and not what sitting tenants pay.",
20
20
  "A median moves with the mix of homes let: a change can be new apartments or a different mix of homes, not rents rising for the same homes.",
21
- "All dwellings and all sizes together: a suburb of units and a suburb of houses are not like for like.",
21
+ "All dwellings and all sizes together: a suburb of units and a suburb of houses are not like for like. 'All dwellings' takes in rooming accommodation as well as flats, houses and town houses: for Queensland as a whole, 3,824 of its 53,770 new bonds are under the RTA's label 'Rooming Accommodation' (median $349 a week, against $650 for 'General Tenancies'). The workbook gives that split for the state only. Where many rooms are let, a suburb's all-dwellings median can sit far below what a flat or a house rents for there, and its change on a year can be a change in that mix: check the suburb's flats and houses in the companion file of rents by dwelling type, published beside this one, and where the all-dwellings figure is far below them do not quote it as a typical rent.",
22
22
  "Null where the RTA published no median (too few bonds); rows resting on fewer than 30 new bonds are flagged small_sample.",
23
23
  "Suburb and council names are the RTA's own, e.g. \"Brisbane (C)\". change_pct is DwellDelta's calculation, not the RTA's.",
24
24
  "Information, not financial or tenancy advice."
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "publisher": "DwellDelta, a service of Xcelerent Pty Ltd",
3
- "built": "2026-10-05",
3
+ "built": "2026-10-03",
4
4
  "what": "Victorian rents by suburb group, all properties: median weekly rent of new leases",
5
5
  "quarter": "Sep 2025",
6
6
  "compared_with": "Sep 2024",