@cyanheads/usaspending-mcp-server 0.7.0 → 0.7.2
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 +8 -5
- package/CLAUDE.md +8 -5
- package/README.md +48 -27
- package/changelog/0.7.x/0.7.1.md +26 -0
- package/changelog/0.7.x/0.7.2.md +33 -0
- package/changelog/template.md +10 -3
- package/dist/config/server-config.d.ts +13 -0
- package/dist/config/server-config.d.ts.map +1 -1
- package/dist/config/server-config.js +24 -0
- package/dist/config/server-config.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.d.ts +14 -2
- package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.js +136 -40
- package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/count-limit.d.ts +69 -0
- package/dist/mcp-server/tools/definitions/count-limit.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/count-limit.js +87 -0
- package/dist/mcp-server/tools/definitions/count-limit.js.map +1 -0
- package/dist/mcp-server/tools/definitions/disaster-spending.tool.d.ts +16 -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 +107 -37
- package/dist/mcp-server/tools/definitions/disaster-spending.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/filters.d.ts +63 -1
- package/dist/mcp-server/tools/definitions/filters.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/filters.js +116 -1
- package/dist/mcp-server/tools/definitions/filters.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-agency.tool.d.ts +7 -0
- package/dist/mcp-server/tools/definitions/get-agency.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-agency.tool.js +94 -50
- package/dist/mcp-server/tools/definitions/get-agency.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-award-federal-accounts.tool.d.ts +5 -0
- package/dist/mcp-server/tools/definitions/get-award-federal-accounts.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-award-federal-accounts.tool.js +15 -12
- package/dist/mcp-server/tools/definitions/get-award-federal-accounts.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-award-subawards.tool.d.ts +5 -0
- package/dist/mcp-server/tools/definitions/get-award-subawards.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-award-subawards.tool.js +14 -11
- package/dist/mcp-server/tools/definitions/get-award-subawards.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-award-transactions.tool.d.ts +5 -0
- package/dist/mcp-server/tools/definitions/get-award-transactions.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-award-transactions.tool.js +17 -11
- package/dist/mcp-server/tools/definitions/get-award-transactions.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-award.tool.d.ts +30 -0
- package/dist/mcp-server/tools/definitions/get-award.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-award.tool.js +110 -2
- package/dist/mcp-server/tools/definitions/get-award.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-federal-account-breakdown.tool.d.ts +5 -0
- package/dist/mcp-server/tools/definitions/get-federal-account-breakdown.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-federal-account-breakdown.tool.js +18 -11
- package/dist/mcp-server/tools/definitions/get-federal-account-breakdown.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-idv-awards.tool.d.ts +16 -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 +29 -19
- 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 +40 -1
- package/dist/mcp-server/tools/definitions/get-recipient.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-recipient.tool.js +185 -5
- package/dist/mcp-server/tools/definitions/get-recipient.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/index.d.ts +327 -6
- package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/list-agencies.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/list-agencies.tool.js +3 -5
- package/dist/mcp-server/tools/definitions/list-agencies.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/locations.d.ts +20 -9
- package/dist/mcp-server/tools/definitions/locations.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/locations.js +106 -84
- package/dist/mcp-server/tools/definitions/locations.js.map +1 -1
- package/dist/mcp-server/tools/definitions/pagination.d.ts +9 -8
- package/dist/mcp-server/tools/definitions/pagination.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/pagination.js +9 -8
- package/dist/mcp-server/tools/definitions/pagination.js.map +1 -1
- package/dist/mcp-server/tools/definitions/search-awards.tool.d.ts +50 -3
- package/dist/mcp-server/tools/definitions/search-awards.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/search-awards.tool.js +199 -70
- package/dist/mcp-server/tools/definitions/search-awards.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/search-federal-accounts.tool.d.ts +5 -0
- package/dist/mcp-server/tools/definitions/search-federal-accounts.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/search-federal-accounts.tool.js +18 -16
- package/dist/mcp-server/tools/definitions/search-federal-accounts.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/search-recipients.tool.d.ts +5 -0
- package/dist/mcp-server/tools/definitions/search-recipients.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/search-recipients.tool.js +13 -13
- package/dist/mcp-server/tools/definitions/search-recipients.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/spending-by-category.tool.d.ts +47 -0
- 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 +124 -33
- 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 +39 -0
- 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 +74 -17
- 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 +41 -0
- 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 +87 -11
- package/dist/mcp-server/tools/definitions/spending-over-time.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/unavailable-sections.d.ts +42 -0
- package/dist/mcp-server/tools/definitions/unavailable-sections.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/unavailable-sections.js +63 -0
- package/dist/mcp-server/tools/definitions/unavailable-sections.js.map +1 -0
- package/dist/services/usaspending/types.d.ts +102 -5
- package/dist/services/usaspending/types.d.ts.map +1 -1
- package/dist/services/usaspending/types.js +5 -1
- package/dist/services/usaspending/types.js.map +1 -1
- package/dist/services/usaspending/usaspending-service.d.ts +73 -6
- package/dist/services/usaspending/usaspending-service.d.ts.map +1 -1
- package/dist/services/usaspending/usaspending-service.js +206 -20
- package/dist/services/usaspending/usaspending-service.js.map +1 -1
- package/package.json +7 -7
- package/server.json +3 -3
- package/skills/usaspending-guide/SKILL.md +9 -5
|
@@ -6,13 +6,16 @@ import { tool, z } from '@cyanheads/mcp-ts-core';
|
|
|
6
6
|
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
7
7
|
import { escapeMarkdownInline } from '@cyanheads/mcp-ts-core/utils';
|
|
8
8
|
import { getUSASpendingService } from '../../../services/usaspending/usaspending-service.js';
|
|
9
|
+
import { countLimit, LimitClampSchema, limitClampTrailer } from './count-limit.js';
|
|
9
10
|
import { ANALYTICS_DATE_FIELDS, filledBoundNotice, floorViolationMessage, invertedRangeMessage, optionalIsoDate, } from './dates.js';
|
|
10
|
-
import { analyticsTypeMismatch, buildFilters, CODE_FILTER_FIELDS, codeFilterEcho, describeCodeFilters, } from './filters.js';
|
|
11
|
+
import { analyticsTypeMismatch, applyLocationFilters, buildFilters, CODE_FILTER_FIELDS, codeFilterEcho, describeCodeFilters, describeLocationFilters, LOCATION_FILTER_FIELDS, locationFilterEcho, normalizeEffectiveFilters, resolveLocationFilters, } from './filters.js';
|
|
11
12
|
import { formatCurrency } from './formatting.js';
|
|
12
13
|
import { formatPaginationLine } from './pagination.js';
|
|
14
|
+
/** Upstream's page maximum; one above it answers HTTP 422. */
|
|
15
|
+
const LIMIT = countLimit({ tool: 'usaspending_spending_by_category', default: 10, cap: 100 });
|
|
13
16
|
export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
14
17
|
title: 'Spending by Category',
|
|
15
|
-
description: 'Aggregate federal spending grouped by a specific dimension: NAICS industry code, PSC product/service code, awarding
|
|
18
|
+
description: 'Aggregate federal spending grouped by a specific dimension: NAICS industry code, PSC product/service code, awarding or funding agency or subagency, CFDA assistance program, recipient, federal account, or Disaster Emergency Fund Code (DEF). 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, place of performance or recipient location, or date range. federal_account and defc amounts are whole transaction obligations, counted under every federal account or DEF code the award carries, so rows overlap and never sum to a total; on defc, filters.def_codes selects awards but the rows still list every code those awards carry. Chain NAICS, PSC, CFDA, and DEF codes back into these filters, into usaspending_search_awards filters, or into usaspending_autocomplete_filters lookups; a federal_account code (AGENCY-MAIN, e.g. 047-4534) opens in usaspending_get_federal_account. Agency rows carry agency_slug, which opens the agency in usaspending_get_agency — on a subagency row, its parent department. recipient_duns rows carry recipient_id, which opens the recipient profile in usaspending_get_recipient, and uei.',
|
|
16
19
|
annotations: { readOnlyHint: true, openWorldHint: true, idempotentHint: true },
|
|
17
20
|
input: z.object({
|
|
18
21
|
category: z
|
|
@@ -25,11 +28,16 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
25
28
|
'funding_subagency',
|
|
26
29
|
'cfda',
|
|
27
30
|
'recipient_duns',
|
|
31
|
+
'federal_account',
|
|
32
|
+
'defc',
|
|
28
33
|
])
|
|
29
|
-
.describe('Breakdown dimension: naics (industry), psc (product/service code), awarding_agency, awarding_subagency, funding_agency, funding_subagency, cfda (assistance programs),
|
|
34
|
+
.describe('Breakdown dimension: naics (industry), psc (product/service code), awarding_agency, awarding_subagency, funding_agency, funding_subagency, cfda (assistance programs), recipient_duns (recipients), federal_account (appropriations accounts; code is the AGENCY-MAIN account code usaspending_get_federal_account takes), or defc (Disaster Emergency Fund Codes; code is the DEF code the def_codes filters take). federal_account and defc amounts are whole transaction obligations, counted under every account or DEF code the award carries, so rows overlap and never sum to a total; on defc, filters.def_codes selects awards but the rows still list every code those awards carry.'),
|
|
30
35
|
filters: z
|
|
31
36
|
.object({
|
|
32
|
-
keywords: z
|
|
37
|
+
keywords: z
|
|
38
|
+
.array(z.string())
|
|
39
|
+
.optional()
|
|
40
|
+
.describe('Full-text keyword filters; each effective term needs at least three characters, including significant whitespace'),
|
|
33
41
|
award_type_codes: z
|
|
34
42
|
.array(z.string())
|
|
35
43
|
.optional()
|
|
@@ -38,16 +46,23 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
38
46
|
.string()
|
|
39
47
|
.optional()
|
|
40
48
|
.describe('Awarding top-tier or sub-tier agency name — use the matched name from usaspending_autocomplete_filters type=awarding_agency; use toptier_name to select the whole parent department. A sub-tier name shared by several parents matches under all parents.'),
|
|
41
|
-
recipient_id: z
|
|
42
|
-
|
|
49
|
+
recipient_id: z
|
|
50
|
+
.string()
|
|
51
|
+
.optional()
|
|
52
|
+
.describe('recipient_id from usaspending_search_recipients: hexadecimal 8-4-4-4-12 hash plus uppercase -P, -C, or -R; hash letters normalize to lowercase; empty is unset'),
|
|
53
|
+
naics_codes: z
|
|
54
|
+
.array(z.string())
|
|
55
|
+
.optional()
|
|
56
|
+
.describe('NAICS codes: canonical 2, 4, or 6 digits; recognized ASCII integer aliases normalize whitespace, plus, leading zeros and digit underscores; unclassified spellings remain provider-validated'),
|
|
43
57
|
...CODE_FILTER_FIELDS,
|
|
58
|
+
...LOCATION_FILTER_FIELDS,
|
|
44
59
|
time_period_start: optionalIsoDate('Start date (YYYY-MM-DD), 2007-10-01 or later. Given alone, the window runs through today (UTC).'),
|
|
45
60
|
time_period_end: optionalIsoDate('End date (YYYY-MM-DD). Given alone, the window starts at 2007-10-01, the earliest searchable date.'),
|
|
46
61
|
})
|
|
47
62
|
.strict()
|
|
48
63
|
.optional()
|
|
49
64
|
.describe('Optional filters to scope the aggregation'),
|
|
50
|
-
limit:
|
|
65
|
+
limit: LIMIT.schema.describe('Items per page. Default 10, at most 100 per call.'),
|
|
51
66
|
page: z.number().int().min(1).default(1).describe('Page number (1-based)'),
|
|
52
67
|
}),
|
|
53
68
|
output: z.object({
|
|
@@ -55,12 +70,19 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
55
70
|
results: z
|
|
56
71
|
.array(z
|
|
57
72
|
.object({
|
|
58
|
-
id: z
|
|
73
|
+
id: z
|
|
74
|
+
.string()
|
|
75
|
+
.optional()
|
|
76
|
+
.describe('Item identifier (varies by category); absent on recipient_duns and defc rows'),
|
|
59
77
|
code: z
|
|
60
78
|
.string()
|
|
61
79
|
.optional()
|
|
62
|
-
.describe('Code value
|
|
80
|
+
.describe('Code value: NAICS, PSC, agency code, CFDA number, recipient DUNS, federal account code (AGENCY-MAIN, e.g. 047-4534), or DEF code (e.g. Z)'),
|
|
63
81
|
name: z.string().optional().describe('Item name or description'),
|
|
82
|
+
agency_slug: z
|
|
83
|
+
.string()
|
|
84
|
+
.optional()
|
|
85
|
+
.describe("Agency slug (awarding_agency, awarding_subagency, funding_agency, funding_subagency rows; on a subagency row, its parent department's) — pass to usaspending_get_agency as agency_slug. Absent when upstream has none."),
|
|
64
86
|
amount: z.number().optional().describe('Total obligation amount in USD'),
|
|
65
87
|
recipient_id: z
|
|
66
88
|
.string()
|
|
@@ -84,6 +106,10 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
84
106
|
}),
|
|
85
107
|
// Agent-facing context: pagination totals and a recovery notice for empty pages.
|
|
86
108
|
enrichment: {
|
|
109
|
+
applied_recipient_id: z
|
|
110
|
+
.string()
|
|
111
|
+
.optional()
|
|
112
|
+
.describe('Normalized recipient hash and level sent'),
|
|
87
113
|
totalCount: z
|
|
88
114
|
.number()
|
|
89
115
|
.optional()
|
|
@@ -108,6 +134,14 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
108
134
|
.string()
|
|
109
135
|
.optional()
|
|
110
136
|
.describe('DEF codes sent, uppercased (comma-separated)'),
|
|
137
|
+
applied_location: z
|
|
138
|
+
.string()
|
|
139
|
+
.optional()
|
|
140
|
+
.describe('Place of performance location sent, as normalized (e.g. country=USA, state=NM, county=049)'),
|
|
141
|
+
applied_recipient_location: z
|
|
142
|
+
.string()
|
|
143
|
+
.optional()
|
|
144
|
+
.describe('Recipient location sent, as normalized (e.g. country=USA, state=WA)'),
|
|
111
145
|
applied_time_period_start: z
|
|
112
146
|
.string()
|
|
113
147
|
.optional()
|
|
@@ -116,15 +150,45 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
116
150
|
.string()
|
|
117
151
|
.optional()
|
|
118
152
|
.describe('End date sent (YYYY-MM-DD), including a filled-in end'),
|
|
153
|
+
limitClamp: LimitClampSchema,
|
|
119
154
|
notice: z
|
|
120
155
|
.string()
|
|
121
156
|
.optional()
|
|
122
|
-
.describe('Names a date bound that was filled in because only the other was supplied, and — when results are empty —
|
|
157
|
+
.describe('Names a limit reduced to the per-call maximum, a date bound that was filled in because only the other was supplied, and — when results are empty — any Assistance Listing, PSC, or DEF codes, recipient_id, and locations sent, with how to broaden filters. Absent when none applies.'),
|
|
123
158
|
},
|
|
124
159
|
enrichmentTrailer: {
|
|
160
|
+
limitClamp: limitClampTrailer,
|
|
125
161
|
notice: { render: (notice) => (notice ? `> ${escapeMarkdownInline(notice)}` : '') },
|
|
126
162
|
},
|
|
127
163
|
errors: [
|
|
164
|
+
{
|
|
165
|
+
reason: 'invalid_keyword',
|
|
166
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
167
|
+
when: 'An effective keyword has fewer than three characters.',
|
|
168
|
+
retryable: false,
|
|
169
|
+
recovery: 'Supply keywords of at least three characters; whitespace is significant.',
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
reason: 'invalid_naics_code',
|
|
173
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
174
|
+
when: 'An effective NAICS code is known to be invalid.',
|
|
175
|
+
retryable: false,
|
|
176
|
+
recovery: 'Use a 2, 4, or 6 digit NAICS code from usaspending_autocomplete_filters type=naics.',
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
reason: 'invalid_recipient_id',
|
|
180
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
181
|
+
when: 'An active analytics recipient_id is malformed.',
|
|
182
|
+
retryable: false,
|
|
183
|
+
recovery: 'Use recipient_id from usaspending_search_recipients: hexadecimal 8-4-4-4-12 hash followed by uppercase -P, -C, or -R.',
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
reason: 'invalid_location',
|
|
187
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
188
|
+
when: 'filters.place_of_performance_location or filters.recipient_location names an unknown US state, a county without a state or under an armed-forces code, a county or FIPS-number state under a non-USA country, or parts that place it in different states.',
|
|
189
|
+
retryable: false,
|
|
190
|
+
recovery: "Under country USA (the default) or a US territory code, send state as a postal code (NM) or 2-digit FIPS code (35), and county as 3 digits with that state or as the 5-digit state + county code (35049). Under another country, send state as that country's own 2-letter subdivision code and no county.",
|
|
191
|
+
},
|
|
128
192
|
{
|
|
129
193
|
reason: 'api_unavailable',
|
|
130
194
|
code: JsonRpcErrorCode.ServiceUnavailable,
|
|
@@ -171,13 +235,22 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
171
235
|
},
|
|
172
236
|
],
|
|
173
237
|
async handler(input, ctx) {
|
|
238
|
+
const limit = LIMIT.apply(ctx, 'limit', input.limit);
|
|
174
239
|
ctx.log.info('usaspending_spending_by_category', {
|
|
175
240
|
category: input.category,
|
|
176
|
-
limit:
|
|
241
|
+
limit: limit.applied,
|
|
177
242
|
page: input.page,
|
|
178
243
|
});
|
|
179
244
|
const svc = getUSASpendingService();
|
|
180
|
-
const
|
|
245
|
+
const effective = normalizeEffectiveFilters(input.filters ?? {});
|
|
246
|
+
if ('reason' in effective)
|
|
247
|
+
throw ctx.fail(effective.reason, effective.message);
|
|
248
|
+
const located = resolveLocationFilters(input.filters ?? {});
|
|
249
|
+
if (!located.ok)
|
|
250
|
+
throw ctx.fail('invalid_location', located.message);
|
|
251
|
+
const { locations } = located;
|
|
252
|
+
const { filters, timePeriod, codes } = buildFilters({ ...input.filters, ...effective });
|
|
253
|
+
applyLocationFilters(filters, locations);
|
|
181
254
|
const inverted = invertedRangeMessage(timePeriod, ANALYTICS_DATE_FIELDS);
|
|
182
255
|
if (inverted) {
|
|
183
256
|
throw ctx.fail('date_range_inverted', inverted);
|
|
@@ -195,11 +268,12 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
195
268
|
if (mismatch?.filter === 'psc_codes') {
|
|
196
269
|
throw ctx.fail('psc_codes_type_mismatch', mismatch.message);
|
|
197
270
|
}
|
|
198
|
-
const data = await svc.spendingByCategory(input.category, { filters, limit:
|
|
271
|
+
const data = await svc.spendingByCategory(input.category, { filters, limit: limit.applied, page: input.page }, ctx);
|
|
199
272
|
const results = (data.results ?? []).map((r) => ({
|
|
200
273
|
...(r.id != null ? { id: String(r.id) } : {}),
|
|
201
274
|
...(r.code ? { code: r.code } : {}),
|
|
202
275
|
...(r.name || r.description ? { name: r.name ?? r.description ?? undefined } : {}),
|
|
276
|
+
...(r.agency_slug ? { agency_slug: r.agency_slug } : {}),
|
|
203
277
|
...(typeof r.amount === 'number' ? { amount: r.amount } : {}),
|
|
204
278
|
...(r.recipient_id ? { recipient_id: r.recipient_id } : {}),
|
|
205
279
|
...(r.uei ? { uei: r.uei } : {}),
|
|
@@ -216,7 +290,7 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
216
290
|
has_next: pageMeta.hasNext ?? false,
|
|
217
291
|
page: pageMeta.page ?? input.page,
|
|
218
292
|
...(typeof pageMeta.total === 'number' ? { total: pageMeta.total } : {}),
|
|
219
|
-
limit:
|
|
293
|
+
limit: limit.applied,
|
|
220
294
|
};
|
|
221
295
|
if (typeof page_metadata.total === 'number')
|
|
222
296
|
ctx.enrich.total(page_metadata.total);
|
|
@@ -227,10 +301,12 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
227
301
|
? { applied_keywords: input.filters.keywords.join(', ') }
|
|
228
302
|
: {}),
|
|
229
303
|
...(input.filters?.agency_name ? { applied_agency_name: input.filters.agency_name } : {}),
|
|
230
|
-
...(
|
|
231
|
-
|
|
304
|
+
...(effective.recipient_id ? { applied_recipient_id: effective.recipient_id } : {}),
|
|
305
|
+
...(effective.naics_codes?.length
|
|
306
|
+
? { applied_naics_codes: effective.naics_codes.join(', ') }
|
|
232
307
|
: {}),
|
|
233
308
|
...codeFilterEcho(codes),
|
|
309
|
+
...locationFilterEcho(locations),
|
|
234
310
|
...(timePeriod
|
|
235
311
|
? {
|
|
236
312
|
applied_time_period_start: timePeriod.start_date,
|
|
@@ -239,9 +315,12 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
239
315
|
: {}),
|
|
240
316
|
});
|
|
241
317
|
// enrich.notice is last-wins, so every notice source joins into one string.
|
|
242
|
-
const notices = [filledBoundNotice(timePeriod, ANALYTICS_DATE_FIELDS)];
|
|
318
|
+
const notices = [limit.notice, filledBoundNotice(timePeriod, ANALYTICS_DATE_FIELDS)];
|
|
243
319
|
if (results.length === 0) {
|
|
244
320
|
const codeParts = describeCodeFilters(codes);
|
|
321
|
+
if (effective.recipient_id)
|
|
322
|
+
codeParts.push(`recipient_id=${effective.recipient_id}`);
|
|
323
|
+
codeParts.push(...describeLocationFilters(locations));
|
|
245
324
|
notices.push(`No ${input.category} data matched the filters${codeParts.length ? ` (${codeParts.join(', ')})` : ''}. Try broadening filters or selecting a different category.`);
|
|
246
325
|
}
|
|
247
326
|
const notice = notices.filter(Boolean).join(' ');
|
|
@@ -256,25 +335,37 @@ export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
|
256
335
|
];
|
|
257
336
|
if (result.results.length > 0) {
|
|
258
337
|
/**
|
|
259
|
-
* Recipient identifiers get their own columns only when a row
|
|
260
|
-
* other categories keep their table; a missing one is an empty cell.
|
|
338
|
+
* Recipient identifiers and agency slugs get their own columns only when a row
|
|
339
|
+
* carries one, so other categories keep their table; a missing one is an empty cell.
|
|
261
340
|
*/
|
|
262
341
|
const recipientCols = result.results.some((r) => r.recipient_id || r.uei);
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
342
|
+
const slugCol = result.results.some((r) => r.agency_slug);
|
|
343
|
+
const header = [
|
|
344
|
+
'Rank',
|
|
345
|
+
'ID',
|
|
346
|
+
'Name',
|
|
347
|
+
'Code',
|
|
348
|
+
...(recipientCols ? ['UEI', 'Recipient ID'] : []),
|
|
349
|
+
...(slugCol ? ['Agency Slug'] : []),
|
|
350
|
+
'Obligation',
|
|
351
|
+
];
|
|
352
|
+
lines.push('', `| ${header.join(' | ')} |`);
|
|
353
|
+
lines.push(`|${header.map((h) => `:${'-'.repeat(h.length + 1)}`).join('|')}|`);
|
|
354
|
+
// Ranks continue across pages: page 2 at limit 3 starts at 4.
|
|
355
|
+
const firstRank = (result.page_metadata.page - 1) * result.page_metadata.limit + 1;
|
|
272
356
|
result.results.forEach((r, i) => {
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
357
|
+
const cells = [
|
|
358
|
+
String(firstRank + i),
|
|
359
|
+
escapeMarkdownInline(r.id ?? 'N/A'),
|
|
360
|
+
escapeMarkdownInline(r.name ?? 'N/A'),
|
|
361
|
+
escapeMarkdownInline(r.code ?? 'N/A'),
|
|
362
|
+
...(recipientCols
|
|
363
|
+
? [escapeMarkdownInline(r.uei ?? ''), escapeMarkdownInline(r.recipient_id ?? '')]
|
|
364
|
+
: []),
|
|
365
|
+
...(slugCol ? [escapeMarkdownInline(r.agency_slug ?? '')] : []),
|
|
366
|
+
r.amount !== undefined ? formatCurrency(r.amount) : 'N/A',
|
|
367
|
+
];
|
|
368
|
+
lines.push(`| ${cells.join(' | ')} |`);
|
|
278
369
|
});
|
|
279
370
|
}
|
|
280
371
|
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,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,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,E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AC,CAAC,EAAE,IAAI,KAAK,CAAC,MAAM,oBAAoB,CAAC,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,MAAM,oBAAoB,CAAC,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,KAAK,SAAS,IAAI,GAAG,IAAI,CACnK,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"}
|
|
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,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,yBAAyB,EACzB,sBAAsB,GACvB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,8DAA8D;AAC9D,MAAM,KAAK,GAAG,UAAU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AI,EAAE,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;wBACjF,CAAC,CAAC,EAAE,CAAC;oBACP,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC/D,CAAC,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK;iBAC1D,CAAC;gBACF,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACzC,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"}
|
|
@@ -18,6 +18,18 @@ export declare const spendingByGeographyTool: import("@cyanheads/mcp-ts-core").T
|
|
|
18
18
|
assistance_listings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
19
19
|
psc_codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
20
20
|
def_codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
21
|
+
place_of_performance_location: z.ZodOptional<z.ZodObject<{
|
|
22
|
+
country: z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
|
|
23
|
+
state: z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
|
|
24
|
+
county: z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
|
|
25
|
+
city: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, z.core.$strict>>;
|
|
27
|
+
recipient_location: z.ZodOptional<z.ZodObject<{
|
|
28
|
+
country: z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
|
|
29
|
+
state: z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
|
|
30
|
+
county: z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
|
|
31
|
+
city: z.ZodOptional<z.ZodString>;
|
|
32
|
+
}, z.core.$strict>>;
|
|
21
33
|
keywords: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
22
34
|
award_type_codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
23
35
|
agency_name: z.ZodOptional<z.ZodString>;
|
|
@@ -42,6 +54,30 @@ export declare const spendingByGeographyTool: import("@cyanheads/mcp-ts-core").T
|
|
|
42
54
|
total: z.ZodNumber;
|
|
43
55
|
total_areas_available: z.ZodNumber;
|
|
44
56
|
}, z.core.$strip>, readonly [{
|
|
57
|
+
readonly reason: "invalid_keyword";
|
|
58
|
+
readonly code: JsonRpcErrorCode.ValidationError;
|
|
59
|
+
readonly when: "An effective keyword has fewer than three characters.";
|
|
60
|
+
readonly retryable: false;
|
|
61
|
+
readonly recovery: "Supply keywords of at least three characters; whitespace is significant.";
|
|
62
|
+
}, {
|
|
63
|
+
readonly reason: "invalid_naics_code";
|
|
64
|
+
readonly code: JsonRpcErrorCode.ValidationError;
|
|
65
|
+
readonly when: "An effective NAICS code is known to be invalid.";
|
|
66
|
+
readonly retryable: false;
|
|
67
|
+
readonly recovery: "Use a 2, 4, or 6 digit NAICS code from usaspending_autocomplete_filters type=naics.";
|
|
68
|
+
}, {
|
|
69
|
+
readonly reason: "invalid_recipient_id";
|
|
70
|
+
readonly code: JsonRpcErrorCode.ValidationError;
|
|
71
|
+
readonly when: "An active analytics recipient_id is malformed.";
|
|
72
|
+
readonly retryable: false;
|
|
73
|
+
readonly recovery: "Use recipient_id from usaspending_search_recipients: hexadecimal 8-4-4-4-12 hash followed by uppercase -P, -C, or -R.";
|
|
74
|
+
}, {
|
|
75
|
+
readonly reason: "invalid_location";
|
|
76
|
+
readonly code: JsonRpcErrorCode.ValidationError;
|
|
77
|
+
readonly when: "filters.place_of_performance_location or filters.recipient_location names an unknown US state, a county without a state or under an armed-forces code, a county or FIPS-number state under a non-USA country, or parts that place it in different states.";
|
|
78
|
+
readonly retryable: false;
|
|
79
|
+
readonly recovery: "Under country USA (the default) or a US territory code, send state as a postal code (NM) or 2-digit FIPS code (35), and county as 3 digits with that state or as the 5-digit state + county code (35049). Under another country, send state as that country's own 2-letter subdivision code and no county.";
|
|
80
|
+
}, {
|
|
45
81
|
readonly reason: "api_unavailable";
|
|
46
82
|
readonly code: JsonRpcErrorCode.ServiceUnavailable;
|
|
47
83
|
readonly when: "USAspending.gov API is unreachable or returns an error.";
|
|
@@ -80,6 +116,7 @@ export declare const spendingByGeographyTool: import("@cyanheads/mcp-ts-core").T
|
|
|
80
116
|
readonly retryable: false;
|
|
81
117
|
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.";
|
|
82
118
|
}], {
|
|
119
|
+
readonly applied_recipient_id: z.ZodOptional<z.ZodString>;
|
|
83
120
|
readonly applied_scope: z.ZodString;
|
|
84
121
|
readonly applied_geo_layer: z.ZodString;
|
|
85
122
|
readonly area_count: z.ZodNumber;
|
|
@@ -90,6 +127,8 @@ export declare const spendingByGeographyTool: import("@cyanheads/mcp-ts-core").T
|
|
|
90
127
|
readonly applied_assistance_listings: z.ZodOptional<z.ZodString>;
|
|
91
128
|
readonly applied_psc_codes: z.ZodOptional<z.ZodString>;
|
|
92
129
|
readonly applied_def_codes: z.ZodOptional<z.ZodString>;
|
|
130
|
+
readonly applied_location: z.ZodOptional<z.ZodString>;
|
|
131
|
+
readonly applied_recipient_location: z.ZodOptional<z.ZodString>;
|
|
93
132
|
readonly applied_time_period_start: z.ZodOptional<z.ZodString>;
|
|
94
133
|
readonly applied_time_period_end: z.ZodOptional<z.ZodString>;
|
|
95
134
|
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;AA0HjE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8ZlC,CAAC"}
|
|
@@ -6,8 +6,9 @@ import { tool, z } from '@cyanheads/mcp-ts-core';
|
|
|
6
6
|
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
7
7
|
import { escapeMarkdownInline } from '@cyanheads/mcp-ts-core/utils';
|
|
8
8
|
import { getUSASpendingService } from '../../../services/usaspending/usaspending-service.js';
|
|
9
|
+
import { countInput } from './count-limit.js';
|
|
9
10
|
import { ANALYTICS_DATE_FIELDS, filledBoundNotice, floorViolationMessage, invertedRangeMessage, optionalIsoDate, } from './dates.js';
|
|
10
|
-
import { analyticsTypeMismatch, buildFilters, CODE_FILTER_FIELDS, codeFilterEcho, describeCodeFilters, } from './filters.js';
|
|
11
|
+
import { analyticsTypeMismatch, applyLocationFilters, buildFilters, CODE_FILTER_FIELDS, codeFilterEcho, describeCodeFilters, describeLocationFilters, LOCATION_FILTER_FIELDS, locationFilterEcho, normalizeEffectiveFilters, resolveLocationFilters, } from './filters.js';
|
|
11
12
|
import { formatCurrency } from './formatting.js';
|
|
12
13
|
/** Common filter fields for spending analytics tools */
|
|
13
14
|
const SpendingFiltersSchema = z
|
|
@@ -15,7 +16,7 @@ const SpendingFiltersSchema = z
|
|
|
15
16
|
keywords: z
|
|
16
17
|
.array(z.string())
|
|
17
18
|
.optional()
|
|
18
|
-
.describe('Full-text keyword
|
|
19
|
+
.describe('Full-text keyword filters; each effective term needs at least three characters, including significant whitespace'),
|
|
19
20
|
award_type_codes: z
|
|
20
21
|
.array(z.string())
|
|
21
22
|
.optional()
|
|
@@ -24,9 +25,16 @@ const SpendingFiltersSchema = z
|
|
|
24
25
|
.string()
|
|
25
26
|
.optional()
|
|
26
27
|
.describe('Awarding top-tier or sub-tier agency name — use the matched name from usaspending_autocomplete_filters type=awarding_agency; use toptier_name to select the whole parent department. A sub-tier name shared by several parents matches under all parents.'),
|
|
27
|
-
recipient_id: z
|
|
28
|
-
|
|
28
|
+
recipient_id: z
|
|
29
|
+
.string()
|
|
30
|
+
.optional()
|
|
31
|
+
.describe('recipient_id from usaspending_search_recipients: hexadecimal 8-4-4-4-12 hash plus uppercase -P, -C, or -R; hash letters normalize to lowercase; empty is unset'),
|
|
32
|
+
naics_codes: z
|
|
33
|
+
.array(z.string())
|
|
34
|
+
.optional()
|
|
35
|
+
.describe('NAICS codes: canonical 2, 4, or 6 digits; recognized ASCII integer aliases normalize whitespace, plus, leading zeros and digit underscores; unclassified spellings remain provider-validated'),
|
|
29
36
|
...CODE_FILTER_FIELDS,
|
|
37
|
+
...LOCATION_FILTER_FIELDS,
|
|
30
38
|
time_period_start: optionalIsoDate('Start of time period (YYYY-MM-DD), 2007-10-01 or later. Given alone, the period runs through today (UTC).'),
|
|
31
39
|
time_period_end: optionalIsoDate('End of time period (YYYY-MM-DD). Given alone, the period starts at 2007-10-01, the earliest searchable date.'),
|
|
32
40
|
})
|
|
@@ -83,7 +91,7 @@ const SHAPE_CODE_FORM = {
|
|
|
83
91
|
};
|
|
84
92
|
export const spendingByGeographyTool = tool('usaspending_spending_by_geography', {
|
|
85
93
|
title: 'Spending by Geography',
|
|
86
|
-
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
|
|
94
|
+
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, place of performance or recipient location, or date range. scope picks the location results are grouped by, separately from the location filters: the counties of one state are geo_layer county with filters.place_of_performance_location set to that state and scope place_of_performance. 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 a state, county, or district name to its code with usaspending_autocomplete_filters type=location. Chain per-capita results with Census population data for meaningful comparisons.',
|
|
87
95
|
annotations: { readOnlyHint: true, openWorldHint: true, idempotentHint: true },
|
|
88
96
|
input: z.object({
|
|
89
97
|
scope: z
|
|
@@ -93,13 +101,9 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
93
101
|
.enum(['state', 'county', 'district'])
|
|
94
102
|
.describe('Geographic granularity: state (states, DC, and territories), county (county-level), or district (congressional district)'),
|
|
95
103
|
filters: SpendingFiltersSchema,
|
|
96
|
-
limit:
|
|
97
|
-
.number()
|
|
98
|
-
.int()
|
|
99
|
-
.min(1)
|
|
100
|
-
.max(500)
|
|
104
|
+
limit: countInput()
|
|
101
105
|
.default(50)
|
|
102
|
-
.describe('Maximum geographic areas to return, ranked by aggregated_amount descending
|
|
106
|
+
.describe('Maximum geographic areas to return, ranked by aggregated_amount descending. Default 50, no maximum. 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; raise limit to see them all, or use shape_codes to retrieve one ranked past the cap.'),
|
|
103
107
|
shape_codes: z
|
|
104
108
|
.array(z
|
|
105
109
|
.string()
|
|
@@ -108,7 +112,7 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
108
112
|
.min(1)
|
|
109
113
|
.max(500)
|
|
110
114
|
.optional()
|
|
111
|
-
.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.'),
|
|
115
|
+
.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). usaspending_autocomplete_filters type=location resolves a state, county, or district name to its code. 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.'),
|
|
112
116
|
subawards: z
|
|
113
117
|
.boolean()
|
|
114
118
|
.default(false)
|
|
@@ -151,6 +155,10 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
151
155
|
// Agent-facing context: scope, layer, count, the applied filters, disclosure of the
|
|
152
156
|
// no-filter award-type default, the client-side cap, and a recovery notice for empty results.
|
|
153
157
|
enrichment: {
|
|
158
|
+
applied_recipient_id: z
|
|
159
|
+
.string()
|
|
160
|
+
.optional()
|
|
161
|
+
.describe('Normalized recipient hash and level sent'),
|
|
154
162
|
applied_scope: z
|
|
155
163
|
.string()
|
|
156
164
|
.describe('Location scope applied: place_of_performance or recipient_location'),
|
|
@@ -180,6 +188,14 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
180
188
|
.string()
|
|
181
189
|
.optional()
|
|
182
190
|
.describe('DEF codes sent, uppercased (comma-separated)'),
|
|
191
|
+
applied_location: z
|
|
192
|
+
.string()
|
|
193
|
+
.optional()
|
|
194
|
+
.describe('Place of performance location sent, as normalized (e.g. country=USA, state=NM, county=049)'),
|
|
195
|
+
applied_recipient_location: z
|
|
196
|
+
.string()
|
|
197
|
+
.optional()
|
|
198
|
+
.describe('Recipient location sent, as normalized (e.g. country=USA, state=WA)'),
|
|
183
199
|
applied_time_period_start: z
|
|
184
200
|
.string()
|
|
185
201
|
.optional()
|
|
@@ -202,12 +218,40 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
202
218
|
notice: z
|
|
203
219
|
.string()
|
|
204
220
|
.optional()
|
|
205
|
-
.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.'),
|
|
221
|
+
.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, recipient_id, and locations sent and how to broaden filters. Absent when none applies.'),
|
|
206
222
|
},
|
|
207
223
|
enrichmentTrailer: {
|
|
208
224
|
notice: { render: (notice) => (notice ? `> ${escapeMarkdownInline(notice)}` : '') },
|
|
209
225
|
},
|
|
210
226
|
errors: [
|
|
227
|
+
{
|
|
228
|
+
reason: 'invalid_keyword',
|
|
229
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
230
|
+
when: 'An effective keyword has fewer than three characters.',
|
|
231
|
+
retryable: false,
|
|
232
|
+
recovery: 'Supply keywords of at least three characters; whitespace is significant.',
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
reason: 'invalid_naics_code',
|
|
236
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
237
|
+
when: 'An effective NAICS code is known to be invalid.',
|
|
238
|
+
retryable: false,
|
|
239
|
+
recovery: 'Use a 2, 4, or 6 digit NAICS code from usaspending_autocomplete_filters type=naics.',
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
reason: 'invalid_recipient_id',
|
|
243
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
244
|
+
when: 'An active analytics recipient_id is malformed.',
|
|
245
|
+
retryable: false,
|
|
246
|
+
recovery: 'Use recipient_id from usaspending_search_recipients: hexadecimal 8-4-4-4-12 hash followed by uppercase -P, -C, or -R.',
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
reason: 'invalid_location',
|
|
250
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
251
|
+
when: 'filters.place_of_performance_location or filters.recipient_location names an unknown US state, a county without a state or under an armed-forces code, a county or FIPS-number state under a non-USA country, or parts that place it in different states.',
|
|
252
|
+
retryable: false,
|
|
253
|
+
recovery: "Under country USA (the default) or a US territory code, send state as a postal code (NM) or 2-digit FIPS code (35), and county as 3 digits with that state or as the 5-digit state + county code (35049). Under another country, send state as that country's own 2-letter subdivision code and no county.",
|
|
254
|
+
},
|
|
211
255
|
{
|
|
212
256
|
reason: 'api_unavailable',
|
|
213
257
|
code: JsonRpcErrorCode.ServiceUnavailable,
|
|
@@ -259,7 +303,15 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
259
303
|
geo_layer: input.geo_layer,
|
|
260
304
|
});
|
|
261
305
|
const svc = getUSASpendingService();
|
|
262
|
-
const
|
|
306
|
+
const effective = normalizeEffectiveFilters(input.filters ?? {});
|
|
307
|
+
if ('reason' in effective)
|
|
308
|
+
throw ctx.fail(effective.reason, effective.message);
|
|
309
|
+
const located = resolveLocationFilters(input.filters ?? {});
|
|
310
|
+
if (!located.ok)
|
|
311
|
+
throw ctx.fail('invalid_location', located.message);
|
|
312
|
+
const { locations } = located;
|
|
313
|
+
const { filters, timePeriod, codes } = buildFilters({ ...input.filters, ...effective });
|
|
314
|
+
applyLocationFilters(filters, locations);
|
|
263
315
|
const inverted = invertedRangeMessage(timePeriod, ANALYTICS_DATE_FIELDS);
|
|
264
316
|
if (inverted) {
|
|
265
317
|
throw ctx.fail('date_range_inverted', inverted);
|
|
@@ -319,10 +371,12 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
319
371
|
? { applied_keywords: input.filters.keywords.join(', ') }
|
|
320
372
|
: {}),
|
|
321
373
|
...(input.filters?.agency_name ? { applied_agency_name: input.filters.agency_name } : {}),
|
|
322
|
-
...(
|
|
323
|
-
|
|
374
|
+
...(effective.recipient_id ? { applied_recipient_id: effective.recipient_id } : {}),
|
|
375
|
+
...(effective.naics_codes?.length
|
|
376
|
+
? { applied_naics_codes: effective.naics_codes.join(', ') }
|
|
324
377
|
: {}),
|
|
325
378
|
...codeFilterEcho(codes),
|
|
379
|
+
...locationFilterEcho(locations),
|
|
326
380
|
...(timePeriod
|
|
327
381
|
? {
|
|
328
382
|
applied_time_period_start: timePeriod.start_date,
|
|
@@ -342,7 +396,7 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
342
396
|
const ceiling = results.at(-1)?.aggregated_amount;
|
|
343
397
|
const guidance = wanted
|
|
344
398
|
? `Showing the ${results.length} highest-obligation of the ${selected.length} selected areas. Raise limit to ${selected.length} to see every selected area.`
|
|
345
|
-
: `Showing the ${results.length} highest-obligation areas of ${areas.length}. ${
|
|
399
|
+
: `Showing the ${results.length} highest-obligation areas of ${areas.length}. Raise limit to ${areas.length} to see every area, list an omitted area's code in shape_codes, or narrow with agency_name, keywords, or a coarser geo_layer to reach the rest.`;
|
|
346
400
|
ctx.enrich.truncated({
|
|
347
401
|
shown: results.length,
|
|
348
402
|
cap: input.limit,
|
|
@@ -357,6 +411,9 @@ export const spendingByGeographyTool = tool('usaspending_spending_by_geography',
|
|
|
357
411
|
notices.push(filledBoundNotice(timePeriod, ANALYTICS_DATE_FIELDS));
|
|
358
412
|
if (areas.length === 0) {
|
|
359
413
|
const codeParts = describeCodeFilters(codes);
|
|
414
|
+
if (effective.recipient_id)
|
|
415
|
+
codeParts.push(`recipient_id=${effective.recipient_id}`);
|
|
416
|
+
codeParts.push(...describeLocationFilters(locations));
|
|
360
417
|
notices.push(`No spending data matched the filters${codeParts.length ? ` (${codeParts.join(', ')})` : ''} for the selected geography. ` +
|
|
361
418
|
'Try broader filters, a different scope (place_of_performance vs recipient_location), or remove the time period constraint.');
|
|
362
419
|
}
|