dwelldelta-mcp 0.11.0 → 0.12.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
@@ -4,11 +4,12 @@ An MCP server that lets an AI assistant check a weekly rent against the ABS rent
4
4
  by area in five states and NSW median sale prices, and quote sourced Australian property and lending indicators. From
5
5
  [DwellDelta](https://dwelldelta.com.au/), a service of Xcelerent Pty Ltd, built on public data.
6
6
 
7
- Six read-only tools, and one that adds the user's own rent when they ask:
7
+ Seven read-only tools, and one that adds the user's own rent when they ask:
8
8
 
9
9
  | Tool | What it answers |
10
10
  |---|---|
11
- | `rent_check` | a weekly rent, and any proposed new rent, against the ABS rents index for the capital city since the lease began (the same arithmetic as the rent check at tools.dwelldelta.com.au) |
11
+ | `rent_check` | a weekly rent, and any proposed new rent, against the ABS rents index for the capital city since the lease began (the same arithmetic as the rent check at tools.dwelldelta.com.au); or, given a `place` instead of a lease start, against that place's median of new bonds or leases, and its quartiles where published (from 0.12.0) |
12
+ | `property_rents` | the rents of a place asked with no state - a suburb, locality or postcode - answered from the state that holds it (NSW, Victoria, Queensland, WA or SA); an NSW suburb is answered for its postcode, and a name held in more than one state is listed, not chosen (from 0.12.0) |
12
13
  | `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
14
  | `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
15
  | `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), SA by suburb (SA Housing Trust, Private Rent Report; its publisher's page states no licence, and the national catalogues list CC BY); each file states CC BY 4.0 (from 0.6.0; SA from 0.11.0) |
@@ -133,6 +134,45 @@ copy city by city (each city's series starts no later and ends no earlier than i
133
134
  later than the current one; otherwise, or with `DWELLDELTA_OFFLINE=1`, the bundled copy answers.
134
135
  `data_as_of` and the `Cite:` line's period say which month the answer runs to.
135
136
 
137
+ ### Answers on the first call, pages and citations (from 0.12.0)
138
+
139
+ - A NSW suburb's name is answered on the first call where the NSW suburb list (NSW Spatial Services, CC BY 3.0 AU)
140
+ places it in exactly one postcode, counted across the whole list, and the file holds that postcode: the answer is
141
+ that whole postcode's, and its first line says so and credits the list. A name in several postcodes is refused
142
+ with the ones to try, and names any the file has no row for.
143
+ - `area_rents` and `nsw_sale_prices` answers gain new fields: `place_note`, `page_url` (the place's page on
144
+ tools.dwelldelta.com.au, the state's page for the state's own figure, else null), `pages` and `cite_as` (null when
145
+ every figure is refused); the text gains `Page:` and `Cite as:` lines. Results stay text only, readable by clients
146
+ on every protocol version the server accepts. No earlier field changes.
147
+ - The server sends `instructions` in its initialize result: what it holds, when it applies, how to cite it, its limits.
148
+ - A URL in an answer's text is never followed by punctuation run into it: one that would be is written `<...>`. This
149
+ changes the `Cite:` line's text: its URLs now read `<https://...>` where a `;` or `.` follows them.
150
+
151
+ ### Asking by place, and a rent against the local median (from 0.12.0)
152
+
153
+ - `rent_check` without `lease_start`: give `place` (a suburb, locality or postcode in NSW, Victoria, Queensland, WA
154
+ or SA; a state may follow, as "Richmond, VIC") with `current_rent` (and `proposed_rent`, `dwelling_type` and
155
+ `bedrooms` where the state publishes them), and the answer places the rent against that place's median of new
156
+ bonds: the dollars and per cent from the median and, where the publisher gives quartiles (DCJ, NSW), between which
157
+ of them, in the web rent check's words. It is information, not a judgement of the rent. `result` is null in this
158
+ mode and `local` holds the placement; the place's own answer follows, with its limits and source. A figure the
159
+ publisher marks small, or whose count it withholds, opens with the web card's caution, and `local.small_sample`,
160
+ `local.n` and `local.n_band` say so; a median that is not a number in the data file is refused as no median. With
161
+ `lease_start`, `rent_check` is unchanged (and `city` is needed with it); an argument of the other mode is named in
162
+ a first line, "Not used: ...", and in `ignored`.
163
+ - `property_rents(place, dwelling_type?, bedrooms?)` (place-tool.mjs) answers a place with no state: the place is
164
+ found by its exact name in every file held and answered by `area_rents` or `vic_rents` for that state. A name held
165
+ in more than one state ("Richmond": NSW, SA, VIC) is listed with each, never chosen. A trailing state word is
166
+ the state where the rest is held there ("East Perth WA"); otherwise a held name is read whole ("Mount Victoria" is
167
+ NSW's), and "Mt" and "Mount" are one. A postcode
168
+ given with a name is used only where the NSW suburb list gives it for that name ("Alison 2259"); a NSW postcode it
169
+ does not give is refused, naming both; outside NSW, whose feeds are by name, it only says the state. A postcode
170
+ alone is looked for in DCJ's file first (it reports 2611 and 2900, in Australia Post's ACT ranges, as NSW's).
171
+ Tasmania, the ACT, the Northern Territory and New Zealand are otherwise said to be not held. Both servers list it
172
+ from 0.12.0, and the server's instructions say what it takes.
173
+ - tools/list: a field copied from a data file is now declared `{}` (any value) rather than `anyOf [type, {}]`, which
174
+ accepts exactly the same values; this made room for the above under the 32,000-character cap.
175
+
136
176
  ### Checkable provenance (from 0.9.0)
137
177
 
138
178
  Every answer that gives a figure ends with a `Cite:` line to quote with it: the source, the period, the licence id
@@ -189,7 +229,7 @@ answer states - for example ABS data is CC BY 4.0, "Based on Australian Bureau o
189
229
 
190
230
  ## Development
191
231
 
192
- `npm test` here starts the server and calls the six read-only tools, and the first (consent) call of
232
+ `npm test` here starts the server and calls the seven read-only tools, and the first (consent) call of
193
233
  `contribute_rent`, over MCP, and `test/provenance.test.mjs` holds the provenance above on the vendored files and
194
234
  fixtures; the repository's root `npm test` holds the
195
235
  tool answers themselves and checks that `vendor/` matches its sources. `npm pack` runs `scripts/vendor.mjs` first.
@@ -26,6 +26,7 @@ import { loadJson, envelope, ToolError, FOOTER, FETCH_TIMEOUT_MS, feedSource, CA
26
26
  figureFields, nWords, citeLine, staleNote, flagged, refusalMark, isRecord, passes, readChecked, quiet,
27
27
  warnPublished, fromCopy } from "./tools.mjs";
28
28
  import { quarterKey } from "./vic-rents-tool.mjs";
29
+ import { rentPage, citeFields, withPlace } from "./pages.mjs";
29
30
 
30
31
  const HERE = dirname(fileURLToPath(import.meta.url));
31
32
  const LIVE_DIR = join(HERE, "..", "..", "dwelldelta-data", "market");
@@ -149,17 +150,55 @@ export function match(rows, key, wanted) {
149
150
  return exact.length ? exact : real.filter((r) => norm(r[key]).includes(norm(wanted)));
150
151
  }
151
152
 
153
+ /** Where the place note's pairing of a suburb with a postcode comes from, named in every answer that rests on it. */
154
+ export const SUBURB_LIST_CREDIT = "NSW suburb list: NSW Spatial Services, CC BY 3.0 AU";
155
+
152
156
  /**
153
- * People ask NSW by suburb, and DCJ reports by postcode. For a name that matched no postcode: the suburbs of that name
154
- * in the NSW suburb list ("Parramatta (2150)", already shipped for contribute_rent), with the postcodes this feed
155
- * holds - offered as the next step, never answered silently, because a postcode's median is not a suburb's.
157
+ * People ask NSW by suburb, and DCJ reports by postcode. For a name the call does not answer (nswResolve): the suburbs
158
+ * of that name in the NSW suburb list ("Parramatta (2150)", already shipped for contribute_rent), with the postcodes
159
+ * this feed holds, offered as the next step. Where the exact name is also in postcodes this feed holds no row for,
160
+ * they are named as such, so a name in two postcodes is never read as being in one. With no held postcode to offer,
161
+ * nothing is said of the list: a postcode with no row would send the agent to a second failure.
156
162
  */
157
163
  export function nswPostcodes(wanted, suburbs, feed) {
158
- const held = new Set(feed.areas.filter(isRecord).map((r) => r.area));
159
- const named = suburbs.map((s) => /^(.*) \((\d{4})\)$/.exec(s)).filter((m) => m && held.has(m[2]));
164
+ const held = new Set(feed.areas.filter(isRecord).map((r) => String(r.area)));
165
+ const all = suburbs.map((s) => /^(.*) \((\d{4})\)$/.exec(s)).filter(Boolean);
166
+ const named = all.filter((m) => held.has(m[2]));
160
167
  const exact = named.filter((m) => norm(m[1]) === norm(wanted));
161
168
  const found = exact.length ? exact : named.filter((m) => norm(m[1]).includes(norm(wanted)));
162
- return found.slice(0, 5).map((m) => `${m[1]} is in postcode ${m[2]}`);
169
+ const lines = found.slice(0, 5).map((m) => `${m[1]} is in postcode ${m[2]}`);
170
+ const elsewhere = exact.length ? [...new Set(all.filter((m) => !held.has(m[2]) && norm(m[1]) === norm(wanted))
171
+ .map((m) => m[2]))] : [];
172
+ if (elsewhere.length) {
173
+ lines.push(`the list also places ${exact[0][1]} in postcode${elsewhere.length > 1 ? "s" : ""} ${elsewhere.join(", ")}, ` +
174
+ "which this file has no row for");
175
+ }
176
+ return lines;
177
+ }
178
+
179
+ /**
180
+ * A suburb's name answered on the first call (0.12.0, 2026-11-03: a model asking "Parramatta" was refused, told the
181
+ * postcode, and often went no further). Where the NSW suburb list places that exact name in ONE postcode - counted
182
+ * across the whole list, not only the postcodes this feed holds (review of #74: "Maryland" is in 2287 and 4377, and
183
+ * the rents feed holds only 2287) - and the feed holds it, the answer is that postcode's row, with a note saying the
184
+ * figure is the whole postcode's and where the pairing comes from. A name in several postcodes, in one the feed has
185
+ * no row for, or matching only in part, is not resolved (null): the call refuses with the postcodes to try.
186
+ */
187
+ export function nswResolve(wanted, suburbs, feed) {
188
+ const held = new Set(feed.areas.filter(isRecord).map((r) => String(r.area)));
189
+ const exact = suburbs.map((s) => /^(.*) \((\d{4})\)$/.exec(s)).filter((m) => m && norm(m[1]) === norm(wanted));
190
+ const codes = [...new Set(exact.map((m) => m[2]))];
191
+ if (codes.length !== 1 || !held.has(codes[0])) return null;
192
+ const suburb = exact[0][1], postcode = codes[0];
193
+ return { suburb, postcode,
194
+ note: `${suburb} is in postcode ${postcode} (${SUBURB_LIST_CREDIT}). These figures are for the whole ` +
195
+ `postcode, not ${suburb} alone.` };
196
+ }
197
+
198
+ /** The note when a resolved suburb's name is also a council's: the council's figure is a call of its own. */
199
+ export function councilToo(wanted, councils) {
200
+ const c = (councils ?? []).filter(isRecord).find((r) => norm(r.council) === norm(wanted));
201
+ return c ? ` ${c.council} is also a council; its figure is answered with council: ${JSON.stringify(c.council)}.` : "";
163
202
  }
164
203
 
165
204
  /**
@@ -186,8 +225,16 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
186
225
  }
187
226
  const kind = feed.area_kind;
188
227
  let areas = [], councils = [], regions = [];
228
+ let resolved = null;
189
229
  if (area != null && String(area).trim()) {
190
230
  areas = match(feed.areas, "area", area);
231
+ if (!areas.length && state === "NSW") {
232
+ resolved = nswResolve(area, nswSuburbs, feed);
233
+ if (resolved) {
234
+ areas = match(feed.areas, "area", resolved.postcode);
235
+ resolved.note += council == null || !String(council).trim() ? councilToo(area, feed.councils) : "";
236
+ }
237
+ }
191
238
  if (!areas.length) {
192
239
  const named = state === "NSW" ? nswPostcodes(area, nswSuburbs, feed) : [];
193
240
  throw new ToolError(`No ${info.name} ${kind} matches ${JSON.stringify(area)}.`,
@@ -204,9 +251,23 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
204
251
  }
205
252
  }
206
253
  const whole = !areas.length && !councils.length;
254
+ // The page and citation fields (pages.mjs), and the resolved suburb's note, added to whichever answer is given.
255
+ const finish = (res, byKind) => {
256
+ const shownAreas = areas.slice(0, byKind ? MAX_TYPE_PLACES : MAX_ROWS);
257
+ const places = shownAreas.map((r) => ({ name: r.area, url: rentPage(state, feed.areas, r) }));
258
+ const label = shownAreas.length === 1 && !councils.length ? `${shownAreas[0].area} (${kind}), ${info.name}`
259
+ : whole ? info.name : `${info.name}, ${shownAreas.length + councils.length} places`;
260
+ const cite = citeFields({ state, places: councils.length ? [] : places, whole,
261
+ what: `Median weekly rent of new bonds${byKind ? " by dwelling type" : ""}, ${label}`, period: feed.quarter,
262
+ by: feed.rights_holder ?? feed.source, licence: feed.licence, allRefused: res.structured.all_refused === true });
263
+ if (councils.length) cite.pages = places.filter((p) => p.url).map((p) => ({ place: p.name, url: p.url }));
264
+ const note = resolved?.note ?? null;
265
+ return { text: withPlace(res.text, { note, ...cite }, FOOTER),
266
+ structured: { ...res.structured, place_note: note, ...cite } };
267
+ };
207
268
  if (wantsByType({ dwelling_type, bedrooms })) {
208
- return byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas, councils, file: byType[state],
209
- refusedFile: byType.refused?.[state] ?? null, hosted }, now);
269
+ return finish(byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas, councils, file: byType[state],
270
+ refusedFile: byType.refused?.[state] ?? null, hosted }, now), true);
210
271
  }
211
272
  if (whole) regions = feed.regions.filter(isRecord);
212
273
  const dropped = [];
@@ -248,12 +309,12 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
248
309
  notice: env.sources[0].source_notice_url, feedUrl, stale: flagged(env) }),
249
310
  FOOTER,
250
311
  ].join("\n");
251
- return { text, structured: { ...env, state, state_name: info.name, area_kind: kind, quarter: feed.quarter,
252
- compared_with: feed.compared_with, derived: feed.derived === true,
253
- state_total: whole ? marked(feed.state_total) : null, regions: regions.map(marked),
254
- councils: councils.map(marked), areas: areas.map(marked),
255
- truncated: dropped.length > 0, limits: feed.limits, changes_made: feed.changes_made,
256
- ...figureFields(figures), sample_rule: rule } };
312
+ return finish({ text, structured: { ...env, state, state_name: info.name, area_kind: kind, quarter: feed.quarter,
313
+ compared_with: feed.compared_with, derived: feed.derived === true,
314
+ state_total: whole ? marked(feed.state_total) : null, regions: regions.map(marked),
315
+ councils: councils.map(marked), areas: areas.map(marked),
316
+ truncated: dropped.length > 0, limits: feed.limits, changes_made: feed.changes_made,
317
+ ...figureFields(figures), sample_rule: rule } }, false);
257
318
  }
258
319
 
259
320
  // --- by dwelling type and bedrooms --------------------------------------------------------------------------------
@@ -32,9 +32,12 @@ const obj = (shape) => z.looseObject(shape);
32
32
  const opt = (s) => s.optional();
33
33
  /**
34
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.
35
+ * answered as it stands. In tools/list: {} - any value. Until 0.12.0 it was anyOf [s, {}], which accepts exactly the
36
+ * same values (the {} branch takes everything) and spent about 34 characters a field saying what today's file holds:
37
+ * 123 such fields, some 4,100 characters, which the place-first tool and rent_check's local mode needed under the
38
+ * 32,000 cap. Nothing is checked differently. s stays in the code, for the reader: what the field holds today.
36
39
  */
37
- const fromFile = (s) => z.union([s, z.unknown()]).optional();
40
+ const fromFile = (s) => z.unknown().optional();
38
41
  /** A place's name from a data file: a postcode, read as a string or a number. */
39
42
  const placeName = z.union([z.string(), z.number()]);
40
43
 
@@ -158,6 +161,9 @@ const salePlace = obj({
158
161
  /** The source's limits, as its data file states them. */
159
162
  const fileLimits = fromFile(z.array(str));
160
163
 
164
+ // Only page_url and cite_as are declared: place_note and pages are allowed as every unnamed key is (tools/list's size).
165
+ const cited = { page_url: opt(nstr), cite_as: opt(nstr) };
166
+
161
167
  export const OUTPUT_SCHEMAS = {
162
168
  // result: the comparison - the ABS rents index's move from startUsed to latest, and the rent it tracks to. Every
163
169
  // field of it, and the limits, are the rent check's own (vendor/rent-check.mjs), not a data file's.
@@ -167,7 +173,12 @@ export const OUTPUT_SCHEMAS = {
167
173
  city: str, leaseStart: str, startUsed: str, latest: str, truncated: z.boolean(),
168
174
  indexPct: z.number(), currentRent: z.number(), trackedRent: z.number(),
169
175
  proposedRent: opt(z.number()), proposedPct: opt(z.number()), gapPoints: opt(z.number()), gapDollars: opt(z.number()),
170
- }),
176
+ }).nullable(),
177
+ // New in 0.12.0, the local mode (no lease_start; place-tool.mjs rentCheckLocal): result is null, and local places
178
+ // the rent against the median of new bonds for one place - diff_dollars and diff_pct from the median, position in
179
+ // words. The place's answer's other fields (its rows, page_url, cite_as) are allowed as every unnamed key is.
180
+ local: opt(obj({ place: str, state: str, median: z.number(), n_unit: str, small_sample: z.boolean(),
181
+ current: obj({ rent: z.number(), diff_dollars: z.number(), diff_pct: z.number(), position: str }) })),
171
182
  limits: z.array(str),
172
183
  sample_size: z.null(),
173
184
  sample_size_note: str,
@@ -203,6 +214,9 @@ export const OUTPUT_SCHEMAS = {
203
214
  ...figures,
204
215
  }),
205
216
 
217
+ // New in 0.12.0 (pages.mjs), on area_rents and nsw_sale_prices: place_note, the note when a suburb's name was
218
+ // answered for its whole postcode; page_url, the answer's one page on tools.dwelldelta.com.au, or null; pages, every
219
+ // shown place with a page; cite_as, a line to quote with a figure from the answer.
206
220
  // Two kinds of answer: all dwellings together (state_total, regions, councils, areas), or by dwelling type and
207
221
  // bedrooms (asked, rows) - so the keys of each kind are optional. area_kind: postcode, suburb or locality, from the
208
222
  // file. derived: the medians are DwellDelta's own calculation from the bond records (WA). A row's figure is the
@@ -234,6 +248,7 @@ export const OUTPUT_SCHEMAS = {
234
248
  limits: fileLimits,
235
249
  changes_made: fromFile(str),
236
250
  ...figures,
251
+ ...cited,
237
252
  }),
238
253
 
239
254
  // unit: the unit of every price field, thousands of Australian dollars, as the file states it.
@@ -255,8 +270,14 @@ export const OUTPUT_SCHEMAS = {
255
270
  limits: fileLimits,
256
271
  changes_made: fromFile(str),
257
272
  ...figures,
273
+ ...cited,
258
274
  }),
259
275
 
276
+ // property_rents (0.12.0, place-tool.mjs): the answer of area_rents or vic_rents for the state that holds the
277
+ // place, as that tool gives it (allowed as every unnamed key is), and resolved_state and resolved_place: the state
278
+ // and the place in words the question was read as.
279
+ property_rents: obj({ ...envelope, resolved_state: str, resolved_place: str }),
280
+
260
281
  // Two answers: the consent text and token (stored: false), or the deletion code once the rent is added (stored:
261
282
  // true). stored: whether a rent was added by this call.
262
283
  contribute_rent: obj({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dwelldelta-mcp",
3
- "version": "0.11.0",
4
- "description": "Is an Australian rent fair? A rent check on the ABS rents index, rents by area for five states, NSW median sale prices, and sourced property and lending indicators, for AI agents.",
3
+ "version": "0.12.0",
4
+ "description": "Australian rents by area for five states, asked by place with no state, a rent placed against its local median, NSW median sale prices, an ABS rents index check, and sourced property and lending indicators, for AI agents.",
5
5
  "mcpName": "au.com.dwelldelta/dwelldelta",
6
6
  "license": "MIT",
7
7
  "homepage": "https://dwelldelta.com.au/",
@@ -27,13 +27,15 @@
27
27
  "vic-rents-tool.mjs",
28
28
  "area-rents-tool.mjs",
29
29
  "sale-prices-tool.mjs",
30
+ "pages.mjs",
31
+ "place-tool.mjs",
30
32
  "vendor/",
31
33
  "LICENSE",
32
34
  "README.md"
33
35
  ],
34
36
  "scripts": {
35
37
  "prepack": "node scripts/vendor.mjs",
36
- "test": "node --test test/*.test.mjs"
38
+ "test": "node --test --test-timeout=120000 --test-force-exit test/*.test.mjs"
37
39
  },
38
40
  "dependencies": {
39
41
  "@modelcontextprotocol/sdk": "^1.30.1",
package/pages.mjs ADDED
@@ -0,0 +1,87 @@
1
+ /**
2
+ * The tools site's page for a place, so an answer can name a page a person (or a model citing it) can open (2026-11-03,
3
+ * the agent-usage review: answers cited raw JSON files and copyright notices, never a page). The addresses are the
4
+ * ones tools/render-area-pages.mjs gives, worked out the same way here because the npm package cannot import outside
5
+ * its own folder; tests/mcp-pages.test.mjs holds the two to one rule, page for page, across every published file.
6
+ *
7
+ * A page is named only where the site builds one: a place with a median (a South Australian suburb with a count too),
8
+ * an NSW postcode with a rent or a sale median, and each state's own page. A council has no page of its own; neither
9
+ * does a place whose median is withheld. Where it is not known that a page exists, the answer names none.
10
+ */
11
+ import { isRecord } from "./tools.mjs";
12
+
13
+ export const SITE = "https://tools.dwelldelta.com.au";
14
+ /** The states the area pages cover (render-area-pages.mjs, area/lookup.mjs STATES). */
15
+ export const PAGE_STATES = ["NSW", "VIC", "QLD", "WA", "SA"];
16
+
17
+ /** The site's own slug: lower case, accents folded, every run of other characters one hyphen. */
18
+ export const slug = (s) => String(s).toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
19
+
20
+ export const statePage = (state) => (PAGE_STATES.includes(state) ? `${SITE}/area/${state.toLowerCase()}/` : null);
21
+
22
+ // Addresses are given across EVERY place in a file, in an order of the names alone, the later of two clashing names
23
+ // taking the next free "-2", "-3" (render-area-pages.mjs places()). Worked out once per list of places.
24
+ const memo = new WeakMap();
25
+ function addresses(names) {
26
+ const rows = [...new Set(names.map(String))].map((name) => ({ name, slug: slug(name) }));
27
+ const byName = rows.sort((a, b) => (a.slug < b.slug ? -1 : a.slug > b.slug ? 1 : a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
28
+ const seen = new Set(), out = new Map();
29
+ for (const p of byName) {
30
+ if (!p.slug) continue;
31
+ let s = p.slug;
32
+ for (let n = 2; seen.has(s); n++) s = `${p.slug}-${n}`;
33
+ seen.add(s);
34
+ out.set(p.name, s);
35
+ }
36
+ return out;
37
+ }
38
+
39
+ function addressBook(rows) {
40
+ if (!memo.has(rows)) memo.set(rows, addresses(rows.filter(isRecord).map((r) => r.area)));
41
+ return memo.get(rows);
42
+ }
43
+
44
+ /**
45
+ * The page of one rents row (a postcode, suburb, locality or Victorian suburb group): its address, or null where the
46
+ * site builds no page for it. rows: every place row of the file the row came from (the addresses are given across all
47
+ * of them).
48
+ */
49
+ export function rentPage(state, rows, row) {
50
+ if (!PAGE_STATES.includes(state) || !isRecord(row) || row.median_weekly_rent_aud == null) return null;
51
+ if (state === "SA" && row.new_bonds == null) return null;
52
+ if (state === "NSW") return `${SITE}/area/nsw/${slug(row.area)}/`;
53
+ const s = addressBook(rows).get(String(row.area));
54
+ return s ? `${SITE}/area/${state.toLowerCase()}/${s}/` : null;
55
+ }
56
+
57
+ /** The page of one NSW sale-price postcode row: the site builds a page for a postcode with a sale median. */
58
+ export function salePage(row) {
59
+ return isRecord(row) && isRecord(row.total) && row.total.median_price_k_aud != null
60
+ ? `${SITE}/area/nsw/${slug(row.area)}/` : null;
61
+ }
62
+
63
+ /**
64
+ * The fields an answer gains (new in 0.12.0; no earlier field changes): page_url, the one page for the answer (the
65
+ * place's own when one place is shown, the state's when the state's own figure is), else null; pages, every shown
66
+ * place that has a page; cite_as, a line to quote with a figure from the answer - null when the answer gives no
67
+ * figure to quote (every one refused, allRefused: review of #74).
68
+ */
69
+ export function citeFields({ state, places, whole, what, period, by, licence, allRefused = false }) {
70
+ const pages = places.filter((p) => p.url).map((p) => ({ place: p.name, url: p.url }));
71
+ const pageUrl = whole && !places.length ? statePage(state) : places.length === 1 ? places[0].url ?? null : null;
72
+ const where = pageUrl ?? statePage(state) ?? SITE;
73
+ const citeAs = allRefused ? null : `${what}, ${period}. Source: ${String(by ?? "").replace(/[.\s]+$/, "")}` +
74
+ `${licence ? `, ${licence}` : ""}. Via DwellDelta: ${where}`;
75
+ return { page_url: pageUrl, pages, cite_as: citeAs };
76
+ }
77
+
78
+ /**
79
+ * An answer's text with its place note first and its page and citation lines just before the footer. URLs stand
80
+ * alone, never with punctuation glued to them (unglue in register-tools.mjs).
81
+ */
82
+ export function withPlace(text, { note = null, page_url = null, cite_as = null } = {}, footer) {
83
+ const lines = text.split("\n");
84
+ const end = lines.length && lines[lines.length - 1] === footer ? lines.length - 1 : lines.length;
85
+ const tail = [...(page_url ? [`Page: ${page_url}`] : []), ...(cite_as ? [`Cite as: ${cite_as}`] : [])];
86
+ return [...(note ? [note, ""] : []), ...lines.slice(0, end), ...tail, ...lines.slice(end)].join("\n");
87
+ }
package/place-tool.mjs ADDED
@@ -0,0 +1,361 @@
1
+ /**
2
+ * Asking by place, with no state (prepared 2026-11-03 for 0.12.0; the agent-usage review: a model asking "median rent
3
+ * in Fremantle" had to know the state, and the tool for it, before any call could answer).
4
+ *
5
+ * - property_rents(place, dwelling_type?, bedrooms?): any held Australian suburb, postcode or locality. The place is
6
+ * looked up, by its exact name, in every file held - the NSW suburb list (whose postcodes DCJ reports by), the
7
+ * Queensland, WA and SA feeds' own area names and Victoria's suburb groups - and answered by that state's own
8
+ * tool (area_rents or vic_rents), with every rule, refusal, page and citation of that tool. A name held in more
9
+ * than one state is never guessed: the answer lists where it is held and how to ask ("Richmond, VIC"). A place in
10
+ * Tasmania, the ACT, the Northern Territory or New Zealand is said to be not held.
11
+ * - rent_check's local mode (rentCheckLocal): a weekly rent placed against the median of new bonds for one place -
12
+ * between the quartiles where the publisher gives them (DCJ, NSW) - in the words the web rent check uses
13
+ * (rent/local.mjs position), as information, never a verdict on the rent.
14
+ *
15
+ * property_rents is one of READ_ONLY_TOOLS from 0.12.0: registerReadOnlyTools calls registerPlaceTools for both servers.
16
+ * The docs (llms.txt, the hosted server's page) list the hosted server's tools and are published when this
17
+ * repository's main branch is, so it was wired in by the release that deploys it (0.12.0), with them.
18
+ */
19
+ import { z } from "zod";
20
+ import { isRecord, ToolError } from "./tools.mjs";
21
+ import { areaRentsResult, STATES, norm, wantsByType, dollars } from "./area-rents-tool.mjs";
22
+ import { vicRentsResult } from "./vic-rents-tool.mjs";
23
+ import { OUTPUT_SCHEMAS } from "./output-schemas.mjs";
24
+
25
+ /** The states whose rents are held by area, and those that are not (with New Zealand). */
26
+ export const HELD = ["NSW", "VIC", "QLD", "WA", "SA"];
27
+ export const NOT_HELD = { TAS: "Tasmania", ACT: "the Australian Capital Territory", NT: "the Northern Territory",
28
+ NZ: "New Zealand" };
29
+ const STATE_WORDS = {
30
+ NSW: ["nsw", "new south wales"], VIC: ["vic", "victoria"], QLD: ["qld", "queensland"], WA: ["wa", "western australia"],
31
+ SA: ["sa", "south australia"], TAS: ["tas", "tasmania"], ACT: ["act", "australian capital territory"],
32
+ NT: ["nt", "northern territory"], NZ: ["nz", "new zealand", "aotearoa"],
33
+ };
34
+ const WORD_STATE = new Map(Object.entries(STATE_WORDS).flatMap(([s, ws]) => ws.map((w) => [w, s])));
35
+ const STATE_TAIL = new RegExp(`^(.*?)[\\s,(]+(${[...WORD_STATE.keys()].sort((a, b) => b.length - a.length)
36
+ .map((w) => w.replace(/ /g, "\\s+")).join("|")})\\)?$`, "i");
37
+
38
+ /**
39
+ * "Richmond, VIC" -> { name: "Richmond", state: "VIC" }; "Parramatta NSW 2150" -> { name: "Parramatta", state:
40
+ * "NSW", postcode: "2150" }; "2150" and "2150 NSW" -> { postcode: "2150" } (with the state). A state named in words
41
+ * or letters after the place, with a comma, a space or a bracket before it, is the asker's; nothing else is read as a
42
+ * state - and not even that when the rest is not held in that state but the whole text is a held name (isHeld(name,
43
+ * state?)): "Mount Victoria" is a NSW suburb, not "Mount" in Victoria, while "East Perth WA" is East Perth in WA, not
44
+ * the WA feed's own stray row spelled with its state (the reviews of #75).
45
+ */
46
+ export function parsePlace(raw, isHeld = () => false) {
47
+ let text = String(raw ?? "").trim().replace(/\s+/g, " ");
48
+ let postcode = null, state = null;
49
+ const pc = /^(.*?)[\s,]*\b(\d{4})$/.exec(text) ?? /^()(\d{4})\b[\s,]*(.*)$/.exec(text);
50
+ if (pc) { postcode = pc[2]; text = (pc[1] || pc[3] || "").trim(); }
51
+ const tail = STATE_TAIL.exec(text);
52
+ const rest = tail?.[1].replace(/[,(]+$/, "").trim();
53
+ const said = tail && WORD_STATE.get(tail[2].toLowerCase().replace(/\s+/g, " "));
54
+ if (rest && isHeld(rest, said)) return { name: rest, state: said, postcode };
55
+ const whole = text.replace(/[,(]+$/, "").trim();
56
+ if (whole && !WORD_STATE.has(whole.toLowerCase()) && isHeld(whole)) return { name: whole, state, postcode };
57
+ if (tail && tail[1].trim()) { state = WORD_STATE.get(tail[2].toLowerCase().replace(/\s+/g, " ")); text = tail[1].trim(); }
58
+ else if (WORD_STATE.has(text.toLowerCase())) { state = WORD_STATE.get(text.toLowerCase()); text = ""; }
59
+ return { name: text.replace(/[,(]+$/, "").trim(), state, postcode };
60
+ }
61
+
62
+ /**
63
+ * The state of an Australian postcode, from Australia Post's ranges (a few PO Box ranges included). New Zealand's
64
+ * postcodes are four digits too: a bare four-digit number is read as Australian, and the asker names NZ to say not.
65
+ */
66
+ export function postcodeState(postcode) {
67
+ const n = Number(postcode);
68
+ if (!/^\d{4}$/.test(String(postcode))) return null;
69
+ if ((n >= 200 && n <= 299) || (n >= 2600 && n <= 2618) || (n >= 2900 && n <= 2920)) return "ACT";
70
+ if (n >= 800 && n <= 999) return "NT";
71
+ if (n >= 1000 && n <= 2999) return "NSW";
72
+ if ((n >= 3000 && n <= 3999) || (n >= 8000 && n <= 8999)) return "VIC";
73
+ if ((n >= 4000 && n <= 4999) || (n >= 9000 && n <= 9999)) return "QLD";
74
+ if (n >= 5000 && n <= 5999) return "SA";
75
+ if (n >= 6000 && n <= 6999) return "WA";
76
+ if (n >= 7000 && n <= 7999) return "TAS";
77
+ return null;
78
+ }
79
+
80
+ /** A name and its "Mt"/"Mount" twin: the files spell it one way ("Mount Victoria"), an asker often the other. */
81
+ const spellings = (name) => {
82
+ const n = norm(name);
83
+ return new Set([n, n.replace(/\bmt\.?\s/g, "mount "), n.replace(/\bmount\s/g, "mt ")]);
84
+ };
85
+
86
+ /** Every held place of exactly this name, by state: [{ state, area | suburb_group, postcodes?, label }]. */
87
+ export function placeCandidates(name, { suburbs = [], areaRents = {}, vic = null } = {}) {
88
+ if (!norm(name)) return [];
89
+ const want = spellings(name);
90
+ const out = [];
91
+ const nsw = suburbs.map((s) => /^(.*) \((\d{4})\)$/.exec(String(s))).filter((m) => m && want.has(norm(m[1])));
92
+ const codes = [...new Set(nsw.map((m) => m[2]))];
93
+ if (codes.length) out.push({ state: "NSW", area: nsw[0][1], postcodes: codes,
94
+ label: `NSW, postcode${codes.length > 1 ? "s" : ""} ${codes.join(", ")}` });
95
+ for (const state of ["QLD", "WA", "SA"]) {
96
+ const rows = (areaRents[state]?.areas ?? []).filter((r) => isRecord(r) && want.has(norm(r.area)));
97
+ for (const r of rows) out.push({ state, area: r.area, label: `${state}, ${areaRents[state].area_kind} ${r.area}` });
98
+ }
99
+ for (const g of (vic?.suburb_groups ?? []).filter(isRecord)) {
100
+ const group = String(g.suburb_group ?? "");
101
+ if (want.has(norm(group)) || group.split("-").some((part) => want.has(norm(part)))) {
102
+ out.push({ state: "VIC", suburb_group: group, label: `VIC, suburb group ${group}` });
103
+ }
104
+ }
105
+ return out;
106
+ }
107
+
108
+ const notHeld = (place, state) => new ToolError(`${place} is in ${NOT_HELD[state]}, whose rents DwellDelta does not hold.`,
109
+ `Rents by area are held for NSW, Victoria, Queensland, WA and SA only; ${NOT_HELD[state]} is not covered, so there is ` +
110
+ "no figure to give for it.");
111
+
112
+ /**
113
+ * Where a place's question goes: { state, args, how } - the state's tool and its arguments - or a ToolError that says
114
+ * why it cannot be answered and how to ask instead. Never a guess between two places of one name.
115
+ */
116
+ export function resolvePlace(raw, data) {
117
+ const asked = String(raw ?? "").trim();
118
+ const { name, state: said, postcode } = parsePlace(asked,
119
+ (t, st) => placeCandidates(t, data).some((c) => !st || c.state === st));
120
+ const stateOfCode = postcode ? postcodeState(postcode) : null;
121
+ if (!name && !postcode) {
122
+ throw new ToolError(`No place was given (${JSON.stringify(asked)}).`,
123
+ "Give a suburb, locality or postcode, e.g. \"Fremantle\", \"Richmond, VIC\" or \"2150\".");
124
+ }
125
+ if (said && NOT_HELD[said]) throw notHeld(asked, said);
126
+ const nswArgs = (how) => ({ state: "NSW", args: { state: "NSW", area: postcode }, how });
127
+ const mismatch = () => new ToolError(`${asked}: postcode ${postcode} is in ${stateOfCode ?? "no state"}, not ${said}.`,
128
+ "Give the place with its own state or its postcode alone.");
129
+ // A postcode alone: NSW's rents are by postcode; the other held states' are by name. DCJ's file is looked in first:
130
+ // it reports some postcodes in Australia Post's ACT ranges (2611, 2900...) as NSW's.
131
+ if (!name) {
132
+ const dcj = (data.areaRents?.NSW?.areas ?? []).some((r) => isRecord(r) && String(r.area) === postcode);
133
+ if (dcj && (!said || said === "NSW")) {
134
+ return nswArgs(`postcode ${postcode}, New South Wales` + (stateOfCode !== "NSW"
135
+ ? ` (DCJ reports it with NSW; Australia Post's range for it is ${NOT_HELD[stateOfCode] ?? stateOfCode})` : ""));
136
+ }
137
+ if (said && stateOfCode && said !== stateOfCode) throw mismatch();
138
+ if (NOT_HELD[stateOfCode]) throw notHeld(`Postcode ${postcode}`, stateOfCode);
139
+ if (stateOfCode === "NSW") return nswArgs(`postcode ${postcode}, New South Wales`);
140
+ if (!stateOfCode) throw new ToolError(`${postcode} is not an Australian postcode.`, "Give a suburb or locality name.");
141
+ throw new ToolError(`Postcode ${postcode} is in ${stateOfCode}, whose rents are held by place name, not postcode.`,
142
+ `Give the suburb's or locality's name, e.g. "Fremantle, WA".`);
143
+ }
144
+ const found = placeCandidates(name, data);
145
+ // A name and a postcode: the postcode is used only where the NSW suburb list gives it for that name ("Alison 2259",
146
+ // "Barooga 3644"); a NSW postcode the list does not give for the name is refused, naming both, never one chosen.
147
+ if (postcode) {
148
+ const nsw = found.find((c) => c.state === "NSW");
149
+ if (nsw?.postcodes.includes(postcode) && (!said || said === "NSW")) {
150
+ return nswArgs(`${nsw.area}, postcode ${postcode}, New South Wales`);
151
+ }
152
+ if (stateOfCode === "NSW" || said === "NSW") {
153
+ throw new ToolError(`${asked}: ${nsw ? `the NSW suburb list gives ${nsw.area} postcode${nsw.postcodes.length > 1
154
+ ? "s" : ""} ${nsw.postcodes.join(", ")}, not ${postcode}` : `the NSW suburb list has no ${JSON.stringify(name)}`}; ` +
155
+ `the name and postcode ${postcode} do not agree.`,
156
+ `Ask again with the suburb alone or postcode ${postcode} alone, whichever is meant. Neither is chosen here.`);
157
+ }
158
+ if (said && said !== stateOfCode) throw mismatch();
159
+ // Only the postcode is known to be there: "Fremantle 0800" is not a place in the NT.
160
+ if (NOT_HELD[stateOfCode]) throw notHeld(`Postcode ${postcode}, given with ${name},`, stateOfCode);
161
+ if (!stateOfCode) throw new ToolError(`${asked}: ${postcode} is not an Australian postcode.`, "Give the place without it.");
162
+ }
163
+ const where = said ?? stateOfCode;
164
+ const pick = where ? found.filter((c) => c.state === where) : found;
165
+ if (!pick.length) {
166
+ if (where) {
167
+ // A state word joined by a space may be part of the name ("Port Victoria"): say both readings were looked for.
168
+ const spoken = asked.replace(/[\s,]*\b\d{4}$/, "").replace(/^\d{4}\b[\s,]*/, "").trim();
169
+ const whole = said && /^[^,(]*$/.test(spoken) && norm(spoken) !== norm(name) ? ` (nor is any place named ${JSON.stringify(spoken)})` : "";
170
+ throw new ToolError(`No ${where} place named ${JSON.stringify(name)} is held${whole}.`, where === "VIC"
171
+ ? "Call vic_rents with part of the name: Victoria's rents are by suburb group."
172
+ : `Call area_rents with state ${where} and part of the name, or give the postcode (NSW).`);
173
+ }
174
+ throw new ToolError(`No place named ${JSON.stringify(name)} is held in the NSW, Victorian, Queensland, WA or SA files.`,
175
+ "Not held at all: Tasmania, the ACT, the Northern Territory and New Zealand - a place there has no figure here. " +
176
+ "For part of a name, call area_rents with the state, or vic_rents.");
177
+ }
178
+ const states = [...new Set(pick.map((c) => c.state))];
179
+ if (states.length > 1 || (pick.length > 1 && pick[0].state !== "NSW")) {
180
+ throw new ToolError(`${JSON.stringify(name)} is held in more than one place: ${pick.map((c) => c.label).join("; ")}.`,
181
+ `Call property_rents again with the state, e.g. ${JSON.stringify(`${name}, ${pick[0].state}`)}, or ask ` +
182
+ "which one is meant. No one of them is chosen here.");
183
+ }
184
+ const c = pick[0];
185
+ // Outside NSW the feeds are by name: a postcode given with the name has only said which state it is in.
186
+ const byName = postcode ? ` (postcode ${postcode} read for its state only; this feed is by name)` : "";
187
+ if (c.state === "VIC") {
188
+ return { state: "VIC", args: { suburb_group: c.suburb_group },
189
+ how: `Victoria, Homes Victoria's suburb group ${c.suburb_group}${byName}` };
190
+ }
191
+ // An NSW name is answered by its postcode, which area_rents picks: propertyRentsResult labels from that row.
192
+ if (c.state === "NSW") return { state: "NSW", args: { state: "NSW", area: c.area }, how: "New South Wales", nswName: c.area };
193
+ return { state: c.state, args: { state: c.state, area: c.area },
194
+ how: `${STATES[c.state].name}, ${data.areaRents[c.state].area_kind} ${c.area}${byName}` };
195
+ }
196
+
197
+ /**
198
+ * property_rents: the place resolved (resolvePlace), then answered by its state's own tool. byType: the by-type
199
+ * files for NSW and Queensland (only waited for when dwelling_type or bedrooms is asked).
200
+ */
201
+ export async function propertyRentsResult({ place, dwelling_type, bedrooms } = {}, data, now = new Date(),
202
+ { byType = async () => ({}), hosted = false } = {}) {
203
+ const r = resolvePlace(place, data);
204
+ let res;
205
+ if (r.state === "VIC") {
206
+ if (wantsByType({ dwelling_type, bedrooms })) {
207
+ throw new ToolError("Victoria's rents are held for all properties together, not by dwelling type or bedrooms.",
208
+ `Call property_rents for ${JSON.stringify(place)} without dwelling_type and bedrooms.`);
209
+ }
210
+ if (!data.vic) throw new ToolError("The Victorian rents feed is not on this machine.", "Call vic_rents for its own next step.");
211
+ res = vicRentsResult(r.args, data.vic, now);
212
+ } else {
213
+ res = areaRentsResult({ ...r.args, dwelling_type, bedrooms }, data.areaRents, now,
214
+ { nswSuburbs: data.suburbs, byType: wantsByType({ dwelling_type, bedrooms }) ? await byType() : {}, hosted });
215
+ }
216
+ // The cold review of #76: "New South Wales" beside postcode 2150's figure read as the whole state. The label names
217
+ // the postcode actually answered, and the whole state only when no postcode row came back. An all-dwellings answer
218
+ // gives areas[].area; a by-type one gives rows[].place with place_kind "postcode" (the re-check of 3f8e619).
219
+ const s = res.structured ?? {};
220
+ const codes = r.nswName ? [...new Set([...(s.areas ?? []).map((a) => String(a?.area ?? "")),
221
+ ...(s.rows ?? []).filter((x) => x?.place_kind === "postcode").map((x) => String(x.place ?? ""))]
222
+ .filter((a) => /^\d{4}$/.test(a)))] : [];
223
+ const how = codes.length
224
+ ? `${r.nswName}, postcode${codes.length > 1 ? "s" : ""} ${codes.join(", ")}, New South Wales` : r.how;
225
+ const line = `Place: ${String(place).trim()}, read as ${how}.`;
226
+ return { text: `${line}\n${res.text}`, structured: { ...res.structured, resolved_state: r.state, resolved_place: how } };
227
+ }
228
+
229
+ // --- rent_check's local mode ---------------------------------------------------------------------------------------
230
+
231
+ /**
232
+ * Where a rent sits among the quartiles, in the web rent check's own words (rent/local.mjs position(): the same
233
+ * wording, kept here because the npm package ships mcp/ only; mcp/test/place.test.mjs holds the two to one answer).
234
+ */
235
+ export function position(rent, q1, med, q3) {
236
+ if (rent === med) return "at the median.";
237
+ if (rent > q3) return `above the third quartile of ${dollars(q3)}. Roughly three in four of these new bonds, or more, were lodged for less.`;
238
+ if (rent === q3) return "at the third quartile.";
239
+ if (rent > med) return "above the median and below the third quartile.";
240
+ if (rent > q1) return "below the median and above the first quartile.";
241
+ if (rent === q1) return "at the first quartile.";
242
+ return `below the first quartile of ${dollars(q1)}. Roughly three in four of these new bonds, or more, were lodged for more.`;
243
+ }
244
+
245
+ const ENVELOPE_KEYS = ["publisher", "server_version", "retrieved_at", "data_as_of", "snapshot_built", "snapshot_origin",
246
+ "stale", "stale_reason", "stale_after", "cadence", "period_due_by", "period_overdue", "period_overdue_reason",
247
+ "sources", "advice"];
248
+
249
+ /** The one figure an answer gives for one place and group, or a ToolError saying why there is none to place against. */
250
+ function oneFigure(s, place) {
251
+ if (Array.isArray(s.rows)) { // by dwelling type or bedrooms
252
+ if (s.rows.length !== 1) {
253
+ throw new ToolError(`${place}: ${s.rows.length} groups match the dwelling_type and bedrooms asked; a rent is placed ` +
254
+ "against one.", "Give both dwelling_type and bedrooms, or neither for all dwellings together.");
255
+ }
256
+ return { row: s.rows[0], cell: s.rows[0].figure, group: s.rows[0].label ?? `${s.rows[0].dwelling_type}, ${s.rows[0].bedrooms}` };
257
+ }
258
+ const rows = s.areas ?? s.suburb_groups ?? [];
259
+ if (rows.length !== 1) {
260
+ throw new ToolError(`${place} matches ${rows.length} places; a rent is placed against one.`, "Give one place.");
261
+ }
262
+ return { row: rows[0], cell: rows[0], group: "all dwellings" };
263
+ }
264
+
265
+ /**
266
+ * rent_check without lease_start: the rent (and any proposed rent) placed against the median of new bonds for one
267
+ * place. Nothing is said of whether a rent is fair: where it sits, the dollars and per cent from the median, and,
268
+ * where the publisher gives quartiles, between which of them - with the place's own answer, its limits and its source.
269
+ */
270
+ export async function rentCheckLocal({ place, current_rent, proposed_rent, dwelling_type, bedrooms } = {}, data,
271
+ now = new Date(), opts = {}) {
272
+ const res = await propertyRentsResult({ place, dwelling_type, bedrooms }, data, now, opts);
273
+ const s = res.structured;
274
+ const { row, cell, group: g } = oneFigure(s, place);
275
+ const group = String(g);
276
+ // Every figure here is copied from a data file: a median that is not a number (a newer file's "750") is refused as
277
+ // no median, never placed against and never passed to the output schema (the review of #75: -32602 otherwise).
278
+ const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : null);
279
+ const med = isRecord(cell) ? num(cell.median_weekly_rent_aud) : null;
280
+ if (med == null || med <= 0 || row?.refused === true) {
281
+ throw new ToolError(`${place}: there is no published median for ${group} to place a rent against` +
282
+ `${row?.refused === true && typeof s.refusals?.[0]?.reason === "string" ? ` (${s.refusals[0].reason})` : ""}.`,
283
+ "Ask for a wider group (no dwelling_type or bedrooms) or a neighbouring place; a gap is not filled from another figure.");
284
+ }
285
+ // A quartile that is not a number is treated as not given.
286
+ const q1 = num(cell.first_quartile_aud), q3 = num(cell.third_quartile_aud);
287
+ const n = num(cell.new_bonds) ?? num(cell.new_leases);
288
+ const unit = cell.new_leases != null ? "new leases" : "new bonds";
289
+ const band = [cell.new_bonds_band, cell.new_bonds_range].find((b) => typeof b === "string") ?? null;
290
+ // As the web rent check (rent/local.mjs find): a figure the publisher marks small, or whose count it withholds.
291
+ const small = cell.small_sample === true || n == null;
292
+ const quartiles = q1 != null && q3 != null;
293
+ // Halves away from zero, so -$0.005 and +$0.005 round alike (Math.round rounds -0.5 up, to 0).
294
+ const round = (x, k) => (Math.sign(x) * Math.round(Math.abs(x) * k)) / k || 0;
295
+ const placed = (rent) => {
296
+ const diff = round(rent - med, 100), pct = round(((rent - med) / med) * 100, 10);
297
+ const side = diff === 0 ? "the same as the median" : `${dollars(Math.abs(diff))} (${Math.abs(pct)}%) ${diff > 0 ? "above" : "below"} the median`;
298
+ return { rent, diff_dollars: diff, diff_pct: pct, words: side,
299
+ position: quartiles ? position(rent, q1, med, q3) : diff === 0 ? "at the median." : `${diff > 0 ? "above" : "below"} the median.` };
300
+ };
301
+ const now_ = placed(current_rent);
302
+ const next = proposed_rent != null ? placed(proposed_rent) : null;
303
+ const quarter = s.quarter ?? s.data_as_of;
304
+ const count = n != null ? `${n.toLocaleString("en-AU")} ${unit}`
305
+ : band ? `between ${band.replace(" to ", " and ")} ${unit}` : `an unpublished number of ${unit}`;
306
+ const lines = [
307
+ // The caution first, in the web card's words (rent/page.mjs), as the card leads with it.
308
+ ...(small ? [`Small sample. Treat these figures with caution. ${n == null
309
+ ? `They rest on ${count}. At that size ${s.resolved_state === "NSW" ? "DCJ withholds the count and asks for care"
310
+ : "the publisher withholds the count"}: a handful of homes can move every figure here.`
311
+ : `They rest on ${count}: a handful of homes can move every figure here.`}`] : []),
312
+ `Your rent of ${dollars(current_rent)} a week, against ${unit} for ${group} in ${s.resolved_place} (${quarter}): ` +
313
+ `the median was ${dollars(med)}, from ${count}. ${dollars(current_rent)} is ${now_.words}.`,
314
+ // Among the quartiles, in the web rent check's words, only where the publisher gives them (DCJ, NSW); equal
315
+ // quartiles as rent/local.mjs opening() words them, not "between $270 and $270".
316
+ ...(quartiles ? [`${q1 === q3 ? `The middle half of these ${unit} were all lodged at ${dollars(med)} a week, which ` +
317
+ "is also the median" : `Half of these ${unit} were lodged between ${dollars(q1)} and ${dollars(q3)}`}; ` +
318
+ `${dollars(current_rent)} is ${now_.position}`] : []),
319
+ ...(next ? [`The proposed ${dollars(proposed_rent)} is ${next.words}` +
320
+ `${quartiles ? `; among these ${unit} it is ${next.position}` : "."}`] : []),
321
+ `This places a rent among ${unit} in one quarter. It is information, not a judgement of the rent and not tenancy ` +
322
+ `advice; a median of ${unit} is not what sitting tenants pay.`,
323
+ "",
324
+ ];
325
+ const env = Object.fromEntries(ENVELOPE_KEYS.map((k) => [k, s[k] ?? null]));
326
+ return {
327
+ text: lines.join("\n") + res.text,
328
+ structured: { ...env, result: null,
329
+ local: { place: s.resolved_place, state: s.resolved_state, group, quarter, median: med, first_quartile: q1,
330
+ third_quartile: q3, n, n_band: band, n_unit: unit, small_sample: small, current: now_, proposed: next },
331
+ limits: (s.limits ?? []).filter((l) => typeof l === "string"), sample_size: null,
332
+ sample_size_note: `the place's own count is local.n (${unit})`, page_url: s.page_url ?? null, cite_as: s.cite_as ?? null },
333
+ };
334
+ }
335
+
336
+ /** What the server says of property_rents once it is wired in (added to the server's instructions then). */
337
+ export const PLACE_INSTRUCTIONS = "property_rents takes a place with no state - a suburb, locality or postcode - and " +
338
+ "answers from the state that holds it; a name held in more than one state is listed, not chosen.";
339
+
340
+ /**
341
+ * Registers property_rents on an McpServer. Called by registerReadOnlyTools (register-tools.mjs) from 0.12.0, so the
342
+ * stdio and hosted servers list it.
343
+ */
344
+ export function registerPlaceTools(server, data, { byType = async () => ({}), hosted = false, titled, readOnly, guard }) {
345
+ server.registerTool("property_rents", titled({
346
+ title: "Rents by place, any held state",
347
+ description: "Median weekly rent of new bonds for an Australian suburb, locality or postcode, with no state " +
348
+ "needed: the place is found in the NSW, Victorian, Queensland, WA or SA files and answered as area_rents or " +
349
+ "vic_rents answer it, with their limits, sources and refusals. A name held in more than one state is listed " +
350
+ "with its states, not chosen. Tasmania, the ACT, the Northern Territory and New Zealand are not held. For " +
351
+ "questions such as \"median rent in Fremantle\".",
352
+ inputSchema: {
353
+ place: z.string().describe("A suburb, locality or postcode; a state may follow (\"Richmond, VIC\")"),
354
+ dwelling_type: z.string().optional().describe("As area_rents (NSW and QLD only)"),
355
+ bedrooms: z.string().optional().describe("As area_rents (NSW and QLD only)"),
356
+ },
357
+ outputSchema: OUTPUT_SCHEMAS.property_rents,
358
+ annotations: readOnly,
359
+ }), guard((args) => propertyRentsResult(args, data, new Date(), { byType, hosted })));
360
+ }
361
+
@@ -1,10 +1,10 @@
1
1
  /**
2
- * The six read-only DwellDelta tools as one MCP registration - names, titles, descriptions, input schemas,
2
+ * The seven read-only DwellDelta tools as one MCP registration - names, titles, descriptions, input schemas,
3
3
  * annotations and handlers - and the data they answer from. Prepared 2026-10-20, after 0.8.0 (not on npm), so the
4
4
  * two servers cannot drift:
5
- * - server.mjs, the npm package's stdio server, registers these six and then contribute_rent, which stays there:
5
+ * - server.mjs, the npm package's stdio server, registers these seven and then contribute_rent, which stays there:
6
6
  * it sends a rent, and it is offered only on the user's own machine;
7
- * - remote/endpoint.mjs, the hosted read-only server (not yet deployed), registers these six and nothing else.
7
+ * - remote/endpoint.mjs, the hosted read-only server (not yet deployed), registers these seven and nothing else.
8
8
  * Moved here from server.mjs unchanged, word for word: the stdio server's tool list and answers are what they were.
9
9
  *
10
10
  * Later on 2026-10-20, for the Claude and ChatGPT directory reviews (not in a released version yet): each description
@@ -20,9 +20,11 @@ import { loadVicRents, vicRentsResult } from "./vic-rents-tool.mjs";
20
20
  import { loadAllAreaRents, loadAllRentsByType, wantsByType, areaRentsResult, STATES } from "./area-rents-tool.mjs";
21
21
  import { loadNswSales, salePricesResult, DWELLING_TYPES } from "./sale-prices-tool.mjs";
22
22
  import { OUTPUT_SCHEMAS } from "./output-schemas.mjs";
23
+ import { rentCheckLocal, registerPlaceTools, PLACE_INSTRUCTIONS } from "./place-tool.mjs";
23
24
 
24
25
  /** The tools registered here, in the order a client lists them. contribute_rent is not one of them. */
25
- export const READ_ONLY_TOOLS = ["rent_check", "market_indicators", "data_sources", "vic_rents", "area_rents", "nsw_sale_prices"];
26
+ export const READ_ONLY_TOOLS = ["rent_check", "market_indicators", "data_sources", "vic_rents", "area_rents", "nsw_sale_prices",
27
+ "property_rents"];
26
28
  export const SUBURBS_PATH = new URL("./vendor/nsw-suburbs.json", import.meta.url);
27
29
  export const readOnly = { readOnlyHint: true, idempotentHint: true, openWorldHint: false, destructiveHint: false };
28
30
  /**
@@ -33,11 +35,38 @@ export const readOnly = { readOnlyHint: true, idempotentHint: true, openWorldHin
33
35
  */
34
36
  export const titled = (config) => ({ ...config, annotations: { title: config.title, ...config.annotations } });
35
37
 
36
- export const ok = ({ text, structured }) => ({ content: [{ type: "text", text }], structuredContent: structured });
38
+ /**
39
+ * A URL with a full stop, comma, semicolon, colon or closing bracket straight after it is put in angle brackets (RFC
40
+ * 3986, appendix C), so the punctuation is not read as part of the address (2026-11-03: answers cited
41
+ * ".../nsw-rents.json." and "...disclaimer.html;"). A URL followed by a space or the end of a line is left as it is.
42
+ */
43
+ export const unglue = (text) => text.replace(/(?<![<\w])(https?:\/\/[^\s<>"]*?)([.,;:)\]]+)(?=\s|$)/gm, "<$1>$2");
44
+ /**
45
+ * A result: its text and its structured result. Text only: a resource_link item (MCP 2025-06-18) is refused by the
46
+ * result schema of clients on the earlier protocol versions the server still accepts (review of #74, SDK 1.12.0), and
47
+ * the page is in the text ("Page:") and in page_url already.
48
+ */
49
+ export const ok = ({ text, structured }) => ({ content: [{ type: "text", text: unglue(text) }], structuredContent: structured });
37
50
  export const fail = (err) => ({
38
- content: [{ type: "text", text: `Error: ${err.message}${err.recovery ? `\nNext step: ${err.recovery}` : ""}` }],
51
+ content: [{ type: "text", text: unglue(`Error: ${err.message}${err.recovery ? `\nNext step: ${err.recovery}` : ""}`) }],
39
52
  isError: true,
40
53
  });
54
+
55
+ /**
56
+ * What the server answers, sent in the initialize result (new in 0.12.0; the agent-usage review found none, and
57
+ * clients that search for tools by text read it). Facts only: what is held, when it applies, how to cite, the limits.
58
+ */
59
+ export const SERVER_INSTRUCTIONS = "DwellDelta answers Australian property questions from public data. Held: median " +
60
+ "weekly rents of new bonds by area for NSW (postcode or council), Queensland (suburb or council), WA (locality), SA " +
61
+ "(suburb) and Victoria (suburb group, vic_rents); NSW median sale prices by postcode or council; ABS and RBA " +
62
+ "indicators by capital city and state; and a check of a rent against the ABS rents index for its capital city, or, " +
63
+ "given a place instead of a lease start, against that place's median of new bonds. " +
64
+ "It applies to questions about what a place rents or sells for, how rents or prices have changed, and whether a " +
65
+ "rent is in line. A suburb name works for NSW: one in a single postcode is answered for that whole postcode. Each " +
66
+ "answer carries its quarter, source, licence and limits; area_rents and nsw_sale_prices answers also carry a " +
67
+ "page_url to cite where the place has a page on tools.dwelldelta.com.au, and a cite_as line. Not held: Tasmania, the ACT, the Northern Territory and New Zealand; " +
68
+ "sale prices outside NSW; any one home's price or rent. Figures are information, not financial or tenancy advice. " +
69
+ PLACE_INSTRUCTIONS;
41
70
  export const guard = (fn) => async (args) => {
42
71
  try {
43
72
  return ok(await fn(args));
@@ -45,9 +74,12 @@ export const guard = (fn) => async (args) => {
45
74
  return fail(err instanceof ToolError ? err : new ToolError(err.message, "Report this to lingtao@xcelerent.com."));
46
75
  }
47
76
  };
77
+ /** An answer with a first line naming the arguments it did not use, and why (0.12.0, rent_check's two modes). */
78
+ const ignoring = (res, keys, why) => (keys.length ? { text: `Not used: ${keys.join(", ")} (${why}).\n${res.text}`,
79
+ structured: { ...res.structured, ignored: keys } } : res);
48
80
 
49
81
  /**
50
- * Every feed the six tools answer from, loaded the way the stdio server has loaded them since 0.8.0 and in the same
82
+ * Every feed the seven tools answer from, loaded the way the stdio server has loaded them since 0.8.0 and in the same
51
83
  * order: the published copy where it is well formed and not older than the bundled one, else the bundled copy
52
84
  * (DWELLDELTA_OFFLINE=1 never fetches). opts (env, fetchImpl) go to every loader; left out, each loader's defaults
53
85
  * apply. The *Origin fields and the origin on each feed say which copy answered; the remote server uses them to keep
@@ -101,7 +133,7 @@ export async function byTypeFiles(rentsByType, waitMs = null) {
101
133
  const BY_TYPE_LATE = Symbol("by-type files not loaded in time");
102
134
 
103
135
  /**
104
- * Registers the six read-only tools on an McpServer, answering from data (as loadData returns it). byTypeWaitMs: the
136
+ * Registers the seven read-only tools on an McpServer, answering from data (as loadData returns it). byTypeWaitMs: the
105
137
  * longest a by-type question waits for the by-type files (byTypeFiles); the stdio server passes none. hosted: the
106
138
  * hosted server's wording where a by-type file is missing (no variable to set on it).
107
139
  */
@@ -127,16 +159,41 @@ export function registerReadOnlyTools(server, data, { byTypeWaitMs = null, hoste
127
159
  description: "Compares a weekly rent, and any proposed new rent, with how the ABS rents index for the tenant's " +
128
160
  "Australian capital city has moved since the lease began. city is one of the eight capital cities, whose " +
129
161
  "index is city-wide, not suburb-level. The answer is information, not advice, and carries the months " +
130
- "compared, the source and the index's limits.",
162
+ "compared, the source and the index's limits. Without lease_start, place (a suburb, locality or postcode in " +
163
+ "NSW, Victoria, Queensland, WA or SA) gives instead where the rent sits against that place's median of new " +
164
+ "bonds, and between its quartiles where the publisher gives them.",
131
165
  inputSchema: {
132
- city: z.enum(Object.keys(rents.cities).sort()).describe("Capital city whose ABS rents index the rent is compared with"),
133
- lease_start: z.string().regex(/^\d{4}-(0[1-9]|1[0-2])$/).describe("Month the lease began, YYYY-MM"),
166
+ city: z.enum(Object.keys(rents.cities).sort()).optional().describe("Capital city whose ABS rents index the rent is compared with (with lease_start)"),
167
+ lease_start: z.string().regex(/^\d{4}-(0[1-9]|1[0-2])$/).optional().describe("Month the lease began, YYYY-MM"),
134
168
  current_rent: z.number().positive().describe("Current weekly rent in Australian dollars"),
135
169
  proposed_rent: z.number().positive().optional().describe("Proposed new weekly rent in Australian dollars"),
170
+ place: z.string().optional().describe("Without lease_start: a suburb, locality or postcode; a state may follow (\"Richmond, VIC\")"),
171
+ dwelling_type: z.string().optional().describe("With place: as area_rents (NSW and QLD only)"),
172
+ bedrooms: z.string().optional().describe("With place: as area_rents (NSW and QLD only)"),
136
173
  },
137
174
  outputSchema: OUTPUT_SCHEMAS.rent_check,
138
175
  annotations: readOnly,
139
- }), guard((args) => rentCheckResult(args, rents)));
176
+ }), guard(async (args) => {
177
+ // With lease_start: the city-wide index check, as it has been since 0.1.0. Without it: the local mode (0.12.0).
178
+ if (args.lease_start != null) {
179
+ if (args.city == null) {
180
+ throw new ToolError("rent_check with lease_start needs city: the ABS rents index is by capital city.",
181
+ `Give city (${Object.keys(rents.cities).sort().join(", ")}), or leave lease_start out and give place for ` +
182
+ "the local median of new bonds.");
183
+ }
184
+ // An argument of the other mode is said to be unused, never silently dropped.
185
+ return ignoring(rentCheckResult(args, rents), ["place", "dwelling_type", "bedrooms"].filter((k) => args[k] != null),
186
+ "with lease_start, the rent is compared with the city's ABS rents index; leave lease_start out for the place's " +
187
+ "median of new bonds");
188
+ }
189
+ if (args.place == null || !String(args.place).trim()) {
190
+ throw new ToolError("rent_check needs lease_start with city (the city-wide index check), or place (the local " +
191
+ "median of new bonds).", "Give lease_start and city, or a suburb, locality or postcode as place.");
192
+ }
193
+ return ignoring(await rentCheckLocal(args, data, new Date(), { byType: () => byTypeFiles(rentsByType, byTypeWaitMs), hosted }),
194
+ args.city != null ? ["city"] : [], "without lease_start, the rent is placed against the place's own median; give " +
195
+ "lease_start for the city's ABS rents index");
196
+ }));
140
197
 
141
198
  server.registerTool("market_indicators", titled({
142
199
  title: "Australian property market indicators",
@@ -199,10 +256,11 @@ export function registerReadOnlyTools(server, data, { byTypeWaitMs = null, hoste
199
256
  "give the publisher's figure for that kind of home instead - a two-bedroom unit, a three-bedroom house. Only " +
200
257
  "combinations the publisher reports are answered: one with no published median is said to have none, and " +
201
258
  "neither another area's figure nor the all-dwellings figure stands in for it. Many such figures rest on few " +
202
- "bonds. WA and SA have no figures by dwelling type or bedrooms.",
259
+ "bonds. WA and SA have no figures by dwelling type or bedrooms. For questions such as \"median rent in " +
260
+ "Parramatta\".",
203
261
  inputSchema: {
204
262
  state: z.enum(Object.keys(STATES)).describe("NSW, QLD, WA or SA - one state per call"),
205
- area: z.string().optional().describe("NSW: a four-digit postcode (a suburb name returns its postcodes to try). " +
263
+ area: z.string().optional().describe("NSW: a postcode, or a suburb (answered for its whole postcode). " +
206
264
  "QLD: a suburb. WA: a locality. SA: a suburb. Part of a suburb or locality name works"),
207
265
  council: z.string().optional().describe("A council (NSW or QLD), or part of its name"),
208
266
  dwelling_type: z.string().optional().describe("NSW and QLD only. NSW (DCJ's labels): House, Townhouse, " +
@@ -231,9 +289,10 @@ export function registerReadOnlyTools(server, data, { byTypeWaitMs = null, hoste
231
289
  "few very large sales or by many sales at one identical price, and is not a going price. A total noted as " +
232
290
  "mostly a marked row's sales may be moved by them, and the file shows nothing more about it. A line with any " +
233
291
  "other mark or note is not a going price either, and the file does not say why. Each answer names the " +
234
- "dwelling type, the quarter and the source line, and states the limits.",
292
+ "dwelling type, the quarter and the source line, and states the limits. For questions such as \"house prices " +
293
+ "in Coogee\".",
235
294
  inputSchema: {
236
- area: z.string().optional().describe("A four-digit NSW postcode (a suburb name returns its postcodes to try)"),
295
+ area: z.string().optional().describe("An NSW postcode, or a suburb (answered for its whole postcode)"),
237
296
  council: z.string().optional().describe("An NSW council, or part of its name"),
238
297
  dwelling_type: z.enum(DWELLING_TYPES).optional().describe("total, non_strata (houses) or strata (units, town " +
239
298
  "houses, villas); without it, all three are given"),
@@ -241,4 +300,7 @@ export function registerReadOnlyTools(server, data, { byTypeWaitMs = null, hoste
241
300
  outputSchema: OUTPUT_SCHEMAS.nsw_sale_prices,
242
301
  annotations: readOnly,
243
302
  }), guard((args) => salePricesResult(args, nswSales, new Date(), { nswSuburbs: suburbs, refused: refused.nswSales })));
303
+
304
+ // property_rents (0.12.0): registered with the others so the stdio and hosted servers list the same tools.
305
+ registerPlaceTools(server, data, { byType: () => byTypeFiles(rentsByType, byTypeWaitMs), hosted, titled, readOnly, guard });
244
306
  }
@@ -29,7 +29,8 @@ import { loadJson, envelope, ToolError, FOOTER, FETCH_TIMEOUT_MS, feedSource, CA
29
29
  figureFields, nWords, citeLine, staleNote, flagged, refusalMark, passes, readChecked, quiet,
30
30
  warnPublished, fromCopy } from "./tools.mjs";
31
31
  import { quarterKey } from "./vic-rents-tool.mjs";
32
- import { signed, match, nswPostcodes, MAX_ROWS, BUNDLED_DIR, PUBLISHED_BASE } from "./area-rents-tool.mjs";
32
+ import { signed, match, nswPostcodes, nswResolve, councilToo, MAX_ROWS, BUNDLED_DIR, PUBLISHED_BASE } from "./area-rents-tool.mjs";
33
+ import { salePage, citeFields, withPlace } from "./pages.mjs";
33
34
 
34
35
  const HERE = dirname(fileURLToPath(import.meta.url));
35
36
  const LIVE_DIR = join(HERE, "..", "..", "dwelldelta-data", "market");
@@ -142,8 +143,17 @@ export function salePricesResult({ area, council, dwelling_type } = {}, feed, no
142
143
  }
143
144
  const types = dwelling_type ? [dwelling_type] : DWELLING_TYPES;
144
145
  let areas = [], councils = [];
146
+ let resolved = null;
145
147
  if (area != null && String(area).trim()) {
146
148
  areas = match(feed.areas, "area", area);
149
+ if (!areas.length) {
150
+ // A suburb's name in one postcode is answered on the first call (nswResolve, 0.12.0), as area_rents does.
151
+ resolved = nswResolve(area, nswSuburbs, feed);
152
+ if (resolved) {
153
+ areas = match(feed.areas, "area", resolved.postcode);
154
+ resolved.note += council == null || !String(council).trim() ? councilToo(area, feed.councils) : "";
155
+ }
156
+ }
147
157
  if (!areas.length) {
148
158
  const named = nswPostcodes(area, nswSuburbs, feed);
149
159
  throw new ToolError(`No NSW postcode matches ${JSON.stringify(area)}.`,
@@ -212,12 +222,22 @@ export function salePricesResult({ area, council, dwelling_type } = {}, feed, no
212
222
  // and its not_published refusal is in refusals[]. Copies: the loaded feed is never written to.
213
223
  const pick = (g) => Object.fromEntries(Object.entries(g).filter(([k]) => !DWELLING_TYPES.includes(k) || types.includes(k))
214
224
  .map(([k, v]) => [k, DWELLING_TYPES.includes(k) && v && typeof v === "object" ? { ...v, ...refusalMark(judged.get(g)[k]) } : v]));
215
- return { text, structured: { ...env, state: "NSW", measure: "sale_price", unit: feed.unit, area_kind: "postcode",
216
- quarter: feed.quarter, compared_with: feed.compared_with,
217
- dwelling_types: feed.dwelling_types ?? null,
218
- state_total: whole ? pick(feed.state_total) : null,
219
- councils: councils.map(pick), areas: areas.map(pick), any_unusual: marked,
220
- any_unusual_part: noted,
221
- truncated: dropped.length > 0, limits: feed.limits, changes_made: feed.changes_made,
222
- ...figureFields(figures), sample_rule: RULE } };
225
+ // The page and citation fields (pages.mjs) and the resolved suburb's note (0.12.0): new fields, no earlier one changes.
226
+ const places = areas.map((g) => ({ name: g.area, url: salePage(g) }));
227
+ const label = areas.length === 1 && !councils.length ? `${areas[0].area} (postcode), New South Wales`
228
+ : whole ? "New South Wales" : `New South Wales, ${areas.length + councils.length} places`;
229
+ const cite = citeFields({ state: "NSW", places: councils.length ? [] : places, whole,
230
+ what: `Median sale price of homes sold, ${label}`, period: feed.quarter, by: feed.rights_holder ?? feed.source,
231
+ licence: feed.licence, allRefused: figureFields(figures).all_refused === true });
232
+ if (councils.length) cite.pages = places.filter((p) => p.url).map((p) => ({ place: p.name, url: p.url }));
233
+ const note = resolved?.note ?? null;
234
+ return { text: withPlace(text, { note, ...cite }, FOOTER),
235
+ structured: { ...env, state: "NSW", measure: "sale_price", unit: feed.unit, area_kind: "postcode",
236
+ quarter: feed.quarter, compared_with: feed.compared_with,
237
+ dwelling_types: feed.dwelling_types ?? null,
238
+ state_total: whole ? pick(feed.state_total) : null,
239
+ councils: councils.map(pick), areas: areas.map(pick), any_unusual: marked,
240
+ any_unusual_part: noted,
241
+ truncated: dropped.length > 0, limits: feed.limits, changes_made: feed.changes_made,
242
+ ...figureFields(figures), sample_rule: RULE, place_note: note, ...cite } };
223
243
  }
package/server.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  // DwellDelta MCP server: Australian property market data for AI agents. Runs on the user's machine over stdio and
3
3
  // records nothing unless the user chooses to add their rent. From 0.4.0 it fetches the week's indicators once at start from tools.dwelldelta.com.au - one
4
4
  // public file; nothing about the user or their questions is sent - and falls back to its bundled copy
5
- // (DWELLDELTA_OFFLINE=1 never fetches); from 0.9.0 so is the ABS rents index behind rent_check. Six read-only
5
+ // (DWELLDELTA_OFFLINE=1 never fetches); from 0.9.0 so is the ABS rents index behind rent_check. Seven read-only
6
6
  // tools; the logic lives in tools.mjs, vic_rents
7
7
  // (Victorian rents by suburb group, 0.5.0) in vic-rents-tool.mjs, area_rents (NSW postcodes, Queensland suburbs
8
8
  // and WA localities, 0.6.0) in area-rents-tool.mjs, and nsw_sale_prices (NSW median sale prices by postcode, 0.7.0)
@@ -15,14 +15,14 @@
15
15
  // cannot read a failure as data. A missing indicators snapshot does not stop the server: rent_check still works,
16
16
  // and the other two say what is missing and how it is built.
17
17
  //
18
- // Prepared 2026-10-20, after 0.8.0: the six read-only tools and the feeds they answer from are registered by
18
+ // Prepared 2026-10-20, after 0.8.0: the read-only tools and the feeds they answer from are registered by
19
19
  // register-tools.mjs, which the hosted read-only server (remote/, not in this package) registers too, so the two
20
20
  // cannot drift. contribute_rent is registered here and only here: it is offered on the user's own machine alone.
21
21
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
22
22
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
23
23
  import { z } from "zod";
24
24
  import { SERVER_VERSION } from "./tools.mjs";
25
- import { loadData, registerReadOnlyTools, guard, titled } from "./register-tools.mjs";
25
+ import { loadData, registerReadOnlyTools, guard, titled, SERVER_INSTRUCTIONS } from "./register-tools.mjs";
26
26
  import { makeContributeTool, INTENDED_USE } from "./contribute-tool.mjs";
27
27
  import { HOME_TYPES, BEDROOMS, LEASE_KINDS, WHOSE } from "./vendor/contribute.mjs";
28
28
  import { OUTPUT_SCHEMAS } from "./output-schemas.mjs";
@@ -31,7 +31,7 @@ import { OUTPUT_SCHEMAS } from "./output-schemas.mjs";
31
31
  const data = await loadData({ warn: (line) => process.stderr.write(`dwelldelta-mcp: ${line}\n`) });
32
32
  const contributeRent = makeContributeTool({ suburbs: data.suburbs });
33
33
 
34
- const server = new McpServer({ name: "dwelldelta", version: SERVER_VERSION });
34
+ const server = new McpServer({ name: "dwelldelta", version: SERVER_VERSION }, { instructions: SERVER_INSTRUCTIONS });
35
35
  registerReadOnlyTools(server, data);
36
36
 
37
37
  server.registerTool("contribute_rent", titled({
package/tools.mjs CHANGED
@@ -112,7 +112,7 @@ export async function loadSnapshot({ env = process.env, fetchImpl = globalThis.f
112
112
  }
113
113
 
114
114
  export const FOOTER = "Information, not advice. From DwellDelta (dwelldelta.com.au), built on public data.";
115
- export const SERVER_VERSION = "0.11.0";
115
+ export const SERVER_VERSION = "0.12.0";
116
116
  // The indicators snapshot is rebuilt every Monday. Older than this and the answer says so, in words and in the
117
117
  // structured result, rather than serving a stale figure as current.
118
118
  export const STALE_DAYS = 10;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "publisher": "DwellDelta, a service of Xcelerent Pty Ltd",
3
- "built": "2026-11-01",
3
+ "built": "2026-11-02",
4
4
  "indicators": [
5
5
  {
6
6
  "id": "cash_rate",
@@ -405,15 +405,15 @@
405
405
  "id": "approvals",
406
406
  "name": "Dwellings approved, seasonally adjusted",
407
407
  "geography": "NSW",
408
- "value": 13848.0,
408
+ "value": 13895.0,
409
409
  "unit": "dwellings per quarter",
410
- "period": "2026-06",
410
+ "period": "2026-09",
411
411
  "source": "ABS Building Approvals (8731.0), Table 7: total dwelling units approved by state, seasonally adjusted, monthly",
412
412
  "licence": "CC BY 4.0",
413
413
  "attribution": "Based on Australian Bureau of Statistics data",
414
414
  "source_url": "https://www.abs.gov.au/statistics/industry/building-and-construction/building-approvals-australia/latest-release",
415
415
  "change": {
416
- "value": -1.6,
416
+ "value": 5.9,
417
417
  "unit": "percent",
418
418
  "over": "year"
419
419
  },
@@ -4,6 +4,7 @@
4
4
  "licence": "CC BY 4.0",
5
5
  "release": "sep-2026",
6
6
  "measures": "an index of what tenants pay across new and continuing leases, not a dollar rent and not an advertised rent",
7
+ "source_url": "https://www.abs.gov.au/statistics/economy/price-indexes-and-inflation/consumer-price-index-australia/latest-release",
7
8
  "cities": {
8
9
  "Adelaide": {
9
10
  "series_id": "A130398806J",