@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
package/changelog/template.md
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
# Required. One-line GitHub Release-style headline. 350 character cap — a
|
|
8
8
|
# ceiling, not a target. Default short and scannable. Don't pad, don't stitch
|
|
9
|
-
# unrelated changes with commas/semicolons into an inventory — pick the
|
|
10
|
-
# headline
|
|
9
|
+
# unrelated changes with commas/semicolons into an inventory — pick the one
|
|
10
|
+
# headline the release is about. Quotes required: unquoted YAML treats
|
|
11
11
|
# `: ` inside the value as a key separator and fails GitHub's strict parser.
|
|
12
12
|
summary: ""
|
|
13
13
|
|
|
@@ -117,30 +117,13 @@ security: false
|
|
|
117
117
|
in that unrelated item's metadata.
|
|
118
118
|
|
|
119
119
|
TAG ANNOTATIONS — the annotated tag body renders as the GitHub Release body
|
|
120
|
-
via `gh release create --notes-from-tag`.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
Dependency bumps: ← section header
|
|
128
|
-
← blank line
|
|
129
|
-
- `@cyanheads/mcp-ts-core` ^0.9.1 → ^0.9.6 ← bullet
|
|
130
|
-
← blank line
|
|
131
|
-
Changed: ← only sections with entries
|
|
132
|
-
← blank line
|
|
133
|
-
- `format()` output includes `query` in text mode
|
|
134
|
-
← blank line
|
|
135
|
-
Added:
|
|
136
|
-
← blank line
|
|
137
|
-
- `manifest.json` scaffolded for MCPB bundle support
|
|
138
|
-
- Install badges (Claude Desktop, Cursor, VS Code)
|
|
139
|
-
← blank line
|
|
140
|
-
<N> tests pass; `bun run devcheck` clean. ← footer
|
|
141
|
-
|
|
142
|
-
Never a flat comma-separated string. Always structured markdown with
|
|
143
|
-
sections. The tag must scan well as a rendered GitHub Release page.
|
|
120
|
+
via `gh release create --notes-from-tag`. It is a condensed digest of this
|
|
121
|
+
entry, never a copy, and its format is owned by the `release-and-publish`
|
|
122
|
+
skill (step 4, "Create the annotated tag"): a short subject line without the
|
|
123
|
+
version, flat headline bullets — no Keep-a-Changelog section headers, no
|
|
124
|
+
gates line — at most one deps line, issue backlinks, and the changelog link
|
|
125
|
+
last. In release-PR mode the `git-wrapup` skill authors those bullets as the
|
|
126
|
+
PR body's `## Changes` and the tag copies them.
|
|
144
127
|
-->
|
|
145
128
|
|
|
146
129
|
## Added
|
package/dist/index.js
CHANGED
|
@@ -25,8 +25,16 @@ await createApp({
|
|
|
25
25
|
cacheHints: {
|
|
26
26
|
'tools/list': { ttlMs: 3_600_000, cacheScope: 'public' },
|
|
27
27
|
},
|
|
28
|
+
/**
|
|
29
|
+
* Every tool answers from the USAspending.gov response alone — no handler
|
|
30
|
+
* calls `ctx.requestInput`, so none needs a session to be resumed into.
|
|
31
|
+
* Declaring the posture here keeps it with the code rather than only in
|
|
32
|
+
* `.env.example` and the Dockerfile; `MCP_SESSION_MODE` still wins when it
|
|
33
|
+
* carries a meaningful value.
|
|
34
|
+
*/
|
|
35
|
+
sessionMode: 'stateless',
|
|
28
36
|
instructions: 'USAspending.gov MCP server — federal award, recipient, agency, and spending data from the US Treasury DATA Act platform.\n' +
|
|
29
|
-
'- Start with usaspending_list_agencies or usaspending_autocomplete_filters to discover agency codes
|
|
37
|
+
'- Start with usaspending_list_agencies or usaspending_autocomplete_filters to discover agency codes, NAICS/PSC codes, and Assistance Listing numbers\n' +
|
|
30
38
|
'- Use usaspending_search_awards to find awards, then usaspending_get_award for full details\n' +
|
|
31
39
|
'- Chain recipient_id from usaspending_get_award into usaspending_get_recipient for entity profiles\n' +
|
|
32
40
|
'- Search window: 2007-10-01 onward. DoD contracts have a 90-day publication lag.',
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAC;AAEvF,MAAM,SAAS,CAAC;IACd,IAAI,EAAE,wBAAwB;IAC9B,KAAK,EAAE,wBAAwB;IAC/B,KAAK,EAAE,CAAC,GAAG,kBAAkB,CAAC;IAC9B,SAAS,EAAE,EAAE;IACb,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE;IAC/B;;;;;;OAMG;IACH,UAAU,EAAE;QACV,YAAY,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE;KACzD;IACD,YAAY,EACV,4HAA4H;QAC5H,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAC;AAEvF,MAAM,SAAS,CAAC;IACd,IAAI,EAAE,wBAAwB;IAC9B,KAAK,EAAE,wBAAwB;IAC/B,KAAK,EAAE,CAAC,GAAG,kBAAkB,CAAC;IAC9B,SAAS,EAAE,EAAE;IACb,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE;IAC/B;;;;;;OAMG;IACH,UAAU,EAAE;QACV,YAAY,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE;KACzD;IACD;;;;;;OAMG;IACH,WAAW,EAAE,WAAW;IACxB,YAAY,EACV,4HAA4H;QAC5H,wJAAwJ;QACxJ,+FAA+F;QAC/F,sGAAsG;QACtG,kFAAkF;IACpF,KAAK,CAAC,IAAI;QACR,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC;QACvC,sBAAsB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAClE,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -36,12 +36,14 @@ export declare const autocompleteFiltersTool: import("@cyanheads/mcp-ts-core").T
|
|
|
36
36
|
readonly code: JsonRpcErrorCode.ServiceUnavailable;
|
|
37
37
|
readonly when: "USAspending.gov API is unreachable or returns an error.";
|
|
38
38
|
readonly retryable: true;
|
|
39
|
+
readonly thrownBy: "service";
|
|
39
40
|
readonly recovery: "The API may be temporarily down. Retry the request after a few seconds.";
|
|
40
41
|
}, {
|
|
41
42
|
readonly reason: "api_timeout";
|
|
42
43
|
readonly code: JsonRpcErrorCode.Timeout;
|
|
43
44
|
readonly when: "USAspending.gov did not respond before the request deadline elapsed.";
|
|
44
45
|
readonly retryable: true;
|
|
46
|
+
readonly thrownBy: "service";
|
|
45
47
|
readonly recovery: "Retry with a longer search_text and a smaller limit to shrink the match set.";
|
|
46
48
|
}], {
|
|
47
49
|
readonly lookup_type: z.ZodString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete-filters.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/autocomplete-filters.tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAQ,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAIjE,eAAO,MAAM,uBAAuB
|
|
1
|
+
{"version":3,"file":"autocomplete-filters.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/autocomplete-filters.tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAQ,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAIjE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+MlC,CAAC"}
|
|
@@ -13,7 +13,7 @@ export const autocompleteFiltersTool = tool('usaspending_autocomplete_filters',
|
|
|
13
13
|
input: z.object({
|
|
14
14
|
type: z
|
|
15
15
|
.enum(['naics', 'psc', 'cfda', 'awarding_agency', 'recipient'])
|
|
16
|
-
.describe('Lookup table to search: naics (industry codes), psc (product/service codes), cfda (
|
|
16
|
+
.describe('Lookup table to search: naics (industry codes), psc (product/service codes), cfda (Assistance Listing program numbers, for usaspending_search_awards assistance_listings), awarding_agency (agency names), recipient (recipient names)'),
|
|
17
17
|
search_text: z
|
|
18
18
|
.string()
|
|
19
19
|
.min(1)
|
|
@@ -35,7 +35,7 @@ export const autocompleteFiltersTool = tool('usaspending_autocomplete_filters',
|
|
|
35
35
|
code: z
|
|
36
36
|
.string()
|
|
37
37
|
.optional()
|
|
38
|
-
.describe('Code value (NAICS code, PSC code, CFDA number, or agency code); use this in filter parameters'),
|
|
38
|
+
.describe('Code value (NAICS code, PSC code, Assistance Listing/CFDA number, or agency code); use this in filter parameters — an Assistance Listing number goes in usaspending_search_awards assistance_listings'),
|
|
39
39
|
name: z.string().optional().describe('Human-readable name or description'),
|
|
40
40
|
id: z
|
|
41
41
|
.string()
|
|
@@ -76,6 +76,7 @@ export const autocompleteFiltersTool = tool('usaspending_autocomplete_filters',
|
|
|
76
76
|
code: JsonRpcErrorCode.ServiceUnavailable,
|
|
77
77
|
when: 'USAspending.gov API is unreachable or returns an error.',
|
|
78
78
|
retryable: true,
|
|
79
|
+
thrownBy: 'service',
|
|
79
80
|
recovery: 'The API may be temporarily down. Retry the request after a few seconds.',
|
|
80
81
|
},
|
|
81
82
|
{
|
|
@@ -83,6 +84,7 @@ export const autocompleteFiltersTool = tool('usaspending_autocomplete_filters',
|
|
|
83
84
|
code: JsonRpcErrorCode.Timeout,
|
|
84
85
|
when: 'USAspending.gov did not respond before the request deadline elapsed.',
|
|
85
86
|
retryable: true,
|
|
87
|
+
thrownBy: 'service',
|
|
86
88
|
recovery: 'Retry with a longer search_text and a smaller limit to shrink the match set.',
|
|
87
89
|
},
|
|
88
90
|
],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete-filters.tool.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/autocomplete-filters.tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAC;AAEtF,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC,kCAAkC,EAAE;IAC9E,KAAK,EAAE,8BAA8B;IACrC,WAAW,EACT,4dAA4d;IAC9d,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE;IAE9E,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;QACd,IAAI,EAAE,CAAC;aACJ,IAAI,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,WAAW,CAAC,CAAC;aAC9D,QAAQ,CACP,
|
|
1
|
+
{"version":3,"file":"autocomplete-filters.tool.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/autocomplete-filters.tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAC;AAEtF,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC,kCAAkC,EAAE;IAC9E,KAAK,EAAE,8BAA8B;IACrC,WAAW,EACT,4dAA4d;IAC9d,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE;IAE9E,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;QACd,IAAI,EAAE,CAAC;aACJ,IAAI,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,WAAW,CAAC,CAAC;aAC9D,QAAQ,CACP,wOAAwO,CACzO;QACH,WAAW,EAAE,CAAC;aACX,MAAM,EAAE;aACR,GAAG,CAAC,CAAC,CAAC;aACN,QAAQ,CACP,uFAAuF,CACxF;QACH,KAAK,EAAE,CAAC;aACL,MAAM,EAAE;aACR,GAAG,EAAE;aACL,GAAG,CAAC,CAAC,CAAC;aACN,GAAG,CAAC,GAAG,CAAC;aACR,OAAO,CAAC,EAAE,CAAC;aACX,QAAQ,CACP,0fAA0f,CAC3f;KACJ,CAAC;IAEF,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CAAC,EAAE,CAAC,CAAC;QACvC,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,gBAAgB,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;QAC3C,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Date inputs shared by the award search and spending analytics
|
|
3
|
+
* tools: the advertised `YYYY-MM-DD` schemas, zero-padding, the searchable
|
|
4
|
+
* floor, and resolution of a half-open range into the two-ended range the
|
|
5
|
+
* endpoints require.
|
|
6
|
+
* @module mcp-server/tools/definitions/dates
|
|
7
|
+
*/
|
|
8
|
+
import { z } from '@cyanheads/mcp-ts-core';
|
|
9
|
+
/**
|
|
10
|
+
* Earliest date `search/spending_by_award/`, `search/spending_by_category/`,
|
|
11
|
+
* `search/spending_by_geography/`, and `search/spending_over_time/` accept —
|
|
12
|
+
* each answers an earlier start with a 422 naming this date.
|
|
13
|
+
*/
|
|
14
|
+
export declare const EARLIEST_SEARCH_DATE = "2007-10-01";
|
|
15
|
+
/**
|
|
16
|
+
* Year, month, day. Month and day may be unpadded (`2024-1-1`): the analytics
|
|
17
|
+
* endpoints accept that form but `search/spending_by_award/` answers it with an
|
|
18
|
+
* empty-bodied 503, so every handler pads before sending ({@link padIsoDate}).
|
|
19
|
+
* A calendar-impossible date (`2024-02-30`) passes and is left to upstream,
|
|
20
|
+
* whose 4xx names the field.
|
|
21
|
+
*/
|
|
22
|
+
export declare const ISO_DATE_PATTERN: RegExp;
|
|
23
|
+
/**
|
|
24
|
+
* A date input that also accepts `""` — what form-based clients send for an
|
|
25
|
+
* untouched field — as "no date". The union follows the form-client convention:
|
|
26
|
+
* the advertised schema is `anyOf ["", pattern]`, so a client that validates
|
|
27
|
+
* before calling accepts the blank and still sees the `YYYY-MM-DD` pattern.
|
|
28
|
+
* A whitespace-only value is read as blank too — before the pattern existed a
|
|
29
|
+
* lone one was dropped like any blank — while a whitespace-padded date fails
|
|
30
|
+
* the pattern. Handlers read a blank as absent. The preprocess wrapper leaves
|
|
31
|
+
* the `anyOf` in the advertised schema.
|
|
32
|
+
*/
|
|
33
|
+
export declare function blankableIsoDate(description: string): z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>;
|
|
34
|
+
/** An optional {@link blankableIsoDate}: omitted and `""` both mean no date. */
|
|
35
|
+
export declare function optionalIsoDate(description: string): z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
|
|
36
|
+
/** Zero-pads month and day of a pattern-valid date: `2024-1-1` → `2024-01-01`. */
|
|
37
|
+
export declare function padIsoDate(date: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Today's date in UTC. UTC keeps the fill independent of where the server runs;
|
|
40
|
+
* when UTC is already a day ahead of US time the date is in the future there,
|
|
41
|
+
* which the endpoints accept.
|
|
42
|
+
*/
|
|
43
|
+
export declare function todayUtc(now?: Date): string;
|
|
44
|
+
/** A two-ended range as sent upstream, and which end (if any) was filled in. */
|
|
45
|
+
export interface DateRange {
|
|
46
|
+
end_date: string;
|
|
47
|
+
filled?: 'start_date' | 'end_date';
|
|
48
|
+
start_date: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Resolves optional start and end dates into the two-ended range the endpoints
|
|
52
|
+
* require, padding both. A lone start runs through today (UTC); a lone end runs
|
|
53
|
+
* from {@link EARLIEST_SEARCH_DATE}. The filled end never inverts the range — an
|
|
54
|
+
* inverted range draws an HTML 500 from the analytics endpoints — so a lone
|
|
55
|
+
* start after today closes on itself, and a lone end before the floor opens on
|
|
56
|
+
* itself (which the endpoints then reject for preceding the floor).
|
|
57
|
+
*
|
|
58
|
+
* @returns `undefined` when neither end is supplied.
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveDateRange(start: string | undefined, end: string | undefined, today?: string): DateRange | undefined;
|
|
61
|
+
/** The two input paths a tool reads a range's start and end from. */
|
|
62
|
+
export interface DateFields {
|
|
63
|
+
end: string;
|
|
64
|
+
start: string;
|
|
65
|
+
}
|
|
66
|
+
/** The input paths that carry the date range on the spending analytics tools. */
|
|
67
|
+
export declare const ANALYTICS_DATE_FIELDS: {
|
|
68
|
+
readonly start: 'filters.time_period_start';
|
|
69
|
+
readonly end: 'filters.time_period_end';
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* The rejection message for a range whose start falls after its end, naming the
|
|
73
|
+
* two input fields that carried them and telling the caller to swap them — or
|
|
74
|
+
* `undefined` when the range is ordered, has equal ends, or is absent. Padded
|
|
75
|
+
* dates order correctly as strings. A half range {@link resolveDateRange}
|
|
76
|
+
* filled never inverts, so only a range supplied with both ends can fail here.
|
|
77
|
+
* Upstream answers an inverted range with an HTML 500 on the analytics
|
|
78
|
+
* endpoints and by ignoring it on `search/spending_by_award/`, so callers check
|
|
79
|
+
* before any request.
|
|
80
|
+
*/
|
|
81
|
+
export declare function invertedRangeMessage(range: DateRange | undefined, fields: DateFields): string | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* The rejection message for a range starting before {@link EARLIEST_SEARCH_DATE},
|
|
84
|
+
* or `undefined` when it starts on or after it. Every search endpoint answers
|
|
85
|
+
* such a start with its own 422, so callers check before any request. A lone end
|
|
86
|
+
* before the floor opens the range on itself, so it is named as the end date.
|
|
87
|
+
*/
|
|
88
|
+
export declare function floorViolationMessage(range: DateRange | undefined): string | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* The notice disclosing which bound {@link resolveDateRange} filled, naming the
|
|
91
|
+
* input field (from `fields`) the caller omitted and the date used for it.
|
|
92
|
+
* `undefined` when both ends were supplied or no range applies.
|
|
93
|
+
*/
|
|
94
|
+
export declare function filledBoundNotice(range: DateRange | undefined, fields: DateFields): string | undefined;
|
|
95
|
+
//# sourceMappingURL=dates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/dates.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AAE3C;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,eAAe,CAAC;AAEjD;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,QAA4B,CAAC;AAI1D;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,kFAanD;AAED,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,iGAElD;AAED,kFAAkF;AAClF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG/C;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,GAAE,IAAiB,GAAG,MAAM,CAEvD;AAED,gFAAgF;AAChF,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;IACnC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,KAAK,GAAE,MAAmB,GACzB,SAAS,GAAG,SAAS,CAmBvB;AAED,qEAAqE;AACrE,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAED,iFAAiF;AACjF,eAAO,MAAM,qBAAqB;oBACzB,2BAA2B;kBAC7B,yBAAyB;CACD,CAAC;AAEhC;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,SAAS,GAAG,SAAS,EAC5B,MAAM,EAAE,UAAU,GACjB,MAAM,GAAG,SAAS,CAGpB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAKtF;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,SAAS,GAAG,SAAS,EAC5B,MAAM,EAAE,UAAU,GACjB,MAAM,GAAG,SAAS,CAgBpB"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Date inputs shared by the award search and spending analytics
|
|
3
|
+
* tools: the advertised `YYYY-MM-DD` schemas, zero-padding, the searchable
|
|
4
|
+
* floor, and resolution of a half-open range into the two-ended range the
|
|
5
|
+
* endpoints require.
|
|
6
|
+
* @module mcp-server/tools/definitions/dates
|
|
7
|
+
*/
|
|
8
|
+
import { z } from '@cyanheads/mcp-ts-core';
|
|
9
|
+
/**
|
|
10
|
+
* Earliest date `search/spending_by_award/`, `search/spending_by_category/`,
|
|
11
|
+
* `search/spending_by_geography/`, and `search/spending_over_time/` accept —
|
|
12
|
+
* each answers an earlier start with a 422 naming this date.
|
|
13
|
+
*/
|
|
14
|
+
export const EARLIEST_SEARCH_DATE = '2007-10-01';
|
|
15
|
+
/**
|
|
16
|
+
* Year, month, day. Month and day may be unpadded (`2024-1-1`): the analytics
|
|
17
|
+
* endpoints accept that form but `search/spending_by_award/` answers it with an
|
|
18
|
+
* empty-bodied 503, so every handler pads before sending ({@link padIsoDate}).
|
|
19
|
+
* A calendar-impossible date (`2024-02-30`) passes and is left to upstream,
|
|
20
|
+
* whose 4xx names the field.
|
|
21
|
+
*/
|
|
22
|
+
export const ISO_DATE_PATTERN = /^\d{4}-\d{1,2}-\d{1,2}$/;
|
|
23
|
+
const DATE_FORMAT_MESSAGE = 'Expected a date as YYYY-MM-DD (e.g. 2024-01-31)';
|
|
24
|
+
/**
|
|
25
|
+
* A date input that also accepts `""` — what form-based clients send for an
|
|
26
|
+
* untouched field — as "no date". The union follows the form-client convention:
|
|
27
|
+
* the advertised schema is `anyOf ["", pattern]`, so a client that validates
|
|
28
|
+
* before calling accepts the blank and still sees the `YYYY-MM-DD` pattern.
|
|
29
|
+
* A whitespace-only value is read as blank too — before the pattern existed a
|
|
30
|
+
* lone one was dropped like any blank — while a whitespace-padded date fails
|
|
31
|
+
* the pattern. Handlers read a blank as absent. The preprocess wrapper leaves
|
|
32
|
+
* the `anyOf` in the advertised schema.
|
|
33
|
+
*/
|
|
34
|
+
export function blankableIsoDate(description) {
|
|
35
|
+
return z
|
|
36
|
+
.preprocess((value) => (typeof value === 'string' && value.trim() === '' ? '' : value), z.union([
|
|
37
|
+
z.literal(''),
|
|
38
|
+
z
|
|
39
|
+
.string()
|
|
40
|
+
.regex(ISO_DATE_PATTERN, DATE_FORMAT_MESSAGE)
|
|
41
|
+
.describe('Date as YYYY-MM-DD; month and day may be unpadded'),
|
|
42
|
+
]))
|
|
43
|
+
.describe(description);
|
|
44
|
+
}
|
|
45
|
+
/** An optional {@link blankableIsoDate}: omitted and `""` both mean no date. */
|
|
46
|
+
export function optionalIsoDate(description) {
|
|
47
|
+
return blankableIsoDate(description).optional();
|
|
48
|
+
}
|
|
49
|
+
/** Zero-pads month and day of a pattern-valid date: `2024-1-1` → `2024-01-01`. */
|
|
50
|
+
export function padIsoDate(date) {
|
|
51
|
+
const [year, month = '', day = ''] = date.split('-');
|
|
52
|
+
return `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Today's date in UTC. UTC keeps the fill independent of where the server runs;
|
|
56
|
+
* when UTC is already a day ahead of US time the date is in the future there,
|
|
57
|
+
* which the endpoints accept.
|
|
58
|
+
*/
|
|
59
|
+
export function todayUtc(now = new Date()) {
|
|
60
|
+
return now.toISOString().slice(0, 10);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Resolves optional start and end dates into the two-ended range the endpoints
|
|
64
|
+
* require, padding both. A lone start runs through today (UTC); a lone end runs
|
|
65
|
+
* from {@link EARLIEST_SEARCH_DATE}. The filled end never inverts the range — an
|
|
66
|
+
* inverted range draws an HTML 500 from the analytics endpoints — so a lone
|
|
67
|
+
* start after today closes on itself, and a lone end before the floor opens on
|
|
68
|
+
* itself (which the endpoints then reject for preceding the floor).
|
|
69
|
+
*
|
|
70
|
+
* @returns `undefined` when neither end is supplied.
|
|
71
|
+
*/
|
|
72
|
+
export function resolveDateRange(start, end, today = todayUtc()) {
|
|
73
|
+
const startDate = start ? padIsoDate(start) : undefined;
|
|
74
|
+
const endDate = end ? padIsoDate(end) : undefined;
|
|
75
|
+
if (startDate && endDate)
|
|
76
|
+
return { start_date: startDate, end_date: endDate };
|
|
77
|
+
if (startDate) {
|
|
78
|
+
return {
|
|
79
|
+
start_date: startDate,
|
|
80
|
+
end_date: startDate > today ? startDate : today,
|
|
81
|
+
filled: 'end_date',
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (endDate) {
|
|
85
|
+
return {
|
|
86
|
+
start_date: endDate < EARLIEST_SEARCH_DATE ? endDate : EARLIEST_SEARCH_DATE,
|
|
87
|
+
end_date: endDate,
|
|
88
|
+
filled: 'start_date',
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
/** The input paths that carry the date range on the spending analytics tools. */
|
|
94
|
+
export const ANALYTICS_DATE_FIELDS = {
|
|
95
|
+
start: 'filters.time_period_start',
|
|
96
|
+
end: 'filters.time_period_end',
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* The rejection message for a range whose start falls after its end, naming the
|
|
100
|
+
* two input fields that carried them and telling the caller to swap them — or
|
|
101
|
+
* `undefined` when the range is ordered, has equal ends, or is absent. Padded
|
|
102
|
+
* dates order correctly as strings. A half range {@link resolveDateRange}
|
|
103
|
+
* filled never inverts, so only a range supplied with both ends can fail here.
|
|
104
|
+
* Upstream answers an inverted range with an HTML 500 on the analytics
|
|
105
|
+
* endpoints and by ignoring it on `search/spending_by_award/`, so callers check
|
|
106
|
+
* before any request.
|
|
107
|
+
*/
|
|
108
|
+
export function invertedRangeMessage(range, fields) {
|
|
109
|
+
if (!range || range.start_date <= range.end_date)
|
|
110
|
+
return;
|
|
111
|
+
return `${fields.start} (${range.start_date}) falls after ${fields.end} (${range.end_date}). Swap the two dates so the range starts on or before it ends.`;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The rejection message for a range starting before {@link EARLIEST_SEARCH_DATE},
|
|
115
|
+
* or `undefined` when it starts on or after it. Every search endpoint answers
|
|
116
|
+
* such a start with its own 422, so callers check before any request. A lone end
|
|
117
|
+
* before the floor opens the range on itself, so it is named as the end date.
|
|
118
|
+
*/
|
|
119
|
+
export function floorViolationMessage(range) {
|
|
120
|
+
if (!range || range.start_date >= EARLIEST_SEARCH_DATE)
|
|
121
|
+
return;
|
|
122
|
+
const [bound, date] = range.filled === 'start_date' ? ['End', range.end_date] : ['Start', range.start_date];
|
|
123
|
+
return `${bound} date ${date} precedes ${EARLIEST_SEARCH_DATE}, the earliest date this endpoint can search.`;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The notice disclosing which bound {@link resolveDateRange} filled, naming the
|
|
127
|
+
* input field (from `fields`) the caller omitted and the date used for it.
|
|
128
|
+
* `undefined` when both ends were supplied or no range applies.
|
|
129
|
+
*/
|
|
130
|
+
export function filledBoundNotice(range, fields) {
|
|
131
|
+
if (range?.filled === 'end_date') {
|
|
132
|
+
const why = range.end_date === range.start_date
|
|
133
|
+
? 'the start date itself, since it falls after today (UTC)'
|
|
134
|
+
: 'today (UTC)';
|
|
135
|
+
return `${fields.end} was not supplied, so the range runs from ${range.start_date} through ${range.end_date} — ${why}.`;
|
|
136
|
+
}
|
|
137
|
+
if (range?.filled === 'start_date') {
|
|
138
|
+
const why = range.start_date === EARLIEST_SEARCH_DATE
|
|
139
|
+
? 'the earliest date this endpoint searches'
|
|
140
|
+
: 'the end date itself';
|
|
141
|
+
return `${fields.start} was not supplied, so the range runs from ${range.start_date} — ${why} — through ${range.end_date}.`;
|
|
142
|
+
}
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=dates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dates.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/dates.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AAE3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAE1D,MAAM,mBAAmB,GAAG,iDAAiD,CAAC;AAE9E;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAAC,WAAmB;IAClD,OAAO,CAAC;SACL,UAAU,CACT,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,EAC1E,CAAC,CAAC,KAAK,CAAC;QACN,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;QACb,CAAC;aACE,MAAM,EAAE;aACR,KAAK,CAAC,gBAAgB,EAAE,mBAAmB,CAAC;aAC5C,QAAQ,CAAC,mDAAmD,CAAC;KACjE,CAAC,CACH;SACA,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC3B,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,eAAe,CAAC,WAAmB;IACjD,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAC;AAClD,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,MAAM,CAAC,IAAI,EA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CAAC;IACD,IAAI,KAAK,EAAE,MAAM,KAAK,YAAY,EAAE,CAAC;QACnC,MAAM,GAAG,GACP,KAAK,CAAC,UAAU,KAAK,oBAAoB;YACvC,CAAC,CAAC,0CAA0C;YAC5C,CAAC,CAAC,qBAAqB,CAAC;QAC5B,OAAO,GAAG,MAAM,CAAC,KAAK,6CAA6C,KAAK,CAAC,UAAU,MAAM,GAAG,cAAc,KAAK,CAAC,QAAQ,GAAG,CAAC;IAC9H,CAAC;IACD,OAAO;AACT,CAAC"}
|
|
@@ -45,12 +45,19 @@ export declare const disasterSpendingTool: import("@cyanheads/mcp-ts-core").Tool
|
|
|
45
45
|
public_law: z.ZodOptional<z.ZodString>;
|
|
46
46
|
}, z.core.$strip>>>;
|
|
47
47
|
}, z.core.$strip>>;
|
|
48
|
+
totals: z.ZodOptional<z.ZodObject<{
|
|
49
|
+
obligation: z.ZodOptional<z.ZodNumber>;
|
|
50
|
+
outlay: z.ZodOptional<z.ZodNumber>;
|
|
51
|
+
total_budgetary_resources: z.ZodOptional<z.ZodNumber>;
|
|
52
|
+
award_count: z.ZodOptional<z.ZodNumber>;
|
|
53
|
+
}, z.core.$strip>>;
|
|
48
54
|
results: z.ZodArray<z.ZodObject<{
|
|
49
55
|
id: z.ZodOptional<z.ZodString>;
|
|
50
56
|
code: z.ZodOptional<z.ZodString>;
|
|
51
57
|
name: z.ZodOptional<z.ZodString>;
|
|
52
58
|
obligation: z.ZodOptional<z.ZodNumber>;
|
|
53
59
|
outlay: z.ZodOptional<z.ZodNumber>;
|
|
60
|
+
total_budgetary_resources: z.ZodOptional<z.ZodNumber>;
|
|
54
61
|
award_count: z.ZodOptional<z.ZodNumber>;
|
|
55
62
|
face_value_of_loan: z.ZodOptional<z.ZodNumber>;
|
|
56
63
|
shape_code: z.ZodOptional<z.ZodString>;
|
|
@@ -70,13 +77,15 @@ export declare const disasterSpendingTool: import("@cyanheads/mcp-ts-core").Tool
|
|
|
70
77
|
readonly code: JsonRpcErrorCode.ServiceUnavailable;
|
|
71
78
|
readonly when: "USAspending.gov API is unreachable or returns an error.";
|
|
72
79
|
readonly retryable: true;
|
|
80
|
+
readonly thrownBy: "service";
|
|
73
81
|
readonly recovery: "The API may be temporarily down. Retry the request after a few seconds.";
|
|
74
82
|
}, {
|
|
75
83
|
readonly reason: "api_timeout";
|
|
76
84
|
readonly code: JsonRpcErrorCode.Timeout;
|
|
77
85
|
readonly when: "USAspending.gov did not respond before the request deadline elapsed.";
|
|
78
86
|
readonly retryable: true;
|
|
79
|
-
readonly
|
|
87
|
+
readonly thrownBy: "service";
|
|
88
|
+
readonly recovery: "By dimension — agency, cfda, recipient: pass fewer filters.def_codes or a smaller limit, then retry. geography: pass fewer filters.def_codes, then retry. overview: the upstream endpoint can run past the request budget on its own, so retry later, or call dimension \"agency\" with filters.def_codes (e.g. [\"L\", \"M\", \"N\", \"O\", \"P\"] for COVID-19), spending_type \"total\", and limit 100 for per-agency obligations and outlays plus overall totals.";
|
|
80
89
|
}], {
|
|
81
90
|
readonly applied_dimension: z.ZodString;
|
|
82
91
|
readonly totalCount: z.ZodOptional<z.ZodNumber>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"disaster-spending.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/disaster-spending.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":"disaster-spending.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/disaster-spending.tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAQ,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAmB,MAAM,+BAA+B,CAAC;AAoDlF,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6d/B,CAAC"}
|