@cyanheads/usaspending-mcp-server 0.4.4 → 0.5.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/AGENTS.md +12 -11
- package/CLAUDE.md +12 -11
- package/Dockerfile +91 -44
- package/README.md +34 -30
- package/changelog/0.4.x/0.4.5.md +31 -0
- package/changelog/0.5.x/0.5.0.md +50 -0
- package/dist/config/server-config.d.ts.map +1 -1
- package/dist/config/server-config.js +3 -3
- package/dist/config/server-config.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.d.ts +8 -1
- package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.js +94 -35
- package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/disaster-spending.tool.d.ts +2 -1
- package/dist/mcp-server/tools/definitions/disaster-spending.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/disaster-spending.tool.js +60 -26
- package/dist/mcp-server/tools/definitions/disaster-spending.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/filters.d.ts +73 -4
- package/dist/mcp-server/tools/definitions/filters.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/filters.js +138 -4
- package/dist/mcp-server/tools/definitions/filters.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-agency.tool.d.ts +22 -3
- package/dist/mcp-server/tools/definitions/get-agency.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-agency.tool.js +170 -33
- package/dist/mcp-server/tools/definitions/get-agency.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-award.tool.d.ts +8 -3
- package/dist/mcp-server/tools/definitions/get-award.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-award.tool.js +149 -140
- package/dist/mcp-server/tools/definitions/get-award.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-federal-account.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-federal-account.tool.js +1 -1
- package/dist/mcp-server/tools/definitions/get-federal-account.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-idv-awards.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-idv-awards.tool.js +14 -12
- package/dist/mcp-server/tools/definitions/get-idv-awards.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-recipient.tool.d.ts +2 -8
- package/dist/mcp-server/tools/definitions/get-recipient.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-recipient.tool.js +29 -29
- package/dist/mcp-server/tools/definitions/get-recipient.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/index.d.ts +130 -28
- package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/locations.d.ts +45 -0
- package/dist/mcp-server/tools/definitions/locations.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/locations.js +206 -0
- package/dist/mcp-server/tools/definitions/locations.js.map +1 -0
- package/dist/mcp-server/tools/definitions/search-awards.tool.d.ts +28 -8
- package/dist/mcp-server/tools/definitions/search-awards.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/search-awards.tool.js +112 -84
- package/dist/mcp-server/tools/definitions/search-awards.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/spending-by-category.tool.d.ts +21 -2
- package/dist/mcp-server/tools/definitions/spending-by-category.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/spending-by-category.tool.js +79 -14
- package/dist/mcp-server/tools/definitions/spending-by-category.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/spending-by-geography.tool.d.ts +21 -2
- package/dist/mcp-server/tools/definitions/spending-by-geography.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/spending-by-geography.tool.js +95 -22
- package/dist/mcp-server/tools/definitions/spending-by-geography.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/spending-over-time.tool.d.ts +19 -1
- package/dist/mcp-server/tools/definitions/spending-over-time.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/spending-over-time.tool.js +62 -14
- package/dist/mcp-server/tools/definitions/spending-over-time.tool.js.map +1 -1
- package/dist/services/usaspending/types.d.ts +24 -16
- package/dist/services/usaspending/types.d.ts.map +1 -1
- package/dist/services/usaspending/usaspending-service.d.ts +45 -27
- package/dist/services/usaspending/usaspending-service.d.ts.map +1 -1
- package/dist/services/usaspending/usaspending-service.js +103 -64
- package/dist/services/usaspending/usaspending-service.js.map +1 -1
- package/package.json +15 -13
- package/server.json +10 -24
|
@@ -6,12 +6,12 @@ import { tool, z } from '@cyanheads/mcp-ts-core';
|
|
|
6
6
|
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
7
7
|
import { getUSASpendingService } from '../../../services/usaspending/usaspending-service.js';
|
|
8
8
|
import { ANALYTICS_DATE_FIELDS, filledBoundNotice, floorViolationMessage, invertedRangeMessage, optionalIsoDate, } from './dates.js';
|
|
9
|
-
import { buildFilters } from './filters.js';
|
|
9
|
+
import { analyticsTypeMismatch, buildFilters, CODE_FILTER_FIELDS, codeFilterEcho, describeCodeFilters, } from './filters.js';
|
|
10
10
|
import { formatCurrency } from './formatting.js';
|
|
11
11
|
import { formatPaginationLine } from './pagination.js';
|
|
12
12
|
export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
13
13
|
title: 'Spending by Category',
|
|
14
|
-
description: 'Aggregate federal spending grouped by a specific dimension: NAICS industry code, PSC product/service code, awarding agency, funding agency, CFDA assistance program, or recipient. Returns top items with obligation amounts — useful for trend and breakdown analysis. Chain NAICS codes into usaspending_search_awards filters or usaspending_autocomplete_filters lookups.',
|
|
14
|
+
description: 'Aggregate federal spending grouped by a specific dimension: NAICS industry code, PSC product/service code, awarding agency, funding agency, CFDA assistance program, or recipient. Returns top items with obligation amounts — useful for trend and breakdown analysis. Filter by keyword, award type, agency, recipient, NAICS code, Assistance Listing, PSC, DEF code, or date range. Chain NAICS, PSC, and CFDA codes back into these filters, into usaspending_search_awards filters, or into usaspending_autocomplete_filters lookups. recipient_duns rows carry recipient_id, which opens the recipient profile in usaspending_get_recipient, and uei.',
|
|
15
15
|
annotations: { readOnlyHint: true, openWorldHint: true, idempotentHint: true },
|
|
16
16
|
input: z.object({
|
|
17
17
|
category: z
|
|
@@ -24,9 +24,8 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
24
24
|
'funding_subagency',
|
|
25
25
|
'cfda',
|
|
26
26
|
'recipient_duns',
|
|
27
|
-
'recipient_parent_duns',
|
|
28
27
|
])
|
|
29
|
-
.describe('Breakdown dimension: naics (industry), psc (product/service code), awarding_agency, awarding_subagency, funding_agency, funding_subagency, cfda (assistance programs), recipient_duns
|
|
28
|
+
.describe('Breakdown dimension: naics (industry), psc (product/service code), awarding_agency, awarding_subagency, funding_agency, funding_subagency, cfda (assistance programs), or recipient_duns (recipients)'),
|
|
30
29
|
filters: z
|
|
31
30
|
.object({
|
|
32
31
|
keywords: z.array(z.string()).optional().describe('Full-text keyword filters'),
|
|
@@ -34,12 +33,17 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
34
33
|
.array(z.string())
|
|
35
34
|
.optional()
|
|
36
35
|
.describe('Award type code filters (A/B/C/D, 02–05, etc.)'),
|
|
37
|
-
agency_name: z
|
|
36
|
+
agency_name: z
|
|
37
|
+
.string()
|
|
38
|
+
.optional()
|
|
39
|
+
.describe('Awarding agency name filter, top-tier only (e.g., "Department of Defense") — the toptier_name from usaspending_autocomplete_filters type=awarding_agency; a sub-agency name matches nothing'),
|
|
38
40
|
recipient_id: z.string().optional().describe('Exact recipient hash ID filter'),
|
|
39
41
|
naics_codes: z.array(z.string()).optional().describe('NAICS code filters'),
|
|
42
|
+
...CODE_FILTER_FIELDS,
|
|
40
43
|
time_period_start: optionalIsoDate('Start date (YYYY-MM-DD), 2007-10-01 or later. Given alone, the window runs through today (UTC).'),
|
|
41
44
|
time_period_end: optionalIsoDate('End date (YYYY-MM-DD). Given alone, the window starts at 2007-10-01, the earliest searchable date.'),
|
|
42
45
|
})
|
|
46
|
+
.strict()
|
|
43
47
|
.optional()
|
|
44
48
|
.describe('Optional filters to scope the aggregation'),
|
|
45
49
|
limit: z.number().int().min(1).max(100).default(10).describe('Maximum items to return (1–100)'),
|
|
@@ -51,9 +55,20 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
51
55
|
.array(z
|
|
52
56
|
.object({
|
|
53
57
|
id: z.string().optional().describe('Item identifier (varies by category)'),
|
|
54
|
-
code: z
|
|
58
|
+
code: z
|
|
59
|
+
.string()
|
|
60
|
+
.optional()
|
|
61
|
+
.describe('Code value (NAICS, PSC, CFDA number, recipient DUNS, etc.)'),
|
|
55
62
|
name: z.string().optional().describe('Item name or description'),
|
|
56
63
|
amount: z.number().optional().describe('Total obligation amount in USD'),
|
|
64
|
+
recipient_id: z
|
|
65
|
+
.string()
|
|
66
|
+
.optional()
|
|
67
|
+
.describe('Recipient hash ID (recipient_duns rows) — pass to usaspending_get_recipient for the profile. Absent when upstream has none.'),
|
|
68
|
+
uei: z
|
|
69
|
+
.string()
|
|
70
|
+
.optional()
|
|
71
|
+
.describe('Recipient Unique Entity Identifier (recipient_duns rows). Absent when upstream has none.'),
|
|
57
72
|
})
|
|
58
73
|
.describe('Category item with code, name, and obligation amount'))
|
|
59
74
|
.describe('Top items in this category by obligation amount'),
|
|
@@ -80,6 +95,18 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
80
95
|
.string()
|
|
81
96
|
.optional()
|
|
82
97
|
.describe('NAICS code filters applied (comma-separated)'),
|
|
98
|
+
applied_assistance_listings: z
|
|
99
|
+
.string()
|
|
100
|
+
.optional()
|
|
101
|
+
.describe('Assistance Listing numbers sent (comma-separated)'),
|
|
102
|
+
applied_psc_codes: z
|
|
103
|
+
.string()
|
|
104
|
+
.optional()
|
|
105
|
+
.describe('PSC codes sent, uppercased (comma-separated)'),
|
|
106
|
+
applied_def_codes: z
|
|
107
|
+
.string()
|
|
108
|
+
.optional()
|
|
109
|
+
.describe('DEF codes sent, uppercased (comma-separated)'),
|
|
83
110
|
applied_time_period_start: z
|
|
84
111
|
.string()
|
|
85
112
|
.optional()
|
|
@@ -91,7 +118,7 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
91
118
|
notice: z
|
|
92
119
|
.string()
|
|
93
120
|
.optional()
|
|
94
|
-
.describe('Names a date bound that was filled in because only the other was supplied, and suggests how to broaden filters
|
|
121
|
+
.describe('Names a date bound that was filled in because only the other was supplied, and — when results are empty — names any Assistance Listing, PSC, or DEF codes sent and suggests how to broaden filters. Absent when neither applies.'),
|
|
95
122
|
},
|
|
96
123
|
errors: [
|
|
97
124
|
{
|
|
@@ -124,6 +151,20 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
124
151
|
retryable: false,
|
|
125
152
|
recovery: 'Re-request with a start date of 2007-10-01 or later. For award data back to 2000-10-01, use the Custom Award Download feature on usaspending.gov or the bulk_download API endpoints.',
|
|
126
153
|
},
|
|
154
|
+
{
|
|
155
|
+
reason: 'assistance_listings_type_mismatch',
|
|
156
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
157
|
+
when: 'filters.assistance_listings was given while every code in filters.award_type_codes is a contract or IDV code.',
|
|
158
|
+
retryable: false,
|
|
159
|
+
recovery: 'Add an assistance group to filters.award_type_codes — grants 02/03/04/05/F001/F002, direct payments 06/10/F006/F007, loans 07/08/F003/F004, or other assistance 09/11/-1/F005/F008/F009/F010 — or leave award_type_codes out to cover every award type.',
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
reason: 'psc_codes_type_mismatch',
|
|
163
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
164
|
+
when: 'filters.psc_codes was given while every code in filters.award_type_codes is an assistance code.',
|
|
165
|
+
retryable: false,
|
|
166
|
+
recovery: 'Add contracts A/B/C/D or IDVs IDV_A/IDV_B/IDV_B_A/IDV_B_B/IDV_B_C/IDV_C/IDV_D/IDV_E to filters.award_type_codes, or leave award_type_codes out to cover every award type.',
|
|
167
|
+
},
|
|
127
168
|
],
|
|
128
169
|
async handler(input, ctx) {
|
|
129
170
|
ctx.log.info('usaspending_spending_by_category', {
|
|
@@ -132,15 +173,23 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
132
173
|
page: input.page,
|
|
133
174
|
});
|
|
134
175
|
const svc = getUSASpendingService();
|
|
135
|
-
const { filters, timePeriod } = buildFilters(input.filters);
|
|
176
|
+
const { filters, timePeriod, codes } = buildFilters(input.filters);
|
|
136
177
|
const inverted = invertedRangeMessage(timePeriod, ANALYTICS_DATE_FIELDS);
|
|
137
178
|
if (inverted) {
|
|
138
|
-
throw ctx.fail('date_range_inverted', inverted
|
|
179
|
+
throw ctx.fail('date_range_inverted', inverted);
|
|
139
180
|
}
|
|
140
181
|
// Upstream answers a start before the floor with an undeclared 422.
|
|
141
182
|
const beforeFloor = floorViolationMessage(timePeriod);
|
|
142
183
|
if (beforeFloor) {
|
|
143
|
-
throw ctx.fail('date_before_earliest', beforeFloor
|
|
184
|
+
throw ctx.fail('date_before_earliest', beforeFloor);
|
|
185
|
+
}
|
|
186
|
+
// Upstream answers a code filter no award type here can carry with $0 and no message.
|
|
187
|
+
const mismatch = analyticsTypeMismatch(codes, input.filters?.award_type_codes, 'filters.award_type_codes');
|
|
188
|
+
if (mismatch?.filter === 'assistance_listings') {
|
|
189
|
+
throw ctx.fail('assistance_listings_type_mismatch', mismatch.message);
|
|
190
|
+
}
|
|
191
|
+
if (mismatch?.filter === 'psc_codes') {
|
|
192
|
+
throw ctx.fail('psc_codes_type_mismatch', mismatch.message);
|
|
144
193
|
}
|
|
145
194
|
const data = await svc.spendingByCategory(input.category, { filters, limit: input.limit, page: input.page }, ctx);
|
|
146
195
|
const results = (data.results ?? []).map((r) => ({
|
|
@@ -148,6 +197,8 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
148
197
|
...(r.code ? { code: r.code } : {}),
|
|
149
198
|
...(r.name || r.description ? { name: r.name ?? r.description ?? undefined } : {}),
|
|
150
199
|
...(typeof r.amount === 'number' ? { amount: r.amount } : {}),
|
|
200
|
+
...(r.recipient_id ? { recipient_id: r.recipient_id } : {}),
|
|
201
|
+
...(r.uei ? { uei: r.uei } : {}),
|
|
151
202
|
}));
|
|
152
203
|
const pageMeta = data.page_metadata ?? {};
|
|
153
204
|
/**
|
|
@@ -175,6 +226,7 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
175
226
|
...(input.filters?.naics_codes?.length
|
|
176
227
|
? { applied_naics_codes: input.filters.naics_codes.join(', ') }
|
|
177
228
|
: {}),
|
|
229
|
+
...codeFilterEcho(codes),
|
|
178
230
|
...(timePeriod
|
|
179
231
|
? {
|
|
180
232
|
applied_time_period_start: timePeriod.start_date,
|
|
@@ -185,7 +237,8 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
185
237
|
// enrich.notice is last-wins, so every notice source joins into one string.
|
|
186
238
|
const notices = [filledBoundNotice(timePeriod, ANALYTICS_DATE_FIELDS)];
|
|
187
239
|
if (results.length === 0) {
|
|
188
|
-
|
|
240
|
+
const codeParts = describeCodeFilters(codes);
|
|
241
|
+
notices.push(`No ${input.category} data matched the filters${codeParts.length ? ` (${codeParts.join(', ')})` : ''}. Try broadening filters or selecting a different category.`);
|
|
189
242
|
}
|
|
190
243
|
const notice = notices.filter(Boolean).join(' ');
|
|
191
244
|
if (notice)
|
|
@@ -198,12 +251,24 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
198
251
|
formatPaginationLine(result.page_metadata),
|
|
199
252
|
];
|
|
200
253
|
if (result.results.length > 0) {
|
|
254
|
+
/**
|
|
255
|
+
* Recipient identifiers get their own columns only when a row carries one, so
|
|
256
|
+
* other categories keep their table; a missing one is an empty cell.
|
|
257
|
+
*/
|
|
258
|
+
const recipientCols = result.results.some((r) => r.recipient_id || r.uei);
|
|
201
259
|
lines.push('');
|
|
202
|
-
|
|
203
|
-
|
|
260
|
+
if (recipientCols) {
|
|
261
|
+
lines.push('| Rank | ID | Name | Code | UEI | Recipient ID | Obligation |');
|
|
262
|
+
lines.push('|:-----|:---|:-----|:-----|:----|:-------------|:-----------|');
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
lines.push('| Rank | ID | Name | Code | Obligation |');
|
|
266
|
+
lines.push('|:-----|:---|:-----|:-----|:-----------|');
|
|
267
|
+
}
|
|
204
268
|
result.results.forEach((r, i) => {
|
|
205
269
|
const amt = r.amount !== undefined ? formatCurrency(r.amount) : 'N/A';
|
|
206
|
-
|
|
270
|
+
const recipient = recipientCols ? ` ${r.uei ?? ''} | ${r.recipient_id ?? ''} |` : '';
|
|
271
|
+
lines.push(`| ${i + 1} | ${r.id ?? 'N/A'} | ${r.name ?? 'N/A'} | ${r.code ?? 'N/A'} |${recipient} ${amt} |`);
|
|
207
272
|
});
|
|
208
273
|
}
|
|
209
274
|
return [{ type: 'text', text: lines.join('\n') }];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spending-by-category.tool.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/spending-by-category.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAC;AACtF,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,
|
|
1
|
+
{"version":3,"file":"spending-by-category.tool.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/spending-by-category.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAC;AACtF,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC,kCAAkC,EAAE;IAC7E,KAAK,EAAE,sBAAsB;IAC7B,WAAW,EACT,8nBAA8nB;IAChoB,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE;IAE9E,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;QACd,QAAQ,EAAE,CAAC;aACR,IAAI,CAAC;YACJ,OAAO;YACP,KAAK;YACL,iBAAiB;YACjB,oBAAoB;YACpB,gBAAgB;YAChB,mBAAmB;YACnB,MAAM;YACN,gBAAgB;SACjB,CAAC;aACD,QAAQ,CACP,uMAAuM,CACxM;QACH,OAAO,EAAE,CAAC;aACP,MAAM,CAAC;YACN,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,2BAA2B,CAAC;YAC9E,gBAAgB,EAAE,CAAC;iBAChB,KAAK,CAAC,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AE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;gBACrF,KAAK,CAAC,IAAI,CACR,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,KAAK,MAAM,CAAC,CAAC,IAAI,IAAI,KAAK,MAAM,CAAC,CAAC,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,GAAG,IAAI,CACjG,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -15,6 +15,9 @@ export declare const spendingByGeographyTool: import("@cyanheads/mcp-ts-core").T
|
|
|
15
15
|
state: "state";
|
|
16
16
|
}>;
|
|
17
17
|
filters: z.ZodOptional<z.ZodObject<{
|
|
18
|
+
assistance_listings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
19
|
+
psc_codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
20
|
+
def_codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
18
21
|
keywords: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
19
22
|
award_type_codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
20
23
|
agency_name: z.ZodOptional<z.ZodString>;
|
|
@@ -22,8 +25,9 @@ export declare const spendingByGeographyTool: import("@cyanheads/mcp-ts-core").T
|
|
|
22
25
|
naics_codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
23
26
|
time_period_start: z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
|
|
24
27
|
time_period_end: z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
|
|
25
|
-
}, z.core.$
|
|
28
|
+
}, z.core.$strict>>;
|
|
26
29
|
limit: z.ZodDefault<z.ZodNumber>;
|
|
30
|
+
shape_codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
27
31
|
subawards: z.ZodDefault<z.ZodBoolean>;
|
|
28
32
|
}, z.core.$strip>, z.ZodObject<{
|
|
29
33
|
scope: z.ZodString;
|
|
@@ -34,7 +38,6 @@ export declare const spendingByGeographyTool: import("@cyanheads/mcp-ts-core").T
|
|
|
34
38
|
aggregated_amount: z.ZodOptional<z.ZodNumber>;
|
|
35
39
|
population: z.ZodOptional<z.ZodNumber>;
|
|
36
40
|
per_capita: z.ZodOptional<z.ZodNumber>;
|
|
37
|
-
award_count: z.ZodOptional<z.ZodNumber>;
|
|
38
41
|
}, z.core.$strip>>;
|
|
39
42
|
total: z.ZodNumber;
|
|
40
43
|
total_areas_available: z.ZodNumber;
|
|
@@ -64,13 +67,29 @@ export declare const spendingByGeographyTool: import("@cyanheads/mcp-ts-core").T
|
|
|
64
67
|
readonly when: "The resolved start date precedes the 2007-10-01 earliest date this endpoint can search.";
|
|
65
68
|
readonly retryable: false;
|
|
66
69
|
readonly recovery: "Re-request with a start date of 2007-10-01 or later. For award data back to 2000-10-01, use the Custom Award Download feature on usaspending.gov or the bulk_download API endpoints.";
|
|
70
|
+
}, {
|
|
71
|
+
readonly reason: "assistance_listings_type_mismatch";
|
|
72
|
+
readonly code: JsonRpcErrorCode.ValidationError;
|
|
73
|
+
readonly when: "filters.assistance_listings was given while every code in filters.award_type_codes is a contract or IDV code.";
|
|
74
|
+
readonly retryable: false;
|
|
75
|
+
readonly recovery: "Add an assistance group to filters.award_type_codes — grants 02/03/04/05/F001/F002, direct payments 06/10/F006/F007, loans 07/08/F003/F004, or other assistance 09/11/-1/F005/F008/F009/F010 — or leave award_type_codes out to cover every award type.";
|
|
76
|
+
}, {
|
|
77
|
+
readonly reason: "psc_codes_type_mismatch";
|
|
78
|
+
readonly code: JsonRpcErrorCode.ValidationError;
|
|
79
|
+
readonly when: "filters.psc_codes was given while every code in filters.award_type_codes is an assistance code.";
|
|
80
|
+
readonly retryable: false;
|
|
81
|
+
readonly recovery: "Add contracts A/B/C/D or IDVs IDV_A/IDV_B/IDV_B_A/IDV_B_B/IDV_B_C/IDV_C/IDV_D/IDV_E to filters.award_type_codes, or leave award_type_codes out to cover every award type.";
|
|
67
82
|
}], {
|
|
68
83
|
readonly applied_scope: z.ZodString;
|
|
69
84
|
readonly applied_geo_layer: z.ZodString;
|
|
70
85
|
readonly area_count: z.ZodNumber;
|
|
86
|
+
readonly applied_shape_codes: z.ZodOptional<z.ZodString>;
|
|
71
87
|
readonly applied_keywords: z.ZodOptional<z.ZodString>;
|
|
72
88
|
readonly applied_agency_name: z.ZodOptional<z.ZodString>;
|
|
73
89
|
readonly applied_naics_codes: z.ZodOptional<z.ZodString>;
|
|
90
|
+
readonly applied_assistance_listings: z.ZodOptional<z.ZodString>;
|
|
91
|
+
readonly applied_psc_codes: z.ZodOptional<z.ZodString>;
|
|
92
|
+
readonly applied_def_codes: z.ZodOptional<z.ZodString>;
|
|
74
93
|
readonly applied_time_period_start: z.ZodOptional<z.ZodString>;
|
|
75
94
|
readonly applied_time_period_end: z.ZodOptional<z.ZodString>;
|
|
76
95
|
readonly applied_award_type_default: z.ZodOptional<z.ZodString>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spending-by-geography.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/spending-by-geography.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAQ,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"spending-by-geography.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/spending-by-geography.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAQ,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAqGjE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuWlC,CAAC"}
|
|
@@ -6,7 +6,7 @@ import { tool, z } from '@cyanheads/mcp-ts-core';
|
|
|
6
6
|
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
7
7
|
import { getUSASpendingService } from '../../../services/usaspending/usaspending-service.js';
|
|
8
8
|
import { ANALYTICS_DATE_FIELDS, filledBoundNotice, floorViolationMessage, invertedRangeMessage, optionalIsoDate, } from './dates.js';
|
|
9
|
-
import { buildFilters } from './filters.js';
|
|
9
|
+
import { analyticsTypeMismatch, buildFilters, CODE_FILTER_FIELDS, codeFilterEcho, describeCodeFilters, } from './filters.js';
|
|
10
10
|
import { formatCurrency } from './formatting.js';
|
|
11
11
|
/** Common filter fields for spending analytics tools */
|
|
12
12
|
const SpendingFiltersSchema = z
|
|
@@ -19,12 +19,17 @@ const SpendingFiltersSchema = z
|
|
|
19
19
|
.array(z.string())
|
|
20
20
|
.optional()
|
|
21
21
|
.describe('Award type codes: A/B/C/D (contracts), IDV_A–IDV_E (IDVs), 02–05 (grants), 06/10 (direct payments), 07/08 (loans), 09/11 (insurance and other assistance), -1 (unspecified). Groups may be mixed here. Omit to aggregate every type.'),
|
|
22
|
-
agency_name: z
|
|
22
|
+
agency_name: z
|
|
23
|
+
.string()
|
|
24
|
+
.optional()
|
|
25
|
+
.describe('Awarding agency name filter, top-tier only (e.g., "Department of Defense") — the toptier_name from usaspending_autocomplete_filters type=awarding_agency; a sub-agency name matches nothing'),
|
|
23
26
|
recipient_id: z.string().optional().describe('Exact recipient hash ID to filter awards'),
|
|
24
27
|
naics_codes: z.array(z.string()).optional().describe('NAICS industry codes to include'),
|
|
28
|
+
...CODE_FILTER_FIELDS,
|
|
25
29
|
time_period_start: optionalIsoDate('Start of time period (YYYY-MM-DD), 2007-10-01 or later. Given alone, the period runs through today (UTC).'),
|
|
26
30
|
time_period_end: optionalIsoDate('End of time period (YYYY-MM-DD). Given alone, the period starts at 2007-10-01, the earliest searchable date.'),
|
|
27
31
|
})
|
|
32
|
+
.strict()
|
|
28
33
|
.optional()
|
|
29
34
|
.describe('Optional filters to scope the spending aggregation');
|
|
30
35
|
/**
|
|
@@ -69,9 +74,15 @@ const ALL_AWARD_TYPE_CODES = [
|
|
|
69
74
|
'F010',
|
|
70
75
|
'-1',
|
|
71
76
|
];
|
|
77
|
+
/** The `shape_code` form each layer returns, and so the form `shape_codes` selects by. */
|
|
78
|
+
const SHAPE_CODE_FORM = {
|
|
79
|
+
state: 'a 2-letter postal code ("NY")',
|
|
80
|
+
county: 'a 5-digit state + county FIPS code ("36117")',
|
|
81
|
+
district: 'a 4-digit state FIPS + district number ("3623")',
|
|
82
|
+
};
|
|
72
83
|
export const spendingByGeographyTool = tool('usaspending_spending_by_geography', {
|
|
73
84
|
title: 'Spending by Geography',
|
|
74
|
-
description: 'Aggregate federal spending by state, county, or congressional district. Useful for per-capita analysis, regional comparisons, and mapping federal investment patterns.
|
|
85
|
+
description: 'Aggregate federal spending by state, county, or congressional district. Useful for per-capita analysis, regional comparisons, and mapping federal investment patterns. Filter by keyword, award type, agency, recipient, NAICS code, Assistance Listing, PSC, DEF code, or date range. Areas are ranked by obligation and capped at limit; to retrieve specific areas, including ones ranked past the cap, list their codes in shape_codes — a 2-letter postal code for state, a 5-digit state + county FIPS code for county, or a 4-digit state FIPS + district number for district — NOT place names. Resolve place names to these codes using a geocoding server (Census or OpenStreetMap) first. Chain per-capita results with Census population data for meaningful comparisons.',
|
|
75
86
|
annotations: { readOnlyHint: true, openWorldHint: true, idempotentHint: true },
|
|
76
87
|
input: z.object({
|
|
77
88
|
scope: z
|
|
@@ -79,7 +90,7 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
79
90
|
.describe('Which location to aggregate by: place_of_performance (where work is done) or recipient_location (where the recipient is based)'),
|
|
80
91
|
geo_layer: z
|
|
81
92
|
.enum(['state', 'county', 'district'])
|
|
82
|
-
.describe('Geographic granularity: state (
|
|
93
|
+
.describe('Geographic granularity: state (states, DC, and territories), county (county-level), or district (congressional district)'),
|
|
83
94
|
filters: SpendingFiltersSchema,
|
|
84
95
|
limit: z
|
|
85
96
|
.number()
|
|
@@ -87,7 +98,16 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
87
98
|
.min(1)
|
|
88
99
|
.max(500)
|
|
89
100
|
.default(50)
|
|
90
|
-
.describe('Maximum geographic areas to return, ranked by aggregated_amount descending (1–500). The upstream endpoint is not paginated — it returns every matching area in one response — so this caps client-side. A nationwide county query matches over 3,000 areas.'),
|
|
101
|
+
.describe('Maximum geographic areas to return, ranked by aggregated_amount descending (1–500). The upstream endpoint is not paginated — it returns every matching area in one response — so this caps client-side. A nationwide county query matches over 3,000 areas; use shape_codes to retrieve one ranked past the cap.'),
|
|
102
|
+
shape_codes: z
|
|
103
|
+
.array(z
|
|
104
|
+
.string()
|
|
105
|
+
.regex(/^(?:[A-Za-z]{2}|\d{4,5})$/)
|
|
106
|
+
.describe('One area code: 2-letter postal code (e.g. "NY"), 5-digit county FIPS (e.g. "36117"), or 4-digit district code (e.g. "3623")'))
|
|
107
|
+
.min(1)
|
|
108
|
+
.max(500)
|
|
109
|
+
.optional()
|
|
110
|
+
.describe('Return only these areas (1–500 codes), in the shape_code form this tool returns for geo_layer: 2-letter postal code for state ("NY"), 5-digit state + county FIPS for county ("36117" is Wayne County, NY), or 4-digit state FIPS + 2-digit district number for district ("3623" is NY-23, "5600" is Wyoming\'s at-large seat). Selection runs over every area the filters matched, so it reaches areas ranked past limit; selected areas stay ranked by aggregated_amount and capped at limit. A code that matches no area is named in the notice.'),
|
|
91
111
|
subawards: z
|
|
92
112
|
.boolean()
|
|
93
113
|
.default(false)
|
|
@@ -102,7 +122,7 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
102
122
|
shape_code: z
|
|
103
123
|
.string()
|
|
104
124
|
.optional()
|
|
105
|
-
.describe('
|
|
125
|
+
.describe('Area code, the form shape_codes takes: 2-letter postal code (state), 5-digit state + county FIPS (county), or 4-digit state FIPS + district number (district). Absent on the row for spending with no recorded location.'),
|
|
106
126
|
display_name: z
|
|
107
127
|
.string()
|
|
108
128
|
.optional()
|
|
@@ -119,14 +139,13 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
119
139
|
.number()
|
|
120
140
|
.optional()
|
|
121
141
|
.describe('Per-capita obligation amount in USD (aggregated_amount / population)'),
|
|
122
|
-
award_count: z.number().optional().describe('Number of awards in this area'),
|
|
123
142
|
})
|
|
124
143
|
.describe('Geographic area with spending totals and optional per-capita data'))
|
|
125
144
|
.describe('Spending totals by geographic area'),
|
|
126
145
|
total: z.number().describe('Number of geographic areas returned'),
|
|
127
146
|
total_areas_available: z
|
|
128
147
|
.number()
|
|
129
|
-
.describe('Number of geographic areas the filters matched, before limit
|
|
148
|
+
.describe('Number of geographic areas the filters matched, before shape_codes selection and limit were applied'),
|
|
130
149
|
}),
|
|
131
150
|
// Agent-facing context: scope, layer, count, the applied filters, disclosure of the
|
|
132
151
|
// no-filter award-type default, the client-side cap, and a recovery notice for empty results.
|
|
@@ -138,12 +157,28 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
138
157
|
.string()
|
|
139
158
|
.describe('Geographic granularity applied: state, county, or district'),
|
|
140
159
|
area_count: z.number().describe('Number of geographic areas returned'),
|
|
160
|
+
applied_shape_codes: z
|
|
161
|
+
.string()
|
|
162
|
+
.optional()
|
|
163
|
+
.describe('Area codes listed in shape_codes, letters uppercased and duplicates removed (comma-separated)'),
|
|
141
164
|
applied_keywords: z.string().optional().describe('Keyword filters applied (comma-separated)'),
|
|
142
165
|
applied_agency_name: z.string().optional().describe('Awarding agency name filter applied'),
|
|
143
166
|
applied_naics_codes: z
|
|
144
167
|
.string()
|
|
145
168
|
.optional()
|
|
146
169
|
.describe('NAICS code filters applied (comma-separated)'),
|
|
170
|
+
applied_assistance_listings: z
|
|
171
|
+
.string()
|
|
172
|
+
.optional()
|
|
173
|
+
.describe('Assistance Listing numbers sent (comma-separated)'),
|
|
174
|
+
applied_psc_codes: z
|
|
175
|
+
.string()
|
|
176
|
+
.optional()
|
|
177
|
+
.describe('PSC codes sent, uppercased (comma-separated)'),
|
|
178
|
+
applied_def_codes: z
|
|
179
|
+
.string()
|
|
180
|
+
.optional()
|
|
181
|
+
.describe('DEF codes sent, uppercased (comma-separated)'),
|
|
147
182
|
applied_time_period_start: z
|
|
148
183
|
.string()
|
|
149
184
|
.optional()
|
|
@@ -166,7 +201,7 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
166
201
|
notice: z
|
|
167
202
|
.string()
|
|
168
203
|
.optional()
|
|
169
|
-
.describe('How to reach areas omitted by limit, which time-period bound was filled in when only the other was supplied, and
|
|
204
|
+
.describe('How to reach areas omitted by limit, which shape_codes matched no area, which time-period bound was filled in when only the other was supplied, and — when the filters matched no area — any Assistance Listing, PSC, or DEF codes sent and how to broaden filters. Absent when none applies.'),
|
|
170
205
|
},
|
|
171
206
|
errors: [
|
|
172
207
|
{
|
|
@@ -199,6 +234,20 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
199
234
|
retryable: false,
|
|
200
235
|
recovery: 'Re-request with a start date of 2007-10-01 or later. For award data back to 2000-10-01, use the Custom Award Download feature on usaspending.gov or the bulk_download API endpoints.',
|
|
201
236
|
},
|
|
237
|
+
{
|
|
238
|
+
reason: 'assistance_listings_type_mismatch',
|
|
239
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
240
|
+
when: 'filters.assistance_listings was given while every code in filters.award_type_codes is a contract or IDV code.',
|
|
241
|
+
retryable: false,
|
|
242
|
+
recovery: 'Add an assistance group to filters.award_type_codes — grants 02/03/04/05/F001/F002, direct payments 06/10/F006/F007, loans 07/08/F003/F004, or other assistance 09/11/-1/F005/F008/F009/F010 — or leave award_type_codes out to cover every award type.',
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
reason: 'psc_codes_type_mismatch',
|
|
246
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
247
|
+
when: 'filters.psc_codes was given while every code in filters.award_type_codes is an assistance code.',
|
|
248
|
+
retryable: false,
|
|
249
|
+
recovery: 'Add contracts A/B/C/D or IDVs IDV_A/IDV_B/IDV_B_A/IDV_B_B/IDV_B_C/IDV_C/IDV_D/IDV_E to filters.award_type_codes, or leave award_type_codes out to cover every award type.',
|
|
250
|
+
},
|
|
202
251
|
],
|
|
203
252
|
async handler(input, ctx) {
|
|
204
253
|
ctx.log.info('usaspending_spending_by_geography', {
|
|
@@ -206,15 +255,23 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
206
255
|
geo_layer: input.geo_layer,
|
|
207
256
|
});
|
|
208
257
|
const svc = getUSASpendingService();
|
|
209
|
-
const { filters, timePeriod } = buildFilters(input.filters);
|
|
258
|
+
const { filters, timePeriod, codes } = buildFilters(input.filters);
|
|
210
259
|
const inverted = invertedRangeMessage(timePeriod, ANALYTICS_DATE_FIELDS);
|
|
211
260
|
if (inverted) {
|
|
212
|
-
throw ctx.fail('date_range_inverted', inverted
|
|
261
|
+
throw ctx.fail('date_range_inverted', inverted);
|
|
213
262
|
}
|
|
214
263
|
// Upstream answers a start before the floor with an undeclared 422.
|
|
215
264
|
const beforeFloor = floorViolationMessage(timePeriod);
|
|
216
265
|
if (beforeFloor) {
|
|
217
|
-
throw ctx.fail('date_before_earliest', beforeFloor
|
|
266
|
+
throw ctx.fail('date_before_earliest', beforeFloor);
|
|
267
|
+
}
|
|
268
|
+
// Upstream answers a code filter no award type here can carry with $0 and no message.
|
|
269
|
+
const mismatch = analyticsTypeMismatch(codes, input.filters?.award_type_codes, 'filters.award_type_codes');
|
|
270
|
+
if (mismatch?.filter === 'assistance_listings') {
|
|
271
|
+
throw ctx.fail('assistance_listings_type_mismatch', mismatch.message);
|
|
272
|
+
}
|
|
273
|
+
if (mismatch?.filter === 'psc_codes') {
|
|
274
|
+
throw ctx.fail('psc_codes_type_mismatch', mismatch.message);
|
|
218
275
|
}
|
|
219
276
|
// The endpoint answers HTTP 500 to `filters: {}`; any one populated key satisfies it.
|
|
220
277
|
const defaultedAwardTypes = Object.keys(filters).length === 0;
|
|
@@ -234,16 +291,26 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
234
291
|
: {}),
|
|
235
292
|
...(typeof r.population === 'number' ? { population: r.population } : {}),
|
|
236
293
|
...(typeof r.per_capita === 'number' ? { per_capita: r.per_capita } : {}),
|
|
237
|
-
...(typeof r.award_count === 'number' ? { award_count: r.award_count } : {}),
|
|
238
294
|
}));
|
|
239
295
|
// Upstream returns every matching area in one unordered page — rank before capping so the
|
|
240
296
|
// head answers "which areas got the most" and the omitted tail is bounded by the last row.
|
|
241
297
|
areas.sort((a, b) => (b.aggregated_amount ?? 0) - (a.aggregated_amount ?? 0));
|
|
242
|
-
|
|
298
|
+
/**
|
|
299
|
+
* Selection runs over the whole aggregate already in hand. Upstream's geo_layer_filters
|
|
300
|
+
* runs after the same full aggregation, so it would save no upstream work.
|
|
301
|
+
*/
|
|
302
|
+
const wanted = input.shape_codes && new Set(input.shape_codes.map((code) => code.toUpperCase()));
|
|
303
|
+
const selected = wanted
|
|
304
|
+
? areas.filter((a) => a.shape_code !== undefined && wanted.has(a.shape_code))
|
|
305
|
+
: areas;
|
|
306
|
+
const results = selected.slice(0, input.limit);
|
|
307
|
+
const matchedCodes = new Set(selected.map((a) => a.shape_code));
|
|
308
|
+
const unmatched = wanted ? [...wanted].filter((code) => !matchedCodes.has(code)) : [];
|
|
243
309
|
ctx.enrich({
|
|
244
310
|
applied_scope: input.scope,
|
|
245
311
|
applied_geo_layer: input.geo_layer,
|
|
246
312
|
area_count: results.length,
|
|
313
|
+
...(wanted ? { applied_shape_codes: [...wanted].join(', ') } : {}),
|
|
247
314
|
...(input.filters?.keywords?.length
|
|
248
315
|
? { applied_keywords: input.filters.keywords.join(', ') }
|
|
249
316
|
: {}),
|
|
@@ -251,6 +318,7 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
251
318
|
...(input.filters?.naics_codes?.length
|
|
252
319
|
? { applied_naics_codes: input.filters.naics_codes.join(', ') }
|
|
253
320
|
: {}),
|
|
321
|
+
...codeFilterEcho(codes),
|
|
254
322
|
...(timePeriod
|
|
255
323
|
? {
|
|
256
324
|
applied_time_period_start: timePeriod.start_date,
|
|
@@ -266,9 +334,11 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
266
334
|
// enrich.notice is last-wins, and enrich.truncated writes the notice too, so
|
|
267
335
|
// every notice source joins into one string written after both.
|
|
268
336
|
const notices = [];
|
|
269
|
-
if (
|
|
337
|
+
if (selected.length > results.length) {
|
|
270
338
|
const ceiling = results.at(-1)?.aggregated_amount;
|
|
271
|
-
const guidance =
|
|
339
|
+
const guidance = wanted
|
|
340
|
+
? `Showing the ${results.length} highest-obligation of the ${selected.length} selected areas. Raise limit to ${selected.length} to see every selected area.`
|
|
341
|
+
: `Showing the ${results.length} highest-obligation areas of ${areas.length}. ${input.limit < 500 ? 'Raise limit (max 500), list' : 'List'} an omitted area's code in shape_codes, or narrow with agency_name, keywords, or a coarser geo_layer to reach the rest.`;
|
|
272
342
|
ctx.enrich.truncated({
|
|
273
343
|
shown: results.length,
|
|
274
344
|
cap: input.limit,
|
|
@@ -277,9 +347,13 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
277
347
|
});
|
|
278
348
|
notices.push(guidance);
|
|
279
349
|
}
|
|
350
|
+
if (unmatched.length > 0) {
|
|
351
|
+
notices.push(`shape_codes ${unmatched.join(', ')} matched no ${input.geo_layer} area for these filters. A ${input.geo_layer} code is ${SHAPE_CODE_FORM[input.geo_layer]}, and an area with no spending under the filters is not listed.`);
|
|
352
|
+
}
|
|
280
353
|
notices.push(filledBoundNotice(timePeriod, ANALYTICS_DATE_FIELDS));
|
|
281
|
-
if (
|
|
282
|
-
|
|
354
|
+
if (areas.length === 0) {
|
|
355
|
+
const codeParts = describeCodeFilters(codes);
|
|
356
|
+
notices.push(`No spending data matched the filters${codeParts.length ? ` (${codeParts.join(', ')})` : ''} for the selected geography. ` +
|
|
283
357
|
'Try broader filters, a different scope (place_of_performance vs recipient_location), or remove the time period constraint.');
|
|
284
358
|
}
|
|
285
359
|
const notice = notices.filter(Boolean).join(' ');
|
|
@@ -298,15 +372,14 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
298
372
|
`## Federal Spending by Geography`,
|
|
299
373
|
`**Scope:** ${result.scope} | **Layer:** ${result.geo_layer} | **Areas:** ${result.total} of ${result.total_areas_available} matched`,
|
|
300
374
|
'',
|
|
301
|
-
'| Area | Code | Obligation | Population | Per Capita |
|
|
302
|
-
'
|
|
375
|
+
'| Area | Code | Obligation | Population | Per Capita |',
|
|
376
|
+
'|:-----|:-----|:-----------|:-----------|:-----------|',
|
|
303
377
|
];
|
|
304
378
|
for (const r of result.results) {
|
|
305
379
|
const amt = r.aggregated_amount !== undefined ? formatCurrency(r.aggregated_amount) : 'N/A';
|
|
306
380
|
const pop = r.population !== undefined ? r.population.toLocaleString() : 'N/A';
|
|
307
381
|
const perCap = r.per_capita !== undefined ? formatCurrency(r.per_capita) : 'N/A';
|
|
308
|
-
|
|
309
|
-
lines.push(`| ${r.display_name ?? 'N/A'} | ${r.shape_code ?? 'N/A'} | ${amt} | ${pop} | ${perCap} | ${awards} |`);
|
|
382
|
+
lines.push(`| ${r.display_name ?? 'N/A'} | ${r.shape_code ?? 'N/A'} | ${amt} | ${pop} | ${perCap} |`);
|
|
310
383
|
}
|
|
311
384
|
return [{ type: 'text', text: lines.join('\n') }];
|
|
312
385
|
},
|