dwelldelta-mcp 0.9.0 → 0.10.1

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
@@ -12,7 +12,7 @@ Six read-only tools, and one that adds the user's own rent when they ask:
12
12
  | `market_indicators` | the latest RBA cash rate, unemployment, wage growth, rents for all eight capitals, NSW lending, lending standards and arrears, approvals and completions - each with period, source, licence and limits; filter by `geography` |
13
13
  | `vic_rents` | Victorian rents by suburb group from Homes Victoria's Rental Report: the median weekly rent of new leases, the lease count and the change on a year before, for 146 suburb groups and 13 regions; filter by `suburb_group` or `region` (from 0.5.0) |
14
14
  | `area_rents` | median weekly rent of new bonds, all dwellings together, with the bond count and the change on a year before, for one state per call: NSW by postcode or council (NSW Department of Communities and Justice), Queensland by suburb or council (Residential Tenancies Authority), WA by locality (calculated by DwellDelta from the Government of Western Australia's bond records); each CC BY 4.0 (from 0.6.0) |
15
- | `nsw_sale_prices` | NSW median sale prices by postcode or council from the NSW Department of Communities and Justice's Rent and Sales Report (CC BY 4.0): the median, the quartiles, the number of sales and the change on a year before, each for all dwellings, houses (non-strata) and units and town houses (strata). Medians of homes sold - never what any one home sold for; a line a few very large sales have set is marked UNUSUAL (from 0.7.0) |
15
+ | `nsw_sale_prices` | NSW median sale prices by postcode or council from the NSW Department of Communities and Justice's Rent and Sales Report (CC BY 4.0): the median, the quartiles, the number of sales and the change on a year before, each for all dwellings, houses (non-strata) and units and town houses (strata). Medians of homes sold - never what any one home sold for; a line set by a few very large sales or by many sales at one identical price is marked UNUSUAL (from 0.7.0), and is not a going price |
16
16
  | `data_sources` | the sources, their licences, and what DwellDelta cannot answer |
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,7 +19,8 @@ import { existsSync } from "node:fs";
19
19
  import { fileURLToPath } from "node:url";
20
20
  import { dirname, join } from "node:path";
21
21
  import { loadJson, envelope, ToolError, FOOTER, FETCH_TIMEOUT_MS, feedSource, CADENCE, SAMPLE_RULES, judgeFigure,
22
- figureFields, nWords, citeLine, staleNote, flagged, refusalMark } from "./tools.mjs";
22
+ figureFields, nWords, citeLine, staleNote, flagged, refusalMark, isRecord, passes, readChecked, quiet,
23
+ warnPublished, fromCopy } from "./tools.mjs";
23
24
  import { quarterKey } from "./vic-rents-tool.mjs";
24
25
 
25
26
  const HERE = dirname(fileURLToPath(import.meta.url));
@@ -43,24 +44,30 @@ export const RULES = { NSW: SAMPLE_RULES.NSW_RENTS, QLD: SAMPLE_RULES.QLD_RENTS,
43
44
  /** Rows shown in one answer; a wider match says how many more there are instead of dropping them silently. */
44
45
  export const MAX_ROWS = 25;
45
46
 
47
+ // A row of its lists that is not a row is skipped where the tool reads them, and a row's name of another type matches
48
+ // nothing (tools.mjs, "What a copy must be before it answers"): the checks here are the ones the feed always had.
46
49
  const wellFormed = (f, state) => f && f.state === state && quarterKey(f.quarter) > 0
47
50
  && Array.isArray(f.areas) && f.areas.length > 0 && Array.isArray(f.councils) && Array.isArray(f.regions)
48
51
  && f.state_total && Array.isArray(f.limits) && f.licence && f.attribution && f.changes_made;
49
52
 
50
53
  /** One state's feed and where it came from ("env", "live", "published" or "bundled"); { feed: null } if none. */
51
54
  export async function loadAreaRents(state, { env = process.env, fetchImpl = globalThis.fetch, liveDir = LIVE_DIR,
52
- bundledDir = BUNDLED_DIR } = {}) {
55
+ bundledDir = BUNDLED_DIR, warn = quiet } = {}) {
53
56
  const { file } = STATES[state];
57
+ const what = `the ${STATES[state].name} rents feed`;
54
58
  // A copy that is not this state's feed is no copy: the wrong file under the right name must never answer.
55
- const read = (path) => loadJson(path).then((f) => (wellFormed(f, state) ? f : null)).catch(() => null);
56
- if (env.DWELLDELTA_STATE_RENTS_DIR) return { feed: await read(join(env.DWELLDELTA_STATE_RENTS_DIR, file)), origin: "env" };
57
- if (existsSync(join(liveDir, file))) return { feed: await read(join(liveDir, file)), origin: "live" };
58
- const shipped = await read(join(bundledDir, file));
59
+ const read = (path, variable) => readChecked(path, (f) => wellFormed(f, state), what, variable, warn);
60
+ if (env.DWELLDELTA_STATE_RENTS_DIR) {
61
+ return fromCopy(await read(join(env.DWELLDELTA_STATE_RENTS_DIR, file), "DWELLDELTA_STATE_RENTS_DIR"), "feed", "env");
62
+ }
63
+ if (existsSync(join(liveDir, file))) return fromCopy(await read(join(liveDir, file)), "feed", "live");
64
+ const shipped = (await read(join(bundledDir, file))).copy;
59
65
  if (env.DWELLDELTA_OFFLINE !== "1" && typeof fetchImpl === "function") {
60
66
  try {
61
67
  const res = await fetchImpl(PUBLISHED_BASE + file, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
62
68
  const got = res.ok ? await res.json() : null;
63
- if (wellFormed(got, state) && (!shipped || quarterKey(got.quarter) >= quarterKey(shipped.quarter))) {
69
+ if (got != null && !passes(wellFormed, got, state)) warnPublished(warn, what, PUBLISHED_BASE + file, shipped);
70
+ if (passes(wellFormed, got, state) && (!shipped || quarterKey(got.quarter) >= quarterKey(shipped.quarter))) {
64
71
  return { feed: got, origin: "published" };
65
72
  }
66
73
  } catch {
@@ -70,11 +77,21 @@ export async function loadAreaRents(state, { env = process.env, fetchImpl = glob
70
77
  return { feed: shipped, origin: shipped ? "bundled" : null };
71
78
  }
72
79
 
73
- /** Every state's feed, loaded together at start: { NSW: feed-with-origin | null, QLD: ..., WA: ... }. */
80
+ /**
81
+ * Every state's feed, loaded together at start: { NSW: feed-with-origin | null, QLD: ..., WA: ... }. A state whose copy
82
+ * was refused is named, with that copy, in its refused property - not enumerable, so the states are all there is to
83
+ * list - for the tool to say that copy could not be used (withRefused).
84
+ */
74
85
  export async function loadAllAreaRents(opts) {
75
86
  const loaded = await Promise.all(Object.keys(STATES).map((s) => loadAreaRents(s, opts)));
76
- return Object.fromEntries(Object.keys(STATES).map((s, i) =>
77
- [s, loaded[i].feed ? { ...loaded[i].feed, origin: loaded[i].origin } : null]));
87
+ return withRefused(Object.fromEntries(Object.keys(STATES).map((s, i) =>
88
+ [s, loaded[i].feed ? { ...loaded[i].feed, origin: loaded[i].origin } : null])), Object.keys(STATES), loaded);
89
+ }
90
+ /** feeds, with the refused copies of states[i] (loaded[i].refused) as a property that is not enumerable. */
91
+ export function withRefused(feeds, states, loaded) {
92
+ const refused = Object.fromEntries(states.map((s, i) => [s, loaded[i]?.refused ?? null]).filter(([, r]) => r));
93
+ if (Object.keys(refused).length) Object.defineProperty(feeds, "refused", { value: refused, enumerable: false });
94
+ return feeds;
78
95
  }
79
96
 
80
97
  // Exported for sale-prices-tool.mjs (0.7.0), which matches names and words figures the same way.
@@ -110,8 +127,10 @@ function line(r, name, rule = null) {
110
127
 
111
128
  /** Exact name first, so "Brighton" does not drag in "Brighton East"; otherwise every name containing the words. */
112
129
  export function match(rows, key, wanted) {
113
- const exact = rows.filter((r) => norm(r[key]) === norm(wanted));
114
- return exact.length ? exact : rows.filter((r) => norm(r[key]).includes(norm(wanted)));
130
+ // A row that is not a row is skipped (tools.mjs, "What a copy must be before it answers").
131
+ const real = rows.filter(isRecord);
132
+ const exact = real.filter((r) => norm(r[key]) === norm(wanted));
133
+ return exact.length ? exact : real.filter((r) => norm(r[key]).includes(norm(wanted)));
115
134
  }
116
135
 
117
136
  /**
@@ -120,7 +139,7 @@ export function match(rows, key, wanted) {
120
139
  * holds - offered as the next step, never answered silently, because a postcode's median is not a suburb's.
121
140
  */
122
141
  export function nswPostcodes(wanted, suburbs, feed) {
123
- const held = new Set(feed.areas.map((r) => r.area));
142
+ const held = new Set(feed.areas.filter(isRecord).map((r) => r.area));
124
143
  const named = suburbs.map((s) => /^(.*) \((\d{4})\)$/.exec(s)).filter((m) => m && held.has(m[2]));
125
144
  const exact = named.filter((m) => norm(m[1]) === norm(wanted));
126
145
  const found = exact.length ? exact : named.filter((m) => norm(m[1]).includes(norm(wanted)));
@@ -133,7 +152,7 @@ export function nswPostcodes(wanted, suburbs, feed) {
133
152
  * start by loadAllRentsByType) - see byTypeResult below.
134
153
  */
135
154
  export function areaRentsResult({ state, area, council, dwelling_type, bedrooms } = {}, feeds, now = new Date(),
136
- { nswSuburbs = [], byType = {} } = {}) {
155
+ { nswSuburbs = [], byType = {}, hosted = false } = {}) {
137
156
  const info = STATES[state];
138
157
  if (!info) {
139
158
  throw new ToolError(`No area rents for ${JSON.stringify(state)}.`,
@@ -141,6 +160,10 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
141
160
  `the Northern Territory are not covered.`);
142
161
  }
143
162
  const feed = feeds[state];
163
+ if (!feed && feeds.refused?.[state]) {
164
+ throw new ToolError(`The ${info.name} rents feed could not be used: ${feeds.refused[state]} failed the check of the file.`,
165
+ `Point DWELLDELTA_STATE_RENTS_DIR at a folder holding a good copy of ${PUBLISHED_BASE}${info.file}.`);
166
+ }
144
167
  if (!feed) {
145
168
  throw new ToolError(`The ${info.name} rents feed is not on this machine.`,
146
169
  `Point DWELLDELTA_STATE_RENTS_DIR at a folder holding a copy of ${PUBLISHED_BASE}${info.file}.`);
@@ -166,9 +189,10 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
166
189
  }
167
190
  const whole = !areas.length && !councils.length;
168
191
  if (wantsByType({ dwelling_type, bedrooms })) {
169
- return byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas, councils, file: byType[state] }, now);
192
+ return byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas, councils, file: byType[state],
193
+ refusedFile: byType.refused?.[state] ?? null, hosted }, now);
170
194
  }
171
- if (whole) regions = feed.regions;
195
+ if (whole) regions = feed.regions.filter(isRecord);
172
196
  const dropped = [];
173
197
  for (const [label, rows] of [[kind, areas], ["council", councils]]) {
174
198
  if (rows.length > MAX_ROWS) dropped.push(`${rows.length - MAX_ROWS} more ${label} rows match: narrow the name.`);
@@ -240,34 +264,52 @@ export const MAX_TYPE_PLACES = 5;
240
264
  export const wantsByType = ({ dwelling_type, bedrooms } = {}) =>
241
265
  [dwelling_type, bedrooms].some((v) => v != null && String(v).trim() !== "");
242
266
 
267
+ // The labels a question can name are read from the state's breakdown: the publisher's labels, each to a cell
268
+ // (Queensland) or to a row of sizes, each to a cell (NSW). So the breakdown is an object, and no NSW type's sizes are
269
+ // null (the sizes of each are listed); a place row that is not a row is skipped (tools.mjs).
243
270
  const wellFormedByType = (f, state) => f && f.state === state && f.detail === "dwelling_type_and_bedrooms"
244
271
  && quarterKey(f.quarter) > 0 && Array.isArray(f.areas) && f.areas.length > 0 && Array.isArray(f.councils)
245
- && f.state_total && f.state_total.breakdown && Array.isArray(f.limits) && f.licence && f.attribution
246
- && f.changes_made && f.absent_means && f.labels;
272
+ && f.state_total && isRecord(f.state_total.breakdown)
273
+ && (state !== "NSW" || Object.values(f.state_total.breakdown).every((sizes) => sizes !== null))
274
+ && Array.isArray(f.limits) && f.licence && f.attribution && f.changes_made && f.absent_means && f.labels;
247
275
 
248
- /** One state's by-type file and where it came from ("env", "live" or "published"); { feed: null } if none. */
249
- export async function loadRentsByType(state, { env = process.env, fetchImpl = globalThis.fetch, liveDir = LIVE_DIR } = {}) {
276
+ /**
277
+ * One state's by-type file and where it came from ("env", "live", "published" or "bundled"); { feed: null } if none.
278
+ * byTypeDir: a folder holding bundled copies. The npm package has none (the files are large), so the stdio server
279
+ * passes none; the hosted server's deploy package carries them (infra/mcp-remote/build.py, remote/data.mjs), and
280
+ * there, as for every other feed, the published copy answers only when it is well formed and not older.
281
+ */
282
+ export async function loadRentsByType(state, { env = process.env, fetchImpl = globalThis.fetch, liveDir = LIVE_DIR,
283
+ byTypeDir = null, warn = quiet } = {}) {
250
284
  const file = BY_TYPE[state];
251
- const read = (path) => loadJson(path).then((f) => (wellFormedByType(f, state) ? f : null)).catch(() => null);
252
- if (env.DWELLDELTA_STATE_RENTS_DIR) return { feed: await read(join(env.DWELLDELTA_STATE_RENTS_DIR, file)), origin: "env" };
253
- if (existsSync(join(liveDir, file))) return { feed: await read(join(liveDir, file)), origin: "live" };
285
+ const what = `the ${STATES[state].name} rents by dwelling type file`;
286
+ const read = (path, variable) => readChecked(path, (f) => wellFormedByType(f, state), what, variable, warn);
287
+ if (env.DWELLDELTA_STATE_RENTS_DIR) {
288
+ return fromCopy(await read(join(env.DWELLDELTA_STATE_RENTS_DIR, file), "DWELLDELTA_STATE_RENTS_DIR"), "feed", "env");
289
+ }
290
+ if (existsSync(join(liveDir, file))) return fromCopy(await read(join(liveDir, file)), "feed", "live");
291
+ const shipped = byTypeDir ? (await read(join(byTypeDir, file))).copy : null;
254
292
  if (env.DWELLDELTA_OFFLINE !== "1" && typeof fetchImpl === "function") {
255
293
  try {
256
294
  const res = await fetchImpl(PUBLISHED_BASE + file, { signal: AbortSignal.timeout(BY_TYPE_TIMEOUT_MS) });
257
295
  const got = res.ok ? await res.json() : null;
258
- if (wellFormedByType(got, state)) return { feed: got, origin: "published" };
296
+ if (passes(wellFormedByType, got, state) && (!shipped || quarterKey(got.quarter) >= quarterKey(shipped.quarter))) {
297
+ return { feed: got, origin: "published" };
298
+ }
299
+ if (got != null && !passes(wellFormedByType, got, state)) warnPublished(warn, what, PUBLISHED_BASE + file, shipped);
259
300
  } catch {
260
- // Offline, blocked or slow: there is no bundled copy, and a by-type question will say what to do.
301
+ // Offline, blocked or slow: the bundled copy answers where there is one; else a by-type question says what to do.
261
302
  }
262
303
  }
263
- return { feed: null, origin: null };
304
+ return { feed: shipped, origin: shipped ? "bundled" : null };
264
305
  }
265
306
 
266
307
  /** Both states' by-type files: { NSW: file-with-origin | null, QLD: ... }. It never rejects. */
267
308
  export async function loadAllRentsByType(opts) {
268
309
  const states = Object.keys(BY_TYPE);
269
310
  const loaded = await Promise.all(states.map((s) => loadRentsByType(s, opts).catch(() => ({ feed: null }))));
270
- return Object.fromEntries(states.map((s, i) => [s, loaded[i].feed ? { ...loaded[i].feed, origin: loaded[i].origin } : null]));
311
+ return withRefused(Object.fromEntries(states.map((s, i) => [s, loaded[i].feed ? { ...loaded[i].feed, origin: loaded[i].origin } : null])),
312
+ states, loaded);
271
313
  }
272
314
 
273
315
  const NSW_TYPES = ["House", "Townhouse", "Flat/Unit", "Other", "Total"];
@@ -395,12 +437,24 @@ function qldAsked(file, dwelling_type, bedrooms) {
395
437
  }
396
438
 
397
439
  /** area_rents with dwelling_type or bedrooms: the publisher's own cells for the places matched, and no others. */
398
- function byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas, councils, file }, now) {
440
+ function byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas, councils, file, refusedFile = null,
441
+ hosted = false }, now) {
399
442
  if (!BY_TYPE[state]) {
400
443
  throw new ToolError(`${info.name} rents are not published by dwelling type or bedrooms.`,
401
444
  "WA's bond records carry neither. Call area_rents for WA without dwelling_type and bedrooms: every WA figure " +
402
445
  "is all dwellings together.");
403
446
  }
447
+ // On the hosted server (hosted: remote/endpoint.mjs) the user can set no variable on it: the error says the server
448
+ // could not load the file, and what to ask instead.
449
+ if (!file && hosted) {
450
+ throw new ToolError(`This server could not load the ${info.name} rents by dwelling type file just now.`,
451
+ "Try again later. Without dwelling_type and bedrooms, area_rents answers now for all dwellings together.");
452
+ }
453
+ if (!file && refusedFile) {
454
+ throw new ToolError(`The ${info.name} rents by dwelling type file could not be used: ${refusedFile} failed the check of the file.`,
455
+ `Point DWELLDELTA_STATE_RENTS_DIR at a folder holding a good copy of ${PUBLISHED_BASE}${BY_TYPE[state]}. Without ` +
456
+ "dwelling_type and bedrooms, area_rents still answers for all dwellings together.");
457
+ }
404
458
  if (!file) {
405
459
  throw new ToolError(`The ${info.name} rents by dwelling type file is not on this machine.`,
406
460
  `It is read once at start from ${PUBLISHED_BASE}${BY_TYPE[state]}. Offline, point DWELLDELTA_STATE_RENTS_DIR at ` +
@@ -415,9 +469,9 @@ function byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas
415
469
  const kind = feed.area_kind;
416
470
  const places = whole ? [{ name: `${info.name} (whole state)`, place: info.name, place_kind: "state", group: file.state_total }]
417
471
  : [...councils.map((r) => ({ name: `${r.council} (council)`, place: r.council, place_kind: "council",
418
- group: file.councils.find((g) => g.council === r.council) })),
472
+ group: file.councils.find((g) => isRecord(g) && g.council === r.council) })),
419
473
  ...areas.map((r) => ({ name: `${r.area} (${kind})`, place: r.area, place_kind: kind,
420
- group: file.areas.find((g) => g.area === r.area) }))];
474
+ group: file.areas.find((g) => isRecord(g) && g.area === r.area) }))];
421
475
  const shown = places.slice(0, MAX_TYPE_PLACES);
422
476
  const rule = RULES[state];
423
477
  const lines = [], rows = [], figures = [];
@@ -34,9 +34,15 @@ export const NOT_COLLECTING = "Contributions are not being collected yet, so not
34
34
  export const WHOSE_REFUSAL = "Only the user's own rent can be added: their own tenancy, or a property they own. " +
35
35
  "A figure read on a website, in a listing or from anyone else cannot be added.";
36
36
 
37
- // The tool's own instruction to every assistant, repeated in its description (server.mjs).
38
- export const INSTRUCTION = "Call only when the user has asked to add their rent, or has said yes to the consent " +
39
- "text. Never add a rent on the user's behalf by default, never batch, and never add a figure found online.";
37
+ // What the tool is for, closing its description (server.mjs). Until 2026-10-20 this was INSTRUCTION, worded as an
38
+ // instruction to the assistant ("Call only when...", "Never add..."); the directories' reviews read tool
39
+ // descriptions that instruct the model as a risk, so it now states the same limits as facts, every one kept: the
40
+ // user asks or agrees first; never on the user's behalf by default; one rent, for one consent, never a batch of rents
41
+ // ("never batch" - not merely one rent per call, which a loop of calls would meet); never a figure found online.
42
+ // mcp/test/output-schema.test.mjs holds the registered description to all four.
43
+ export const INTENDED_USE = "The tool is for a rent the user has asked to add, or has agreed to add on seeing the " +
44
+ "consent text - one rent, for one consent, never a batch of rents; never added on the user's behalf by default; " +
45
+ "and never a figure found online.";
40
46
 
41
47
  /** The details as the page would record them, from the tool's argument names. */
42
48
  function toRecordInput(a) {
@@ -0,0 +1,268 @@
1
+ /**
2
+ * The output schema of each tool (prepared 2026-10-20, after 0.9.0's preparation; not in a released version yet): what
3
+ * its structuredContent holds, declared in tools/list as outputSchema. The Claude and ChatGPT directories ask for one
4
+ * on every tool that returns structured data. Each schema describes the structured results the tools ALREADY
5
+ * return - no key or value changes for it - and it was drawn from them across the published files, every state and
6
+ * capital city, refused and given rows, stale and current answers (mcp/test/output-schema.test.mjs holds them to it).
7
+ *
8
+ * Why it is drawn loosely, on purpose:
9
+ * - The SDK checks every successful result against its tool's schema before answering, and a client checks it again
10
+ * on arrival. A result that does not fit is not answered: the call fails. So a schema here must never be
11
+ * narrower than what the tools return - a newer published file included.
12
+ * - Every object allows keys it does not name (additionalProperties), so an added field never fails a call. Only
13
+ * keys the code always writes, with a value the code makes, are required and typed. Every field copied from a
14
+ * data file - a string, a number, a boolean, an object or a list alike - may be missing, null or of any other
15
+ * type (fromFile below): the loaders check only a few fields of a file, the code passes the rest through as the
16
+ * file gives them, and a newer file that drops, nulls or retypes any one of them must still be answered. The
17
+ * type each is declared with is the one today's files give, kept for the reader; it is not a check. A sale-price
18
+ * type row the code passes through as the file gives it (anything but an object) is a scalar or null.
19
+ * - A failed call (isError) carries no structuredContent and is not checked.
20
+ * - The five shapes repeated across the tools (a source, a refusal, a rents row, a sale-price row, a sale-price
21
+ * place) carry an id, so tools/list declares each once per tool, under definitions, and points to it ($ref).
22
+ * - No field here carries a description: tools/list stays under 32,000 characters (a test holds it), and a
23
+ * description validates nothing. What each field means is in the comments here and in mcp/README.md.
24
+ * A released tool pins a field's meaning: a field whose meaning changes gets a new name, and this file gains it.
25
+ */
26
+ import { z } from "zod";
27
+
28
+ const str = z.string();
29
+ const nstr = z.string().nullable();
30
+ const nnum = z.number().nullable();
31
+ const obj = (shape) => z.looseObject(shape);
32
+ const opt = (s) => s.optional();
33
+ /**
34
+ * A field copied from a data file: it may be missing, null or of another type than today's file gives it (s), and is
35
+ * answered as it stands. In tools/list: anyOf [s, {}] - s says what the field holds today; {} accepts the rest.
36
+ */
37
+ const fromFile = (s) => z.union([s, z.unknown()]).optional();
38
+ /** A place's name from a data file: a postcode, read as a string or a number. */
39
+ const placeName = z.union([z.string(), z.number()]);
40
+
41
+ /**
42
+ * One source behind an answer, as envelope() in tools.mjs writes it: source (the publisher and table) and licence as
43
+ * the data file names them; licence_id, the SPDX id of the licence, or null where it has none (the RBA's permission);
44
+ * source_url, the data's own page as the data file gives it, null when it gives none; source_notice_url, the
45
+ * publisher's copyright notice where the attribution rests on one; feed_url, DwellDelta's published data file the
46
+ * answer was read from.
47
+ */
48
+ const source = obj({
49
+ source: fromFile(str),
50
+ licence: fromFile(str),
51
+ attribution: fromFile(str),
52
+ licence_id: fromFile(str),
53
+ licence_url: fromFile(str),
54
+ source_url: nstr,
55
+ source_notice_url: nstr,
56
+ feed_url: fromFile(str),
57
+ period: fromFile(str),
58
+ }).meta({ id: "source" });
59
+
60
+ /**
61
+ * The provenance every answer carries (envelope() in tools.mjs). retrieved_at: when the answer was made (ISO 8601).
62
+ * data_as_of: the latest period of the figures given, from the data file. snapshot_built: the day the weekly
63
+ * indicators snapshot was built, null for answers without one. snapshot_origin: which copy answered (env, live,
64
+ * published or bundled). stale: the weekly indicators snapshot is more than its stale age old. cadence: how often the
65
+ * data is released (weekly, monthly or quarterly). period_due_by: the day by which the release after this period was
66
+ * due; period_overdue: it was due and has not reached the data file. advice: false on every answer.
67
+ */
68
+ const envelope = {
69
+ publisher: str,
70
+ server_version: str,
71
+ retrieved_at: str,
72
+ data_as_of: fromFile(str),
73
+ snapshot_built: fromFile(str),
74
+ snapshot_origin: nstr,
75
+ stale: z.boolean(),
76
+ stale_reason: nstr,
77
+ stale_after: nstr,
78
+ cadence: nstr,
79
+ period_due_by: nstr,
80
+ period_overdue: z.boolean(),
81
+ period_overdue_reason: nstr,
82
+ sources: z.array(source),
83
+ advice: z.boolean(),
84
+ };
85
+
86
+ /**
87
+ * One refusal: a figure that rests on too few records, or that the publisher does not publish. type is
88
+ * too_few_records or not_published.
89
+ */
90
+ const refusal = obj({
91
+ refused: z.boolean(),
92
+ type: str,
93
+ reason: fromFile(str),
94
+ n: nnum,
95
+ n_band: fromFile(str),
96
+ unit: str,
97
+ min_n: nnum,
98
+ rule: str,
99
+ }).meta({ id: "refusal" });
100
+
101
+ /**
102
+ * Each figure an answer gives or refuses, in the order of its lines (judgeFigure in tools.mjs). n: the records the
103
+ * figure rests on, where the publisher gives the count; n_band: the publisher's band for the count, where it
104
+ * withholds the exact number.
105
+ */
106
+ const figure = obj({
107
+ name: str,
108
+ n: nnum,
109
+ n_band: fromFile(str),
110
+ unit: str,
111
+ small_sample: z.boolean(),
112
+ refusal: refusal.nullable(),
113
+ });
114
+
115
+ /** The fields every figure-giving answer adds (figureFields in tools.mjs), and its publisher's small-sample rule. */
116
+ const figures = {
117
+ figures: z.array(figure),
118
+ refusals: z.array(refusal.extend({ name: str })),
119
+ all_refused: z.boolean(),
120
+ sample_rule: obj({ unit: str, min_n: nnum, rule: str }),
121
+ };
122
+
123
+ /**
124
+ * Each row's own marker (refusalMark in tools.mjs): refused, the answer refused this row's figure; refusal_type,
125
+ * too_few_records or not_published, null for a figure that is given.
126
+ */
127
+ const marked = {
128
+ refused: z.boolean(),
129
+ refusal_type: nstr,
130
+ };
131
+
132
+ /** A rents row as the data file gives it, plus its marker. Medians and counts are null where none is published. */
133
+ const rentRow = obj({
134
+ region: fromFile(str), council: fromFile(str), area: fromFile(placeName), suburb_group: fromFile(str),
135
+ median_weekly_rent_aud: fromFile(z.number()), first_quartile_aud: fromFile(z.number()),
136
+ third_quartile_aud: fromFile(z.number()), year_ago_median_aud: fromFile(z.number()), change_pct: fromFile(z.number()),
137
+ new_bonds: fromFile(z.number()), new_leases: fromFile(z.number()), small_sample: fromFile(z.boolean()),
138
+ ...marked,
139
+ }).meta({ id: "rent_row" });
140
+
141
+ /** A sale-price row for one dwelling type: prices in thousands of Australian dollars, as DCJ reports them. */
142
+ const saleRow = obj({
143
+ median_price_k_aud: fromFile(z.number()), first_quartile_k_aud: fromFile(z.number()),
144
+ third_quartile_k_aud: fromFile(z.number()), sales: fromFile(z.number()), change_pct: fromFile(z.number()),
145
+ small_sample: fromFile(z.boolean()),
146
+ ...marked,
147
+ }).meta({ id: "sale_row" });
148
+ /**
149
+ * A place's sale prices, for the dwelling types asked for. A type with no row in DCJ's table is null. A type's row is
150
+ * the file's object with its marker added; anything else the file gives there is passed through as it stands.
151
+ */
152
+ const saleSlot = z.union([saleRow, z.string(), z.number(), z.boolean(), z.null()]).optional();
153
+ const salePlace = obj({
154
+ area: fromFile(placeName), council: fromFile(str),
155
+ total: saleSlot, non_strata: saleSlot, strata: saleSlot,
156
+ }).meta({ id: "sale_place" });
157
+
158
+ /** The source's limits, as its data file states them. */
159
+ const fileLimits = fromFile(z.array(str));
160
+
161
+ export const OUTPUT_SCHEMAS = {
162
+ // result: the comparison - the ABS rents index's move from startUsed to latest, and the rent it tracks to. Every
163
+ // field of it, and the limits, are the rent check's own (vendor/rent-check.mjs), not a data file's.
164
+ rent_check: obj({
165
+ ...envelope,
166
+ result: obj({
167
+ city: str, leaseStart: str, startUsed: str, latest: str, truncated: z.boolean(),
168
+ indexPct: z.number(), currentRent: z.number(), trackedRent: z.number(),
169
+ proposedRent: opt(z.number()), proposedPct: opt(z.number()), gapPoints: opt(z.number()), gapDollars: opt(z.number()),
170
+ }),
171
+ limits: z.array(str),
172
+ sample_size: z.null(),
173
+ sample_size_note: str,
174
+ }),
175
+
176
+ // Each indicator as the snapshot gives it, plus licence_id, source_url and sample_size, which the code adds.
177
+ market_indicators: obj({
178
+ ...envelope,
179
+ indicators: z.array(obj({
180
+ id: fromFile(str), name: fromFile(str), geography: fromFile(str), value: fromFile(z.number()), unit: fromFile(str),
181
+ period: fromFile(str), source: fromFile(str), licence: fromFile(str), attribution: fromFile(str),
182
+ limit: fromFile(str),
183
+ change: fromFile(obj({ value: fromFile(z.number()), unit: fromFile(str), over: fromFile(str) })),
184
+ licence_id: nstr, source_url: nstr, sample_size: z.null(),
185
+ })),
186
+ sample_size: z.null(),
187
+ sample_size_note: str,
188
+ }),
189
+
190
+ data_sources: obj({
191
+ ...envelope,
192
+ cannot_answer: fromFile(z.array(str)),
193
+ rules: fromFile(str),
194
+ }),
195
+
196
+ vic_rents: obj({
197
+ ...envelope,
198
+ quarter: fromFile(str),
199
+ compared_with: fromFile(str),
200
+ regions: z.array(rentRow),
201
+ suburb_groups: z.array(rentRow),
202
+ limits: fileLimits,
203
+ ...figures,
204
+ }),
205
+
206
+ // Two kinds of answer: all dwellings together (state_total, regions, councils, areas), or by dwelling type and
207
+ // bedrooms (asked, rows) - so the keys of each kind are optional. area_kind: postcode, suburb or locality, from the
208
+ // file. derived: the medians are DwellDelta's own calculation from the bond records (WA). A row's figure is the
209
+ // publisher's cell, as the file gives it; null where none is published.
210
+ area_rents: obj({
211
+ ...envelope,
212
+ state: str,
213
+ state_name: str,
214
+ area_kind: fromFile(str),
215
+ quarter: fromFile(str),
216
+ compared_with: fromFile(str),
217
+ derived: opt(z.boolean()),
218
+ state_total: opt(rentRow.nullable()),
219
+ regions: opt(z.array(rentRow)),
220
+ councils: opt(z.array(rentRow)),
221
+ areas: opt(z.array(rentRow)),
222
+ detail: fromFile(str),
223
+ asked: opt(obj({ dwelling_type: opt(nstr), bedrooms: opt(z.union([z.string(), z.number()]).nullable()),
224
+ labels: opt(z.array(str)) })),
225
+ notes: opt(z.array(str)),
226
+ rows: opt(z.array(obj({
227
+ place: fromFile(placeName), place_kind: fromFile(str), dwelling_type: opt(nstr), bedrooms: opt(nstr),
228
+ label: opt(nstr), figure: fromFile(obj({})),
229
+ ...marked,
230
+ }))),
231
+ absent_means: fromFile(str),
232
+ labels: fromFile(str),
233
+ truncated: z.boolean(),
234
+ limits: fileLimits,
235
+ changes_made: fromFile(str),
236
+ ...figures,
237
+ }),
238
+
239
+ // unit: the unit of every price field, thousands of Australian dollars, as the file states it.
240
+ nsw_sale_prices: obj({
241
+ ...envelope,
242
+ state: str,
243
+ measure: str,
244
+ unit: fromFile(str),
245
+ area_kind: str,
246
+ quarter: fromFile(str),
247
+ compared_with: fromFile(str),
248
+ dwelling_types: z.unknown(),
249
+ state_total: salePlace.nullable(),
250
+ councils: z.array(salePlace),
251
+ areas: z.array(salePlace),
252
+ any_unusual: z.boolean(),
253
+ any_unusual_part: z.boolean(),
254
+ truncated: z.boolean(),
255
+ limits: fileLimits,
256
+ changes_made: fromFile(str),
257
+ ...figures,
258
+ }),
259
+
260
+ // Two answers: the consent text and token (stored: false), or the deletion code once the rent is added (stored:
261
+ // true). stored: whether a rent was added by this call.
262
+ contribute_rent: obj({
263
+ stored: z.boolean(),
264
+ consent_text: opt(str), terms_url: opt(str), privacy_url: opt(str), terms_version: opt(str),
265
+ consent_token: opt(str), expires_in_minutes: opt(z.number()),
266
+ deletion_code: opt(str), delete_by_emailing: opt(str),
267
+ }),
268
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dwelldelta-mcp",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
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",
@@ -21,6 +21,8 @@
21
21
  "files": [
22
22
  "server.mjs",
23
23
  "tools.mjs",
24
+ "register-tools.mjs",
25
+ "output-schemas.mjs",
24
26
  "contribute-tool.mjs",
25
27
  "vic-rents-tool.mjs",
26
28
  "area-rents-tool.mjs",