@cyanheads/usaspending-mcp-server 0.4.5 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/AGENTS.md +3 -3
  2. package/CLAUDE.md +3 -3
  3. package/Dockerfile +3 -3
  4. package/README.md +30 -24
  5. package/changelog/0.5.x/0.5.0.md +50 -0
  6. package/dist/config/server-config.d.ts.map +1 -1
  7. package/dist/config/server-config.js +3 -3
  8. package/dist/config/server-config.js.map +1 -1
  9. package/dist/index.js +1 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.d.ts +8 -1
  12. package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.d.ts.map +1 -1
  13. package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.js +94 -35
  14. package/dist/mcp-server/tools/definitions/autocomplete-filters.tool.js.map +1 -1
  15. package/dist/mcp-server/tools/definitions/disaster-spending.tool.d.ts +2 -1
  16. package/dist/mcp-server/tools/definitions/disaster-spending.tool.d.ts.map +1 -1
  17. package/dist/mcp-server/tools/definitions/disaster-spending.tool.js +60 -26
  18. package/dist/mcp-server/tools/definitions/disaster-spending.tool.js.map +1 -1
  19. package/dist/mcp-server/tools/definitions/filters.d.ts +73 -4
  20. package/dist/mcp-server/tools/definitions/filters.d.ts.map +1 -1
  21. package/dist/mcp-server/tools/definitions/filters.js +138 -4
  22. package/dist/mcp-server/tools/definitions/filters.js.map +1 -1
  23. package/dist/mcp-server/tools/definitions/get-agency.tool.d.ts +22 -3
  24. package/dist/mcp-server/tools/definitions/get-agency.tool.d.ts.map +1 -1
  25. package/dist/mcp-server/tools/definitions/get-agency.tool.js +166 -29
  26. package/dist/mcp-server/tools/definitions/get-agency.tool.js.map +1 -1
  27. package/dist/mcp-server/tools/definitions/get-award.tool.d.ts +8 -3
  28. package/dist/mcp-server/tools/definitions/get-award.tool.d.ts.map +1 -1
  29. package/dist/mcp-server/tools/definitions/get-award.tool.js +148 -139
  30. package/dist/mcp-server/tools/definitions/get-award.tool.js.map +1 -1
  31. package/dist/mcp-server/tools/definitions/get-idv-awards.tool.d.ts.map +1 -1
  32. package/dist/mcp-server/tools/definitions/get-idv-awards.tool.js +14 -12
  33. package/dist/mcp-server/tools/definitions/get-idv-awards.tool.js.map +1 -1
  34. package/dist/mcp-server/tools/definitions/get-recipient.tool.d.ts +2 -8
  35. package/dist/mcp-server/tools/definitions/get-recipient.tool.d.ts.map +1 -1
  36. package/dist/mcp-server/tools/definitions/get-recipient.tool.js +28 -28
  37. package/dist/mcp-server/tools/definitions/get-recipient.tool.js.map +1 -1
  38. package/dist/mcp-server/tools/definitions/index.d.ts +130 -28
  39. package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -1
  40. package/dist/mcp-server/tools/definitions/locations.d.ts +45 -0
  41. package/dist/mcp-server/tools/definitions/locations.d.ts.map +1 -0
  42. package/dist/mcp-server/tools/definitions/locations.js +206 -0
  43. package/dist/mcp-server/tools/definitions/locations.js.map +1 -0
  44. package/dist/mcp-server/tools/definitions/search-awards.tool.d.ts +28 -8
  45. package/dist/mcp-server/tools/definitions/search-awards.tool.d.ts.map +1 -1
  46. package/dist/mcp-server/tools/definitions/search-awards.tool.js +107 -79
  47. package/dist/mcp-server/tools/definitions/search-awards.tool.js.map +1 -1
  48. package/dist/mcp-server/tools/definitions/spending-by-category.tool.d.ts +21 -2
  49. package/dist/mcp-server/tools/definitions/spending-by-category.tool.d.ts.map +1 -1
  50. package/dist/mcp-server/tools/definitions/spending-by-category.tool.js +77 -12
  51. package/dist/mcp-server/tools/definitions/spending-by-category.tool.js.map +1 -1
  52. package/dist/mcp-server/tools/definitions/spending-by-geography.tool.d.ts +21 -2
  53. package/dist/mcp-server/tools/definitions/spending-by-geography.tool.d.ts.map +1 -1
  54. package/dist/mcp-server/tools/definitions/spending-by-geography.tool.js +93 -20
  55. package/dist/mcp-server/tools/definitions/spending-by-geography.tool.js.map +1 -1
  56. package/dist/mcp-server/tools/definitions/spending-over-time.tool.d.ts +19 -1
  57. package/dist/mcp-server/tools/definitions/spending-over-time.tool.d.ts.map +1 -1
  58. package/dist/mcp-server/tools/definitions/spending-over-time.tool.js +60 -12
  59. package/dist/mcp-server/tools/definitions/spending-over-time.tool.js.map +1 -1
  60. package/dist/services/usaspending/types.d.ts +24 -16
  61. package/dist/services/usaspending/types.d.ts.map +1 -1
  62. package/dist/services/usaspending/usaspending-service.d.ts +45 -27
  63. package/dist/services/usaspending/usaspending-service.d.ts.map +1 -1
  64. package/dist/services/usaspending/usaspending-service.js +93 -53
  65. package/dist/services/usaspending/usaspending-service.js.map +1 -1
  66. package/package.json +5 -5
  67. package/server.json +3 -3
package/AGENTS.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Developer Protocol
2
2
 
3
3
  **Server:** usaspending-mcp-server
4
- **Version:** 0.4.5
5
- **Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.13`
4
+ **Version:** 0.5.0
5
+ **Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.15`
6
6
  **Engines:** Bun ≥1.4.0, Node ≥24.0.0
7
- **MCP SDK:** `@modelcontextprotocol/server` ^2.2.0
7
+ **MCP SDK:** `@modelcontextprotocol/server` ^2.3.1
8
8
  **Zod:** ^4.6.5
9
9
 
10
10
  > **Read the framework docs first:** `node_modules/@cyanheads/mcp-ts-core/CLAUDE.md` contains the full API reference — builders, Context, error codes, exports, patterns. This file covers server-specific conventions only.
package/CLAUDE.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Developer Protocol
2
2
 
3
3
  **Server:** usaspending-mcp-server
4
- **Version:** 0.4.5
5
- **Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.13`
4
+ **Version:** 0.5.0
5
+ **Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.15`
6
6
  **Engines:** Bun ≥1.4.0, Node ≥24.0.0
7
- **MCP SDK:** `@modelcontextprotocol/server` ^2.2.0
7
+ **MCP SDK:** `@modelcontextprotocol/server` ^2.3.1
8
8
  **Zod:** ^4.6.5
9
9
 
10
10
  > **Read the framework docs first:** `node_modules/@cyanheads/mcp-ts-core/CLAUDE.md` contains the full API reference — builders, Context, error codes, exports, patterns. This file covers server-specific conventions only.
package/Dockerfile CHANGED
@@ -14,7 +14,7 @@
14
14
  # output. A stage that compiles a native addon needs the target-arch toolchain
15
15
  # and cannot cross-compile this way — drop the flag there.
16
16
  # ==============================================================================
17
- FROM --platform=$BUILDPLATFORM oven/bun:1.4.2 AS build
17
+ FROM --platform=$BUILDPLATFORM oven/bun:1.4.3 AS build
18
18
 
19
19
  WORKDIR /usr/src/app
20
20
 
@@ -46,7 +46,7 @@ RUN bun run build
46
46
  # A clean image rather than `FROM build`: the build stage's node_modules holds
47
47
  # devDependencies.
48
48
  # ==============================================================================
49
- FROM --platform=$BUILDPLATFORM oven/bun:1.4.2 AS deps
49
+ FROM --platform=$BUILDPLATFORM oven/bun:1.4.3 AS deps
50
50
 
51
51
  WORKDIR /usr/src/app
52
52
 
@@ -114,7 +114,7 @@ RUN rm -rf node_modules/@socketsecurity/bun-security-scanner
114
114
  # dependencies and build artifacts. Its only Bun invocations are HEALTHCHECK
115
115
  # and CMD, which run on the real target at container start.
116
116
  # ==============================================================================
117
- FROM oven/bun:1.4.2-slim AS production
117
+ FROM oven/bun:1.4.3-slim AS production
118
118
 
119
119
  WORKDIR /usr/src/app
120
120
 
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  <div align="center">
9
9
 
10
- [![Version](https://img.shields.io/badge/Version-0.4.5-blue.svg?style=flat-square)](./CHANGELOG.md) [![License](https://img.shields.io/badge/License-Apache%202.0-orange.svg?style=flat-square)](./LICENSE) [![Docker](https://img.shields.io/badge/Docker-ghcr.io-2496ED?style=flat-square&logo=docker&logoColor=white)](https://github.com/users/cyanheads/packages/container/package/usaspending-mcp-server) [![MCP SDK](https://img.shields.io/badge/MCP%20SDK-^2.2.0-green.svg?style=flat-square)](https://modelcontextprotocol.io/) [![npm](https://img.shields.io/npm/v/@cyanheads/usaspending-mcp-server?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@cyanheads/usaspending-mcp-server) [![TypeScript](https://img.shields.io/badge/TypeScript-^7.0.2-3178C6.svg?style=flat-square)](https://www.typescriptlang.org/) [![Bun](https://img.shields.io/badge/Bun-v1.4.2-blueviolet.svg?style=flat-square)](https://bun.sh/)
10
+ [![Version](https://img.shields.io/badge/Version-0.5.0-blue.svg?style=flat-square)](./CHANGELOG.md) [![License](https://img.shields.io/badge/License-Apache%202.0-orange.svg?style=flat-square)](./LICENSE) [![Docker](https://img.shields.io/badge/Docker-ghcr.io-2496ED?style=flat-square&logo=docker&logoColor=white)](https://github.com/users/cyanheads/packages/container/package/usaspending-mcp-server) [![MCP SDK](https://img.shields.io/badge/MCP%20SDK-^2.3.1-green.svg?style=flat-square)](https://modelcontextprotocol.io/) [![npm](https://img.shields.io/npm/v/@cyanheads/usaspending-mcp-server?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@cyanheads/usaspending-mcp-server) [![TypeScript](https://img.shields.io/badge/TypeScript-^7.0.2-3178C6.svg?style=flat-square)](https://www.typescriptlang.org/) [![Bun](https://img.shields.io/badge/Bun-v1.4.3-blueviolet.svg?style=flat-square)](https://bun.sh/)
11
11
 
12
12
  </div>
13
13
 
@@ -37,7 +37,7 @@ Federal award, recipient, agency, and spending data from USAspending.gov, the US
37
37
  |:---|:---|
38
38
  | `usaspending_list_agencies` | List every top-tier federal agency with its toptier code, slug, and current-year budget totals |
39
39
  | `usaspending_autocomplete_filters` | Look up NAICS, PSC, CFDA, agency, or recipient codes from a free-text description |
40
- | `usaspending_search_awards` | Search awards by keyword, recipient, agency, award type, NAICS code, assistance listing, location, or date range |
40
+ | `usaspending_search_awards` | Search awards by keyword, recipient, agency, award type, NAICS code, assistance listing, PSC, DEF code, location, or date range |
41
41
  | `usaspending_get_award` | Fetch one award's full record: amounts, recipient, agencies, codes, parent IDV, DEF-code funding |
42
42
  | `usaspending_get_award_transactions` | List the transactions (modifications, amendments) on an award |
43
43
  | `usaspending_get_award_subawards` | List the subcontracts or subgrants under a prime award |
@@ -66,15 +66,16 @@ Federal award, recipient, agency, and spending data from USAspending.gov, the US
66
66
  ### `usaspending_autocomplete_filters` <sub>tool</sub>
67
67
 
68
68
  - `type` (`naics`, `psc`, `cfda`, `awarding_agency`, `recipient`) plus `search_text`; `limit` 1–500, default 10
69
- - Rows carry `code` and `name`, with `id` for agencies and `uei` / `duns` for recipients; no match fails as `no_match`. A `cfda` code is what `usaspending_search_awards` takes in `assistance_listings`
69
+ - Rows carry `code` and `name`, and `uei` / `duns` for recipients; no match fails as `no_match`. A `cfda` code goes in `assistance_listings` and a `psc` code in `psc_codes` on `usaspending_search_awards` and the three spending analytics tools
70
+ - Agency rows carry the matched agency's own `name`, `abbreviation`, and `tier` (`toptier` or `subtier`), plus its parent's `toptier_name` and `toptier_code`. The `agency_name` filters are top-tier only and take `toptier_name`, so a sub-agency such as the U.S. Geological Survey filters at its whole department
70
71
  - `naics` matches official NAICS title text: "software" resolves, "cybersecurity" does not, so search with the industry term a title would use
71
72
 
72
73
  ---
73
74
 
74
75
  ### `usaspending_search_awards` <sub>tool</sub>
75
76
 
76
- - Filters: `keyword`, `agency_name`, `recipient_name`, `naics_codes`, `assistance_listings` (Assistance Listing numbers such as `93.866`, from `usaspending_autocomplete_filters` `type: cfda`), `time_period` (`YYYY-MM-DD` from 2007-10-01 on; either end may be given alone), and `location_filter`; `award_type_codes` defaults to contracts (`A`–`D`) and must stay in one group: IDVs `IDV_A`–`IDV_E`, grants `02`–`05`/`F001`/`F002`, direct payments `06`/`10`/`F006`/`F007`, loans `07`/`08`/`F003`/`F004`, or other assistance `09`/`11`/`-1`/`F005`/`F008`/`F009`/`F010`; `limit` up to 100
77
- - Rows carry `generated_internal_id` for `usaspending_get_award` and `agency_slug` for `usaspending_get_agency`; loan rows carry `loan_value`, `subsidy_cost`, and `issued_date` in place of amounts and dates. There is no total, and `page_metadata.has_next` is true on any full page. Failures are `assistance_listings_type_mismatch` (listings with a non-assistance group), `unsupported_sort`, `date_range_inverted`, and `date_before_earliest`
77
+ - Filters: `keyword`, `agency_name`, `recipient_name`, `naics_codes`, `assistance_listings` (Assistance Listing numbers such as `93.866`, from `usaspending_autocomplete_filters` `type: cfda`), `psc_codes` (1–4 characters, where a prefix such as `Y1` covers the codes under it; contracts and IDVs only), `def_codes` (Disaster Emergency Fund Codes such as `Z`; PSC and DEF codes are sent uppercased), `time_period` (`YYYY-MM-DD` from 2007-10-01 on; either end may be given alone), and `location_filter` (`country` defaults to `USA`, and a territory code such as `PRI` becomes `USA` plus its state; `state` as a postal or 2-digit FIPS code, `FM`/`MH`/`PW`/`UM` and armed-forces `AA`/`AE`/`AP` included, or under another country as that country's own 2-letter subdivision code such as `ON` with `CAN`; `county` as 3 digits with `state` or the 5-digit FIPS code alone; echoed as `applied_location`); `award_type_codes` defaults to contracts (`A`–`D`) and must stay in one group: IDVs `IDV_A`–`IDV_E`, grants `02`–`05`/`F001`/`F002`, direct payments `06`/`10`/`F006`/`F007`, loans `07`/`08`/`F003`/`F004`, or other assistance `09`/`11`/`-1`/`F005`/`F008`/`F009`/`F010`; `limit` up to 100
78
+ - Rows carry `generated_internal_id` for `usaspending_get_award` and `agency_slug` for `usaspending_get_agency`; loan rows carry `loan_value`, `subsidy_cost`, and `issued_date` in place of amounts and dates. There is no total, and `page_metadata.has_next` is true on any full page. The nested `filters` object takes the analytics tools' `filters` keys, except `recipient_id`, and wins per field over the flat ones. Failures are `assistance_listings_type_mismatch` (listings with a non-assistance group), `psc_codes_type_mismatch` (PSC codes with an assistance group), `unsupported_sort`, `date_range_inverted`, `date_before_earliest`, and `invalid_location` (an unknown state, a 3-digit county without a state, a county under an armed-forces code (`AA`/`AE`/`AP`), a county or FIPS-number state under another country, or parts naming different states)
78
79
  - `sort` depends on the group: loans take `Loan Value` (default), `Subsidy Cost`, `Issued Date`, `Recipient Name`, or `Awarding Agency`; the others `Award Amount` (default), `Total Outlays`, `Start Date`, `End Date` (not IDVs), `Recipient Name`, or `Awarding Agency`. Page numbers stop at a 50,000-result offset (`pagination_limit_exceeded`); past it, page with the `last_record_sort_value` + `last_record_unique_id` cursor, returned below a 10,000-result offset
79
80
 
80
81
  ---
@@ -82,8 +83,10 @@ Federal award, recipient, agency, and spending data from USAspending.gov, the US
82
83
  ### `usaspending_get_award` <sub>tool</sub>
83
84
 
84
85
  - `award_id` is a `generated_unique_award_id`, the `generated_internal_id` from search; an unknown ID fails as `award_not_found`
85
- - Returns `category`, `total_obligation`, `total_outlays`, `subaward_count`, NAICS / PSC or CFDA codes, and `account_obligations_by_defc`
86
- - `recipient.recipient_id` chains to `usaspending_get_recipient` and `parent_award.generated_unique_award_id` to the parent IDV; `category: "idv"` awards list their children via `usaspending_get_idv_awards`
86
+ - Returns `category`, `total_obligation`, `total_outlays`, `subaward_count`, NAICS / PSC codes, `account_obligations_by_defc`, and, on loans, `total_loan_value` and `total_subsidy_cost`
87
+ - `assistance_listings` lists every Assistance Listing on an assistance award, in upstream order, as `number`, `title`, and `obligation`; a `number` goes in `usaspending_search_awards` `assistance_listings`
88
+ - `recipient` carries `uei`, `parent_uei`, `business_categories` (category names, not the `business_types` codes of `usaspending_get_recipient`), and a three-letter `country_code` on its `location`, as does `place_of_performance`; a location with no fields upstream is omitted
89
+ - `recipient.recipient_id` and `recipient.parent_recipient_id` chain to `usaspending_get_recipient` and `parent_award.generated_unique_award_id` to the parent IDV; `category: "idv"` awards list their children via `usaspending_get_idv_awards`
87
90
 
88
91
  ---
89
92
 
@@ -124,44 +127,47 @@ Federal award, recipient, agency, and spending data from USAspending.gov, the US
124
127
 
125
128
  ### `usaspending_get_recipient` <sub>tool</sub>
126
129
 
127
- - `recipient_id` from `usaspending_search_recipients` or `usaspending_get_award`; optional `fiscal_year` (2001–2030) and `award_type` scope the totals; an unknown ID fails as `recipient_not_found`
128
- - Returns address, `business_types`, `parent_name` / `parent_uei`, `alternate_names`, `total_transaction_amount`, `total_transactions`, and loan face-value totals
130
+ - `recipient_id` from `usaspending_search_recipients` or `usaspending_get_award`; optional `fiscal_year` (2001–2030) scopes the totals to that fiscal year, which otherwise cover the trailing 12 months; an unknown ID fails as `recipient_not_found`
131
+ - Returns address, `business_types`, `parent_name` / `parent_uei`, `alternate_names`, `total_transaction_amount`, `total_transactions`, and loan face-value totals, with `period` naming the window (`FY2020` or `trailing 12 months`). Totals span every award type; for totals by type, use `usaspending_spending_over_time` with `filters.recipient_id` and `award_type_codes`
129
132
 
130
133
  ---
131
134
 
132
135
  ### `usaspending_get_agency` <sub>tool</sub>
133
136
 
134
- - One of `toptier_code` (e.g. `097`) or `agency_slug` (e.g. `department-of-defense`); `page` walks the sub-agency list 10 at a time. Failures are `missing_input` and `agency_not_found`
135
- - Returns `mission`, plus `budgetary_resources_amount`, `obligated_amount`, and `outlay_amount` for the latest `fiscal_year`, `sub_agencies` with obligations and transaction and new-award counts, and `def_codes`
137
+ - One of `toptier_code` (e.g. `097`) or `agency_slug` (e.g. `department-of-defense`); `page` walks the sub-agency list 10 at a time. Failures are `missing_input`, `conflicting_input` (both identifiers sent), and `agency_not_found`
138
+ - Returns `mission`, plus `budgetary_resources_amount`, `obligated_amount`, and `outlay_amount` for the most recent `fiscal_year` with reported budget data (a newly opened year with no amounts yet is skipped), `sub_agencies` with obligations and transaction and new-award counts for that same year (`sub_agency_fiscal_year` names it; without a budget year within 5 seconds the breakdown covers the current fiscal year), and `def_codes`
139
+ - A failed budget or sub-agency request still returns the overview: the missing fields are omitted and `unavailable_sections` names each section with its `reason` (`api_unavailable`, `api_timeout`, or `upstream_error`) and whether a retry may load it
136
140
 
137
141
  ---
138
142
 
139
143
  ### `usaspending_spending_by_geography` <sub>tool</sub>
140
144
 
141
- - `scope` (`place_of_performance`, `recipient_location`) and `geo_layer` (`state`, `county`, `district`) are required; `filters` takes `keywords`, `award_type_codes`, `agency_name`, `recipient_id`, `naics_codes`, and `time_period_start` / `time_period_end` (`YYYY-MM-DD`; either alone fills the other, as in `usaspending_search_awards`, `applied_time_period_*` echoes the range sent, a start after the end fails as `date_range_inverted`, and a range starting before 2007-10-01 fails as `date_before_earliest`); `limit` 1–500, default 50
142
- - Rows carry `shape_code`, `display_name`, `aggregated_amount`, `population`, `per_capita`, and `award_count`, ranked by amount; `total_areas_available` counts every match before the cap
145
+ - `scope` (`place_of_performance`, `recipient_location`) and `geo_layer` (`state`, `county`, `district`) are required; `filters` takes `keywords`, `award_type_codes`, `agency_name`, `recipient_id`, `naics_codes`, `assistance_listings`, `psc_codes`, `def_codes` (the same code filters as `usaspending_search_awards`, echoed as `applied_*`), and `time_period_start` / `time_period_end` (`YYYY-MM-DD`; either alone fills the other, as in `usaspending_search_awards`, `applied_time_period_*` echoes the range sent, a start after the end fails as `date_range_inverted`, and a range starting before 2007-10-01 fails as `date_before_earliest`); `limit` 1–500, default 50
146
+ - Award types may mix groups. When every one named is a contract or IDV, `assistance_listings` fails as `assistance_listings_type_mismatch`; when every one is assistance, `psc_codes` fails as `psc_codes_type_mismatch`. Code-filtered amounts cover whole matching awards, and DEF-filtered totals can be negative
147
+ - Rows carry `shape_code`, `display_name`, `aggregated_amount`, `population`, and `per_capita`, ranked by amount; `total_areas_available` counts every match before the cap
148
+ - `shape_codes` (1–500) returns only the listed areas, in the `shape_code` form of the layer: postal code for `state` (`NY`), 5-digit state + county FIPS for `county` (`36117`), 4-digit state FIPS + district for `district` (`3623`). Selection runs over every matched area, so it reaches areas ranked past `limit`; the codes are echoed as `applied_shape_codes`, and a code that matches no area is named in the `notice`
143
149
  - With no filters, every award type is aggregated and `applied_award_type_default` says so; `subawards: true` switches to subaward data
144
150
 
145
151
  ---
146
152
 
147
153
  ### `usaspending_spending_by_category` <sub>tool</sub>
148
154
 
149
- - `category` is `naics`, `psc`, `awarding_agency`, `awarding_subagency`, `funding_agency`, `funding_subagency`, `cfda`, `recipient_duns`, or `recipient_parent_duns`; takes the same `filters` object as `usaspending_spending_by_geography`; `limit` up to 100
150
- - Rows carry `id`, `code`, `name`, and `amount`, ranked by obligation
155
+ - `category` is `naics`, `psc`, `awarding_agency`, `awarding_subagency`, `funding_agency`, `funding_subagency`, `cfda`, or `recipient_duns`; takes the same `filters` object as `usaspending_spending_by_geography`; `limit` up to 100
156
+ - Rows carry `id`, `code`, `name`, and `amount`, ranked by obligation; `recipient_duns` rows carry the DUNS as `code` plus `recipient_id` and `uei` when upstream has them, and `recipient_id` chains to `usaspending_get_recipient`
151
157
 
152
158
  ---
153
159
 
154
160
  ### `usaspending_spending_over_time` <sub>tool</sub>
155
161
 
156
- - `group` is `fiscal_year`, `quarter`, or `month` (fiscal month, where 1 is October); the same `filters` object, with `award_type_codes` defaulting to contracts and limited to one group; `subawards: true` switches to subaward data
162
+ - `group` is `fiscal_year`, `quarter`, or `month` (fiscal month, where 1 is October); the same `filters` object, with `award_type_codes` defaulting to contracts, so `assistance_listings` needs an assistance group named; `subawards: true` switches to subaward data
157
163
  - Rows carry `time_period`, `aggregated_amount`, and per-type `contracts`, `grants`, `direct_payments`, `idvs`, `loans`, and `other`
158
164
 
159
165
  ---
160
166
 
161
167
  ### `usaspending_disaster_spending` <sub>tool</sub>
162
168
 
163
- - `dimension` is `overview`, `agency`, `cfda`, `recipient`, or `geography`; every dimension except `overview` requires `filters.def_codes` (e.g. `["L", "M", "N", "O", "P"]` for COVID-19); `limit` up to 100 on agency, cfda, and recipient; `spending_type` (`award`, the default, or `total`) applies to agency only, and geography takes `filters.geo_layer` (`state`, `county`)
164
- - Rows carry `obligation`, `outlay`, and `award_count`, plus `total_budgetary_resources` on agency rows under `spending_type: total`; `overview` returns totals and `funding_by_def_code`. A recipient row's `id` chains to `usaspending_get_recipient`. The recipient total tops out at 10,000, and a response at that cap is flagged `truncated`
169
+ - `dimension` is `overview`, `agency`, `cfda`, `recipient`, or `geography`; every dimension except `overview` requires `filters.def_codes` (e.g. `["L", "M", "N", "O", "P"]` for COVID-19); `limit` up to 100 on every dimension but `overview`; `spending_type` (`award`, the default, or `total`) applies to agency only, and geography takes `filters.geo_layer` (`state`, `county`)
170
+ - Rows carry `obligation`, `outlay`, and `award_count`, plus `total_budgetary_resources` on agency rows under `spending_type: total`; `overview` returns totals and `funding_by_def_code`. A recipient row's `id` chains to `usaspending_get_recipient`. The recipient total tops out at 10,000, and a response at that cap is flagged `truncated`. Geography areas are ranked by `aggregated_amount` and paged with `limit` and `page`, with the full area count as `total`; a page with areas below it is flagged `truncated`, and `truncationCeiling` is the lowest amount shown. Spending with no recorded place of performance ranks as one unattributed area
165
171
  - Agency, cfda, and recipient also return `totals` across every matching row: `obligation`, `outlay`, and either `total_budgetary_resources` (agency, `total`) or `award_count`. When `overview` outlasts the request budget, the agency breakdown with `spending_type: total` still reports obligations, outlays, and budgetary resources
166
172
 
167
173
  ---
@@ -193,15 +199,15 @@ USAspending-specific:
193
199
 
194
200
  - USAspending.gov API v2, keyless: the data is public under the DATA Act
195
201
  - Award search and the spending analytics tools cover action dates from 2007-10-01 on (an earlier start date fails as `date_before_earliest`), and DoD contract data lags publication by 90 days
196
- - `usaspending_spending_by_category` puts nine category sub-routes behind one `category` enum, and `usaspending_disaster_spending` puts five disaster endpoints behind `dimension`
197
- - Each request runs under a per-attempt timeout and a wall-clock retry budget; failures surface as `api_timeout` or `api_unavailable` with each tool's recovery hint, and a rejected request carries USAspending's own explanation in the error message
202
+ - `usaspending_spending_by_category` puts eight category sub-routes behind one `category` enum, and `usaspending_disaster_spending` puts five disaster endpoints behind `dimension`
203
+ - Each request runs under one wall-clock budget (45 s by default); a slow answer gets the whole budget in one attempt, and only fast failures are retried. Failures surface as `api_timeout` or `api_unavailable` with each tool's recovery hint, and a rejected request carries USAspending's own explanation in the error message
198
204
 
199
205
  Agent-friendly output:
200
206
 
201
207
  - Chaining IDs as explicit fields: `generated_internal_id`, `agency_slug`, `recipient.recipient_id`, `federal_account`, and `account_number`, so agents follow the money without parsing display strings
202
- - Honest pagination: `page_metadata.has_next` on every list, a `total` or `count` where the upstream publishes one, and `truncated` / `shown` / `cap` when a response is capped
208
+ - Honest pagination: `page_metadata.has_next` on every list, a `total` or `count` where the upstream publishes one, and `truncated` / `shown` / `cap` only when rows are known to exist beyond those returned. A full page with no such evidence keeps `has_next` without claiming truncation
203
209
  - Empty results are notices, not errors: an empty page carries a `notice` echoing the filters and how to broaden them. The ID-keyed list tools (transactions, subawards, funding accounts, IDV children, account breakdown) return an empty list for an unknown ID rather than failing
204
- - Typed failures with recovery hints: `award_not_found`, `recipient_not_found`, `agency_not_found`, `account_not_found`, `no_match`, `date_before_earliest`, `date_range_inverted`, `unsupported_sort`, `assistance_listings_type_mismatch`, `pagination_limit_exceeded`
210
+ - Typed failures with recovery hints: `award_not_found`, `recipient_not_found`, `agency_not_found`, `account_not_found`, `no_match`, `conflicting_input`, `date_before_earliest`, `date_range_inverted`, `unsupported_sort`, `assistance_listings_type_mismatch`, `psc_codes_type_mismatch`, `invalid_location`, `pagination_limit_exceeded`
205
211
 
206
212
  ## Getting started
207
213
 
@@ -322,8 +328,8 @@ No variable is required; the defaults work out of the box.
322
328
  | Variable | Description | Default |
323
329
  |:---|:---|:---|
324
330
  | `USASPENDING_BASE_URL` | USAspending.gov API v2 base URL. | `https://api.usaspending.gov/api/v2/` |
325
- | `USASPENDING_TIMEOUT_MS` | Per-attempt HTTP timeout, in ms (1000–120000). | `30000` |
326
- | `USASPENDING_RETRY_BUDGET_MS` | Wall-clock budget for one request across all retry attempts, in ms (1000–300000). | 1.5 × `USASPENDING_TIMEOUT_MS` |
331
+ | `USASPENDING_TIMEOUT_MS` | Per-attempt HTTP timeout, in ms (1000–120000). Each attempt is cut at this or at the time left in the request budget, whichever is smaller; a timed-out attempt is not retried. | `45000` |
332
+ | `USASPENDING_RETRY_BUDGET_MS` | Wall-clock budget for one request, every attempt and backoff included, in ms (1000–300000). Fast failures such as a 503 retry inside it. | `45000`, or `USASPENDING_TIMEOUT_MS` when higher |
327
333
  | `MCP_TRANSPORT_TYPE` | Transport: `stdio` or `http`. | `stdio` |
328
334
  | `MCP_HTTP_PORT` | HTTP server port. | `3010` |
329
335
  | `MCP_SESSION_MODE` | HTTP session mode: `stateless`, `stateful`, or `auto`. | `stateless` |
@@ -0,0 +1,50 @@
1
+ ---
2
+ summary: "Autocomplete agency rows drop id and name the matched agency; get_agency rejects both identifiers; nested filter keys are strict. Fixes location_filter normalization, analytics code filters, geography shape_codes, award-detail fields, recipient fiscal-year totals, agency budget years, truncation labels, and request timeouts."
3
+ breaking: true
4
+ security: false
5
+ ---
6
+
7
+ # 0.5.0 — 2026-10-12
8
+
9
+ ## Added
10
+
11
+ - **`psc_codes`, `def_codes`, and `assistance_listings`** filter the `filters` of `usaspending_spending_by_geography`, `usaspending_spending_by_category`, and `usaspending_spending_over_time`, and `usaspending_search_awards` takes all three both flat and inside its `filters` (it took only a flat `assistance_listings` before), each echoed as `applied_*` ([#77](https://github.com/cyanheads/usaspending-mcp-server/issues/77)). PSC and DEF codes are sent uppercased; `assistance_listings` with only contract or IDV award types fails as `assistance_listings_type_mismatch`, `psc_codes` with only assistance types as `psc_codes_type_mismatch`.
12
+ - **`usaspending_spending_by_geography` `shape_codes`** (1–500, beside `limit`) returns only the listed areas, reaching counties ranked past `limit`; the codes echo as `applied_shape_codes` and an unmatched code is named in the `notice` ([#72](https://github.com/cyanheads/usaspending-mcp-server/issues/72)).
13
+ - **`usaspending_get_award` `assistance_listings[]`** (`number`, `title`, `obligation`), `recipient.parent_uei`, `recipient.parent_recipient_id`, `recipient.business_categories`, and `total_loan_value` / `total_subsidy_cost` on loans; `recipient.uei` and the three-letter `country_code` on `recipient.location` and `place_of_performance` are now populated ([#68](https://github.com/cyanheads/usaspending-mcp-server/issues/68)).
14
+ - **`usaspending_get_recipient` `period`** names the totals window, `FY<year>` or `trailing 12 months` ([#67](https://github.com/cyanheads/usaspending-mcp-server/issues/67)).
15
+ - **`usaspending_get_agency` `sub_agency_fiscal_year`** and an optional **`unavailable_sections`** listing each failed section with its `reason` ([#86](https://github.com/cyanheads/usaspending-mcp-server/issues/86), [#69](https://github.com/cyanheads/usaspending-mcp-server/issues/69)).
16
+ - **`usaspending_spending_by_category`** `recipient_duns` rows carry `recipient_id` and `uei` when upstream has them ([#83](https://github.com/cyanheads/usaspending-mcp-server/issues/83)).
17
+ - **`invalid_location`** (`usaspending_search_awards`), **`psc_codes_type_mismatch`** (`usaspending_search_awards` and the three spending analytics tools), and **`conflicting_input`** (`usaspending_get_agency`) typed failures; `assistance_listings_type_mismatch`, until now on `usaspending_search_awards` alone, is added to the three spending analytics tools.
18
+
19
+ ## Changed
20
+
21
+ - **BREAKING: unknown keys inside the nested `filters`, `time_period`, and `location_filter` objects are rejected** with the key path named (for example `time_period.fiscal_year`); they were dropped and the call ran without them ([#74](https://github.com/cyanheads/usaspending-mcp-server/issues/74)). `usaspending_search_awards` rejects `filters.recipient_id`.
22
+ - **BREAKING: `usaspending_autocomplete_filters` agency rows drop `id`** and carry the matched agency's own `name` (the top-tier parent was returned for a sub-agency), with `abbreviation`, `tier`, and the parent in `toptier_name` / `toptier_code`; `code` is no longer advertised for agencies ([#71](https://github.com/cyanheads/usaspending-mcp-server/issues/71)).
23
+ - **BREAKING: `usaspending_get_agency` rejects any call with both `toptier_code` and `agency_slug`** as `conflicting_input`, a matching pair included ([#75](https://github.com/cyanheads/usaspending-mcp-server/issues/75)).
24
+ - **`usaspending_search_awards` `location_filter` is normalized** (`country` defaults to `USA`, a territory code becomes `USA` plus its state, a 2-digit FIPS `state` becomes its postal code, a 5-digit county FIPS stands alone) and echoed as `applied_location`. A malformed `country`, `state`, or `county` fails as `-32602`; an unknown US state, a county without a state or with an armed-forces state (`AA`/`AE`/`AP`), a county or FIPS-number state under a non-USA country, and parts that name different states fail as `invalid_location` ([#70](https://github.com/cyanheads/usaspending-mcp-server/issues/70)).
25
+ - **`usaspending_get_recipient` totals** cover the requested `fiscal_year` instead of always the trailing 12 months ([#67](https://github.com/cyanheads/usaspending-mcp-server/issues/67)).
26
+ - **`usaspending_get_agency`** reports the most recent fiscal year with budget data, and `sub_agencies` cover that same year ([#81](https://github.com/cyanheads/usaspending-mcp-server/issues/81), [#86](https://github.com/cyanheads/usaspending-mcp-server/issues/86)). A failed budget or sub-agency request omits those fields, and `sub_agency_page` / `has_more_sub_agencies` become optional ([#69](https://github.com/cyanheads/usaspending-mcp-server/issues/69)).
27
+ - **`truncated` / `shown` / `cap` are set only on evidence** (an upstream `hasNext`, or a row received past `limit`) in `usaspending_autocomplete_filters`, `usaspending_search_awards`, and `usaspending_get_idv_awards`, where any full page set them before; a page that exactly fills `limit` is no longer labeled truncated, and the two paged tools still report `has_next`. Autocomplete at `limit: 500`, the upstream maximum, says in its new `notice` that more matches may exist ([#76](https://github.com/cyanheads/usaspending-mcp-server/issues/76)).
28
+ - **`usaspending_disaster_spending` geography** returns a page of `limit` areas (default 10) with `total` counting every area and `has_next` set from the page position ([#73](https://github.com/cyanheads/usaspending-mcp-server/issues/73)).
29
+ - **Request timeouts:** `USASPENDING_TIMEOUT_MS` defaults to 45000 (was 30000) and `USASPENDING_RETRY_BUDGET_MS` to 45000, or the timeout when higher (was 1.5 × the timeout). A timed-out attempt is not retried; 5xx and network failures still retry inside the budget ([#79](https://github.com/cyanheads/usaspending-mcp-server/issues/79)).
30
+ - **Framework (mcp-ts-core 0.13.15):** unknown nested keys are rejected with the key path named (the mechanism behind #74); `{"keyword": null}` and a lone string for an array filter such as `filters.keywords: "water"`, rejected with `-32602` before, are repaired and accepted.
31
+ - **Docker, `.mcpbignore`, docs:** the base image is Bun 1.4.3; the `.mcpb` bundle excludes `tests/`, `src/`, `scripts/`, `docs/`, `coverage/`, `.github/`, and `.vscode/` ([#88](https://github.com/cyanheads/usaspending-mcp-server/issues/88)); `framework-skills/` is synced to 0.13.15.
32
+
33
+ ## Removed
34
+
35
+ - **BREAKING: `usaspending_spending_by_category` `category: "recipient_parent_duns"`**; it always answered 404 upstream ([#80](https://github.com/cyanheads/usaspending-mcp-server/issues/80)).
36
+ - **BREAKING: `usaspending_get_recipient` `award_type`**; the endpoint has no award-type selector, so the value was ignored. Use `usaspending_spending_over_time` with `filters.recipient_id` and `award_type_codes` for totals by type ([#67](https://github.com/cyanheads/usaspending-mcp-server/issues/67)).
37
+ - **`usaspending_get_award` `cfda` and `recipient.business_types`**, never populated; replaced by `assistance_listings[]` and `recipient.business_categories`. An empty `place_of_performance` or `recipient.location` is omitted instead of returned as `{}` ([#68](https://github.com/cyanheads/usaspending-mcp-server/issues/68)).
38
+ - **`usaspending_spending_by_geography` `award_count`** (result field and "Awards" column), never populated ([#82](https://github.com/cyanheads/usaspending-mcp-server/issues/82)).
39
+
40
+ ## Fixed
41
+
42
+ - **An Assistance Listing or PSC filter the award types cannot match** — `filters.psc_codes` or `filters.assistance_listings` on `usaspending_search_awards` or on the three spending analytics tools — was dropped and the call answered without it; it now fails as `assistance_listings_type_mismatch` or `psc_codes_type_mismatch` ([#74](https://github.com/cyanheads/usaspending-mcp-server/issues/74), [#77](https://github.com/cyanheads/usaspending-mcp-server/issues/77)).
43
+
44
+ ## Dependencies
45
+
46
+ - `@cyanheads/mcp-ts-core` `^0.13.13` → `^0.13.15`
47
+ - `pino-pretty` `^13.1.3` → `^13.2.0`
48
+ - `@types/node` `^26.6.4` → `^26.6.5` (dev)
49
+ - `@modelcontextprotocol/server` `2.2.0` → `2.3.1` (lockfile, via the framework)
50
+ - Bun `1.4.2` → `1.4.3` (`packageManager`, Dockerfile base image, README badge)
@@ -1 +1 @@
1
- {"version":3,"file":"server-config.d.ts","sourceRoot":"","sources":["../../src/config/server-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AAG3C,QAAA,MAAM,kBAAkB;;;;iBAsBtB,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAI9D,wBAAgB,eAAe,IAAI,YAAY,CAO9C"}
1
+ {"version":3,"file":"server-config.d.ts","sourceRoot":"","sources":["../../src/config/server-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AAG3C,QAAA,MAAM,kBAAkB;;;;iBAwBtB,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAI9D,wBAAgB,eAAe,IAAI,YAAY,CAO9C"}
@@ -15,15 +15,15 @@ const ServerConfigSchema = z.object({
15
15
  .int()
16
16
  .min(1000)
17
17
  .max(120_000)
18
- .default(30_000)
19
- .describe('HTTP request timeout in milliseconds, per attempt'),
18
+ .default(45_000)
19
+ .describe('Per-attempt HTTP timeout in milliseconds. Each attempt is cut at this or at the time left in the request budget, whichever is smaller, and an attempt that times out is not retried.'),
20
20
  retryBudgetMs: z.coerce
21
21
  .number()
22
22
  .int()
23
23
  .min(1000)
24
24
  .max(300_000)
25
25
  .optional()
26
- .describe('Wall-clock budget covering every retry attempt of one request. Defaults to 1.5x the per-attempt timeout, which leaves room for one retry rather than four full timeouts plus backoff.'),
26
+ .describe('Wall-clock budget in milliseconds for one request, every attempt and retry backoff included. Fast transient failures (5xx, network errors) retry inside it. Defaults to 45000, or to the per-attempt timeout when that is higher, so one attempt can always run its full timeout.'),
27
27
  });
28
28
  let _config;
29
29
  export function getServerConfig() {
@@ -1 +1 @@
1
- {"version":3,"file":"server-config.js","sourceRoot":"","sources":["../../src/config/server-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,OAAO,EAAE,CAAC;SACP,MAAM,EAAE;SACR,GAAG,EAAE;SACL,OAAO,CAAC,qCAAqC,CAAC;SAC9C,QAAQ,CAAC,iCAAiC,CAAC;IAC9C,SAAS,EAAE,CAAC,CAAC,MAAM;SAChB,MAAM,EAAE;SACR,GAAG,EAAE;SACL,GAAG,CAAC,IAAI,CAAC;SACT,GAAG,CAAC,OAAO,CAAC;SACZ,OAAO,CAAC,MAAM,CAAC;SACf,QAAQ,CAAC,mDAAmD,CAAC;IAChE,aAAa,EAAE,CAAC,CAAC,MAAM;SACpB,MAAM,EAAE;SACR,GAAG,EAAE;SACL,GAAG,CAAC,IAAI,CAAC;SACT,GAAG,CAAC,OAAO,CAAC;SACZ,QAAQ,EAAE;SACV,QAAQ,CACP,uLAAuL,CACxL;CACJ,CAAC,CAAC;AAIH,IAAI,OAAiC,CAAC;AAEtC,MAAM,UAAU,eAAe;IAC7B,OAAO,KAAK,cAAc,CAAC,kBAAkB,EAAE;QAC7C,OAAO,EAAE,sBAAsB;QAC/B,SAAS,EAAE,wBAAwB;QACnC,aAAa,EAAE,6BAA6B;KAC7C,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC"}
1
+ {"version":3,"file":"server-config.js","sourceRoot":"","sources":["../../src/config/server-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,OAAO,EAAE,CAAC;SACP,MAAM,EAAE;SACR,GAAG,EAAE;SACL,OAAO,CAAC,qCAAqC,CAAC;SAC9C,QAAQ,CAAC,iCAAiC,CAAC;IAC9C,SAAS,EAAE,CAAC,CAAC,MAAM;SAChB,MAAM,EAAE;SACR,GAAG,EAAE;SACL,GAAG,CAAC,IAAI,CAAC;SACT,GAAG,CAAC,OAAO,CAAC;SACZ,OAAO,CAAC,MAAM,CAAC;SACf,QAAQ,CACP,sLAAsL,CACvL;IACH,aAAa,EAAE,CAAC,CAAC,MAAM;SACpB,MAAM,EAAE;SACR,GAAG,EAAE;SACL,GAAG,CAAC,IAAI,CAAC;SACT,GAAG,CAAC,OAAO,CAAC;SACZ,QAAQ,EAAE;SACV,QAAQ,CACP,mRAAmR,CACpR;CACJ,CAAC,CAAC;AAIH,IAAI,OAAiC,CAAC;AAEtC,MAAM,UAAU,eAAe;IAC7B,OAAO,KAAK,cAAc,CAAC,kBAAkB,EAAE;QAC7C,OAAO,EAAE,sBAAsB;QAC/B,SAAS,EAAE,wBAAwB;QACnC,aAAa,EAAE,6BAA6B;KAC7C,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/dist/index.js CHANGED
@@ -36,6 +36,7 @@ await createApp({
36
36
  instructions: 'USAspending.gov MCP server — federal award, recipient, agency, and spending data from the US Treasury DATA Act platform.\n' +
37
37
  '- Start with usaspending_list_agencies or usaspending_autocomplete_filters to discover agency codes, NAICS/PSC codes, and Assistance Listing numbers\n' +
38
38
  '- Use usaspending_search_awards to find awards, then usaspending_get_award for full details\n' +
39
+ '- Reuse NAICS, PSC, Assistance Listing, and DEF codes as filters on usaspending_search_awards and the usaspending_spending_* tools to see where and when that money went\n' +
39
40
  '- Chain recipient_id from usaspending_get_award into usaspending_get_recipient for entity profiles\n' +
40
41
  '- Search window: 2007-10-01 onward. DoD contracts have a 90-day publication lag.',
41
42
  setup(core) {
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;;;;;;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"}
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,4KAA4K;QAC5K,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"}
@@ -21,7 +21,13 @@ export declare const autocompleteFiltersTool: import("@cyanheads/mcp-ts-core").T
21
21
  results: z.ZodArray<z.ZodObject<{
22
22
  code: z.ZodOptional<z.ZodString>;
23
23
  name: z.ZodOptional<z.ZodString>;
24
- id: z.ZodOptional<z.ZodString>;
24
+ abbreviation: z.ZodOptional<z.ZodString>;
25
+ tier: z.ZodOptional<z.ZodEnum<{
26
+ subtier: "subtier";
27
+ toptier: "toptier";
28
+ }>>;
29
+ toptier_name: z.ZodOptional<z.ZodString>;
30
+ toptier_code: z.ZodOptional<z.ZodString>;
25
31
  uei: z.ZodOptional<z.ZodString>;
26
32
  duns: z.ZodOptional<z.ZodString>;
27
33
  }, z.core.$strip>>;
@@ -52,5 +58,6 @@ export declare const autocompleteFiltersTool: import("@cyanheads/mcp-ts-core").T
52
58
  readonly truncated: z.ZodOptional<z.ZodBoolean>;
53
59
  readonly shown: z.ZodOptional<z.ZodNumber>;
54
60
  readonly cap: z.ZodOptional<z.ZodNumber>;
61
+ readonly notice: z.ZodOptional<z.ZodString>;
55
62
  }>;
56
63
  //# sourceMappingURL=autocomplete-filters.tool.d.ts.map
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+MlC,CAAC"}
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;AAOjE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmSlC,CAAC"}
@@ -6,14 +6,16 @@
6
6
  import { tool, z } from '@cyanheads/mcp-ts-core';
7
7
  import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
8
8
  import { getUSASpendingService } from '../../../services/usaspending/usaspending-service.js';
9
+ /** Largest `limit` every autocomplete route accepts; 501 is rejected with HTTP 400. */
10
+ const UPSTREAM_LIMIT_MAX = 500;
9
11
  export const autocompleteFiltersTool = tool('usaspending_autocomplete_filters', {
10
12
  title: 'Autocomplete Codes and Names',
11
- description: 'Look up valid code values for filter fields by searching free-text descriptions. Use the type parameter to select the lookup table: naics (NAICS industry codes), psc (product/service codes), cfda (CFDA/Assistance Listing program numbers), awarding_agency (agency names and IDs), or recipient (recipient names with UEI/DUNS). Call this before filtering awards when you know a description but not the exact code. Returns matching codes and names for use in other tool filters.',
13
+ description: 'Look up valid code values for filter fields by searching free-text descriptions. Use the type parameter to select the lookup table: naics (NAICS industry codes), psc (product/service codes), cfda (CFDA/Assistance Listing program numbers), awarding_agency (agency and sub-agency names, each with its tier and top-tier parent — the agency_name filters take the top-tier name), or recipient (recipient names with UEI/DUNS). Call this before filtering awards when you know a description but not the exact code. Returns matching codes and names for use in other tool filters.',
12
14
  annotations: { readOnlyHint: true, openWorldHint: true, idempotentHint: true },
13
15
  input: z.object({
14
16
  type: z
15
17
  .enum(['naics', 'psc', 'cfda', 'awarding_agency', 'recipient'])
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)'),
18
+ .describe('Lookup table to search: naics (industry codes), psc (product/service codes, for the psc_codes filter), cfda (Assistance Listing program numbers, for the assistance_listings filter), awarding_agency (agency and sub-agency names), recipient (recipient names). Both filters are taken by usaspending_search_awards and by the filters object of usaspending_spending_by_category, usaspending_spending_by_geography, and usaspending_spending_over_time.'),
17
19
  search_text: z
18
20
  .string()
19
21
  .min(1)
@@ -22,7 +24,7 @@ export const autocompleteFiltersTool = tool('usaspending_autocomplete_filters',
22
24
  .number()
23
25
  .int()
24
26
  .min(1)
25
- .max(500)
27
+ .max(UPSTREAM_LIMIT_MAX)
26
28
  .default(10)
27
29
  .describe('Maximum number of results to return (1–500), enforced client-side. The recipient lookup unions three upstream match buckets (name, UEI, DUNS) and can return up to 3x this value, so its results are capped to this limit before returning — the cap keeps them in bucket order, so name matches fill the page first and identifier matches appear only in whatever room is left. To resolve a specific UEI or DUNS, pass the identifier itself as search_text. naics/psc/cfda/awarding_agency honor this limit exactly.'),
28
30
  }),
@@ -35,12 +37,27 @@ export const autocompleteFiltersTool = tool('usaspending_autocomplete_filters',
35
37
  code: z
36
38
  .string()
37
39
  .optional()
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
- name: z.string().optional().describe('Human-readable name or description'),
40
- id: z
40
+ .describe('Code value (NAICS code, PSC code, or Assistance Listing/CFDA number); use this in filter parameters — an Assistance Listing number goes in usaspending_search_awards assistance_listings. Agency rows carry toptier_code instead.'),
41
+ name: z
41
42
  .string()
42
43
  .optional()
43
- .describe('Numeric or string ID (for the awarding_agency type)'),
44
+ .describe("Human-readable name or description; for awarding_agency, the matched agency's own name, which for a sub-agency differs from toptier_name"),
45
+ abbreviation: z
46
+ .string()
47
+ .optional()
48
+ .describe("awarding_agency only: the matched agency's own abbreviation, when it has one"),
49
+ tier: z
50
+ .enum(['toptier', 'subtier'])
51
+ .optional()
52
+ .describe('awarding_agency only: toptier for a department-level agency, subtier for a component under one'),
53
+ toptier_name: z
54
+ .string()
55
+ .optional()
56
+ .describe('awarding_agency only: the top-tier agency name — the value the agency_name filters on usaspending_search_awards, usaspending_spending_by_category, usaspending_spending_by_geography, and usaspending_spending_over_time take. Those filters are top-tier only, so a sub-agency filters at its parent and the results cover the whole department.'),
57
+ toptier_code: z
58
+ .string()
59
+ .optional()
60
+ .describe('awarding_agency only: the 3-digit top-tier agency code, accepted by usaspending_get_agency'),
44
61
  uei: z
45
62
  .string()
46
63
  .optional()
@@ -50,19 +67,27 @@ export const autocompleteFiltersTool = tool('usaspending_autocomplete_filters',
50
67
  .optional()
51
68
  .describe('DUNS number (legacy) — recipient type only; populated when the search text matches a DUNS'),
52
69
  })
53
- .describe('Matched entry — code/name for code lookups, name plus optional UEI/DUNS for recipients'))
70
+ .describe('Matched entry — code/name for code lookups, name with tier and top-tier parent for agencies, name plus optional UEI/DUNS for recipients'))
54
71
  .describe('Matching codes and names'),
55
72
  total: z.number().describe('Number of results returned'),
56
73
  }),
57
74
  // Agent-facing context: echoed query parameters and result count. The autocomplete
58
- // endpoint returns no total, so a hit-the-cap signal discloses truncation.
75
+ // endpoints return no total, so the handler asks for one row past the limit and
76
+ // discloses truncation only when that row (or a recipient bucket overflow) came back.
59
77
  enrichment: {
60
78
  lookup_type: z.string().describe('Lookup table that was searched'),
61
79
  query: z.string().describe('Search text sent to the autocomplete API'),
62
80
  result_count: z.number().describe('Number of matching results returned'),
63
- truncated: z.boolean().optional().describe('True when results were capped at the limit.'),
64
- shown: z.number().optional().describe('Number of results returned.'),
65
- cap: z.number().optional().describe('The limit that was applied.'),
81
+ truncated: z
82
+ .boolean()
83
+ .optional()
84
+ .describe('True when more matches exist beyond the limit and were left out. Absent when every match was returned.'),
85
+ shown: z.number().optional().describe('Number of results returned, when truncated.'),
86
+ cap: z.number().optional().describe('The limit that was applied, when truncated.'),
87
+ notice: z
88
+ .string()
89
+ .optional()
90
+ .describe('How to reach the matches left out when truncated, or — when limit is 500 and all 500 slots filled — that the upstream maximum was reached and more matches may exist. Absent otherwise.'),
66
91
  },
67
92
  errors: [
68
93
  {
@@ -95,22 +120,28 @@ export const autocompleteFiltersTool = tool('usaspending_autocomplete_filters',
95
120
  });
96
121
  const svc = getUSASpendingService();
97
122
  let rawResults = [];
123
+ /**
124
+ * One row past `limit` tells a capped list from one that exactly fills the page. Every
125
+ * autocomplete route rejects `limit` above 500 with HTTP 400, so at 500 there is no
126
+ * room for the extra row and a full page can only say the ceiling was reached.
127
+ */
128
+ const requested = Math.min(input.limit + 1, UPSTREAM_LIMIT_MAX);
98
129
  if (input.type === 'naics') {
99
- const resp = await svc.autocompleteNaics(input.search_text, input.limit, ctx);
130
+ const resp = await svc.autocompleteNaics(input.search_text, requested, ctx);
100
131
  rawResults = (resp.results ?? []).map((r) => ({
101
132
  ...(r.naics ? { code: r.naics } : {}),
102
133
  ...(r.naics_description ? { name: r.naics_description } : {}),
103
134
  }));
104
135
  }
105
136
  else if (input.type === 'psc') {
106
- const resp = await svc.autocompletePsc(input.search_text, input.limit, ctx);
137
+ const resp = await svc.autocompletePsc(input.search_text, requested, ctx);
107
138
  rawResults = (resp.results ?? []).map((r) => ({
108
139
  ...(r.product_or_service_code ? { code: r.product_or_service_code } : {}),
109
140
  ...(r.psc_description ? { name: r.psc_description } : {}),
110
141
  }));
111
142
  }
112
143
  else if (input.type === 'cfda') {
113
- const resp = await svc.autocompleteCfda(input.search_text, input.limit, ctx);
144
+ const resp = await svc.autocompleteCfda(input.search_text, requested, ctx);
114
145
  rawResults = (resp.results ?? []).map((r) => ({
115
146
  ...(r.program_number ? { code: r.program_number } : {}),
116
147
  ...(r.program_title
@@ -121,24 +152,42 @@ export const autocompleteFiltersTool = tool('usaspending_autocomplete_filters',
121
152
  }));
122
153
  }
123
154
  else if (input.type === 'awarding_agency') {
124
- const resp = await svc.autocompleteAwardingAgency(input.search_text, input.limit, ctx);
125
- rawResults = (resp.results ?? []).map((r) => ({
126
- ...(r.id != null ? { id: String(r.id) } : {}),
127
- ...(r.toptier_agency?.name ? { name: r.toptier_agency.name } : {}),
128
- }));
155
+ const resp = await svc.autocompleteAwardingAgency(input.search_text, requested, ctx);
156
+ rawResults = (resp.results ?? []).map((r) => {
157
+ /**
158
+ * A top-tier row repeats the department under subtier_agency; a sub-agency row
159
+ * names itself there, with its parent under toptier_agency.
160
+ */
161
+ const own = r.toptier_flag ? r.toptier_agency : r.subtier_agency;
162
+ return {
163
+ ...(own?.name ? { name: own.name } : {}),
164
+ ...(own?.abbreviation ? { abbreviation: own.abbreviation } : {}),
165
+ ...(typeof r.toptier_flag === 'boolean'
166
+ ? { tier: r.toptier_flag ? 'toptier' : 'subtier' }
167
+ : {}),
168
+ ...(r.toptier_agency?.name ? { toptier_name: r.toptier_agency.name } : {}),
169
+ ...(r.toptier_agency?.toptier_code
170
+ ? { toptier_code: r.toptier_agency.toptier_code }
171
+ : {}),
172
+ };
173
+ });
129
174
  }
130
175
  else {
131
176
  // recipient
132
- const resp = await svc.autocompleteRecipient(input.search_text, input.limit, ctx);
177
+ const resp = await svc.autocompleteRecipient(input.search_text, requested, ctx);
133
178
  rawResults = (resp.results ?? []).map((r) => ({
134
179
  ...(r.recipient_name ? { name: r.recipient_name } : {}),
135
180
  ...(r.uei ? { uei: r.uei } : {}),
136
181
  ...(r.duns ? { duns: r.duns } : {}),
137
182
  }));
138
183
  }
139
- // `autocomplete/recipient/` applies `limit` per match bucket (name, UEI, DUNS) and
140
- // unions them, so it can hand back up to 3x what was asked for. The other four
141
- // lookups already honor `limit`, so capping here is a no-op for them.
184
+ /**
185
+ * `autocomplete/recipient/` applies `limit` per match bucket (name, UEI, DUNS) and
186
+ * unions them, so it can hand back up to 3x what was asked for; the other four
187
+ * lookups return at most `requested`. Truncation is judged on everything received —
188
+ * for recipients, the bucket union — before the slice to `limit`.
189
+ */
190
+ const received = rawResults.length;
142
191
  rawResults = rawResults.slice(0, input.limit);
143
192
  if (rawResults.length === 0) {
144
193
  throw ctx.fail('no_match', `No ${input.type} results matched "${input.search_text}"`, {
@@ -152,20 +201,28 @@ export const autocompleteFiltersTool = tool('usaspending_autocomplete_filters',
152
201
  query: input.search_text,
153
202
  result_count: rawResults.length,
154
203
  });
155
- if (rawResults.length >= input.limit) {
204
+ const narrow = input.limit < UPSTREAM_LIMIT_MAX
205
+ ? `Raise limit (max ${UPSTREAM_LIMIT_MAX}) or use a more specific search term.`
206
+ : 'Use a more specific search term.';
207
+ if (received > input.limit) {
156
208
  ctx.enrich.truncated({
157
209
  shown: rawResults.length,
158
210
  cap: input.limit,
159
- // The recipient cap is a head-slice over name-then-UEI-then-DUNS, and upstream
160
- // fills the name bucket to `limit` on its own whenever the corpus allows. So a
161
- // saturated recipient page holds name matches only, and raising `limit` raises
162
- // the name bucket with it — it never reaches the identifier buckets behind it.
163
- // Pointing that caller at `limit` would send them somewhere the rows are not.
211
+ /**
212
+ * The recipient cap is a head-slice over name-then-UEI-then-DUNS, and upstream
213
+ * fills the name bucket to the requested size on its own whenever the corpus
214
+ * allows. So a saturated recipient page holds name matches only, and raising
215
+ * `limit` raises the name bucket with it — it never reaches the identifier buckets
216
+ * behind it. Pointing that caller at `limit` alone would misdirect them.
217
+ */
164
218
  guidance: input.type === 'recipient'
165
- ? 'More name matches may exist — raise limit (max 500) or use a more specific search term. Matches on a UEI or DUNS are not reachable this way once name matches fill the page; to resolve one, pass the identifier itself as search_text.'
166
- : 'More matches may exist. Raise limit (max 500) or use a more specific search term.',
219
+ ? `More matches exist beyond limit. ${narrow} Matches on a UEI or DUNS are not reachable this way once name matches fill the page; to resolve one, pass the identifier itself as search_text.`
220
+ : `More matches exist beyond limit. ${narrow}`,
167
221
  });
168
222
  }
223
+ else if (requested === input.limit && received === input.limit) {
224
+ ctx.enrich.notice(`Returned the upstream maximum of ${UPSTREAM_LIMIT_MAX} matches, so more may exist. ${narrow}`);
225
+ }
169
226
  return {
170
227
  type: input.type,
171
228
  search_text: input.search_text,
@@ -179,10 +236,12 @@ export const autocompleteFiltersTool = tool('usaspending_autocomplete_filters',
179
236
  const parts = [];
180
237
  if (r.code)
181
238
  parts.push(`**Code:** ${r.code}`);
182
- if (r.id)
183
- parts.push(`**ID:** ${r.id}`);
184
239
  if (r.name)
185
- parts.push(`**Name:** ${r.name}`);
240
+ parts.push(`**Name:** ${r.name}${r.abbreviation ? ` (${r.abbreviation})` : ''}`);
241
+ if (r.tier)
242
+ parts.push(`**Tier:** ${r.tier}`);
243
+ if (r.toptier_name)
244
+ parts.push(`**Top-tier agency:** ${r.toptier_name}${r.toptier_code ? ` (toptier_code ${r.toptier_code})` : ''}`);
186
245
  if (r.uei)
187
246
  parts.push(`**UEI:** ${r.uei}`);
188
247
  if (r.duns)