@cyanheads/usaspending-mcp-server 0.4.2 → 0.4.4
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 +428 -0
- package/CLAUDE.md +46 -19
- package/Dockerfile +10 -1
- package/README.md +118 -189
- package/changelog/0.4.x/0.4.3.md +33 -0
- package/changelog/0.4.x/0.4.4.md +31 -0
- package/changelog/template.md +9 -26
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.d.ts +2 -0
- package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.js +4 -2
- package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/dates.d.ts +95 -0
- package/dist/mcp-server/tools/definitions/dates.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/dates.js +145 -0
- package/dist/mcp-server/tools/definitions/dates.js.map +1 -0
- package/dist/mcp-server/tools/definitions/disaster-spending.tool.d.ts +10 -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 +95 -14
- package/dist/mcp-server/tools/definitions/disaster-spending.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/filters.d.ts +11 -2
- package/dist/mcp-server/tools/definitions/filters.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/filters.js +12 -5
- package/dist/mcp-server/tools/definitions/filters.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-agency.tool.d.ts +3 -1
- package/dist/mcp-server/tools/definitions/get-agency.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-agency.tool.js +7 -21
- 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 +2 -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 +2 -0
- 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 +2 -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 +2 -0
- 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 +2 -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 +2 -0
- 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 +2 -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 +3 -5
- 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 +2 -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 +2 -0
- package/dist/mcp-server/tools/definitions/get-federal-account-breakdown.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/get-federal-account.tool.d.ts +2 -0
- 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 +3 -5
- 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 +2 -0
- 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 +2 -0
- 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 -0
- package/dist/mcp-server/tools/definitions/get-recipient.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/get-recipient.tool.js +3 -5
- package/dist/mcp-server/tools/definitions/get-recipient.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/index.d.ts +118 -13
- package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/list-agencies.tool.d.ts +2 -0
- package/dist/mcp-server/tools/definitions/list-agencies.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/list-agencies.tool.js +2 -0
- package/dist/mcp-server/tools/definitions/list-agencies.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/search-awards.tool.d.ts +33 -5
- package/dist/mcp-server/tools/definitions/search-awards.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/search-awards.tool.js +215 -60
- 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 +2 -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 +2 -0
- 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 +2 -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 +2 -0
- 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 +16 -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 +46 -12
- 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 +16 -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 +51 -19
- 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 +16 -2
- 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 +46 -12
- package/dist/mcp-server/tools/definitions/spending-over-time.tool.js.map +1 -1
- package/dist/services/usaspending/types.d.ts +28 -2
- package/dist/services/usaspending/types.d.ts.map +1 -1
- package/dist/services/usaspending/usaspending-service.d.ts +10 -14
- package/dist/services/usaspending/usaspending-service.d.ts.map +1 -1
- package/dist/services/usaspending/usaspending-service.js +110 -4
- package/dist/services/usaspending/usaspending-service.js.map +1 -1
- package/package.json +12 -10
- package/server.json +3 -3
|
@@ -11,9 +11,10 @@ export declare const searchAwardsTool: import("@cyanheads/mcp-ts-core").ToolDefi
|
|
|
11
11
|
agency_name: z.ZodOptional<z.ZodString>;
|
|
12
12
|
recipient_name: z.ZodOptional<z.ZodString>;
|
|
13
13
|
naics_codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
14
|
+
assistance_listings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
14
15
|
time_period: z.ZodOptional<z.ZodObject<{
|
|
15
|
-
start_date: z.ZodString
|
|
16
|
-
end_date: z.ZodString
|
|
16
|
+
start_date: z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>;
|
|
17
|
+
end_date: z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>;
|
|
17
18
|
}, z.core.$strip>>;
|
|
18
19
|
location_filter: z.ZodOptional<z.ZodObject<{
|
|
19
20
|
country: z.ZodOptional<z.ZodString>;
|
|
@@ -21,12 +22,15 @@ export declare const searchAwardsTool: import("@cyanheads/mcp-ts-core").ToolDefi
|
|
|
21
22
|
county: z.ZodOptional<z.ZodString>;
|
|
22
23
|
city: z.ZodOptional<z.ZodString>;
|
|
23
24
|
}, z.core.$strip>>;
|
|
24
|
-
sort: z.
|
|
25
|
+
sort: z.ZodOptional<z.ZodEnum<{
|
|
25
26
|
"Award Amount": "Award Amount";
|
|
26
27
|
"Awarding Agency": "Awarding Agency";
|
|
27
28
|
"End Date": "End Date";
|
|
29
|
+
"Issued Date": "Issued Date";
|
|
30
|
+
"Loan Value": "Loan Value";
|
|
28
31
|
"Recipient Name": "Recipient Name";
|
|
29
32
|
"Start Date": "Start Date";
|
|
33
|
+
"Subsidy Cost": "Subsidy Cost";
|
|
30
34
|
"Total Outlays": "Total Outlays";
|
|
31
35
|
}>>;
|
|
32
36
|
order: z.ZodDefault<z.ZodEnum<{
|
|
@@ -43,8 +47,8 @@ export declare const searchAwardsTool: import("@cyanheads/mcp-ts-core").ToolDefi
|
|
|
43
47
|
agency_name: z.ZodOptional<z.ZodString>;
|
|
44
48
|
recipient_name: z.ZodOptional<z.ZodString>;
|
|
45
49
|
naics_codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
46
|
-
time_period_start: z.ZodOptional<z.ZodString
|
|
47
|
-
time_period_end: z.ZodOptional<z.ZodString
|
|
50
|
+
time_period_start: z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
|
|
51
|
+
time_period_end: z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
|
|
48
52
|
}, z.core.$strip>>;
|
|
49
53
|
}, z.core.$strip>, z.ZodObject<{
|
|
50
54
|
results: z.ZodArray<z.ZodObject<{
|
|
@@ -53,6 +57,9 @@ export declare const searchAwardsTool: import("@cyanheads/mcp-ts-core").ToolDefi
|
|
|
53
57
|
recipient_name: z.ZodOptional<z.ZodString>;
|
|
54
58
|
award_amount: z.ZodOptional<z.ZodNumber>;
|
|
55
59
|
total_outlays: z.ZodOptional<z.ZodNumber>;
|
|
60
|
+
loan_value: z.ZodOptional<z.ZodNumber>;
|
|
61
|
+
subsidy_cost: z.ZodOptional<z.ZodNumber>;
|
|
62
|
+
issued_date: z.ZodOptional<z.ZodString>;
|
|
56
63
|
awarding_agency: z.ZodOptional<z.ZodString>;
|
|
57
64
|
awarding_sub_agency: z.ZodOptional<z.ZodString>;
|
|
58
65
|
agency_slug: z.ZodOptional<z.ZodString>;
|
|
@@ -79,12 +86,14 @@ export declare const searchAwardsTool: import("@cyanheads/mcp-ts-core").ToolDefi
|
|
|
79
86
|
readonly code: JsonRpcErrorCode.ServiceUnavailable;
|
|
80
87
|
readonly when: "USAspending.gov API is unreachable or returns an error.";
|
|
81
88
|
readonly retryable: true;
|
|
89
|
+
readonly thrownBy: "service";
|
|
82
90
|
readonly recovery: "The API may be temporarily down. Retry the request after a few seconds.";
|
|
83
91
|
}, {
|
|
84
92
|
readonly reason: "api_timeout";
|
|
85
93
|
readonly code: JsonRpcErrorCode.Timeout;
|
|
86
94
|
readonly when: "USAspending.gov did not respond before the request deadline elapsed.";
|
|
87
95
|
readonly retryable: true;
|
|
96
|
+
readonly thrownBy: "service";
|
|
88
97
|
readonly recovery: "Narrow the search — a shorter time_period, fewer award_type_codes, or a smaller limit — then retry.";
|
|
89
98
|
}, {
|
|
90
99
|
readonly reason: "pagination_limit_exceeded";
|
|
@@ -98,6 +107,24 @@ export declare const searchAwardsTool: import("@cyanheads/mcp-ts-core").ToolDefi
|
|
|
98
107
|
readonly when: "The resolved start date precedes the 2007-10-01 earliest date this endpoint can search.";
|
|
99
108
|
readonly retryable: false;
|
|
100
109
|
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.";
|
|
110
|
+
}, {
|
|
111
|
+
readonly reason: "date_range_inverted";
|
|
112
|
+
readonly code: JsonRpcErrorCode.ValidationError;
|
|
113
|
+
readonly when: "Both ends of the date range were supplied and the start date falls after the end date.";
|
|
114
|
+
readonly retryable: false;
|
|
115
|
+
readonly recovery: "Swap the two dates so the start date is on or before the end date, then retry.";
|
|
116
|
+
}, {
|
|
117
|
+
readonly reason: "unsupported_sort";
|
|
118
|
+
readonly code: JsonRpcErrorCode.ValidationError;
|
|
119
|
+
readonly when: "The sort value is not one the award type group supports.";
|
|
120
|
+
readonly retryable: false;
|
|
121
|
+
readonly recovery: "Re-request with one of the sorts the error lists for this award type group, or omit sort to use the group default (Loan Value for loans, Award Amount otherwise).";
|
|
122
|
+
}, {
|
|
123
|
+
readonly reason: "assistance_listings_type_mismatch";
|
|
124
|
+
readonly code: JsonRpcErrorCode.ValidationError;
|
|
125
|
+
readonly when: "assistance_listings was given while the award type codes include contract or IDV codes, or were left at the contract default.";
|
|
126
|
+
readonly retryable: false;
|
|
127
|
+
readonly recovery: "Set award_type_codes to one assistance group — 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 — alongside assistance_listings.";
|
|
101
128
|
}], {
|
|
102
129
|
readonly page: z.ZodNumber;
|
|
103
130
|
readonly has_next: z.ZodBoolean;
|
|
@@ -108,6 +135,7 @@ export declare const searchAwardsTool: import("@cyanheads/mcp-ts-core").ToolDefi
|
|
|
108
135
|
readonly applied_keyword: z.ZodOptional<z.ZodString>;
|
|
109
136
|
readonly applied_agency_name: z.ZodOptional<z.ZodString>;
|
|
110
137
|
readonly applied_naics_codes: z.ZodOptional<z.ZodString>;
|
|
138
|
+
readonly applied_assistance_listings: z.ZodOptional<z.ZodString>;
|
|
111
139
|
readonly applied_time_period_start: z.ZodOptional<z.ZodString>;
|
|
112
140
|
readonly applied_time_period_end: z.ZodOptional<z.ZodString>;
|
|
113
141
|
readonly notice: z.ZodOptional<z.ZodString>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search-awards.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/search-awards.tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAQ,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAmB,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"search-awards.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/search-awards.tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAQ,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAmB,MAAM,+BAA+B,CAAC;AAiJlF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+rB3B,CAAC"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { tool, z } from '@cyanheads/mcp-ts-core';
|
|
7
7
|
import { JsonRpcErrorCode, validationError } from '@cyanheads/mcp-ts-core/errors';
|
|
8
8
|
import { getUSASpendingService } from '../../../services/usaspending/usaspending-service.js';
|
|
9
|
+
import { ANALYTICS_DATE_FIELDS, blankableIsoDate, filledBoundNotice, floorViolationMessage, invertedRangeMessage, optionalIsoDate, resolveDateRange, } from './dates.js';
|
|
9
10
|
import { formatCurrency } from './formatting.js';
|
|
10
11
|
import { resolveHasNext } from './pagination.js';
|
|
11
12
|
/** Award search default fields — covers summary + chaining IDs. */
|
|
@@ -30,6 +31,79 @@ const AWARD_SEARCH_FIELDS = [
|
|
|
30
31
|
'Awarding Agency Code',
|
|
31
32
|
'agency_slug',
|
|
32
33
|
];
|
|
34
|
+
/**
|
|
35
|
+
* Loan-only fields. A loan row carries no Award Amount, Total Outlays, or
|
|
36
|
+
* dates, and upstream sorts only by a field the request names, so a loan search
|
|
37
|
+
* requests these on top of {@link AWARD_SEARCH_FIELDS}.
|
|
38
|
+
*/
|
|
39
|
+
const LOAN_FIELDS = ['Loan Value', 'Subsidy Cost', 'Issued Date'];
|
|
40
|
+
const CONTRACT_SORTS = [
|
|
41
|
+
'Award Amount',
|
|
42
|
+
'Total Outlays',
|
|
43
|
+
'Start Date',
|
|
44
|
+
'End Date',
|
|
45
|
+
'Recipient Name',
|
|
46
|
+
'Awarding Agency',
|
|
47
|
+
];
|
|
48
|
+
const LOAN_SORTS = [
|
|
49
|
+
'Loan Value',
|
|
50
|
+
'Subsidy Cost',
|
|
51
|
+
'Issued Date',
|
|
52
|
+
'Recipient Name',
|
|
53
|
+
'Awarding Agency',
|
|
54
|
+
];
|
|
55
|
+
/**
|
|
56
|
+
* The award-type groups `search/spending_by_award/` accepts one at a time — the
|
|
57
|
+
* partition its mixed-group 422 lists, F-codes and -1 included — and the sorts
|
|
58
|
+
* each group's field mapping allows; upstream answers any other sort with a 400.
|
|
59
|
+
* IDVs have no End Date; loans have no amount or date fields of the contract
|
|
60
|
+
* kind and sort by their own. Labels follow USAspending's type names.
|
|
61
|
+
*/
|
|
62
|
+
const AWARD_TYPE_GROUPS = {
|
|
63
|
+
contracts: { label: 'contracts', codes: ['A', 'B', 'C', 'D'], sorts: CONTRACT_SORTS },
|
|
64
|
+
idvs: {
|
|
65
|
+
label: 'IDVs',
|
|
66
|
+
codes: ['IDV_A', 'IDV_B', 'IDV_B_A', 'IDV_B_B', 'IDV_B_C', 'IDV_C', 'IDV_D', 'IDV_E'],
|
|
67
|
+
sorts: CONTRACT_SORTS.filter((sort) => sort !== 'End Date'),
|
|
68
|
+
},
|
|
69
|
+
grants: {
|
|
70
|
+
label: 'grants',
|
|
71
|
+
codes: ['02', '03', '04', '05', 'F001', 'F002'],
|
|
72
|
+
sorts: CONTRACT_SORTS,
|
|
73
|
+
},
|
|
74
|
+
direct_payments: {
|
|
75
|
+
label: 'direct payments',
|
|
76
|
+
codes: ['06', '10', 'F006', 'F007'],
|
|
77
|
+
sorts: CONTRACT_SORTS,
|
|
78
|
+
},
|
|
79
|
+
loans: { label: 'loans', codes: ['07', '08', 'F003', 'F004'], sorts: LOAN_SORTS },
|
|
80
|
+
other: {
|
|
81
|
+
label: 'other',
|
|
82
|
+
codes: ['09', '11', '-1', 'F005', 'F008', 'F009', 'F010'],
|
|
83
|
+
sorts: CONTRACT_SORTS,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* The group every code belongs to, or `undefined` when the codes span groups or
|
|
88
|
+
* include one outside them — upstream's own 422 then decides, unguessed.
|
|
89
|
+
*/
|
|
90
|
+
function resolveAwardTypeGroup(codes) {
|
|
91
|
+
const groups = new Set(codes.map((code) => Object.values(AWARD_TYPE_GROUPS).find((g) => g.codes.includes(code))));
|
|
92
|
+
const [only] = groups;
|
|
93
|
+
return groups.size === 1 ? only : undefined;
|
|
94
|
+
}
|
|
95
|
+
/** Codes that never carry an assistance listing: contracts and IDVs. */
|
|
96
|
+
const NON_ASSISTANCE_CODES = new Set([
|
|
97
|
+
...AWARD_TYPE_GROUPS.contracts.codes,
|
|
98
|
+
...AWARD_TYPE_GROUPS.idvs.codes,
|
|
99
|
+
]);
|
|
100
|
+
/** The flat `time_period` object's field paths, as messages name them. */
|
|
101
|
+
const FLAT_DATE_FIELDS = {
|
|
102
|
+
start: 'time_period.start_date',
|
|
103
|
+
end: 'time_period.end_date',
|
|
104
|
+
};
|
|
105
|
+
/** Assistance Listing (CFDA) number: two digits, a dot, three digits or capitals (`11.67A`). */
|
|
106
|
+
const ASSISTANCE_LISTING_PATTERN = /^\d{2}\.[0-9A-Z]{3}$/;
|
|
33
107
|
/**
|
|
34
108
|
* Page-number pagination on search/spending_by_award/ caps at a 50,000-result offset
|
|
35
109
|
* (page × limit). Past that boundary the endpoint requires keyset (after-cursor)
|
|
@@ -45,16 +119,9 @@ const MAX_PAGE_OFFSET = 50_000;
|
|
|
45
119
|
* the cursor must capture it before crossing this line.
|
|
46
120
|
*/
|
|
47
121
|
const CURSOR_WINDOW_OFFSET = 10_000;
|
|
48
|
-
/**
|
|
49
|
-
* Earliest action date search/spending_by_award/ will accept. A start_date before
|
|
50
|
-
* this floor makes the endpoint return a raw HTML 500 with no explanation — unlike
|
|
51
|
-
* the sibling analytics endpoints, which reject the same input with a graceful 422
|
|
52
|
-
* naming the floor. Guarded client-side so the caller gets the boundary instead.
|
|
53
|
-
*/
|
|
54
|
-
const EARLIEST_SEARCH_DATE = '2007-10-01';
|
|
55
122
|
export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
56
123
|
title: 'Search Federal Awards',
|
|
57
|
-
description: 'Search federal awards by keyword, recipient, agency, award type, NAICS code, location, or date range. Returns ranked award summaries including recipient names, amounts, awarding agencies, and generated award IDs for use with usaspending_get_award. Award types: A/B/C/D = contracts, 02/03/04/05 = grants, 06/10 = direct payments, 07/08 = loans,
|
|
124
|
+
description: 'Search federal awards by keyword, recipient, agency, award type, NAICS code, assistance listing (CFDA) number, location, or date range. Returns ranked award summaries including recipient names, amounts, awarding agencies, and generated award IDs for use with usaspending_get_award; loan rows carry loan value, subsidy cost, and issue date in place of award amount and dates. Award types: A/B/C/D = contracts, IDV_A–IDV_E = IDVs, 02/03/04/05/F001/F002 = grants, 06/10/F006/F007 = direct payments, 07/08/F003/F004 = loans, 09/11/-1/F005/F008/F009/F010 = other assistance. Dates must be ISO 8601 (YYYY-MM-DD). Earliest data: 2007-10-01 via search API. DoD contracts have a 90-day publication lag.',
|
|
58
125
|
annotations: { readOnlyHint: true, openWorldHint: true, idempotentHint: true },
|
|
59
126
|
input: z.object({
|
|
60
127
|
keyword: z
|
|
@@ -63,8 +130,9 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
63
130
|
.describe('Full-text search across award descriptions, recipient names, and place names'),
|
|
64
131
|
award_type_codes: z
|
|
65
132
|
.array(z.string())
|
|
133
|
+
.min(1)
|
|
66
134
|
.default(['A', 'B', 'C', 'D'])
|
|
67
|
-
.describe('Filter by award type codes. All codes must belong to a single group: A/B/C/D (contracts), 02/03/04/05 (grants), 06/10 (direct payments), 07/08 (loans),
|
|
135
|
+
.describe('Filter by award type codes. All codes must belong to a single group: A/B/C/D (contracts), IDV_A/IDV_B/IDV_B_A/IDV_B_B/IDV_B_C/IDV_C/IDV_D/IDV_E (IDVs), 02/03/04/05/F001/F002 (grants), 06/10/F006/F007 (direct payments), 07/08/F003/F004 (loans), 09/11/-1/F005/F008/F009/F010 (other assistance). Defaults to contracts. Mixing groups causes a 422 error. The group decides which sort values apply.'),
|
|
68
136
|
agency_name: z
|
|
69
137
|
.string()
|
|
70
138
|
.optional()
|
|
@@ -77,15 +145,20 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
77
145
|
.array(z.string())
|
|
78
146
|
.optional()
|
|
79
147
|
.describe('Filter by NAICS industry codes (e.g., ["541512"]). Use usaspending_autocomplete_filters type=naics to look up codes.'),
|
|
148
|
+
assistance_listings: z
|
|
149
|
+
.array(z
|
|
150
|
+
.string()
|
|
151
|
+
.regex(ASSISTANCE_LISTING_PATTERN, 'Expected an Assistance Listing number as NN.NNN (e.g. 93.866 or 11.67A)')
|
|
152
|
+
.describe('Assistance Listing number, e.g. 93.866'))
|
|
153
|
+
.optional()
|
|
154
|
+
.describe('Filter by Assistance Listing (CFDA) program numbers, e.g. ["93.866"]: two digits, a dot, then three digits or capital letters (11.67A). Matches an award when any of its listings equals one of these exactly; several values match any of them. A row\'s primary listing can differ from the one requested, and its amount is the whole award, not that listing\'s share. Assistance award types only — set award_type_codes to grants, direct payments, loans, or other assistance; contracts and IDVs carry no listings, so pairing them (including the default award_type_codes) is rejected. Use usaspending_autocomplete_filters type=cfda to look up numbers.'),
|
|
80
155
|
time_period: z
|
|
81
156
|
.object({
|
|
82
|
-
start_date:
|
|
83
|
-
|
|
84
|
-
.describe('Start date in ISO 8601 format (YYYY-MM-DD); earliest valid: 2007-10-01'),
|
|
85
|
-
end_date: z.string().describe('End date in ISO 8601 format (YYYY-MM-DD)'),
|
|
157
|
+
start_date: blankableIsoDate('Start date in ISO 8601 format (YYYY-MM-DD); earliest valid: 2007-10-01. Blank ("") leaves the start open, filled with 2007-10-01.'),
|
|
158
|
+
end_date: blankableIsoDate('End date in ISO 8601 format (YYYY-MM-DD). Blank ("") leaves the end open, filled with today (UTC).'),
|
|
86
159
|
})
|
|
87
160
|
.optional()
|
|
88
|
-
.describe('Filter awards by date range (action date)'),
|
|
161
|
+
.describe('Filter awards by date range (action date). Both blank means no date filter; one blank end is filled and named in the notice.'),
|
|
89
162
|
location_filter: z
|
|
90
163
|
.object({
|
|
91
164
|
country: z.string().optional().describe('ISO 3166-1 alpha-3 country code (e.g., USA)'),
|
|
@@ -104,11 +177,14 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
104
177
|
'Total Outlays',
|
|
105
178
|
'Start Date',
|
|
106
179
|
'End Date',
|
|
180
|
+
'Loan Value',
|
|
181
|
+
'Subsidy Cost',
|
|
182
|
+
'Issued Date',
|
|
107
183
|
'Recipient Name',
|
|
108
184
|
'Awarding Agency',
|
|
109
185
|
])
|
|
110
|
-
.
|
|
111
|
-
.describe('Sort field for results'),
|
|
186
|
+
.optional()
|
|
187
|
+
.describe('Sort field for results. Loans (07/08/F003/F004) sort by Loan Value, Subsidy Cost, Issued Date, Recipient Name, or Awarding Agency, defaulting to Loan Value. Every other group sorts by Award Amount, Total Outlays, Start Date, End Date, Recipient Name, or Awarding Agency, defaulting to Award Amount — except IDVs, which have no End Date. A sort the group does not support is rejected before the search runs.'),
|
|
112
188
|
order: z.enum(['asc', 'desc']).default('desc').describe('Sort direction'),
|
|
113
189
|
limit: z
|
|
114
190
|
.number()
|
|
@@ -141,7 +217,7 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
141
217
|
award_type_codes: z
|
|
142
218
|
.array(z.string())
|
|
143
219
|
.optional()
|
|
144
|
-
.describe('Award type codes; all must belong to one group (A/B/C/D, 02/03/04/05, 06/10, 07/08,
|
|
220
|
+
.describe('Award type codes; all must belong to one group (A/B/C/D contracts, IDV_A–IDV_E IDVs, 02/03/04/05/F001/F002 grants, 06/10/F006/F007 direct payments, 07/08/F003/F004 loans, 09/11/-1/F005/F008/F009/F010 other assistance). When non-empty, overrides the top-level award_type_codes and decides which sort values apply; an empty array falls back to the top-level value.'),
|
|
145
221
|
agency_name: z
|
|
146
222
|
.string()
|
|
147
223
|
.optional()
|
|
@@ -154,14 +230,8 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
154
230
|
.array(z.string())
|
|
155
231
|
.optional()
|
|
156
232
|
.describe('NAICS industry codes to require, e.g., ["541512"]'),
|
|
157
|
-
time_period_start:
|
|
158
|
-
|
|
159
|
-
.optional()
|
|
160
|
-
.describe('Start date (YYYY-MM-DD); earliest valid 2007-10-01. Requires time_period_end.'),
|
|
161
|
-
time_period_end: z
|
|
162
|
-
.string()
|
|
163
|
-
.optional()
|
|
164
|
-
.describe('End date (YYYY-MM-DD). Requires time_period_start.'),
|
|
233
|
+
time_period_start: optionalIsoDate('Start date (YYYY-MM-DD); earliest valid 2007-10-01. Given alone, the range runs through today (UTC).'),
|
|
234
|
+
time_period_end: optionalIsoDate('End date (YYYY-MM-DD). Given alone, the range starts at 2007-10-01, the earliest searchable date.'),
|
|
165
235
|
})
|
|
166
236
|
.optional()
|
|
167
237
|
.describe('Optional analytics-style filter object mirroring the shape the spending analytics tools accept, for reusing one filter set across tools. When both this object and the equivalent top-level flat filters are given, this object wins per-field. recipient_id is intentionally not accepted — this endpoint silently ignores it; filter by recipient via recipient_name.'),
|
|
@@ -181,6 +251,18 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
181
251
|
recipient_name: z.string().optional().describe('Name of the award recipient'),
|
|
182
252
|
award_amount: z.number().optional().describe('Total award amount in USD'),
|
|
183
253
|
total_outlays: z.number().optional().describe('Total outlays in USD'),
|
|
254
|
+
loan_value: z
|
|
255
|
+
.number()
|
|
256
|
+
.optional()
|
|
257
|
+
.describe('Face value of the loan in USD (loans only — they carry no award_amount)'),
|
|
258
|
+
subsidy_cost: z
|
|
259
|
+
.number()
|
|
260
|
+
.optional()
|
|
261
|
+
.describe('Original subsidy cost of the loan in USD — the estimated long-term cost to the government (loans only)'),
|
|
262
|
+
issued_date: z
|
|
263
|
+
.string()
|
|
264
|
+
.optional()
|
|
265
|
+
.describe('Date the loan was issued (YYYY-MM-DD; loans only — they carry no start or end date)'),
|
|
184
266
|
awarding_agency: z.string().optional().describe('Name of the awarding agency'),
|
|
185
267
|
awarding_sub_agency: z.string().optional().describe('Name of the awarding sub-agency'),
|
|
186
268
|
agency_slug: z
|
|
@@ -245,15 +327,22 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
245
327
|
.string()
|
|
246
328
|
.optional()
|
|
247
329
|
.describe('NAICS codes filter applied (comma-separated)'),
|
|
330
|
+
applied_assistance_listings: z
|
|
331
|
+
.string()
|
|
332
|
+
.optional()
|
|
333
|
+
.describe('Assistance Listing numbers filter applied (comma-separated)'),
|
|
248
334
|
applied_time_period_start: z
|
|
249
335
|
.string()
|
|
250
336
|
.optional()
|
|
251
|
-
.describe('Start date
|
|
252
|
-
applied_time_period_end: z
|
|
337
|
+
.describe('Start of the date range sent (YYYY-MM-DD), including a filled-in start'),
|
|
338
|
+
applied_time_period_end: z
|
|
339
|
+
.string()
|
|
340
|
+
.optional()
|
|
341
|
+
.describe('End of the date range sent (YYYY-MM-DD), including a filled-in end'),
|
|
253
342
|
notice: z
|
|
254
343
|
.string()
|
|
255
344
|
.optional()
|
|
256
|
-
.describe('
|
|
345
|
+
.describe('How to page on when more results may remain, which date bound was filled in when only the other was supplied, and — when results are empty — the applied filters with how to broaden. Absent when none applies.'),
|
|
257
346
|
},
|
|
258
347
|
// upstream_messages is an array — supply a markdown renderer so the content[] trailer
|
|
259
348
|
// shows a bullet list instead of a one-line JSON blob (structuredContent is unaffected).
|
|
@@ -279,6 +368,7 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
279
368
|
code: JsonRpcErrorCode.ServiceUnavailable,
|
|
280
369
|
when: 'USAspending.gov API is unreachable or returns an error.',
|
|
281
370
|
retryable: true,
|
|
371
|
+
thrownBy: 'service',
|
|
282
372
|
recovery: 'The API may be temporarily down. Retry the request after a few seconds.',
|
|
283
373
|
},
|
|
284
374
|
{
|
|
@@ -286,6 +376,7 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
286
376
|
code: JsonRpcErrorCode.Timeout,
|
|
287
377
|
when: 'USAspending.gov did not respond before the request deadline elapsed.',
|
|
288
378
|
retryable: true,
|
|
379
|
+
thrownBy: 'service',
|
|
289
380
|
recovery: 'Narrow the search — a shorter time_period, fewer award_type_codes, or a smaller limit — then retry.',
|
|
290
381
|
},
|
|
291
382
|
{
|
|
@@ -302,6 +393,27 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
302
393
|
retryable: false,
|
|
303
394
|
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.',
|
|
304
395
|
},
|
|
396
|
+
{
|
|
397
|
+
reason: 'date_range_inverted',
|
|
398
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
399
|
+
when: 'Both ends of the date range were supplied and the start date falls after the end date.',
|
|
400
|
+
retryable: false,
|
|
401
|
+
recovery: 'Swap the two dates so the start date is on or before the end date, then retry.',
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
reason: 'unsupported_sort',
|
|
405
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
406
|
+
when: 'The sort value is not one the award type group supports.',
|
|
407
|
+
retryable: false,
|
|
408
|
+
recovery: 'Re-request with one of the sorts the error lists for this award type group, or omit sort to use the group default (Loan Value for loans, Award Amount otherwise).',
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
reason: 'assistance_listings_type_mismatch',
|
|
412
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
413
|
+
when: 'assistance_listings was given while the award type codes include contract or IDV codes, or were left at the contract default.',
|
|
414
|
+
retryable: false,
|
|
415
|
+
recovery: 'Set award_type_codes to one assistance group — 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 — alongside assistance_listings.',
|
|
416
|
+
},
|
|
305
417
|
],
|
|
306
418
|
async handler(input, ctx) {
|
|
307
419
|
ctx.log.info('usaspending_search_awards', {
|
|
@@ -321,11 +433,7 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
321
433
|
// Page-number pagination caps at a 50,000-result offset; fail fast with the cursor
|
|
322
434
|
// recovery path instead of letting the upstream 422 bubble up unclassified.
|
|
323
435
|
if (!usingCursor && input.page * input.limit > MAX_PAGE_OFFSET) {
|
|
324
|
-
throw ctx.fail('pagination_limit_exceeded', `Requested page ${input.page} at limit ${input.limit} exceeds this endpoint's ${MAX_PAGE_OFFSET.toLocaleString()}-result page-number window.`,
|
|
325
|
-
recovery: {
|
|
326
|
-
hint: `Continue via keyset pagination with last_record_sort_value and last_record_unique_id. The endpoint only returns that pair while page × limit stays under ${CURSOR_WINDOW_OFFSET.toLocaleString()}, so re-page from within that window to capture it.`,
|
|
327
|
-
},
|
|
328
|
-
});
|
|
436
|
+
throw ctx.fail('pagination_limit_exceeded', `Requested page ${input.page} at limit ${input.limit} exceeds this endpoint's ${MAX_PAGE_OFFSET.toLocaleString()}-result page-number window.`, ctx.recoveryFor('pagination_limit_exceeded'));
|
|
329
437
|
}
|
|
330
438
|
// Merge the analytics-style `filters` object over the flat inputs (nested wins
|
|
331
439
|
// per-field). recipient_id is intentionally never mapped: search/spending_by_award/
|
|
@@ -336,24 +444,49 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
336
444
|
: input.keyword
|
|
337
445
|
? [input.keyword]
|
|
338
446
|
: undefined;
|
|
339
|
-
const awardTypeCodes = f?.award_type_codes
|
|
447
|
+
const awardTypeCodes = f?.award_type_codes?.length
|
|
340
448
|
? f.award_type_codes
|
|
341
449
|
: input.award_type_codes;
|
|
342
450
|
const agencyName = f?.agency_name || input.agency_name;
|
|
343
451
|
const recipientName = f?.recipient_name || input.recipient_name;
|
|
344
452
|
const naicsCodes = f?.naics_codes && f.naics_codes.length > 0 ? f.naics_codes : input.naics_codes;
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
//
|
|
348
|
-
//
|
|
349
|
-
|
|
350
|
-
//
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
453
|
+
// Both input paths (the flat time_period and the nested filters.time_period_*)
|
|
454
|
+
// merge here, nested winning per bound; a blank reads as absent. A lone bound
|
|
455
|
+
// is filled to a two-ended range, padded, so a half-blank flat pair is a lone
|
|
456
|
+
// bound and a fully blank one is no range at all.
|
|
457
|
+
const timePeriod = resolveDateRange(f?.time_period_start || input.time_period?.start_date, f?.time_period_end || input.time_period?.end_date);
|
|
458
|
+
// Messages name the path each bound came from. Only a lone bound is filled,
|
|
459
|
+
// so the omitted field belongs to the same path as the one supplied.
|
|
460
|
+
const dateFields = {
|
|
461
|
+
start: f?.time_period_start ? ANALYTICS_DATE_FIELDS.start : FLAT_DATE_FIELDS.start,
|
|
462
|
+
end: f?.time_period_end ? ANALYTICS_DATE_FIELDS.end : FLAT_DATE_FIELDS.end,
|
|
463
|
+
};
|
|
464
|
+
const filledFields = f?.time_period_start || f?.time_period_end ? ANALYTICS_DATE_FIELDS : FLAT_DATE_FIELDS;
|
|
465
|
+
// Upstream ignores an inverted range here and returns rows outside it, so the
|
|
466
|
+
// echo would claim a window that was never applied.
|
|
467
|
+
const inverted = invertedRangeMessage(timePeriod, dateFields);
|
|
468
|
+
if (inverted) {
|
|
469
|
+
throw ctx.fail('date_range_inverted', inverted, ctx.recoveryFor('date_range_inverted'));
|
|
470
|
+
}
|
|
471
|
+
// Upstream rejects a start before the floor with its own 422; failing here
|
|
472
|
+
// instead carries the declared reason and the bulk-download recovery.
|
|
473
|
+
const beforeFloor = floorViolationMessage(timePeriod);
|
|
474
|
+
if (beforeFloor) {
|
|
475
|
+
throw ctx.fail('date_before_earliest', beforeFloor, ctx.recoveryFor('date_before_earliest'));
|
|
476
|
+
}
|
|
477
|
+
// Contracts and IDVs carry no listings: upstream answers 200 with zero rows and
|
|
478
|
+
// no message, which reads as "no such awards" rather than a mismatched filter.
|
|
479
|
+
const listings = input.assistance_listings?.length ? input.assistance_listings : undefined;
|
|
480
|
+
if (listings && awardTypeCodes.some((code) => NON_ASSISTANCE_CODES.has(code))) {
|
|
481
|
+
throw ctx.fail('assistance_listings_type_mismatch', `assistance_listings match only assistance awards, but award_type_codes [${awardTypeCodes.join(', ')}] include contract or IDV codes, which carry no listings. award_type_codes defaults to contracts when omitted.`, ctx.recoveryFor('assistance_listings_type_mismatch'));
|
|
482
|
+
}
|
|
483
|
+
// Upstream checks the sort against the group's field mapping and answers 400
|
|
484
|
+
// outside it. Codes spanning groups skip the check: upstream's 422 decides.
|
|
485
|
+
const group = resolveAwardTypeGroup(awardTypeCodes);
|
|
486
|
+
const isLoan = group === AWARD_TYPE_GROUPS.loans;
|
|
487
|
+
const sort = input.sort ?? (isLoan ? 'Loan Value' : 'Award Amount');
|
|
488
|
+
if (group && !group.sorts.includes(sort)) {
|
|
489
|
+
throw ctx.fail('unsupported_sort', `Sort "${sort}" is not available for ${group.label} (award_type_codes ${awardTypeCodes.join(', ')}). Supported sorts for ${group.label}: ${group.sorts.join(', ')}.`, ctx.recoveryFor('unsupported_sort'));
|
|
357
490
|
}
|
|
358
491
|
const filters = {};
|
|
359
492
|
if (keywords?.length)
|
|
@@ -367,8 +500,10 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
367
500
|
if (naicsCodes?.length) {
|
|
368
501
|
filters.naics_codes = { require: naicsCodes };
|
|
369
502
|
}
|
|
370
|
-
if (
|
|
371
|
-
filters.
|
|
503
|
+
if (listings)
|
|
504
|
+
filters.program_numbers = listings;
|
|
505
|
+
if (timePeriod) {
|
|
506
|
+
filters.time_period = [{ start_date: timePeriod.start_date, end_date: timePeriod.end_date }];
|
|
372
507
|
}
|
|
373
508
|
if (input.location_filter &&
|
|
374
509
|
(input.location_filter.country ||
|
|
@@ -388,8 +523,8 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
388
523
|
}
|
|
389
524
|
const data = await svc.searchAwards({
|
|
390
525
|
filters,
|
|
391
|
-
fields: AWARD_SEARCH_FIELDS,
|
|
392
|
-
sort
|
|
526
|
+
fields: isLoan ? [...AWARD_SEARCH_FIELDS, ...LOAN_FIELDS] : AWARD_SEARCH_FIELDS,
|
|
527
|
+
sort,
|
|
393
528
|
order: input.order,
|
|
394
529
|
limit: input.limit,
|
|
395
530
|
// page and cursor are mutually exclusive; omit page when paging by cursor.
|
|
@@ -409,6 +544,9 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
409
544
|
...(r['Recipient Name'] ? { recipient_name: String(r['Recipient Name']) } : {}),
|
|
410
545
|
...(typeof r['Award Amount'] === 'number' ? { award_amount: r['Award Amount'] } : {}),
|
|
411
546
|
...(typeof r['Total Outlays'] === 'number' ? { total_outlays: r['Total Outlays'] } : {}),
|
|
547
|
+
...(typeof r['Loan Value'] === 'number' ? { loan_value: r['Loan Value'] } : {}),
|
|
548
|
+
...(typeof r['Subsidy Cost'] === 'number' ? { subsidy_cost: r['Subsidy Cost'] } : {}),
|
|
549
|
+
...(r['Issued Date'] ? { issued_date: String(r['Issued Date']) } : {}),
|
|
412
550
|
...(r['Awarding Agency'] ? { awarding_agency: String(r['Awarding Agency']) } : {}),
|
|
413
551
|
...(r['Awarding Sub Agency']
|
|
414
552
|
? { awarding_sub_agency: String(r['Awarding Sub Agency']) }
|
|
@@ -470,32 +608,43 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
470
608
|
...(keywords?.length ? { applied_keyword: keywords.join(', ') } : {}),
|
|
471
609
|
...(agencyName ? { applied_agency_name: agencyName } : {}),
|
|
472
610
|
...(naicsCodes?.length ? { applied_naics_codes: naicsCodes.join(', ') } : {}),
|
|
473
|
-
...(
|
|
474
|
-
...(
|
|
611
|
+
...(listings ? { applied_assistance_listings: listings.join(', ') } : {}),
|
|
612
|
+
...(timePeriod
|
|
613
|
+
? {
|
|
614
|
+
applied_time_period_start: timePeriod.start_date,
|
|
615
|
+
applied_time_period_end: timePeriod.end_date,
|
|
616
|
+
}
|
|
617
|
+
: {}),
|
|
475
618
|
});
|
|
619
|
+
// enrich.notice is last-wins, and enrich.truncated writes the notice too, so
|
|
620
|
+
// every notice source joins into one string written at the end.
|
|
621
|
+
const notices = [];
|
|
476
622
|
// Disclose page-based truncation: a capped page with more results behind has_next
|
|
477
623
|
// (this endpoint returns no total, so the cap/shown pair is the honest signal).
|
|
478
624
|
if (page_metadata.has_next) {
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
guidance: `More results may remain — request the next page, or chain last_record_sort_value + last_record_unique_id from page_metadata to page past the ${MAX_PAGE_OFFSET.toLocaleString()}-result page-number limit. The cursor pair stops being returned once page × limit reaches ${CURSOR_WINDOW_OFFSET.toLocaleString()}, so capture it before then; a short or empty page marks the true end.`,
|
|
483
|
-
});
|
|
625
|
+
const guidance = `More results may remain — request the next page, or chain last_record_sort_value + last_record_unique_id from page_metadata to page past the ${MAX_PAGE_OFFSET.toLocaleString()}-result page-number limit. The cursor pair stops being returned once page × limit reaches ${CURSOR_WINDOW_OFFSET.toLocaleString()}, so capture it before then; a short or empty page marks the true end.`;
|
|
626
|
+
ctx.enrich.truncated({ shown: results.length, cap: input.limit, guidance });
|
|
627
|
+
notices.push(guidance);
|
|
484
628
|
}
|
|
629
|
+
notices.push(filledBoundNotice(timePeriod, filledFields));
|
|
485
630
|
if (results.length === 0) {
|
|
486
631
|
const filterParts = [];
|
|
487
632
|
if (keywords?.length)
|
|
488
633
|
filterParts.push(`keyword="${keywords.join(', ')}"`);
|
|
489
634
|
if (agencyName)
|
|
490
635
|
filterParts.push(`agency="${agencyName}"`);
|
|
636
|
+
if (listings)
|
|
637
|
+
filterParts.push(`assistance_listings=${listings.join(',')}`);
|
|
491
638
|
if (awardTypeCodes?.length) {
|
|
492
639
|
filterParts.push(`types=${awardTypeCodes.join(',')}`);
|
|
493
640
|
}
|
|
494
|
-
|
|
641
|
+
notices.push(filterParts.length > 0
|
|
495
642
|
? `No awards matched: ${filterParts.join(', ')}. Try removing filters or broadening the date range.`
|
|
496
|
-
: 'No awards matched your search. Try a different keyword or remove filters.';
|
|
497
|
-
ctx.enrich.notice(notice);
|
|
643
|
+
: 'No awards matched your search. Try a different keyword or remove filters.');
|
|
498
644
|
}
|
|
645
|
+
const notice = notices.filter(Boolean).join(' ');
|
|
646
|
+
if (notice)
|
|
647
|
+
ctx.enrich.notice(notice);
|
|
499
648
|
return { results, page_metadata };
|
|
500
649
|
},
|
|
501
650
|
format: (result) => {
|
|
@@ -514,6 +663,12 @@ export const searchAwardsTool = tool('usaspending_search_awards', {
|
|
|
514
663
|
lines.push(`**Amount:** ${formatCurrency(r.award_amount)}`);
|
|
515
664
|
if (typeof r.total_outlays === 'number')
|
|
516
665
|
lines.push(`**Outlays:** ${formatCurrency(r.total_outlays)}`);
|
|
666
|
+
if (typeof r.loan_value === 'number')
|
|
667
|
+
lines.push(`**Loan Value:** ${formatCurrency(r.loan_value)}`);
|
|
668
|
+
if (typeof r.subsidy_cost === 'number')
|
|
669
|
+
lines.push(`**Subsidy Cost:** ${formatCurrency(r.subsidy_cost)}`);
|
|
670
|
+
if (r.issued_date)
|
|
671
|
+
lines.push(`**Issued:** ${r.issued_date}`);
|
|
517
672
|
if (r.award_type)
|
|
518
673
|
lines.push(`**Type:** ${r.award_type}`);
|
|
519
674
|
if (r.awarding_agency)
|