@cyanheads/usaspending-mcp-server 0.7.1 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/AGENTS.md +8 -5
  2. package/CLAUDE.md +8 -5
  3. package/README.md +49 -31
  4. package/changelog/0.7.x/0.7.2.md +33 -0
  5. package/changelog/0.7.x/0.7.3.md +29 -0
  6. package/changelog/template.md +10 -3
  7. package/dist/config/server-config.d.ts +13 -0
  8. package/dist/config/server-config.d.ts.map +1 -1
  9. package/dist/config/server-config.js +24 -0
  10. package/dist/config/server-config.js.map +1 -1
  11. package/dist/index.js +1 -6
  12. package/dist/index.js.map +1 -1
  13. package/dist/mcp-server/tools/definitions/agency-filters.d.ts +36 -0
  14. package/dist/mcp-server/tools/definitions/agency-filters.d.ts.map +1 -0
  15. package/dist/mcp-server/tools/definitions/agency-filters.js +123 -0
  16. package/dist/mcp-server/tools/definitions/agency-filters.js.map +1 -0
  17. package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.d.ts +18 -3
  18. package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.d.ts.map +1 -1
  19. package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.js +176 -45
  20. package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.js.map +1 -1
  21. package/dist/mcp-server/tools/definitions/count-limit.d.ts +69 -0
  22. package/dist/mcp-server/tools/definitions/count-limit.d.ts.map +1 -0
  23. package/dist/mcp-server/tools/definitions/count-limit.js +87 -0
  24. package/dist/mcp-server/tools/definitions/count-limit.js.map +1 -0
  25. package/dist/mcp-server/tools/definitions/dates.d.ts +2 -0
  26. package/dist/mcp-server/tools/definitions/dates.d.ts.map +1 -1
  27. package/dist/mcp-server/tools/definitions/dates.js +2 -0
  28. package/dist/mcp-server/tools/definitions/dates.js.map +1 -1
  29. package/dist/mcp-server/tools/definitions/disaster-spending.tool.d.ts +6 -1
  30. package/dist/mcp-server/tools/definitions/disaster-spending.tool.d.ts.map +1 -1
  31. package/dist/mcp-server/tools/definitions/disaster-spending.tool.js +28 -22
  32. package/dist/mcp-server/tools/definitions/disaster-spending.tool.js.map +1 -1
  33. package/dist/mcp-server/tools/definitions/filters.d.ts +60 -10
  34. package/dist/mcp-server/tools/definitions/filters.d.ts.map +1 -1
  35. package/dist/mcp-server/tools/definitions/filters.js +67 -12
  36. package/dist/mcp-server/tools/definitions/filters.js.map +1 -1
  37. package/dist/mcp-server/tools/definitions/get-agency.tool.d.ts +9 -0
  38. package/dist/mcp-server/tools/definitions/get-agency.tool.d.ts.map +1 -1
  39. package/dist/mcp-server/tools/definitions/get-agency.tool.js +114 -55
  40. package/dist/mcp-server/tools/definitions/get-agency.tool.js.map +1 -1
  41. package/dist/mcp-server/tools/definitions/get-award-federal-accounts.tool.d.ts +5 -0
  42. package/dist/mcp-server/tools/definitions/get-award-federal-accounts.tool.d.ts.map +1 -1
  43. package/dist/mcp-server/tools/definitions/get-award-federal-accounts.tool.js +14 -11
  44. package/dist/mcp-server/tools/definitions/get-award-federal-accounts.tool.js.map +1 -1
  45. package/dist/mcp-server/tools/definitions/get-award-subawards.tool.d.ts +5 -0
  46. package/dist/mcp-server/tools/definitions/get-award-subawards.tool.d.ts.map +1 -1
  47. package/dist/mcp-server/tools/definitions/get-award-subawards.tool.js +14 -11
  48. package/dist/mcp-server/tools/definitions/get-award-subawards.tool.js.map +1 -1
  49. package/dist/mcp-server/tools/definitions/get-award-transactions.tool.d.ts +5 -0
  50. package/dist/mcp-server/tools/definitions/get-award-transactions.tool.d.ts.map +1 -1
  51. package/dist/mcp-server/tools/definitions/get-award-transactions.tool.js +17 -11
  52. package/dist/mcp-server/tools/definitions/get-award-transactions.tool.js.map +1 -1
  53. package/dist/mcp-server/tools/definitions/get-award.tool.d.ts +30 -0
  54. package/dist/mcp-server/tools/definitions/get-award.tool.d.ts.map +1 -1
  55. package/dist/mcp-server/tools/definitions/get-award.tool.js +110 -2
  56. package/dist/mcp-server/tools/definitions/get-award.tool.js.map +1 -1
  57. package/dist/mcp-server/tools/definitions/get-federal-account-breakdown.tool.d.ts +5 -0
  58. package/dist/mcp-server/tools/definitions/get-federal-account-breakdown.tool.d.ts.map +1 -1
  59. package/dist/mcp-server/tools/definitions/get-federal-account-breakdown.tool.js +18 -11
  60. package/dist/mcp-server/tools/definitions/get-federal-account-breakdown.tool.js.map +1 -1
  61. package/dist/mcp-server/tools/definitions/get-idv-awards.tool.d.ts +5 -0
  62. package/dist/mcp-server/tools/definitions/get-idv-awards.tool.d.ts.map +1 -1
  63. package/dist/mcp-server/tools/definitions/get-idv-awards.tool.js +18 -18
  64. package/dist/mcp-server/tools/definitions/get-idv-awards.tool.js.map +1 -1
  65. package/dist/mcp-server/tools/definitions/get-recipient.tool.d.ts +41 -2
  66. package/dist/mcp-server/tools/definitions/get-recipient.tool.d.ts.map +1 -1
  67. package/dist/mcp-server/tools/definitions/get-recipient.tool.js +201 -11
  68. package/dist/mcp-server/tools/definitions/get-recipient.tool.js.map +1 -1
  69. package/dist/mcp-server/tools/definitions/index.d.ts +264 -15
  70. package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -1
  71. package/dist/mcp-server/tools/definitions/list-agencies.tool.d.ts.map +1 -1
  72. package/dist/mcp-server/tools/definitions/list-agencies.tool.js +2 -4
  73. package/dist/mcp-server/tools/definitions/list-agencies.tool.js.map +1 -1
  74. package/dist/mcp-server/tools/definitions/locations.d.ts +20 -9
  75. package/dist/mcp-server/tools/definitions/locations.d.ts.map +1 -1
  76. package/dist/mcp-server/tools/definitions/locations.js +106 -84
  77. package/dist/mcp-server/tools/definitions/locations.js.map +1 -1
  78. package/dist/mcp-server/tools/definitions/pagination.d.ts +9 -8
  79. package/dist/mcp-server/tools/definitions/pagination.d.ts.map +1 -1
  80. package/dist/mcp-server/tools/definitions/pagination.js +9 -8
  81. package/dist/mcp-server/tools/definitions/pagination.js.map +1 -1
  82. package/dist/mcp-server/tools/definitions/search-awards.tool.d.ts +46 -6
  83. package/dist/mcp-server/tools/definitions/search-awards.tool.d.ts.map +1 -1
  84. package/dist/mcp-server/tools/definitions/search-awards.tool.js +203 -83
  85. package/dist/mcp-server/tools/definitions/search-awards.tool.js.map +1 -1
  86. package/dist/mcp-server/tools/definitions/search-federal-accounts.tool.d.ts +5 -0
  87. package/dist/mcp-server/tools/definitions/search-federal-accounts.tool.d.ts.map +1 -1
  88. package/dist/mcp-server/tools/definitions/search-federal-accounts.tool.js +15 -13
  89. package/dist/mcp-server/tools/definitions/search-federal-accounts.tool.js.map +1 -1
  90. package/dist/mcp-server/tools/definitions/search-recipients.tool.d.ts +6 -0
  91. package/dist/mcp-server/tools/definitions/search-recipients.tool.d.ts.map +1 -1
  92. package/dist/mcp-server/tools/definitions/search-recipients.tool.js +19 -17
  93. package/dist/mcp-server/tools/definitions/search-recipients.tool.js.map +1 -1
  94. package/dist/mcp-server/tools/definitions/spending-by-category.tool.d.ts +33 -2
  95. package/dist/mcp-server/tools/definitions/spending-by-category.tool.d.ts.map +1 -1
  96. package/dist/mcp-server/tools/definitions/spending-by-category.tool.js +100 -40
  97. package/dist/mcp-server/tools/definitions/spending-by-category.tool.js.map +1 -1
  98. package/dist/mcp-server/tools/definitions/spending-by-geography.tool.d.ts +25 -2
  99. package/dist/mcp-server/tools/definitions/spending-by-geography.tool.d.ts.map +1 -1
  100. package/dist/mcp-server/tools/definitions/spending-by-geography.tool.js +50 -26
  101. package/dist/mcp-server/tools/definitions/spending-by-geography.tool.js.map +1 -1
  102. package/dist/mcp-server/tools/definitions/spending-over-time.tool.d.ts +24 -2
  103. package/dist/mcp-server/tools/definitions/spending-over-time.tool.d.ts.map +1 -1
  104. package/dist/mcp-server/tools/definitions/spending-over-time.tool.js +36 -14
  105. package/dist/mcp-server/tools/definitions/spending-over-time.tool.js.map +1 -1
  106. package/dist/mcp-server/tools/definitions/unavailable-sections.d.ts +42 -0
  107. package/dist/mcp-server/tools/definitions/unavailable-sections.d.ts.map +1 -0
  108. package/dist/mcp-server/tools/definitions/unavailable-sections.js +63 -0
  109. package/dist/mcp-server/tools/definitions/unavailable-sections.js.map +1 -0
  110. package/dist/services/usaspending/types.d.ts +91 -7
  111. package/dist/services/usaspending/types.d.ts.map +1 -1
  112. package/dist/services/usaspending/types.js +5 -1
  113. package/dist/services/usaspending/types.js.map +1 -1
  114. package/dist/services/usaspending/usaspending-service.d.ts +85 -7
  115. package/dist/services/usaspending/usaspending-service.d.ts.map +1 -1
  116. package/dist/services/usaspending/usaspending-service.js +205 -32
  117. package/dist/services/usaspending/usaspending-service.js.map +1 -1
  118. package/package.json +4 -4
  119. package/server.json +3 -3
  120. package/skills/usaspending-guide/SKILL.md +12 -6
@@ -1,11 +1,18 @@
1
1
  /**
2
2
  * @fileoverview Shared filter builder for USAspending analytics endpoints, and the
3
- * program, product/service, and emergency-funding code filters shared by
3
+ * program, product/service, and emergency-funding code filters and the
4
+ * place-of-performance and recipient location filters shared by
4
5
  * `usaspending_search_awards` and the three spending analytics tools.
5
6
  * @module mcp-server/tools/definitions/filters
6
7
  */
7
8
  import { z } from '@cyanheads/mcp-ts-core';
9
+ import { type AgencyFilters } from './agency-filters.js';
8
10
  import { type DateRange } from './dates.js';
11
+ import { LocationFilterSchema, type SentLocation } from './locations.js';
12
+ /** Describe the recipient hash and the attribution role it selects. */
13
+ export declare const RECIPIENT_FILTER_DESCRIPTION = "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. A -P recipient ID covers awards USAspending attributes to that parent. Historical parent attribution can vary. For the entity\u2019s own awards, use the returned -C ID for awards recorded with a parent or the returned -R ID for awards recorded without one. Check both when usaspending_search_recipients returns both. Use returned IDs directly.";
14
+ /** Disclose the attribution scope of an effective, normalized parent ID. */
15
+ export declare function parentRecipientNotice(recipientId: string | undefined): string | undefined;
9
16
  /** Values selected after merge precedence, before an upstream request. */
10
17
  interface EffectiveFilters {
11
18
  keywords?: string[] | undefined;
@@ -17,12 +24,6 @@ export declare function normalizeEffectiveFilters(f: EffectiveFilters): Effectiv
17
24
  reason: 'invalid_keyword' | 'invalid_naics_code' | 'invalid_recipient_id';
18
25
  message: string;
19
26
  };
20
- /** Matches an awarding name at either tier; shared sub-tier names match every parent. */
21
- export declare function awardingAgencyFilters(name: string): {
22
- type: string;
23
- tier: string;
24
- name: string;
25
- }[];
26
27
  /**
27
28
  * Award type codes by the groups `search/spending_by_award/` accepts one at a
28
29
  * time — the partition its mixed-group 422 lists, F-codes and -1 included.
@@ -76,6 +77,54 @@ export declare function codeFilterEcho(codes: CodeFilters): {
76
77
  };
77
78
  /** The code filters sent, as `key=value` parts an empty-result notice names. */
78
79
  export declare function describeCodeFilters(codes: CodeFilters): string[];
80
+ /**
81
+ * The two location filters, keyed as every `filters` object that takes them
82
+ * declares them. One instance per key, spread into each tool's `filters`, so
83
+ * `tools/list` describes them identically everywhere.
84
+ */
85
+ export declare const LOCATION_FILTER_FIELDS: {
86
+ place_of_performance_location: z.ZodOptional<z.ZodObject<{
87
+ country: z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
88
+ state: z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
89
+ county: z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
90
+ city: z.ZodOptional<z.ZodString>;
91
+ }, z.core.$strict>>;
92
+ recipient_location: z.ZodOptional<z.ZodObject<{
93
+ country: z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
94
+ state: z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
95
+ county: z.ZodOptional<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodLiteral<"">, z.ZodString]>, unknown>>;
96
+ city: z.ZodOptional<z.ZodString>;
97
+ }, z.core.$strict>>;
98
+ };
99
+ type LocationFilterKey = keyof typeof LOCATION_FILTER_FIELDS;
100
+ /** The location filters as a call supplied them. */
101
+ export type LocationFilterInput = {
102
+ [K in LocationFilterKey]?: z.infer<typeof LocationFilterSchema>;
103
+ };
104
+ /** The locations sent, normalized; a key whose object was all blank is absent. */
105
+ export type LocationFilters = {
106
+ [K in LocationFilterKey]?: SentLocation;
107
+ };
108
+ /**
109
+ * Resolves both location filters per {@link resolveLocation}, naming the failing
110
+ * key's path (`filters.recipient_location.county "049" …`) in the message.
111
+ */
112
+ export declare function resolveLocationFilters(f: LocationFilterInput): {
113
+ locations: LocationFilters;
114
+ ok: true;
115
+ } | {
116
+ message: string;
117
+ ok: false;
118
+ };
119
+ /** Writes the locations into an upstream `filters` object under the endpoint's keys. */
120
+ export declare function applyLocationFilters(filters: Record<string, unknown>, locations: LocationFilters): void;
121
+ /** The locations sent, as the `applied_*` echo every tool carries. */
122
+ export declare function locationFilterEcho(locations: LocationFilters): {
123
+ applied_location?: string;
124
+ applied_recipient_location?: string;
125
+ };
126
+ /** The locations sent, as `key="…"` parts an empty-result notice names. */
127
+ export declare function describeLocationFilters(locations: LocationFilters): string[];
79
128
  /**
80
129
  * Upstream answers a code filter no award type in the call can carry with $0
81
130
  * and no message, so an analytics call is rejected when every effective award
@@ -97,13 +146,14 @@ export declare function analyticsTypeMismatch(codes: CodeFilters, awardTypeCodes
97
146
  export declare function buildFilters(f?: ({
98
147
  keywords?: string[] | undefined;
99
148
  award_type_codes?: string[] | undefined;
100
- agency_name?: string | undefined;
101
149
  recipient_id?: string | undefined;
102
150
  naics_codes?: string[] | undefined;
103
151
  time_period_start?: string | undefined;
104
152
  time_period_end?: string | undefined;
105
- } & CodeFilterInput) | null): {
106
- filters: Record<string, unknown>;
153
+ } & CodeFilterInput & AgencyFilters) | null): {
154
+ filters: Record<string, unknown> & {
155
+ award_type_codes?: readonly string[];
156
+ };
107
157
  timePeriod: DateRange | undefined;
108
158
  codes: CodeFilters;
109
159
  };
@@ -1 +1 @@
1
- {"version":3,"file":"filters.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/filters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AAC3C,OAAO,EAAE,KAAK,SAAS,EAAoB,MAAM,YAAY,CAAC;AAE9D,0EAA0E;AAC1E,UAAU,gBAAgB;IACxB,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IACnC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;AAED,uFAAuF;AACvF,wBAAgB,yBAAyB,CACvC,CAAC,EAAE,gBAAgB,GAEjB,gBAAgB,GAChB;IAAE,MAAM,EAAE,iBAAiB,GAAG,oBAAoB,GAAG,sBAAsB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAkEjG;AAED,yFAAyF;AACzF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM;;;;IAKjD;AAWD;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;;;CAOgB,CAAC;AAE9C,iGAAiG;AACjG,eAAO,MAAM,4BAA4B,EAAE,WAAW,CAAC,MAAM,CAG3D,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,2BAA2B,EAAE,WAAW,CAAC,MAAM,CAK1D,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,kBAAkB;IAC7B,mBAAmB;IAcnB,SAAS;IAWT,SAAS;CAWV,CAAC;AAEF,wEAAwE;AACxE,MAAM,WAAW,eAAe;IAC9B,mBAAmB,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC3C,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC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ACC,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAChC,gBAAgB,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IACxC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IACnC,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC,GAAG,eAAe,GACjB,aAAa,CAAC,GAChB,IAAI,GACP;IACD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;QAAE,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,CAAC;IAC5E,UAAU,EAAE,SAAS,GAAG,SAAS,CAAC;IAClC,KAAK,EAAE,WAAW,CAAC;CACpB,CAeA"}
@@ -1,11 +1,21 @@
1
1
  /**
2
2
  * @fileoverview Shared filter builder for USAspending analytics endpoints, and the
3
- * program, product/service, and emergency-funding code filters shared by
3
+ * program, product/service, and emergency-funding code filters and the
4
+ * place-of-performance and recipient location filters shared by
4
5
  * `usaspending_search_awards` and the three spending analytics tools.
5
6
  * @module mcp-server/tools/definitions/filters
6
7
  */
7
8
  import { z } from '@cyanheads/mcp-ts-core';
9
+ import { applyAgencyFilters } from './agency-filters.js';
8
10
  import { resolveDateRange } from './dates.js';
11
+ import { describeLocation, LocationFilterSchema, resolveLocation, } from './locations.js';
12
+ const PARENT_RECIPIENT_SCOPE = 'A -P recipient ID covers awards USAspending attributes to that parent. Historical parent attribution can vary. For the entity’s own awards, use the returned -C ID for awards recorded with a parent or the returned -R ID for awards recorded without one. Check both when usaspending_search_recipients returns both. Use returned IDs directly.';
13
+ /** Describe the recipient hash and the attribution role it selects. */
14
+ export const RECIPIENT_FILTER_DESCRIPTION = `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. ${PARENT_RECIPIENT_SCOPE}`;
15
+ /** Disclose the attribution scope of an effective, normalized parent ID. */
16
+ export function parentRecipientNotice(recipientId) {
17
+ return recipientId?.endsWith('-P') ? PARENT_RECIPIENT_SCOPE : undefined;
18
+ }
9
19
  /** Normalize recognized integer aliases; leave Python-only grammar to the provider. */
10
20
  export function normalizeEffectiveFilters(f) {
11
21
  if (f.keywords?.some((keyword) => keyword.length < 3))
@@ -65,13 +75,6 @@ export function normalizeEffectiveFilters(f) {
65
75
  : {}),
66
76
  };
67
77
  }
68
- /** Matches an awarding name at either tier; shared sub-tier names match every parent. */
69
- export function awardingAgencyFilters(name) {
70
- return [
71
- { type: 'awarding', tier: 'toptier', name },
72
- { type: 'awarding', tier: 'subtier', name },
73
- ];
74
- }
75
78
  /** Assistance Listing (CFDA) number: two digits, a dot, three digits or capitals (`11.67A`). */
76
79
  const ASSISTANCE_LISTING_PATTERN = /^\d{2}\.[0-9A-Z]{3}$/;
77
80
  /** Product and Service Code, or a prefix of one: 1–4 letters or digits, either case. */
@@ -131,7 +134,7 @@ export const CODE_FILTER_FIELDS = {
131
134
  .regex(DEF_CODE_PATTERN, 'Expected a DEF code of 1–3 letters or digits')
132
135
  .describe('Disaster Emergency Fund Code, e.g. Z or L'))
133
136
  .optional()
134
- .describe('Filter by Disaster Emergency Fund Codes (DEF), e.g. ["Z"], or ["L", "M", "N", "O", "P"] for COVID-19: 1–3 letters or digits, sent uppercased — the codes usaspending_disaster_spending takes and usaspending_get_agency lists. Matches awards of any type funded under any of these codes. Amounts cover the whole matching award, not the share funded by the code, and DEF-filtered totals can be negative. An unknown code is rejected with the list of codes USAspending accepts.'),
137
+ .describe('Filter by Disaster Emergency Fund Codes (DEF), e.g. ["Z"], or ["L", "M", "N", "O", "P"] for COVID-19: 1–3 letters or digits, sent uppercased. Discover codes with usaspending_autocomplete_filters type=def_code. Matches awards of any type funded under any of these codes. Amounts cover the whole matching award, not the share funded by the code, and DEF-filtered totals can be negative. An unknown code is rejected with the list of codes USAspending accepts.'),
135
138
  };
136
139
  /** Upstream rejects lowercase PSC and DEF codes and an empty list, so both are normalized away. */
137
140
  export function normalizeCodeFilters(f) {
@@ -174,6 +177,60 @@ export function describeCodeFilters(codes) {
174
177
  ...(codes.def_codes ? [`def_codes=${codes.def_codes.join(',')}`] : []),
175
178
  ];
176
179
  }
180
+ /**
181
+ * The two location filters, keyed as every `filters` object that takes them
182
+ * declares them. One instance per key, spread into each tool's `filters`, so
183
+ * `tools/list` describes them identically everywhere.
184
+ */
185
+ export const LOCATION_FILTER_FIELDS = {
186
+ place_of_performance_location: LocationFilterSchema.describe('Filter by place of performance — where the work is done. Takes codes, not place names — resolve a state or county name to its code with usaspending_autocomplete_filters type=location. Blank fields are ignored, and an all-blank object is no location filter. The location sent is echoed as applied_location.'),
187
+ recipient_location: LocationFilterSchema.describe('Filter by recipient location — where the recipient is based, which can differ from where the work is done. Takes codes, not place names — resolve a state or county name to its code with usaspending_autocomplete_filters type=location. Blank fields are ignored, and an all-blank object is no location filter. The location sent is echoed as applied_recipient_location.'),
188
+ };
189
+ /** The upstream `filters` key each location filter is sent under, as a one-element list. */
190
+ const UPSTREAM_LOCATION_KEYS = {
191
+ place_of_performance_location: 'place_of_performance_locations',
192
+ recipient_location: 'recipient_locations',
193
+ };
194
+ const LOCATION_KEYS = Object.keys(UPSTREAM_LOCATION_KEYS);
195
+ /**
196
+ * Resolves both location filters per {@link resolveLocation}, naming the failing
197
+ * key's path (`filters.recipient_location.county "049" …`) in the message.
198
+ */
199
+ export function resolveLocationFilters(f) {
200
+ const locations = {};
201
+ for (const key of LOCATION_KEYS) {
202
+ const resolved = resolveLocation(f[key], `filters.${key}`);
203
+ if (!resolved.ok)
204
+ return resolved;
205
+ if (resolved.location)
206
+ locations[key] = resolved.location;
207
+ }
208
+ return { ok: true, locations };
209
+ }
210
+ /** Writes the locations into an upstream `filters` object under the endpoint's keys. */
211
+ export function applyLocationFilters(filters, locations) {
212
+ for (const key of LOCATION_KEYS) {
213
+ const location = locations[key];
214
+ if (location)
215
+ filters[UPSTREAM_LOCATION_KEYS[key]] = [location];
216
+ }
217
+ }
218
+ /** The locations sent, as the `applied_*` echo every tool carries. */
219
+ export function locationFilterEcho(locations) {
220
+ const pop = locations.place_of_performance_location;
221
+ const recipient = locations.recipient_location;
222
+ return {
223
+ ...(pop ? { applied_location: describeLocation(pop) } : {}),
224
+ ...(recipient ? { applied_recipient_location: describeLocation(recipient) } : {}),
225
+ };
226
+ }
227
+ /** The locations sent, as `key="…"` parts an empty-result notice names. */
228
+ export function describeLocationFilters(locations) {
229
+ return LOCATION_KEYS.flatMap((key) => {
230
+ const location = locations[key];
231
+ return location ? [`${key}="${describeLocation(location)}"`] : [];
232
+ });
233
+ }
177
234
  /**
178
235
  * Upstream answers a code filter no award type in the call can carry with $0
179
236
  * and no message, so an analytics call is rejected when every effective award
@@ -215,9 +272,7 @@ export function buildFilters(f) {
215
272
  filters.keywords = f.keywords;
216
273
  if (f.award_type_codes?.length)
217
274
  filters.award_type_codes = f.award_type_codes;
218
- if (f.agency_name) {
219
- filters.agencies = awardingAgencyFilters(f.agency_name);
220
- }
275
+ applyAgencyFilters(filters, f);
221
276
  if (f.recipient_id)
222
277
  filters.recipient_id = f.recipient_id;
223
278
  if (f.naics_codes?.length)
@@ -1 +1 @@
1
- {"version":3,"file":"filters.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/filters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AAC3C,OAAO,EAAkB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAS9D,uFAAuF;AACvF,MAAM,UAAU,yBAAyB,CACvC,CAAmB;IAInB,IAAI,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;QACnD,OAAO;YACL,MAA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EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IAC5E,MAAM,KAAK,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC;IACtC,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACjC,MAAM,UAAU,GAAG,gBAAgB,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC,CAAC,eAAe,CAAC,CAAC;IAC5E,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,CAAC,WAAW,GAAG,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC/F,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;AACxC,CAAC"}
@@ -18,6 +18,13 @@ export declare const getAgencyTool: import("@cyanheads/mcp-ts-core").ToolDefinit
18
18
  budgetary_resources_amount: z.ZodOptional<z.ZodNumber>;
19
19
  obligated_amount: z.ZodOptional<z.ZodNumber>;
20
20
  outlay_amount: z.ZodOptional<z.ZodNumber>;
21
+ budget_by_fiscal_year: z.ZodOptional<z.ZodArray<z.ZodObject<{
22
+ fiscal_year: z.ZodNumber;
23
+ budgetary_resources_amount: z.ZodOptional<z.ZodNumber>;
24
+ obligated_amount: z.ZodOptional<z.ZodNumber>;
25
+ outlay_amount: z.ZodOptional<z.ZodNumber>;
26
+ reported_through_period: z.ZodOptional<z.ZodNumber>;
27
+ }, z.core.$strip>>>;
21
28
  subtier_agency_count: z.ZodOptional<z.ZodNumber>;
22
29
  sub_agencies: z.ZodOptional<z.ZodArray<z.ZodObject<{
23
30
  name: z.ZodOptional<z.ZodString>;
@@ -38,6 +45,7 @@ export declare const getAgencyTool: import("@cyanheads/mcp-ts-core").ToolDefinit
38
45
  public_law: z.ZodOptional<z.ZodString>;
39
46
  title: z.ZodOptional<z.ZodString>;
40
47
  }, z.core.$strip>>>;
48
+ def_codes_fiscal_year: z.ZodOptional<z.ZodNumber>;
41
49
  website: z.ZodOptional<z.ZodString>;
42
50
  }, z.core.$strip>, readonly [{
43
51
  readonly reason: "agency_not_found";
@@ -75,6 +83,7 @@ export declare const getAgencyTool: import("@cyanheads/mcp-ts-core").ToolDefinit
75
83
  readonly unavailable_sections: z.ZodOptional<z.ZodArray<z.ZodObject<{
76
84
  section: z.ZodEnum<{
77
85
  budgetary_resources: "budgetary_resources";
86
+ def_codes: "def_codes";
78
87
  sub_agencies: "sub_agencies";
79
88
  }>;
80
89
  reason: z.ZodEnum<{
@@ -1 +1 @@
1
- {"version":3,"file":"get-agency.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/get-agency.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAQ,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAY,MAAM,+BAA+B,CAAC;AAsD3E,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6cxB,CAAC"}
1
+ {"version":3,"file":"get-agency.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/get-agency.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAQ,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AA8DjE,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAihBxB,CAAC"}
@@ -3,11 +3,12 @@
3
3
  * @module mcp-server/tools/definitions/get-agency.tool
4
4
  */
5
5
  import { tool, z } from '@cyanheads/mcp-ts-core';
6
- import { JsonRpcErrorCode, McpError } from '@cyanheads/mcp-ts-core/errors';
6
+ import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
7
7
  import { escapeMarkdownInline, markdownLink } from '@cyanheads/mcp-ts-core/utils';
8
8
  import { getUSASpendingService } from '../../../services/usaspending/usaspending-service.js';
9
9
  import { formatCurrency } from './formatting.js';
10
10
  import { formatPaginationLine } from './pagination.js';
11
+ import { renderUnavailableSections, settleSection, unavailableNotice, unavailableSectionSchema, } from './unavailable-sections.js';
11
12
  /** Sub-agency breakdown page size (the endpoint's natural page cap). */
12
13
  const SUB_AGENCY_PAGE_LIMIT = 10;
13
14
  /**
@@ -19,31 +20,30 @@ const SUB_AGENCY_PAGE_LIMIT = 10;
19
20
  * `sub_agency_fiscal_year` discloses.
20
21
  */
21
22
  const BUDGET_YEAR_WAIT_MS = 5_000;
22
- const UnavailableSectionSchema = z
23
- .object({
24
- section: z
25
- .enum(['budgetary_resources', 'sub_agencies'])
26
- .describe('budgetary_resources: fiscal_year and the budget, obligation, and outlay totals. sub_agencies: the sub-agency breakdown and its pagination.'),
27
- reason: z
28
- .enum(['api_unavailable', 'api_timeout', 'upstream_error'])
29
- .describe('api_unavailable: USAspending was unreachable or answered with a server error. api_timeout: no answer before the request deadline. upstream_error: USAspending rejected the request.'),
30
- retryable: z.boolean().describe('Whether retrying the call may load this section.'),
31
- message: z.string().describe('The failure message for this section.'),
32
- })
33
- .describe('A section omitted from the result because its request failed');
23
+ const UnavailableSectionSchema = unavailableSectionSchema(['budgetary_resources', 'sub_agencies', 'def_codes'], 'budgetary_resources: fiscal_year, the budget, obligation, and outlay totals, and budget_by_fiscal_year. sub_agencies: the breakdown and its pagination. def_codes: the disaster/emergency funding codes and their fiscal year.');
34
24
  /**
35
- * The budget row the totals report: the most recent fiscal year carrying at least one
36
- * amount. A new fiscal year opens with a row whose amounts are all null until the
37
- * agency first reports, so that row is skipped; a 0 is data.
25
+ * The budget rows carrying at least one amount, most recent fiscal year first; the
26
+ * first is the year the totals report. A new fiscal year opens with a row whose
27
+ * amounts are all null until the agency first reports, so that row is skipped; a 0
28
+ * is data.
38
29
  */
39
- function selectBudgetRow(rows) {
30
+ function budgetRows(rows) {
40
31
  return [...(rows ?? [])]
41
32
  .sort((a, b) => (b.fiscal_year ?? 0) - (a.fiscal_year ?? 0))
42
- .find((row) => [row.agency_budgetary_resources, row.agency_total_obligated, row.agency_total_outlayed].some((amount) => typeof amount === 'number'));
33
+ .filter((row) => [row.agency_budgetary_resources, row.agency_total_obligated, row.agency_total_outlayed].some((amount) => typeof amount === 'number'));
34
+ }
35
+ /**
36
+ * The last reporting period a budget row covers: the highest period in its
37
+ * obligations-by-period list. Each row is as of its year's latest closed period, so
38
+ * below 12 the row is year-to-date.
39
+ */
40
+ function reportedThroughPeriod(row) {
41
+ const periods = (row.agency_obligation_by_period ?? []).flatMap((p) => typeof p.period === 'number' ? [p.period] : []);
42
+ return periods.length > 0 ? Math.max(...periods) : undefined;
43
43
  }
44
44
  export const getAgencyTool = tool('usaspending_get_agency', {
45
45
  title: 'Get Agency Overview',
46
- description: "Fetch an agency's fiscal-year overview including mission, budgetary resources, obligation and outlay totals (for the most recent fiscal year with reported budget data), sub-agency count, and DEF codes for disaster/emergency funding. Also returns a paginated sub-agency breakdown with obligation and transaction counts for the same fiscal year as the budget totals (the current fiscal year when no budget year is available within 5 seconds); sub_agency_fiscal_year names the year it covers. Accepts exactly one directory toptier_code (e.g., 097 for DoD, 1601 for Labor; one/two-digit numeric inputs are zero-padded to three digits) or an agency_slug (e.g., department-of-defense) — both appear in usaspending_list_agencies results and award search results. When the budget or sub-agency request fails, the overview is still returned and unavailable_sections names each missing section with its reason.",
46
+ description: "Fetch an agency's fiscal-year overview including mission, budgetary resources, obligation and outlay totals (for the most recent fiscal year with reported budget data), sub-agency count, and disaster/emergency funding codes. def_codes_fiscal_year names the fiscal year covered by def_codes, which follows the budget totals when available. budget_by_fiscal_year carries the same totals for every fiscal year with reported data since FY2017, newest first, for budget trends; a row whose reported_through_period is below 12 is year-to-date, so compare it to full years with care. Also returns a paginated sub-agency breakdown with obligation and transaction counts for the same fiscal year as the budget totals (the current fiscal year when no budget year is available within 5 seconds); sub_agency_fiscal_year names the year it covers. Accepts exactly one directory toptier_code (e.g., 097 for DoD, 1601 for Labor; one/two-digit numeric inputs are zero-padded to three digits) or an agency_slug (e.g., department-of-defense) — both appear in usaspending_list_agencies results and award search results. When the budget, sub-agency or DEF code request fails, the overview is still returned and unavailable_sections names each missing section with its reason.",
47
47
  annotations: { readOnlyHint: true, openWorldHint: false, idempotentHint: true },
48
48
  input: z.object({
49
49
  toptier_code: z
@@ -83,6 +83,32 @@ export const getAgencyTool = tool('usaspending_get_agency', {
83
83
  .optional()
84
84
  .describe('Total amount obligated in USD for the fiscal year'),
85
85
  outlay_amount: z.number().optional().describe('Total outlays in USD for the fiscal year'),
86
+ budget_by_fiscal_year: z
87
+ .array(z
88
+ .object({
89
+ fiscal_year: z
90
+ .number()
91
+ .describe('Fiscal year (FY2026 ran October 2025 – September 2026)'),
92
+ budgetary_resources_amount: z
93
+ .number()
94
+ .optional()
95
+ .describe('Total budgetary resources in USD for the year'),
96
+ obligated_amount: z
97
+ .number()
98
+ .optional()
99
+ .describe('Amount obligated in USD for the year, through reported_through_period'),
100
+ outlay_amount: z
101
+ .number()
102
+ .optional()
103
+ .describe('Outlays in USD for the year, through reported_through_period'),
104
+ reported_through_period: z
105
+ .number()
106
+ .optional()
107
+ .describe('Last reporting period the row covers (1–12, 1 = October). Below 12, the year is still being reported and its amounts are year-to-date, not comparable to a full year. Absent when upstream lists no reporting periods for the year.'),
108
+ })
109
+ .describe('One fiscal year of budget data; a null upstream amount is omitted'))
110
+ .optional()
111
+ .describe('Budgetary resources, obligations, and outlays for every fiscal year with reported data since FY2017, newest first. The first row is the year fiscal_year and the totals above report. Each row is as of the latest closed reporting period of its year. Absent when no year carries data or the budget request failed.'),
86
112
  subtier_agency_count: z
87
113
  .number()
88
114
  .optional()
@@ -121,7 +147,11 @@ export const getAgencyTool = tool('usaspending_get_agency', {
121
147
  })
122
148
  .describe('DEF code entry with public law and title'))
123
149
  .optional()
124
- .describe('Disaster/Emergency Funding (DEF) codes applicable to this agency'),
150
+ .describe('Disaster/Emergency Funding (DEF) codes for the budget year, or for the default overview when no budget year is available. Empty when upstream returned no codes. Omitted when unavailable.'),
151
+ def_codes_fiscal_year: z
152
+ .number()
153
+ .optional()
154
+ .describe('Fiscal year covered by def_codes, when USAspending reports it'),
125
155
  website: z.string().optional().describe('Agency website URL'),
126
156
  }),
127
157
  // Agent-facing context: sub-agency pagination state, truncation guidance, and failed sections.
@@ -149,12 +179,7 @@ export const getAgencyTool = tool('usaspending_get_agency', {
149
179
  },
150
180
  enrichmentTrailer: {
151
181
  notice: { render: (notice) => (notice ? `> ${escapeMarkdownInline(notice)}` : '') },
152
- unavailable_sections: {
153
- render: (sections) => [
154
- '**Unavailable sections:**',
155
- ...(sections ?? []).map((s) => `- ${escapeMarkdownInline(s.section)}: ${escapeMarkdownInline(s.reason)}${s.retryable ? ' (retryable)' : ''} — ${escapeMarkdownInline(s.message)}`),
156
- ].join('\n'),
157
- },
182
+ unavailable_sections: { render: renderUnavailableSections },
158
183
  },
159
184
  errors: [
160
185
  {
@@ -222,7 +247,9 @@ export const getAgencyTool = tool('usaspending_get_agency', {
222
247
  throw ctx.fail('missing_input', 'Either toptier_code or agency_slug is required');
223
248
  }
224
249
  const code = toptierCode;
250
+ const deadlineAt = svc.requestDeadline();
225
251
  const budgetRequest = svc.getAgencyBudgetaryResources(code, ctx);
252
+ const budgetRowsRequest = budgetRequest.then((budget) => budgetRows(budget.agency_data_by_year));
226
253
  /**
227
254
  * The breakdown waits on the budget so it covers the same fiscal year as the totals,
228
255
  * by the same rule on every page. Without a budget year — the request failed, no
@@ -233,9 +260,9 @@ export const getAgencyTool = tool('usaspending_get_agency', {
233
260
  */
234
261
  const budgetYear = new Promise((resolve, reject) => {
235
262
  const timer = setTimeout(() => resolve(undefined), BUDGET_YEAR_WAIT_MS);
236
- budgetRequest.then((budget) => {
263
+ budgetRowsRequest.then((rows) => {
237
264
  clearTimeout(timer);
238
- resolve(selectBudgetRow(budget.agency_data_by_year)?.fiscal_year ?? undefined);
265
+ resolve(rows[0]?.fiscal_year ?? undefined);
239
266
  }, (err) => {
240
267
  clearTimeout(timer);
241
268
  if (ctx.signal.aborted)
@@ -254,7 +281,8 @@ export const getAgencyTool = tool('usaspending_get_agency', {
254
281
  }));
255
282
  const overviewRequest = svc.getAgency(code, ctx);
256
283
  // Settled up front, so a leg that rejects after the overview fails is still handled.
257
- const legs = Promise.allSettled([subRequest, budgetRequest]);
284
+ const budgetLegRequest = Promise.allSettled([budgetRowsRequest]);
285
+ const subLegRequest = Promise.allSettled([subRequest]);
258
286
  /**
259
287
  * The overview decides the call and is awaited alone, so its failure surfaces as
260
288
  * soon as it settles rather than after the slower legs. It also decides existence:
@@ -265,32 +293,46 @@ export const getAgencyTool = tool('usaspending_get_agency', {
265
293
  if (!detail?.name) {
266
294
  throw ctx.fail('agency_not_found', `Agency not found: ${toptierCode}`);
267
295
  }
268
- const [subLeg, budgetLeg] = await legs;
269
296
  /**
270
297
  * A failed budget or sub-agency request degrades to a disclosed partial result
271
298
  * rather than failing the call, since the overview alone still answers. Caller
272
299
  * cancellation and unclassified (non-upstream) errors are rethrown.
273
300
  */
274
301
  const unavailable = [];
275
- const settleLeg = (section, leg) => {
276
- if (leg.status === 'fulfilled')
277
- return leg.value;
278
- const err = leg.reason;
279
- if (ctx.signal.aborted || !(err instanceof McpError))
280
- throw err;
281
- const reason = err.data?.reason;
282
- unavailable.push({
283
- section,
284
- reason: reason === 'api_unavailable' || reason === 'api_timeout' ? reason : 'upstream_error',
285
- retryable: err.data?.retryable === true,
286
- message: err.message,
287
- });
288
- return;
289
- };
290
- const budgetData = settleLeg('budgetary_resources', budgetLeg);
291
- const subLegData = settleLeg('sub_agencies', subLeg);
302
+ const [budgetLeg] = await budgetLegRequest;
303
+ const budgetYears = settleSection(ctx, 'budgetary_resources', budgetLeg, unavailable) ?? [];
304
+ const currentBudget = budgetYears[0];
305
+ const finalBudgetYear = currentBudget?.fiscal_year;
306
+ const defLegRequest = Promise.allSettled([
307
+ typeof finalBudgetYear === 'number' && finalBudgetYear !== detail.fiscal_year
308
+ ? svc.getAgencyDefCodes(code, finalBudgetYear, ctx, deadlineAt)
309
+ : detail,
310
+ ]);
311
+ const [[subLeg], [defLeg]] = await Promise.all([subLegRequest, defLegRequest]);
312
+ ctx.signal.throwIfAborted();
313
+ const subLegData = settleSection(ctx, 'sub_agencies', subLeg, unavailable);
314
+ const defData = settleSection(ctx, 'def_codes', defLeg, unavailable);
292
315
  const subAgenciesData = subLegData?.page;
293
- const currentBudget = selectBudgetRow(budgetData?.agency_data_by_year);
316
+ const budgetByFiscalYear = budgetYears.flatMap((row) => {
317
+ if (typeof row.fiscal_year !== 'number')
318
+ return [];
319
+ const through = reportedThroughPeriod(row);
320
+ return [
321
+ {
322
+ fiscal_year: row.fiscal_year,
323
+ ...(typeof row.agency_budgetary_resources === 'number'
324
+ ? { budgetary_resources_amount: row.agency_budgetary_resources }
325
+ : {}),
326
+ ...(typeof row.agency_total_obligated === 'number'
327
+ ? { obligated_amount: row.agency_total_obligated }
328
+ : {}),
329
+ ...(typeof row.agency_total_outlayed === 'number'
330
+ ? { outlay_amount: row.agency_total_outlayed }
331
+ : {}),
332
+ ...(through !== undefined ? { reported_through_period: through } : {}),
333
+ },
334
+ ];
335
+ });
294
336
  // The year upstream says the breakdown covers; the year requested when it does not say.
295
337
  const subYear = typeof subAgenciesData?.fiscal_year === 'number'
296
338
  ? subAgenciesData.fiscal_year
@@ -331,10 +373,7 @@ export const getAgencyTool = tool('usaspending_get_agency', {
331
373
  }
332
374
  if (unavailable.length > 0) {
333
375
  ctx.enrich({ unavailable_sections: unavailable });
334
- const retryable = unavailable.filter((s) => s.retryable).map((s) => s.section);
335
- notices.push(`Partial result: ${unavailable.map((s) => `${s.section} (${s.reason})`).join(' and ')} could not be fetched, so ${unavailable.length === 1 ? 'its fields are' : 'their fields are'} omitted. ${retryable.length > 0
336
- ? `Retry the call to load ${retryable.join(' and ')}.`
337
- : 'Retrying is unlikely to help.'}`);
376
+ notices.push(unavailableNotice(unavailable));
338
377
  }
339
378
  if (notices.length > 0)
340
379
  ctx.enrich.notice(notices.join(' '));
@@ -358,6 +397,7 @@ export const getAgencyTool = tool('usaspending_get_agency', {
358
397
  ...(typeof currentBudget?.agency_total_outlayed === 'number'
359
398
  ? { outlay_amount: currentBudget.agency_total_outlayed }
360
399
  : {}),
400
+ ...(budgetByFiscalYear.length > 0 ? { budget_by_fiscal_year: budgetByFiscalYear } : {}),
361
401
  ...(typeof detail.sub_agency_count === 'number'
362
402
  ? { subtier_agency_count: detail.sub_agency_count }
363
403
  : typeof detail.subtier_agency_count === 'number'
@@ -375,9 +415,12 @@ export const getAgencyTool = tool('usaspending_get_agency', {
375
415
  },
376
416
  }
377
417
  : {}),
378
- ...(detail.def_codes?.length
418
+ ...(defData?.def_codes
379
419
  ? {
380
- def_codes: detail.def_codes.map((d) => ({
420
+ ...(typeof defData.fiscal_year === 'number'
421
+ ? { def_codes_fiscal_year: defData.fiscal_year }
422
+ : {}),
423
+ def_codes: defData.def_codes.map((d) => ({
381
424
  ...(d.code ? { code: d.code } : {}),
382
425
  ...(d.public_law ? { public_law: d.public_law } : {}),
383
426
  ...(d.title ? { title: d.title } : {}),
@@ -411,6 +454,18 @@ export const getAgencyTool = tool('usaspending_get_agency', {
411
454
  lines.push(`**Sub-Agency Fiscal Year:** ${result.sub_agency_fiscal_year}`);
412
455
  if (result.website)
413
456
  lines.push(`**Website:** ${markdownLink(result.website, result.website)}`);
457
+ if (result.budget_by_fiscal_year?.length) {
458
+ const amount = (value) => typeof value === 'number' ? formatCurrency(value) : 'N/A';
459
+ lines.push('\n### Budget by Fiscal Year');
460
+ lines.push('| Fiscal Year | Budgetary Resources | Obligated | Outlays | Reported Through Period |');
461
+ lines.push('|:------------|:--------------------|:----------|:--------|:------------------------|');
462
+ for (const row of result.budget_by_fiscal_year) {
463
+ const through = typeof row.reported_through_period === 'number'
464
+ ? `${row.reported_through_period}${row.reported_through_period < 12 ? ' (year to date)' : ''}`
465
+ : 'N/A';
466
+ lines.push(`| ${row.fiscal_year} | ${amount(row.budgetary_resources_amount)} | ${amount(row.obligated_amount)} | ${amount(row.outlay_amount)} | ${through} |`);
467
+ }
468
+ }
414
469
  if (result.sub_agencies?.length || result.sub_agency_page_metadata) {
415
470
  lines.push('\n### Sub-Agency Breakdown');
416
471
  if (result.sub_agency_page_metadata)
@@ -426,8 +481,12 @@ export const getAgencyTool = tool('usaspending_get_agency', {
426
481
  lines.push(`| ${escapeMarkdownInline(s.name ?? 'N/A')}${s.abbreviation ? ` (${escapeMarkdownInline(s.abbreviation)})` : ''} | ${oblig} | ${txns} | ${newAwards} |`);
427
482
  }
428
483
  }
429
- if (result.def_codes?.length) {
484
+ if (result.def_codes) {
430
485
  lines.push('\n### Disaster/Emergency Funding Codes');
486
+ if (typeof result.def_codes_fiscal_year === 'number')
487
+ lines.push(`**DEF Codes Fiscal Year:** ${result.def_codes_fiscal_year}`);
488
+ if (!result.def_codes.length)
489
+ lines.push('USAspending reported no DEF codes.');
431
490
  for (const d of result.def_codes) {
432
491
  lines.push(`- **${escapeMarkdownInline(d.code ?? 'N/A')}** — ${escapeMarkdownInline(d.title ?? 'N/A')}${d.public_law ? ` (${escapeMarkdownInline(d.public_law)})` : ''}`);
433
492
  }