@cliwant/mcp-sam-gov 1.15.0 → 1.16.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.
Files changed (50) hide show
  1. package/README.ja.md +2 -2
  2. package/README.ko.md +2 -2
  3. package/README.md +4 -4
  4. package/dist/bonfire.d.ts +1 -1
  5. package/dist/bonfire.d.ts.map +1 -1
  6. package/dist/bonfire.js +7 -9
  7. package/dist/bonfire.js.map +1 -1
  8. package/dist/ckan.d.ts +6 -4
  9. package/dist/ckan.d.ts.map +1 -1
  10. package/dist/ckan.js +17 -4
  11. package/dist/ckan.js.map +1 -1
  12. package/dist/data-map.d.ts.map +1 -1
  13. package/dist/data-map.js +56 -1
  14. package/dist/data-map.js.map +1 -1
  15. package/dist/fpds.d.ts.map +1 -1
  16. package/dist/fpds.js +3 -2
  17. package/dist/fpds.js.map +1 -1
  18. package/dist/gao.d.ts.map +1 -1
  19. package/dist/gao.js +17 -6
  20. package/dist/gao.js.map +1 -1
  21. package/dist/gsa-perdiem.d.ts +5 -0
  22. package/dist/gsa-perdiem.d.ts.map +1 -1
  23. package/dist/gsa-perdiem.js +6 -1
  24. package/dist/gsa-perdiem.js.map +1 -1
  25. package/dist/open-checkbook.d.ts +8 -0
  26. package/dist/open-checkbook.d.ts.map +1 -1
  27. package/dist/open-checkbook.js +9 -1
  28. package/dist/open-checkbook.js.map +1 -1
  29. package/dist/pricing.d.ts +1 -0
  30. package/dist/pricing.d.ts.map +1 -1
  31. package/dist/pricing.js +135 -50
  32. package/dist/pricing.js.map +1 -1
  33. package/dist/server.d.ts.map +1 -1
  34. package/dist/server.js +34 -17
  35. package/dist/server.js.map +1 -1
  36. package/dist/socrata.d.ts +16 -1
  37. package/dist/socrata.d.ts.map +1 -1
  38. package/dist/socrata.js +31 -1
  39. package/dist/socrata.js.map +1 -1
  40. package/package.json +1 -1
  41. package/src/bonfire.ts +7 -9
  42. package/src/ckan.ts +17 -4
  43. package/src/data-map.ts +58 -1
  44. package/src/fpds.ts +3 -2
  45. package/src/gao.ts +20 -6
  46. package/src/gsa-perdiem.ts +12 -1
  47. package/src/open-checkbook.ts +26 -3
  48. package/src/pricing.ts +142 -48
  49. package/src/server.ts +41 -17
  50. package/src/socrata.ts +37 -1
package/src/pricing.ts CHANGED
@@ -164,10 +164,26 @@ function epochToIso(v: number | string | undefined): string | null {
164
164
  return null;
165
165
  }
166
166
 
167
+ // Maximum pages to scan when a client-side filter (county / constructionType)
168
+ // requires a full-state sweep. 10 pages × 50 rows = 500 WDs — well above any
169
+ // real state's active DBA stock (IL has 70 as of 2026-09-22).
170
+ const WD_SCAN_PAGE_CAP = 10;
171
+ const WD_SCAN_SIZE = 50; // max the SGS API accepts per request
172
+
173
+ /** Extract constructionTypes as a lowercase string array (handles string[] or unknown). */
174
+ function resultConstructionTypes(r: SgsResult): string[] {
175
+ const ct = r.constructionTypes;
176
+ if (!ct) return [];
177
+ if (Array.isArray(ct)) return ct.map((v) => String(v).toLowerCase());
178
+ if (typeof ct === "string") return [ct.toLowerCase()];
179
+ return [];
180
+ }
181
+
167
182
  export async function searchWageDeterminations(args: {
168
183
  coverage: string;
169
184
  state?: string;
170
185
  county?: string;
186
+ constructionType?: string;
171
187
  query?: string;
172
188
  activeOnly?: boolean;
173
189
  standardOnly?: boolean;
@@ -181,35 +197,47 @@ export async function searchWageDeterminations(args: {
181
197
  const page = Math.max(0, Math.floor(args.page ?? 0));
182
198
  const stateFilter = args.state?.trim().toUpperCase() || undefined;
183
199
  const countyFilter = args.county?.trim().toLowerCase() || undefined;
200
+ const ctFilter = args.constructionType?.trim().toLowerCase() || undefined;
201
+
202
+ // When county or constructionType is given, we must scan ALL pages for the
203
+ // state to avoid missing matching WDs (e.g. IL has 70 DBA WDs — the target
204
+ // Cook County Building WD is on page 1). We use max size=50 per fetch and
205
+ // cap at WD_SCAN_PAGE_CAP pages to keep the request count bounded.
206
+ const needsFullScan = Boolean(countyFilter || ctFilter);
184
207
 
185
- const params = new URLSearchParams({
186
- index,
187
- size: String(limit),
188
- page: String(page),
189
- mode: "search",
190
- sort: "-modifiedDate",
191
- });
192
- if (activeOnly) params.set("is_active", "true");
193
- if (standardOnly) params.set("is_standard", "true");
194
- // `q` matches WD number/title ONLY (NOT occupation) — verified q=guard→0.
195
- if (args.query) params.set("q", args.query);
196
- // `state` IS honored server-side (LIVE-VERIFIED 2026-07-03: index=sca&state=VA
197
- // → 30 vs 1028 unfiltered, and every returned WD's location contains VA;
198
- // state=ZZ → 0). It wants the 2-letter USPS code (a full name like "Virginia"
199
- // → 0). This CORRECTS the earlier brief which assumed state was ignored.
200
208
  const filtersApplied: string[] = [`coverage(${index})`];
201
209
  const filtersDropped: string[] = [];
202
210
  const notes: string[] = [];
203
211
  if (activeOnly) filtersApplied.push("activeOnly");
204
212
  if (standardOnly) filtersApplied.push("standardOnly");
205
213
  if (args.query) filtersApplied.push("query(WD number/title only)");
214
+
215
+ // Build the base URLSearchParams that are shared across every page fetch.
216
+ function buildParams(pg: number, sz: number): URLSearchParams {
217
+ const p = new URLSearchParams({
218
+ index,
219
+ size: String(sz),
220
+ page: String(pg),
221
+ mode: "search",
222
+ sort: "-modifiedDate",
223
+ });
224
+ if (activeOnly) p.set("is_active", "true");
225
+ if (standardOnly) p.set("is_standard", "true");
226
+ // `q` matches WD number/title ONLY (NOT occupation) — verified q=guard→0.
227
+ if (args.query) p.set("q", args.query);
228
+ return p;
229
+ }
230
+
231
+ // `state` IS honored server-side (LIVE-VERIFIED 2026-07-03: index=sca&state=VA
232
+ // → 30 vs 1028 unfiltered, and every returned WD's location contains VA;
233
+ // state=ZZ → 0). It wants the 2-letter USPS code (a full name like "Virginia"
234
+ // → 0). This CORRECTS the earlier brief which assumed state was ignored.
235
+ const needsClientState =
236
+ stateFilter !== undefined && !/^[A-Z]{2}$/.test(stateFilter);
206
237
  if (stateFilter) {
207
- if (/^[A-Z]{2}$/.test(stateFilter)) {
208
- params.set("state", stateFilter);
238
+ if (!needsClientState) {
209
239
  filtersApplied.push("state(server-side)");
210
240
  } else {
211
- // Not a 2-letter code → the server would return 0; apply client-side
212
- // instead so a full name still works, and disclose it.
213
241
  filtersDropped.push("state(server-side; not a 2-letter code)");
214
242
  notes.push(
215
243
  `The state value '${args.state}' is not a 2-letter USPS code; the SGS 'state' param only matches 2-letter codes (a full name returns 0), so it was applied CLIENT-SIDE over the fetched page instead. Pass a 2-letter code (e.g. 'VA') for a precise server-side filter.`,
@@ -217,30 +245,75 @@ export async function searchWageDeterminations(args: {
217
245
  }
218
246
  }
219
247
 
220
- const url = `${SGS_BASE}?${params.toString()}`;
221
- const json = await getJson<SgsSearchResp>(url, SAM_HAL_HEADERS, `sam:sgs:${index}`);
222
- const rawResults = json._embedded?.results ?? [];
223
- const serverTotal = json.page?.totalElements ?? null;
248
+ // ── Fetch: one page (no client filters) OR full-state scan ──────
249
+ let allRaw: SgsResult[];
250
+ let serverTotal: number | null;
251
+ let scanCapHit = false;
252
+
253
+ if (!needsFullScan) {
254
+ // Original single-page path (no county/constructionType filter).
255
+ const params = buildParams(page, limit);
256
+ if (!needsClientState && stateFilter) params.set("state", stateFilter);
257
+ const url = `${SGS_BASE}?${params.toString()}`;
258
+ const json = await getJson<SgsSearchResp>(url, SAM_HAL_HEADERS, `sam:sgs:${index}`);
259
+ allRaw = json._embedded?.results ?? [];
260
+ serverTotal = json.page?.totalElements ?? null;
261
+ } else {
262
+ // Full-state scan: fetch all pages with size=50 until exhausted or cap.
263
+ const scanParams = buildParams(0, WD_SCAN_SIZE);
264
+ if (!needsClientState && stateFilter) scanParams.set("state", stateFilter);
265
+ const firstUrl = `${SGS_BASE}?${scanParams.toString()}`;
266
+ const firstJson = await getJson<SgsSearchResp>(firstUrl, SAM_HAL_HEADERS, `sam:sgs:${index}`);
267
+ allRaw = firstJson._embedded?.results ?? [];
268
+ serverTotal = firstJson.page?.totalElements ?? null;
269
+ const totalPages = firstJson.page?.totalPages ?? 1;
270
+
271
+ const pagesToFetch = Math.min(totalPages, WD_SCAN_PAGE_CAP);
272
+ if (totalPages > WD_SCAN_PAGE_CAP) scanCapHit = true;
273
+
274
+ for (let pg = 1; pg < pagesToFetch; pg++) {
275
+ const p = buildParams(pg, WD_SCAN_SIZE);
276
+ if (!needsClientState && stateFilter) p.set("state", stateFilter);
277
+ const pgJson = await getJson<SgsSearchResp>(
278
+ `${SGS_BASE}?${p.toString()}`,
279
+ SAM_HAL_HEADERS,
280
+ `sam:sgs:${index}`,
281
+ );
282
+ allRaw = allRaw.concat(pgJson._embedded?.results ?? []);
283
+ }
284
+ }
224
285
 
225
- // Client-side filtering: county is NOT a documented SGS server param, so it
226
- // is applied here over the fetched page. A non-2-letter state also lands here.
227
- const needsClientState = filtersDropped.some((f) => f.startsWith("state"));
228
- let filtered = rawResults;
286
+ // ── Client-side filtering ────────────────────────────────────────
287
+ let filtered = allRaw;
229
288
  if (needsClientState && stateFilter) {
230
289
  filtered = filtered.filter((r) =>
231
- resultStateCodes(r).some((c) => c === stateFilter || r.location?.state?.name?.toUpperCase() === stateFilter),
290
+ resultStateCodes(r).some(
291
+ (c) => c === stateFilter || r.location?.state?.name?.toUpperCase() === stateFilter,
292
+ ),
232
293
  );
233
294
  }
234
295
  if (countyFilter) {
235
- filtersApplied.push("county(client-side)");
296
+ filtersApplied.push("county(client-side, full-state scan)");
236
297
  filtered = filtered.filter((r) =>
237
298
  resultCounties(r).some((c) => c.name.toLowerCase().includes(countyFilter)),
238
299
  );
239
- notes.push(
240
- "County is filtered CLIENT-SIDE over the fetched page only (the SGS API has no county filter). A county filter combined with a small limit can miss WDs on later pages — raise `limit` or narrow by `state` (server-side) to be sure.",
300
+ }
301
+ if (ctFilter) {
302
+ filtersApplied.push(`constructionType(client-side, value=${args.constructionType})`);
303
+ filtered = filtered.filter((r) =>
304
+ resultConstructionTypes(r).includes(ctFilter),
241
305
  );
242
306
  }
243
307
 
308
+ // ── Specificity ranking: single-county WDs before multi-county ──
309
+ if (countyFilter) {
310
+ filtered.sort((a, b) => {
311
+ const aCount = resultCounties(a).length;
312
+ const bCount = resultCounties(b).length;
313
+ return aCount - bCount; // 1-county first, then 2-county, etc.
314
+ });
315
+ }
316
+
244
317
  const determinations = filtered.map((r) => {
245
318
  const coverageCode = r.type?.code ?? (index === "sca" ? "SCA" : "DBA");
246
319
  return {
@@ -273,27 +346,48 @@ export async function searchWageDeterminations(args: {
273
346
  "The `q` parameter matches the WD number/title only — it does NOT search by occupation or job title (e.g. q=guard returns 0). To find rates for a specific occupation, open the WD and read its rate table.",
274
347
  );
275
348
 
276
- // totalAvailable: the server total is REAL for the coverage/active/standard/
277
- // query/state filters (state is server-side). But when we additionally filter
278
- // client-side (county, or a non-code state), the returned page count no longer
279
- // reflects a full server total for THAT combined filter → null it out and say so.
280
- const clientFiltered = Boolean(countyFilter) || needsClientState;
281
- const totalAvailable = clientFiltered ? null : serverTotal;
349
+ // ── Honest meta ──────────────────────────────────────────────────
350
+ const clientFiltered = Boolean(countyFilter) || Boolean(ctFilter) || needsClientState;
351
+ const scannedCount = allRaw.length;
282
352
  const returned = determinations.length;
283
- const truncated = clientFiltered
284
- ? true // page-bounded client filter → can't prove completeness
285
- : serverTotal !== null && page * limit + returned < serverTotal;
286
353
 
287
- if (clientFiltered) {
354
+ // When we did a full-state scan, totalAvailable is the REAL count of matching
355
+ // WDs across the scanned pages (not null). Only null it when the scan cap was
356
+ // hit (we didn't see all pages) or when there was no client filter.
357
+ let totalAvailable: number | null;
358
+ let truncated: boolean;
359
+
360
+ if (!clientFiltered) {
361
+ // No client filter: server total is accurate for this result set.
362
+ totalAvailable = serverTotal;
363
+ truncated = serverTotal !== null && page * limit + returned < serverTotal;
364
+ } else if (needsFullScan && !scanCapHit) {
365
+ // Full scan completed: real match count is known.
366
+ totalAvailable = returned;
367
+ truncated = false;
368
+ } else {
369
+ // Scan cap hit or no full scan (shouldn't happen but be safe).
370
+ totalAvailable = null;
371
+ truncated = true;
372
+ }
373
+
374
+ if (needsFullScan) {
375
+ const stateLabel = stateFilter ?? "all states";
376
+ const capNote = scanCapHit
377
+ ? ` (scan cap of ${WD_SCAN_PAGE_CAP * WD_SCAN_SIZE} WDs reached — some WDs may have been missed)`
378
+ : "";
288
379
  notes.push(
289
- "totalAvailable is null because a client-side filter (county and/or a non-code state) was applied over just the fetched page — the true match count for the combined filter is unknown. The server-side total for the coverage/state/active filters was " +
290
- (serverTotal ?? "unknown") +
291
- ".",
380
+ `Scanned ${scannedCount} of ${serverTotal ?? scannedCount} ${stateLabel} ${index.toUpperCase()} WDs across all pages${capNote}. ` +
381
+ (countyFilter ? `County filter applied across all scanned WDs. ` : "") +
382
+ (ctFilter ? `constructionType filter (${args.constructionType}) applied. ` : "") +
383
+ (countyFilter
384
+ ? "Single-county WDs ranked first — they are almost always the most specific match for a given locality. "
385
+ : ""),
292
386
  );
293
387
  }
294
388
 
295
389
  return withMeta(
296
- { determinations, coverageIndex: index, page, limit },
390
+ { determinations, coverageIndex: index, page: needsFullScan ? 0 : page, limit: needsFullScan ? returned : limit },
297
391
  {
298
392
  source: WD_SEARCH_SOURCE,
299
393
  keylessMode: true,
@@ -301,9 +395,9 @@ export async function searchWageDeterminations(args: {
301
395
  totalAvailable,
302
396
  truncated,
303
397
  pagination: {
304
- offset: page * limit,
305
- limit,
306
- nextOffset: truncated ? (page + 1) * limit : null,
398
+ offset: 0,
399
+ limit: needsFullScan ? returned : limit,
400
+ nextOffset: truncated && !needsFullScan ? (page + 1) * limit : null,
307
401
  hasMore: truncated,
308
402
  },
309
403
  filtersApplied,
package/src/server.ts CHANGED
@@ -116,10 +116,21 @@ import {
116
116
  toolNotLoadedEnvelope,
117
117
  } from "./toolsets.js";
118
118
 
119
+ // Where a state-level bid feed lives when it is NOT on OpenGov or Bonfire. Measured,
120
+ // not cosmetic: asked for "Illinois state solicitations", an eval agent searched
121
+ // opengov_list_governments then bonfire_list_organizations, found no state-level IL
122
+ // portal in either, and never reached data.illinois.gov 6rb8-ntpm (in one run it answered
123
+ // with generic portal advice after a single call; in another it ran out of budget). These are
124
+ // the tools an agent reaches for when it thinks "solicitations", so the pointer goes
125
+ // here rather than only on socrata_query, which it never opened.
126
+ const STATE_BID_FEEDS_POINTER =
127
+ "STATE-LEVEL bid feeds on open-data portals are NOT in this directory: TX TxDOT lettings, advertised and taking bids = socrata_query data.texas.gov qh8x-rm8r; IL CDB capital bids that are ANTICIPATED and NOT YET POSTED = socrata_query data.illinois.gov 6rb8-ntpm (~48 rows, not IL's full register). Map: resource samgov://data-map/state-local.";
128
+
129
+
119
130
  const SERVER_NAME = "mcp-sam-gov";
120
131
  // Kept in lockstep with package.json / manifest.json / server.json.
121
132
  // Keep in sync with package.json "version" (asserted at release; see CHANGELOG).
122
- const SERVER_VERSION = "1.15.0";
133
+ const SERVER_VERSION = "1.16.0";
123
134
 
124
135
  // ─── Tool input schemas (Zod) ────────────────────────────────────
125
136
 
@@ -751,13 +762,19 @@ const WageSearchInput = z.object({
751
762
  .string()
752
763
  .optional()
753
764
  .describe(
754
- "2-letter USPS state code (e.g. 'VA'), applied SERVER-SIDE. A full name is applied client-side instead.",
765
+ "2-letter USPS state code (e.g. 'IL'), applied SERVER-SIDE. A full name is applied client-side instead.",
755
766
  ),
756
767
  county: z
757
768
  .string()
758
769
  .optional()
759
770
  .describe(
760
- "County name (substring match), applied CLIENT-SIDE over the fetched page only (the API has no county filter).",
771
+ "County name (substring match, e.g. 'Cook'). When given, ALL pages for the state are scanned before filtering so no WDs are missed.",
772
+ ),
773
+ constructionType: z
774
+ .enum(["Building", "Residential", "Heavy", "Highway"])
775
+ .optional()
776
+ .describe(
777
+ "DBA construction type (Building | Residential | Heavy | Highway). This is the PRIMARY key for a Davis-Bacon lookup: pass state + county + constructionType to pinpoint the correct WD. E.g. Building = federal buildings, schools; Heavy = bridges, utilities; Highway = roads.",
761
778
  ),
762
779
  query: z
763
780
  .string()
@@ -770,8 +787,8 @@ const WageSearchInput = z.object({
770
787
  .boolean()
771
788
  .optional()
772
789
  .describe("Only standard (non-non-standard) WDs (default true)."),
773
- limit: z.number().min(1).max(50).optional().describe("Page size (default 20, max 50)."),
774
- page: z.number().min(0).optional().describe("0-based page index (default 0)."),
790
+ limit: z.number().min(1).max(50).optional().describe("Page size (default 20, max 50). Ignored when county or constructionType is given — a full-state scan is performed instead."),
791
+ page: z.number().min(0).optional().describe("0-based page index (default 0). Ignored when county or constructionType is given — a full-state scan is performed instead."),
775
792
  });
776
793
 
777
794
  const WageRatesInput = z.object({
@@ -1965,7 +1982,14 @@ const SocrataQueryInput = z.object({
1965
1982
  select: z
1966
1983
  .string()
1967
1984
  .optional()
1968
- .describe("Optional SoQL $select (column projection / aggregate), e.g. 'agency,SUM(amount)'."),
1985
+ .describe(
1986
+ "Optional SoQL $select (column projection or aggregate). " +
1987
+ "For a TOTAL: 'sum(amount)' (add a where for vendor/fiscal-year filter). " +
1988
+ "For a TOP-N ranking: 'vendor_name, sum(amount) as total' — pair with order='total DESC'. " +
1989
+ "Any SoQL function call (sum/count/avg/min/max) or 'distinct' activates aggregate mode: " +
1990
+ "totalAvailable becomes null (no raw-row total for aggregates) and the count(*) companion is skipped. " +
1991
+ "NEVER sum rows from one page to get a total — always use an aggregate select.",
1992
+ ),
1969
1993
  where: z
1970
1994
  .string()
1971
1995
  .optional()
@@ -2003,7 +2027,7 @@ const SocrataDiscoverDatasetsInput = z.object({
2003
2027
  q: z
2004
2028
  .string()
2005
2029
  .min(1)
2006
- .describe("Keyword(s) to find datasets, e.g. 'procurement', 'vendor payments', 'checkbook'."),
2030
+ .describe("TOPIC words only, e.g. 'solicitations', 'contract', 'vendor payments', 'checkbook'. Put the JURISDICTION in `domain`, never in q: every q term must match and dataset titles rarely repeat their place name, so q='Illinois solicitations' returns 0 while domain=data.illinois.gov q='solicitations' finds the dataset."),
2007
2031
  domain: SocrataDomainEnum.optional().describe(
2008
2032
  "Optional: scope discovery to ONE portal; omit to search all. The catalog does not index every host (USAC returns 0); those stay queryable via socrata_query with a known 4x4. " +
2009
2033
  "Jurisdiction of non-obvious hosts: cthru.data.socrata.com=MASSACHUSETTS statewide (CTHRU); atlanta.data.socrata.com=Atlanta GA; controllerdata.lacity.org+data.lacity.org=Los Angeles; www.dallasopendata.com=Dallas TX; data.brla.gov=Baton Rouge LA; data.kcmo.org=Kansas City MO; data.cstx.gov=College Station TX; data.weho.org=West Hollywood CA; opendata.usac.org+datahub.usac.org=federal USAC E-rate. data.colorado.gov's procurement data is CITY OF DENVER, not CO state.",
@@ -3082,7 +3106,7 @@ const BonfireSearchOpportunitiesInput = z.object({
3082
3106
  const OpenCheckbookSearchInput = z.object({
3083
3107
  portal: z
3084
3108
  .enum(openCheckbook.OPEN_CHECKBOOK_PORTALS.map((p) => p.key) as [string, ...string[]])
3085
- .describe("The curated Open-Checkbook portal (SSRF allowlist enum). 'sd' = State of South Dakota Open Checkbook (~740,980 vendor payments, ~$8.41B, ~3 most-recent fiscal years)."),
3109
+ .describe("The curated Open-Checkbook portal (SSRF allowlist enum). 'sd' = State of South Dakota Open Checkbook (~740,980 vendor payments, ~$8.41B, ~3 most-recent fiscal years). 'ak' = State of Alaska Open Checkbook (41,751 payments, $1.18B — FY2026 ONLY; FY2019–2025 return count:0 meaning not published, NOT zero spend)."),
3086
3110
  year: z.string().min(1).max(40).optional().describe("Fiscal-year filter (EXACT match), e.g. '2025'. Default 'All Years' = the exposed ~3-year window (NOT full history)."),
3087
3111
  vendor: z.string().min(1).max(200).optional().describe("Vendor name filter (EXACT match, e.g. 'US BANK NA' → 917). A partial/misspelled value returns an honest count:0."),
3088
3112
  org: z.string().min(1).max(200).optional().describe("Department filter (org1, EXACT match, e.g. 'TRANSPORTATION' → 109,887)."),
@@ -4461,7 +4485,7 @@ const GsaPerdiemRatesInput = z
4461
4485
  .regex(/^\d{4}$/)
4462
4486
  .optional()
4463
4487
  .describe(
4464
- "The per-diem fiscal year (default: the current U.S. federal fiscal year, computed at call time — GSA sets rates per FY, Oct 1–Sep 30). Validated ^\\d{4}$ (it rides in the request path).",
4488
+ "U.S. federal fiscal year number (Oct 1–Sep 30). Default: current FY at call time. IMPORTANT: October 2026 = FY2027; September 2026 = FY2026. To get October 2026 rates, pass year='2027'. Validated ^\d{4}$ (it rides in the request path).",
4465
4489
  ),
4466
4490
  })
4467
4491
  .describe(
@@ -5639,7 +5663,7 @@ export const TOOLS: ToolDef[] = [
5639
5663
  defineTool({
5640
5664
  name: "sam_search_wage_determinations",
5641
5665
  description:
5642
- "Find the Service Contract Act (SCA) or Davis-Bacon (DBA) wage determination(s) governing a locality (keyless SAM SGS). Filter by coverage (sca|dba), state (2-letter, server-side), county (client-side), or WD number/title. Returns the structured WD list; follow with sam_get_wage_rates to read the rate table. NOTE: `query` matches WD number/title only, NOT occupation.",
5666
+ "Find the Service Contract Act (SCA) or Davis-Bacon Act (DBA) wage determination(s) for a locality (keyless SAM SGS). For a Davis-Bacon lookup pass state + county + constructionType (e.g. 'IL', 'Cook', 'Building') — the tool scans ALL pages for the state so no WDs are missed, ranks single-county WDs first (the most specific match), and reports real match counts. Then call sam_get_wage_rates on the top result to read the rate table. SCA: pass state + county. constructionType is DBA-only: Building (federal buildings/schools), Residential, Heavy (bridges/utilities), Highway (roads). NOTE: `query` matches WD number/title only, NOT occupation.",
5643
5667
  inputSchema: WageSearchInput,
5644
5668
  handler: (input) => pricing.searchWageDeterminations(input),
5645
5669
  }),
@@ -5843,7 +5867,7 @@ export const TOOLS: ToolDef[] = [
5843
5867
  defineTool({
5844
5868
  name: "socrata_query",
5845
5869
  description:
5846
- "Query rows from an allowlisted Socrata/SODA open-data portal (keyless; ~a dozen US state portals + USAC E-rate on one identical API — state spend/checkbook/contract/vendor-payment datasets). State procurement mirrors: NY ehig-g5x3, NJ ubnu-tqu7, WA s8d5-pj78, MA cthru.data.socrata.com pegc-naaa (~49M payment rows). Full map: read resource samgov://data-map/state-local. Input `domain` (curated allowlist enum — the SSRF host guard), `datasetId` (4x4, from socrata_discover_datasets), optional SoQL `select`/`where`/`order`/`q`, `limit` (≤1000, def 100), `offset`, `withTotal` (def true). HONESTY: SODA's row response has no total, so a count(*) companion supplies an exact totalAvailable; if it fails the rows still return with totalAvailable:null + a note (hasMore is then inferred from page-fill, never a false complete). Genuine-empty ⇒ complete:true/total:0; an outage/400/404 THROWS (never a fake empty). Value fields are strings.",
5870
+ "Query rows from an allowlisted Socrata/SODA open-data portal (keyless; ~a dozen US state portals + USAC E-rate on one identical API — state spend/checkbook/contract/vendor-payment datasets). State procurement mirrors: NY ehig-g5x3, NJ ubnu-tqu7, WA s8d5-pj78, MA cthru.data.socrata.com pegc-naaa (~49M payment rows). Full map: read resource samgov://data-map/state-local. Input `domain` (curated allowlist enum — the SSRF host guard), `datasetId` (4x4, from socrata_discover_datasets), optional SoQL `select`/`where`/`order`/`q`, `limit` (≤1000, def 100), `offset`, `withTotal` (def true). AGGREGATES: for a grand total pass select='sum(amount)' with a where filter; for top-N vendors pass select='vendor_name, sum(amount) as total' with order='total DESC' — these return the final answer directly, NOT a page to manually sum. HONESTY: SODA's row response has no total, so a count(*) companion supplies an exact totalAvailable; if it fails the rows still return with totalAvailable:null + a note (hasMore is then inferred from page-fill, never a false complete). Genuine-empty ⇒ complete:true/total:0; an outage/400/404 THROWS (never a fake empty). Value fields are strings.",
5847
5871
  inputSchema: SocrataQueryInput,
5848
5872
  handler: (input) => socrata.query(input),
5849
5873
  }),
@@ -6202,33 +6226,33 @@ export const TOOLS: ToolDef[] = [
6202
6226
  defineTool({
6203
6227
  name: "opengov_list_governments",
6204
6228
  description:
6205
- "List the government portals on OpenGov Procurement (formerly ProcureNow) — the directory for opengov_search_solicitations (keyless; api.procurement.opengov.com). OpenGov Procurement hosts the live open-solicitation portals of 525+ US state/local governments (cities, counties, school & special districts across 42 states + DC). The WHOLE directory arrives in ONE keyless GET and is filtered client-side: `state` (2-letter), `query` (case-insensitive name substring); `limit`(1..200)/`offset`. Only ACTIVE, non-internal portals are returned. Output: { governments:[{ code, name, city, state, website }] } + honest _meta. Feed a result's `code` to opengov_search_solicitations. HONESTY: this consumes ONLY the anonymous endpoints the public portal itself calls (the official key-gated api-key API is NOT used) — genuinely keyless; totalAvailable is the EXACT filtered portal count (never the page length); a 429/5xx/timeout THROWS (never a fake empty); a non-array body ⇒ schema_drift.",
6229
+ "List the government portals on OpenGov Procurement (formerly ProcureNow) — the directory for opengov_search_solicitations (keyless; api.procurement.opengov.com). OpenGov Procurement hosts the live open-solicitation portals of 525+ US state/local governments (cities, counties, school & special districts across 42 states + DC). The WHOLE directory arrives in ONE keyless GET and is filtered client-side: `state` (2-letter), `query` (case-insensitive name substring); `limit`(1..200)/`offset`. Only ACTIVE, non-internal portals are returned. Output: { governments:[{ code, name, city, state, website }] } + honest _meta. Feed a result's `code` to opengov_search_solicitations. HONESTY: this consumes ONLY the anonymous endpoints the public portal itself calls (the official key-gated api-key API is NOT used) — genuinely keyless; totalAvailable is the EXACT filtered portal count (never the page length); a 429/5xx/timeout THROWS (never a fake empty); a non-array body ⇒ schema_drift." + " " + STATE_BID_FEEDS_POINTER,
6206
6230
  inputSchema: OpengovListGovernmentsInput,
6207
6231
  handler: (input) => opengov.listGovernments(input),
6208
6232
  }),
6209
6233
  defineTool({
6210
6234
  name: "opengov_search_solicitations",
6211
6235
  description:
6212
- "List a government's public solicitations on OpenGov Procurement (keyless; api.procurement.opengov.com, POST /project/list with the required publicView gate). Input `governmentCode` (the portal slug from opengov_list_governments, e.g. 'santacruzca', 'orlando', 'u-46'; REQUIRED), `limit`(1..100)/`offset`. Returns { governmentCode, solicitations:[{ id, title, solicitationNumber, status, type, department, releaseDate, proposalDeadline, contactName, link }] } + honest _meta. ★STATUS: `status` is surfaced VERBATIM — **open = currently ACCEPTING responses**; pending/evaluation/closed are ALSO returned (publicView shows all public projects), so filter status==='open' for live bids. `link` is the public portal page. HONESTY: totalAvailable = the API's `count` = the org's TOTAL public-project count (all statuses), NEVER the page length and NOT an open-only count (a note discloses this); pagination is the API's fixed page (offset is snapped to the page boundary, disclosed); a genuine no-match ⇒ complete:true/returned:0; a 429/5xx/timeout THROWS (never a fake empty); a non-array `projects` ⇒ schema_drift; a bad `governmentCode` ⇒ invalid_input pre-fetch. Genuinely keyless (the key-gated official API is NOT used).",
6236
+ "List a government's public solicitations on OpenGov Procurement (keyless; api.procurement.opengov.com, POST /project/list with the required publicView gate). Input `governmentCode` (the portal slug from opengov_list_governments, e.g. 'santacruzca', 'orlando', 'u-46'; REQUIRED), `limit`(1..100)/`offset`. Returns { governmentCode, solicitations:[{ id, title, solicitationNumber, status, type, department, releaseDate, proposalDeadline, contactName, link }] } + honest _meta. ★STATUS: `status` is surfaced VERBATIM — **open = currently ACCEPTING responses**; pending/evaluation/closed are ALSO returned (publicView shows all public projects), so filter status==='open' for live bids. `link` is the public portal page. HONESTY: totalAvailable = the API's `count` = the org's TOTAL public-project count (all statuses), NEVER the page length and NOT an open-only count (a note discloses this); pagination is the API's fixed page (offset is snapped to the page boundary, disclosed); a genuine no-match ⇒ complete:true/returned:0; a 429/5xx/timeout THROWS (never a fake empty); a non-array `projects` ⇒ schema_drift; a bad `governmentCode` ⇒ invalid_input pre-fetch. Genuinely keyless (the key-gated official API is NOT used)." + " " + STATE_BID_FEEDS_POINTER,
6213
6237
  inputSchema: OpengovSearchSolicitationsInput,
6214
6238
  handler: (input) => opengov.searchSolicitations(input),
6215
6239
  }),
6216
6240
  // ━━━ Bonfire (Euna) — keyless per-org open-opportunity RSS (SLED bids) ━━━
6217
6241
  // SLED bid campaign. Thousands of US state/local govs on Bonfire expose a keyless
6218
- // RSS of open opportunities. Ships a curated 195-org live-verified seed directory
6242
+ // RSS of open opportunities. Ships a curated 187-org live-verified seed directory
6219
6243
  // (Bonfire's authoritative org API is auth-gated → out of bounds). Fixed-suffix
6220
6244
  // SSRF (.bonfirehub.com). RSS = the complete open set (totalAvailable honest).
6221
6245
  defineTool({
6222
6246
  name: "bonfire_list_organizations",
6223
6247
  description:
6224
- "List US governments on the Bonfire (Euna) eProcurement platform — the directory for bonfire_search_opportunities (keyless). Bonfire hosts thousands of US state/local governments' open-bid portals, each with a keyless RSS feed. Filter the curated seed by `state` (2-letter) / `query` (case-insensitive name substring); `limit`(1..200)/`offset`. Output: { organizations:[{ org, name, state }] }. Feed a result's `org` to bonfire_search_opportunities. ★HONESTY: this is a CURATED, live-verified SEED of 195 US orgs — Bonfire has NO keyless org-list API (its authoritative directory is auth-gated, out of bounds), and Euna markets up to ~900 US orgs, so the seed is PARTIAL (disclosed in _meta); probe `{slug}.bonfirehub.com/opportunities/rss` to extend. totalAvailable = the exact filtered seed count.",
6248
+ "List US governments on the Bonfire (Euna) eProcurement platform — the directory for bonfire_search_opportunities (keyless). Bonfire hosts thousands of US state/local governments' open-bid portals, each with a keyless RSS feed. Filter the curated seed by `state` (2-letter) / `query` (case-insensitive name substring); `limit`(1..200)/`offset`. Output: { organizations:[{ org, name, state }] }. Feed a result's `org` to bonfire_search_opportunities. ★HONESTY: this is a CURATED, live-verified SEED of 187 US orgs — Bonfire has NO keyless org-list API (its authoritative directory is auth-gated, out of bounds), and Euna markets up to ~900 US orgs, so the seed is PARTIAL (disclosed in _meta); probe `{slug}.bonfirehub.com/opportunities/rss` to extend. totalAvailable = the exact filtered seed count." + " " + STATE_BID_FEEDS_POINTER,
6225
6249
  inputSchema: BonfireListOrganizationsInput,
6226
6250
  handler: (input) => bonfire.listOrganizations(input),
6227
6251
  }),
6228
6252
  defineTool({
6229
6253
  name: "bonfire_search_opportunities",
6230
6254
  description:
6231
- "List a government's currently-OPEN solicitations on Bonfire (keyless; {org}.bonfirehub.com/opportunities/rss, RSS 2.0). Input `org` (the subdomain slug from bonfire_list_organizations, e.g. 'harriscountytx', 'broward', 'u-46'; REQUIRED), `limit`(1..200)/`offset`. Returns { org, opportunities:[{ referenceNumber, name, description, closeDate, link, pubDate }] } + honest _meta. HONESTY: the RSS is the COMPLETE set of the org's currently-open opportunities (no server pagination), so totalAvailable = the exact open-opportunity count (never a page length) and this tool pages over it client-side; an empty feed (returned 0) means no open opportunities right now (honest empty, complete:true); `closeDate` is parsed best-effort from the description; a 429/5xx/404/timeout THROWS (never a fake empty); a 200 non-RSS body ⇒ schema_drift; a bad `org` ⇒ invalid_input pre-fetch. Fixed-suffix SSRF (.bonfirehub.com) + redirect:error. Keyless (Bonfire's auth-gated directory API is NOT used).",
6255
+ "List a government's currently-OPEN solicitations on Bonfire (keyless; {org}.bonfirehub.com/opportunities/rss, RSS 2.0). Input `org` (the subdomain slug from bonfire_list_organizations, e.g. 'harriscountytx', 'broward', 'u-46'; REQUIRED), `limit`(1..200)/`offset`. Returns { org, opportunities:[{ referenceNumber, name, description, closeDate, link, pubDate }] } + honest _meta. HONESTY: the RSS is the COMPLETE set of the org's currently-open opportunities (no server pagination), so totalAvailable = the exact open-opportunity count (never a page length) and this tool pages over it client-side; an empty feed (returned 0) means no open opportunities right now (honest empty, complete:true); `closeDate` is parsed best-effort from the description; a 429/5xx/404/timeout THROWS (never a fake empty); a 200 non-RSS body ⇒ schema_drift; a bad `org` ⇒ invalid_input pre-fetch. Fixed-suffix SSRF (.bonfirehub.com) + redirect:error. Keyless (Bonfire's auth-gated directory API is NOT used)." + " " + STATE_BID_FEEDS_POINTER,
6232
6256
  inputSchema: BonfireSearchOpportunitiesInput,
6233
6257
  handler: (input) => bonfire.searchOpportunities(input),
6234
6258
  }),
@@ -6520,7 +6544,7 @@ export const TOOLS: ToolDef[] = [
6520
6544
  // never-0; standardRate/isOconus are STRING booleans coerced to real booleans.
6521
6545
  defineTool({
6522
6546
  name: "gsa_perdiem_rates",
6523
- description: "Look up GSA Federal Travel PER-DIEM rates — the max lodging + Meals & Incidental Expenses (M&IE) reimbursement ceilings for official U.S. government travel (api.gsa.gov /travel/perdiem/v2, keyed — DATA_GOV_API_KEY or the shared DEMO_KEY). Input: EITHER `city` + `state` (2-letter) OR `zip` (5-digit) — supplying BOTH or NEITHER → invalid_input with 0 fetch; optional `year` (default: current federal fiscal year). Returns { rates:[{ city, county, state, zip, year, isOconus, standardRate, mealsUsd, monthlyLodgingUsd:[{ month (1-12), monthName, lodgingUsd }] }] } + honest _meta. HONESTY: lodgingUsd is the MAX nightly lodging ceiling for that month — VARIES SEASONALLY (hence a per-month array); mealsUsd is the daily M&IE ceiling; both are integer US dollars, null-when-withheld (NEVER 0 — genuine 0 preserved). standardRate/isOconus are booleans coerced from the API's string 'true'/'false' (unrecognized → null, never fabricated false); months array preserved AS-IS (never padded to 12). API returns COMPLETE rate set (no pagination) → totalAvailable = row count, complete:true. Genuine no-match → honest empty; `errors` field non-null → invalid_input; 429 (DEMO_KEY ~10 req/hr) → rate_limited THROWS; set DATA_GOV_API_KEY (free, api.data.gov/signup) for 1000/hr. 5xx/timeout → upstream_unavailable THROWS; 200 non-JSON → schema_drift. Key rides ONLY in the X-Api-Key header.",
6547
+ description: "Look up GSA Federal Travel PER-DIEM rates — the max lodging + Meals & Incidental Expenses (M&IE) reimbursement ceilings for official U.S. government travel (api.gsa.gov /travel/perdiem/v2, keyed — DATA_GOV_API_KEY or the shared DEMO_KEY). Input: EITHER `city` + `state` (2-letter) OR `zip` (5-digit) — supplying BOTH or NEITHER → invalid_input with 0 fetch; optional `year` (default: current federal fiscal year). Returns { rates:[{ city, county, state, zip, year, fiscalYear (= year, the U.S. FY: Oct 2026 = FY2027), isOconus, standardRate, mealsUsd, monthlyLodgingUsd:[{ month (1-12), monthName, lodgingUsd }] }] } + honest _meta. HONESTY: lodgingUsd is the MAX nightly lodging ceiling for that month — VARIES SEASONALLY (hence a per-month array); mealsUsd is the daily M&IE ceiling; both are integer US dollars, null-when-withheld (NEVER 0 — genuine 0 preserved). standardRate/isOconus are booleans coerced from the API's string 'true'/'false' (unrecognized → null, never fabricated false); months array preserved AS-IS (never padded to 12). API returns COMPLETE rate set (no pagination) → totalAvailable = row count, complete:true. Genuine no-match → honest empty; `errors` field non-null → invalid_input; 429 (DEMO_KEY ~10 req/hr) → rate_limited THROWS; set DATA_GOV_API_KEY (free, api.data.gov/signup) for 1000/hr. 5xx/timeout → upstream_unavailable THROWS; 200 non-JSON → schema_drift. Key rides ONLY in the X-Api-Key header.",
6524
6548
  inputSchema: GsaPerdiemRatesInput,
6525
6549
  handler: (input) => gsaPerdiem.perdiemRates(input),
6526
6550
  }),
package/src/socrata.ts CHANGED
@@ -204,6 +204,7 @@ export const SOCRATA_DOMAINS = [
204
204
  "data.coloradosprings.gov", // Colorado Springs CO (.gov) — e.g. yn6y-xikx (Open Checkbook Vendors ~19k)
205
205
  "data.framinghamma.gov", // Framingham MA (.gov) — e.g. cqve-ehkr (Checkbook ~324k)
206
206
  "data.fultoncountyga.gov", // Fulton County GA (.gov) — e.g. mxhc-krcg (Vendor Payments/disbursements ~217k)
207
+ "sharefulton.fultoncountyga.gov", // Fulton County GA (.gov, second portal) — e.g. kp4p-scak (Vendor Payments 226,797 rows 2014–present, updated 2026-09-14, attribution: "Fulton County Government (GA)")
207
208
  "atlanta.data.socrata.com", // City of Atlanta GA (Socrata-hosted official portal) — e.g. jmke-icfi (Open Checkbook Ledger ~1.78M)
208
209
  "opendata.cityofmesquite.com", // Mesquite TX (.com, official) — e.g. 6tva-azs5 (Check Register ~144k)
209
210
  // ── County/city procurement sweep, wave 3 (loop cycle 20, 2026-07-20). Expanded
@@ -245,7 +246,7 @@ const SOCRATA_DOMAIN_SET: ReadonlySet<string> = new Set(SOCRATA_DOMAINS);
245
246
  *
246
247
  * data.sfgov.org → data.sf.gov (confirmed 2026-09-21; all paths 301)
247
248
  */
248
- const MIGRATED_SOCRATA_HOSTS: ReadonlyMap<string, string> = new Map([
249
+ export const MIGRATED_SOCRATA_HOSTS: ReadonlyMap<string, string> = new Map([
249
250
  ["data.sfgov.org", "data.sf.gov"],
250
251
  ]);
251
252
 
@@ -593,6 +594,22 @@ export async function query(args: {
593
594
  );
594
595
  }
595
596
 
597
+ // ── Response-side aggregate nudge (§A-nudge) ──
598
+ // When the result is truncated (hasMore) and the caller used no aggregate select,
599
+ // the agent only sees a PAGE of rows — NOT the total. Nudge toward an aggregate
600
+ // query so the agent does not try to sum one page manually.
601
+ if (!isAggregateSelect && hasMore) {
602
+ // Find the most likely amount-like column from the first row's keys.
603
+ const firstRow = rows[0];
604
+ const amountKey =
605
+ firstRow !== undefined
606
+ ? (Object.keys(firstRow).find((k) => /amount|amt|total|paid|payment/i.test(k)) ?? "<amount column>")
607
+ : "<amount column>";
608
+ notes.push(
609
+ `This is a PAGE of raw rows (truncated — more rows exist). Do NOT sum this page to get a total. For a grand total: re-query with select='sum(${amountKey})' plus a where filter for vendor/fiscal year. For a top-N ranking: select='vendor_name, sum(${amountKey}) as total' with order='total DESC'. These are aggregate queries — the result is the final answer, not another page.`,
610
+ );
611
+ }
612
+
596
613
  return withMeta(
597
614
  { domain: args.domain, datasetId: args.datasetId, rows },
598
615
  {
@@ -712,6 +729,25 @@ export async function discoverDatasets(args: {
712
729
  `Showing ${returned} of ${totalAvailable} matches; raise limit (≤100) or narrow q for the rest.`,
713
730
  );
714
731
  }
732
+ // HONESTY (false-zero guard). An empty catalog result is easy to read as "this
733
+ // portal has no such data", and the per-host note above even calls the index
734
+ // COMPLETE — but the catalog behaves as if EVERY q term must match, and datasets
735
+ // rarely repeat their own jurisdiction's name. Measured 2026-09-21 on
736
+ // data.illinois.gov: q="Illinois state solicitations" -> 0 and
737
+ // q="Illinois procurement" -> 0, while q="solicitations" -> 1 (6rb8-ntpm). An eval
738
+ // agent took that zero at face value and told the user no Illinois procurement
739
+ // datasets exist. So a zero is reported as possibly false, with the fix.
740
+ if (returned === 0) {
741
+ // Only "more than one word?" matters here, so test for it directly rather than
742
+ // splitting: a raw whitespace split is reserved for disclosure tokenizing
743
+ // (tokenizeForDisclosure, ADR-0022) and this is not a disclosure.
744
+ const multiWord = /\S\s+\S/.test(args.q);
745
+ notes.push(
746
+ multiWord
747
+ ? `0 matches for a multi-word q — likely a FALSE zero, not proof the data is absent: the catalog behaves as if every term must match, and datasets rarely repeat their jurisdiction's name in their title. Put the place in \`domain\` (not in q) and retry with ONE topical term, e.g. 'solicitations', 'bids', 'contract', 'vendor', 'payments', 'purchase'.`
748
+ : `0 matches for q=${JSON.stringify(args.q)} — this is not proof the data is absent: publishers title the same thing differently. Retry with a synonym ('solicitations', 'bids', 'contract', 'vendor', 'payments', 'purchase') before concluding the portal has none.`,
749
+ );
750
+ }
715
751
 
716
752
  return withMeta(
717
753
  { query: args.q, domain: args.domain ?? null, results },