@cyanheads/usaspending-mcp-server 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +405 -0
- package/Dockerfile +98 -0
- package/README.md +391 -0
- package/changelog/0.1.x/0.1.0.md +26 -0
- package/changelog/0.1.x/0.1.1.md +16 -0
- package/changelog/template.md +119 -0
- package/dist/config/server-config.d.ts +13 -0
- package/dist/config/server-config.d.ts.map +1 -0
- package/dist/config/server-config.js +29 -0
- package/dist/config/server-config.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-server/tools/definitions/autocomplete.tool.d.ts +39 -0
- package/dist/mcp-server/tools/definitions/autocomplete.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/autocomplete.tool.js +138 -0
- package/dist/mcp-server/tools/definitions/autocomplete.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/disaster-spending.tool.d.ts +78 -0
- package/dist/mcp-server/tools/definitions/disaster-spending.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/disaster-spending.tool.js +300 -0
- package/dist/mcp-server/tools/definitions/disaster-spending.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/filters.d.ts +15 -0
- package/dist/mcp-server/tools/definitions/filters.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/filters.js +26 -0
- package/dist/mcp-server/tools/definitions/filters.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-agency.tool.d.ts +50 -0
- package/dist/mcp-server/tools/definitions/get-agency.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-agency.tool.js +217 -0
- package/dist/mcp-server/tools/definitions/get-agency.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-award-subawards.tool.d.ts +56 -0
- package/dist/mcp-server/tools/definitions/get-award-subawards.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-award-subawards.tool.js +154 -0
- package/dist/mcp-server/tools/definitions/get-award-subawards.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-award-transactions.tool.d.ts +53 -0
- package/dist/mcp-server/tools/definitions/get-award-transactions.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-award-transactions.tool.js +147 -0
- package/dist/mcp-server/tools/definitions/get-award-transactions.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-award.tool.d.ts +91 -0
- package/dist/mcp-server/tools/definitions/get-award.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-award.tool.js +433 -0
- package/dist/mcp-server/tools/definitions/get-award.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-federal-account.tool.d.ts +32 -0
- package/dist/mcp-server/tools/definitions/get-federal-account.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-federal-account.tool.js +107 -0
- package/dist/mcp-server/tools/definitions/get-federal-account.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-recipient.tool.d.ts +55 -0
- package/dist/mcp-server/tools/definitions/get-recipient.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-recipient.tool.js +194 -0
- package/dist/mcp-server/tools/definitions/get-recipient.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/index.d.ts +678 -0
- package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/index.js +49 -0
- package/dist/mcp-server/tools/definitions/index.js.map +1 -0
- package/dist/mcp-server/tools/definitions/list-agencies.tool.d.ts +36 -0
- package/dist/mcp-server/tools/definitions/list-agencies.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/list-agencies.tool.js +93 -0
- package/dist/mcp-server/tools/definitions/list-agencies.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/search-awards.tool.d.ts +77 -0
- package/dist/mcp-server/tools/definitions/search-awards.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/search-awards.tool.js +300 -0
- package/dist/mcp-server/tools/definitions/search-awards.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/search-recipients.tool.d.ts +46 -0
- package/dist/mcp-server/tools/definitions/search-recipients.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/search-recipients.tool.js +143 -0
- package/dist/mcp-server/tools/definitions/search-recipients.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/spending-by-category.tool.d.ts +57 -0
- package/dist/mcp-server/tools/definitions/spending-by-category.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/spending-by-category.tool.js +136 -0
- package/dist/mcp-server/tools/definitions/spending-by-category.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/spending-by-geography.tool.d.ts +51 -0
- package/dist/mcp-server/tools/definitions/spending-by-geography.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/spending-by-geography.tool.js +153 -0
- package/dist/mcp-server/tools/definitions/spending-by-geography.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/spending-over-time.tool.d.ts +53 -0
- package/dist/mcp-server/tools/definitions/spending-over-time.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/spending-over-time.tool.js +163 -0
- package/dist/mcp-server/tools/definitions/spending-over-time.tool.js.map +1 -0
- package/dist/services/usaspending/types.d.ts +489 -0
- package/dist/services/usaspending/types.d.ts.map +1 -0
- package/dist/services/usaspending/types.js +6 -0
- package/dist/services/usaspending/types.js.map +1 -0
- package/dist/services/usaspending/usaspending-service.d.ts +137 -0
- package/dist/services/usaspending/usaspending-service.d.ts.map +1 -0
- package/dist/services/usaspending/usaspending-service.js +201 -0
- package/dist/services/usaspending/usaspending-service.js.map +1 -0
- package/package.json +80 -0
- package/server.json +99 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Tool to search for federal award recipients by name or UEI.
|
|
3
|
+
* @module mcp-server/tools/definitions/search-recipients.tool
|
|
4
|
+
*/
|
|
5
|
+
import { z } from '@cyanheads/mcp-ts-core';
|
|
6
|
+
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
7
|
+
export declare const searchRecipientsTool: import("@cyanheads/mcp-ts-core").ToolDefinition<z.ZodObject<{
|
|
8
|
+
keyword: z.ZodString;
|
|
9
|
+
award_type: z.ZodOptional<z.ZodEnum<{
|
|
10
|
+
contracts: "contracts";
|
|
11
|
+
grants: "grants";
|
|
12
|
+
direct_payments: "direct_payments";
|
|
13
|
+
loans: "loans";
|
|
14
|
+
other_financial_assistance: "other_financial_assistance";
|
|
15
|
+
}>>;
|
|
16
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
17
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
18
|
+
results: z.ZodArray<z.ZodObject<{
|
|
19
|
+
id: z.ZodOptional<z.ZodString>;
|
|
20
|
+
name: z.ZodOptional<z.ZodString>;
|
|
21
|
+
uei: z.ZodOptional<z.ZodString>;
|
|
22
|
+
duns: z.ZodOptional<z.ZodString>;
|
|
23
|
+
recipient_level: z.ZodOptional<z.ZodString>;
|
|
24
|
+
amount: z.ZodOptional<z.ZodNumber>;
|
|
25
|
+
state: z.ZodOptional<z.ZodString>;
|
|
26
|
+
location: z.ZodOptional<z.ZodObject<{
|
|
27
|
+
city_name: z.ZodOptional<z.ZodString>;
|
|
28
|
+
state_code: z.ZodOptional<z.ZodString>;
|
|
29
|
+
country_code: z.ZodOptional<z.ZodString>;
|
|
30
|
+
}, z.core.$strip>>;
|
|
31
|
+
}, z.core.$strip>>;
|
|
32
|
+
total: z.ZodNumber;
|
|
33
|
+
message: z.ZodOptional<z.ZodString>;
|
|
34
|
+
}, z.core.$strip>, readonly [{
|
|
35
|
+
readonly reason: "no_match";
|
|
36
|
+
readonly code: JsonRpcErrorCode.NotFound;
|
|
37
|
+
readonly when: "No recipients matched the keyword.";
|
|
38
|
+
readonly recovery: "Try a partial name, different spelling, or search by UEI instead of name.";
|
|
39
|
+
}, {
|
|
40
|
+
readonly reason: "api_unavailable";
|
|
41
|
+
readonly code: JsonRpcErrorCode.ServiceUnavailable;
|
|
42
|
+
readonly when: "USAspending.gov API is unreachable or returns an error.";
|
|
43
|
+
readonly retryable: true;
|
|
44
|
+
readonly recovery: "The API may be temporarily down. Retry the request after a few seconds.";
|
|
45
|
+
}]>;
|
|
46
|
+
//# sourceMappingURL=search-recipients.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-recipients.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/search-recipients.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAQ,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAGjE,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoJ/B,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Tool to search for federal award recipients by name or UEI.
|
|
3
|
+
* @module mcp-server/tools/definitions/search-recipients.tool
|
|
4
|
+
*/
|
|
5
|
+
import { tool, z } from '@cyanheads/mcp-ts-core';
|
|
6
|
+
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
7
|
+
import { getUSASpendingService } from '../../../services/usaspending/usaspending-service.js';
|
|
8
|
+
export const searchRecipientsTool = tool('usaspending_search_recipients', {
|
|
9
|
+
title: 'Search Award Recipients',
|
|
10
|
+
description: 'Search for organizations or individuals receiving federal funds by name or UEI (Unique Entity Identifier). Returns recipient IDs (UUID hashes), total award amounts, business type classifications, and location data. Recipient IDs from this tool can be passed to usaspending_get_recipient for full profiles. Recipient level: P = parent organization, C = child entity, R = standalone.',
|
|
11
|
+
annotations: { readOnlyHint: true, openWorldHint: true, idempotentHint: true },
|
|
12
|
+
input: z.object({
|
|
13
|
+
keyword: z
|
|
14
|
+
.string()
|
|
15
|
+
.min(1)
|
|
16
|
+
.describe('Name, UEI, DUNS, or keyword to search for — partial matches are supported'),
|
|
17
|
+
award_type: z
|
|
18
|
+
.enum(['contracts', 'grants', 'direct_payments', 'loans', 'other_financial_assistance'])
|
|
19
|
+
.optional()
|
|
20
|
+
.describe('Filter by award type category to scope the total amounts returned'),
|
|
21
|
+
limit: z
|
|
22
|
+
.number()
|
|
23
|
+
.int()
|
|
24
|
+
.min(1)
|
|
25
|
+
.max(100)
|
|
26
|
+
.default(10)
|
|
27
|
+
.describe('Maximum results to return (1–100)'),
|
|
28
|
+
}),
|
|
29
|
+
output: z.object({
|
|
30
|
+
results: z
|
|
31
|
+
.array(z
|
|
32
|
+
.object({
|
|
33
|
+
id: z
|
|
34
|
+
.string()
|
|
35
|
+
.optional()
|
|
36
|
+
.describe('Recipient hash ID (UUID format with level suffix: -P parent, -C child, -R standalone) — pass to usaspending_get_recipient for full profile'),
|
|
37
|
+
name: z.string().optional().describe('Recipient legal business name'),
|
|
38
|
+
uei: z.string().optional().describe('Unique Entity Identifier (SAM.gov)'),
|
|
39
|
+
duns: z.string().optional().describe('DUNS number (legacy, being phased out)'),
|
|
40
|
+
recipient_level: z
|
|
41
|
+
.string()
|
|
42
|
+
.optional()
|
|
43
|
+
.describe('Hierarchy level: P = parent, C = child, R = standalone'),
|
|
44
|
+
amount: z
|
|
45
|
+
.number()
|
|
46
|
+
.optional()
|
|
47
|
+
.describe('Total award amount in USD for the selected award type'),
|
|
48
|
+
state: z.string().optional().describe('State code of recipient address'),
|
|
49
|
+
location: z
|
|
50
|
+
.object({
|
|
51
|
+
city_name: z.string().optional().describe('City of recipient address'),
|
|
52
|
+
state_code: z.string().optional().describe('State code'),
|
|
53
|
+
country_code: z.string().optional().describe('Country code'),
|
|
54
|
+
})
|
|
55
|
+
.optional()
|
|
56
|
+
.describe('Recipient address location'),
|
|
57
|
+
})
|
|
58
|
+
.describe('Recipient entry with ID, name, and award totals'))
|
|
59
|
+
.describe('Matching recipients'),
|
|
60
|
+
total: z.number().describe('Number of results returned'),
|
|
61
|
+
message: z
|
|
62
|
+
.string()
|
|
63
|
+
.optional()
|
|
64
|
+
.describe('Recovery hint when results are empty — suggests how to broaden the search. Absent when results are present.'),
|
|
65
|
+
}),
|
|
66
|
+
errors: [
|
|
67
|
+
{
|
|
68
|
+
reason: 'no_match',
|
|
69
|
+
code: JsonRpcErrorCode.NotFound,
|
|
70
|
+
when: 'No recipients matched the keyword.',
|
|
71
|
+
recovery: 'Try a partial name, different spelling, or search by UEI instead of name.',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
reason: 'api_unavailable',
|
|
75
|
+
code: JsonRpcErrorCode.ServiceUnavailable,
|
|
76
|
+
when: 'USAspending.gov API is unreachable or returns an error.',
|
|
77
|
+
retryable: true,
|
|
78
|
+
recovery: 'The API may be temporarily down. Retry the request after a few seconds.',
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
async handler(input, ctx) {
|
|
82
|
+
ctx.log.info('usaspending_search_recipients', { keyword: input.keyword, limit: input.limit });
|
|
83
|
+
const svc = getUSASpendingService();
|
|
84
|
+
const rawResults = await svc.searchRecipients({
|
|
85
|
+
keyword: input.keyword,
|
|
86
|
+
...(input.award_type !== undefined ? { award_type: input.award_type } : {}),
|
|
87
|
+
limit: input.limit,
|
|
88
|
+
}, ctx);
|
|
89
|
+
const results = rawResults.map((r) => ({
|
|
90
|
+
...(r.id ? { id: r.id } : {}),
|
|
91
|
+
...(r.name ? { name: r.name } : {}),
|
|
92
|
+
...(r.uei ? { uei: r.uei } : {}),
|
|
93
|
+
...(r.duns ? { duns: r.duns } : {}),
|
|
94
|
+
...(r.recipient_level ? { recipient_level: r.recipient_level } : {}),
|
|
95
|
+
...(typeof r.amount === 'number' ? { amount: r.amount } : {}),
|
|
96
|
+
...(r.state_province ? { state: r.state_province } : {}),
|
|
97
|
+
...(r.location
|
|
98
|
+
? {
|
|
99
|
+
location: {
|
|
100
|
+
...(r.location.city_name ? { city_name: r.location.city_name } : {}),
|
|
101
|
+
...(r.location.state_code ? { state_code: r.location.state_code } : {}),
|
|
102
|
+
...(r.location.country_code ? { country_code: r.location.country_code } : {}),
|
|
103
|
+
},
|
|
104
|
+
}
|
|
105
|
+
: {}),
|
|
106
|
+
}));
|
|
107
|
+
if (results.length === 0) {
|
|
108
|
+
return {
|
|
109
|
+
results,
|
|
110
|
+
total: 0,
|
|
111
|
+
message: `No recipients matched "${input.keyword}". Try a partial name, different spelling, or use a UEI number directly.`,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return { results, total: results.length };
|
|
115
|
+
},
|
|
116
|
+
format: (result) => {
|
|
117
|
+
const lines = [`## Recipient Search Results (${result.total})`];
|
|
118
|
+
if (result.message)
|
|
119
|
+
lines.push(`\n> ${result.message}`);
|
|
120
|
+
for (const r of result.results) {
|
|
121
|
+
lines.push('');
|
|
122
|
+
lines.push(`### ${r.name ?? r.id ?? 'Unknown'}`);
|
|
123
|
+
if (r.id)
|
|
124
|
+
lines.push(`**Recipient ID (for get_recipient):** ${r.id}`);
|
|
125
|
+
if (r.uei)
|
|
126
|
+
lines.push(`**UEI:** ${r.uei}`);
|
|
127
|
+
if (r.duns)
|
|
128
|
+
lines.push(`**DUNS:** ${r.duns}`);
|
|
129
|
+
if (r.recipient_level)
|
|
130
|
+
lines.push(`**Level:** ${r.recipient_level}`);
|
|
131
|
+
if (typeof r.amount === 'number')
|
|
132
|
+
lines.push(`**Award Amount:** $${r.amount.toLocaleString()}`);
|
|
133
|
+
if (r.state)
|
|
134
|
+
lines.push(`**State:** ${r.state}`);
|
|
135
|
+
if (r.location) {
|
|
136
|
+
const loc = r.location;
|
|
137
|
+
lines.push(`**Location:** ${[loc.city_name, loc.state_code, loc.country_code].filter(Boolean).join(', ')}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return [{ type: 'text', text: lines.join('\n') }];
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
//# sourceMappingURL=search-recipients.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-recipients.tool.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/search-recipients.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAC;AAEtF,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC,+BAA+B,EAAE;IACxE,KAAK,EAAE,yBAAyB;IAChC,WAAW,EACT,+XAA+X;IACjY,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE;IAE9E,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;QACd,OAAO,EAAE,CAAC;aACP,MAAM,EAAE;aACR,GAAG,CAAC,CAAC,CAAC;aACN,QAAQ,CAAC,2EAA2E,CAAC;QACxF,UAAU,EAAE,CAAC;aACV,IAAI,CAAC,CAAC,WAAW,EAAE,QAAQ,EAAE,iBAAiB,EAAE,OAAO,EAAE,4BAA4B,CAAC,CAAC;aACvF,QAAQ,EAAE;aACV,QAAQ,CAAC,mEAAmE,CAAC;QAChF,KAAK,EAAE,CAAC;aACL,MAAM,EAAE;aACR,GAAG,EAAE;aACL,GAAG,CAAC,CAAC,CAAC;aACN,GAAG,CAAC,GAAG,CAAC;aACR,OAAO,CAAC,EAAE,CAAC;aACX,QAAQ,CAAC,mCAAmC,CAAC;KACjD,CAAC;IAEF,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACf,OAAO,EAAE,CAAC;aACP,KAAK,CACJ,CAAC;aACE,MAAM,CAAC;YACN,EAAE,EAAE,CAAC;iBACF,MAAM,E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AAsB,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;YAChE,IAAI,CAAC,CAAC,KAAK;gBAAE,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;YACjD,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;gBACf,MAAM,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC;gBACvB,KAAK,CAAC,IAAI,CACR,iBAAiB,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAChG,CAAC;YACJ,CAAC;QACH,CAAC;QACD,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Tool to aggregate federal spending grouped by a dimension (NAICS, PSC, agency, etc.).
|
|
3
|
+
* @module mcp-server/tools/definitions/spending-by-category.tool
|
|
4
|
+
*/
|
|
5
|
+
import { z } from '@cyanheads/mcp-ts-core';
|
|
6
|
+
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
7
|
+
export declare const spendingByCategoryTool: import("@cyanheads/mcp-ts-core").ToolDefinition<z.ZodObject<{
|
|
8
|
+
category: z.ZodEnum<{
|
|
9
|
+
naics: "naics";
|
|
10
|
+
psc: "psc";
|
|
11
|
+
cfda: "cfda";
|
|
12
|
+
awarding_agency: "awarding_agency";
|
|
13
|
+
funding_agency: "funding_agency";
|
|
14
|
+
awarding_subagency: "awarding_subagency";
|
|
15
|
+
funding_subagency: "funding_subagency";
|
|
16
|
+
recipient_duns: "recipient_duns";
|
|
17
|
+
recipient_parent_duns: "recipient_parent_duns";
|
|
18
|
+
}>;
|
|
19
|
+
filters: z.ZodOptional<z.ZodObject<{
|
|
20
|
+
keywords: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
21
|
+
award_type_codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
22
|
+
agency_name: z.ZodOptional<z.ZodString>;
|
|
23
|
+
recipient_id: z.ZodOptional<z.ZodString>;
|
|
24
|
+
naics_codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
|
+
time_period_start: z.ZodOptional<z.ZodString>;
|
|
26
|
+
time_period_end: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>>;
|
|
28
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
29
|
+
page: z.ZodDefault<z.ZodNumber>;
|
|
30
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
31
|
+
category: z.ZodString;
|
|
32
|
+
results: z.ZodArray<z.ZodObject<{
|
|
33
|
+
id: z.ZodOptional<z.ZodString>;
|
|
34
|
+
code: z.ZodOptional<z.ZodString>;
|
|
35
|
+
name: z.ZodOptional<z.ZodString>;
|
|
36
|
+
amount: z.ZodOptional<z.ZodNumber>;
|
|
37
|
+
}, z.core.$strip>>;
|
|
38
|
+
page_metadata: z.ZodObject<{
|
|
39
|
+
has_next: z.ZodBoolean;
|
|
40
|
+
page: z.ZodNumber;
|
|
41
|
+
total: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
limit: z.ZodNumber;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
message: z.ZodOptional<z.ZodString>;
|
|
45
|
+
}, z.core.$strip>, readonly [{
|
|
46
|
+
readonly reason: "no_data";
|
|
47
|
+
readonly code: JsonRpcErrorCode.NotFound;
|
|
48
|
+
readonly when: "No spending data matched the filters for the selected category.";
|
|
49
|
+
readonly recovery: "Broaden filters, try a different category dimension, or widen the time period.";
|
|
50
|
+
}, {
|
|
51
|
+
readonly reason: "api_unavailable";
|
|
52
|
+
readonly code: JsonRpcErrorCode.ServiceUnavailable;
|
|
53
|
+
readonly when: "USAspending.gov API is unreachable or returns an error.";
|
|
54
|
+
readonly retryable: true;
|
|
55
|
+
readonly recovery: "The API may be temporarily down. Retry the request after a few seconds.";
|
|
56
|
+
}]>;
|
|
57
|
+
//# sourceMappingURL=spending-by-category.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spending-by-category.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/spending-by-category.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAQ,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAIjE,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoJjC,CAAC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Tool to aggregate federal spending grouped by a dimension (NAICS, PSC, agency, etc.).
|
|
3
|
+
* @module mcp-server/tools/definitions/spending-by-category.tool
|
|
4
|
+
*/
|
|
5
|
+
import { tool, z } from '@cyanheads/mcp-ts-core';
|
|
6
|
+
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
7
|
+
import { getUSASpendingService } from '../../../services/usaspending/usaspending-service.js';
|
|
8
|
+
import { buildFilters } from './filters.js';
|
|
9
|
+
export const spendingByCategoryTool = tool('usaspending_spending_by_category', {
|
|
10
|
+
title: 'Spending by Category',
|
|
11
|
+
description: 'Aggregate federal spending grouped by a specific dimension: NAICS industry code, PSC product/service code, awarding agency, funding agency, CFDA assistance program, or recipient. Returns top items with obligation amounts — useful for trend and breakdown analysis. Chain NAICS codes into usaspending_search_awards filters or usaspending_autocomplete lookups.',
|
|
12
|
+
annotations: { readOnlyHint: true, openWorldHint: true, idempotentHint: true },
|
|
13
|
+
input: z.object({
|
|
14
|
+
category: z
|
|
15
|
+
.enum([
|
|
16
|
+
'naics',
|
|
17
|
+
'psc',
|
|
18
|
+
'awarding_agency',
|
|
19
|
+
'awarding_subagency',
|
|
20
|
+
'funding_agency',
|
|
21
|
+
'funding_subagency',
|
|
22
|
+
'cfda',
|
|
23
|
+
'recipient_duns',
|
|
24
|
+
'recipient_parent_duns',
|
|
25
|
+
])
|
|
26
|
+
.describe('Breakdown dimension: naics (industry), psc (product/service code), awarding_agency, awarding_subagency, funding_agency, funding_subagency, cfda (assistance programs), recipient_duns, or recipient_parent_duns'),
|
|
27
|
+
filters: z
|
|
28
|
+
.object({
|
|
29
|
+
keywords: z.array(z.string()).optional().describe('Full-text keyword filters'),
|
|
30
|
+
award_type_codes: z
|
|
31
|
+
.array(z.string())
|
|
32
|
+
.optional()
|
|
33
|
+
.describe('Award type code filters (A/B/C/D, 02–05, etc.)'),
|
|
34
|
+
agency_name: z.string().optional().describe('Awarding agency name filter'),
|
|
35
|
+
recipient_id: z.string().optional().describe('Exact recipient hash ID filter'),
|
|
36
|
+
naics_codes: z.array(z.string()).optional().describe('NAICS code filters'),
|
|
37
|
+
time_period_start: z.string().optional().describe('Start date (YYYY-MM-DD)'),
|
|
38
|
+
time_period_end: z.string().optional().describe('End date (YYYY-MM-DD)'),
|
|
39
|
+
})
|
|
40
|
+
.optional()
|
|
41
|
+
.describe('Optional filters to scope the aggregation'),
|
|
42
|
+
limit: z.number().int().min(1).max(100).default(10).describe('Maximum items to return (1–100)'),
|
|
43
|
+
page: z.number().int().min(1).default(1).describe('Page number (1-based)'),
|
|
44
|
+
}),
|
|
45
|
+
output: z.object({
|
|
46
|
+
category: z.string().describe('Breakdown dimension used'),
|
|
47
|
+
results: z
|
|
48
|
+
.array(z
|
|
49
|
+
.object({
|
|
50
|
+
id: z.string().optional().describe('Item identifier (varies by category)'),
|
|
51
|
+
code: z.string().optional().describe('Code value (NAICS, PSC, CFDA number, etc.)'),
|
|
52
|
+
name: z.string().optional().describe('Item name or description'),
|
|
53
|
+
amount: z.number().optional().describe('Total obligation amount in USD'),
|
|
54
|
+
})
|
|
55
|
+
.describe('Category item with code, name, and obligation amount'))
|
|
56
|
+
.describe('Top items in this category by obligation amount'),
|
|
57
|
+
page_metadata: z
|
|
58
|
+
.object({
|
|
59
|
+
has_next: z.boolean().describe('Whether there are more pages'),
|
|
60
|
+
page: z.number().describe('Current page'),
|
|
61
|
+
total: z.number().optional().describe('Total items'),
|
|
62
|
+
limit: z.number().describe('Items per page'),
|
|
63
|
+
})
|
|
64
|
+
.describe('Pagination metadata'),
|
|
65
|
+
message: z
|
|
66
|
+
.string()
|
|
67
|
+
.optional()
|
|
68
|
+
.describe('Recovery hint when results are empty — suggests how to broaden filters. Absent when results are present.'),
|
|
69
|
+
}),
|
|
70
|
+
errors: [
|
|
71
|
+
{
|
|
72
|
+
reason: 'no_data',
|
|
73
|
+
code: JsonRpcErrorCode.NotFound,
|
|
74
|
+
when: 'No spending data matched the filters for the selected category.',
|
|
75
|
+
recovery: 'Broaden filters, try a different category dimension, or widen the time period.',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
reason: 'api_unavailable',
|
|
79
|
+
code: JsonRpcErrorCode.ServiceUnavailable,
|
|
80
|
+
when: 'USAspending.gov API is unreachable or returns an error.',
|
|
81
|
+
retryable: true,
|
|
82
|
+
recovery: 'The API may be temporarily down. Retry the request after a few seconds.',
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
async handler(input, ctx) {
|
|
86
|
+
ctx.log.info('usaspending_spending_by_category', {
|
|
87
|
+
category: input.category,
|
|
88
|
+
limit: input.limit,
|
|
89
|
+
page: input.page,
|
|
90
|
+
});
|
|
91
|
+
const svc = getUSASpendingService();
|
|
92
|
+
const filters = buildFilters(input.filters);
|
|
93
|
+
const data = await svc.spendingByCategory(input.category, { filters, limit: input.limit, page: input.page }, ctx);
|
|
94
|
+
const results = (data.results ?? []).map((r) => ({
|
|
95
|
+
...(r.id != null ? { id: String(r.id) } : {}),
|
|
96
|
+
...(r.code ? { code: r.code } : {}),
|
|
97
|
+
...(r.name || r.description ? { name: r.name ?? r.description ?? undefined } : {}),
|
|
98
|
+
...(typeof r.amount === 'number' ? { amount: r.amount } : {}),
|
|
99
|
+
}));
|
|
100
|
+
const pageMeta = data.page_metadata ?? {};
|
|
101
|
+
const page_metadata = {
|
|
102
|
+
has_next: pageMeta.hasNext ?? false,
|
|
103
|
+
page: pageMeta.page ?? input.page,
|
|
104
|
+
...(typeof pageMeta.total === 'number' ? { total: pageMeta.total } : {}),
|
|
105
|
+
limit: input.limit,
|
|
106
|
+
};
|
|
107
|
+
if (results.length === 0) {
|
|
108
|
+
return {
|
|
109
|
+
category: input.category,
|
|
110
|
+
results,
|
|
111
|
+
page_metadata,
|
|
112
|
+
message: `No ${input.category} data matched the filters. Try broadening filters or selecting a different category.`,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return { category: input.category, results, page_metadata };
|
|
116
|
+
},
|
|
117
|
+
format: (result) => {
|
|
118
|
+
const lines = [
|
|
119
|
+
`## Spending by Category: ${result.category}`,
|
|
120
|
+
`**Page:** ${result.page_metadata.page}${result.page_metadata.total !== undefined ? ` of ~${result.page_metadata.total}` : ''} | **Per page:** ${result.page_metadata.limit} | **Has next:** ${result.page_metadata.has_next ? 'Yes' : 'No'}`,
|
|
121
|
+
];
|
|
122
|
+
if (result.message)
|
|
123
|
+
lines.push(`\n> ${result.message}`);
|
|
124
|
+
if (result.results.length > 0) {
|
|
125
|
+
lines.push('');
|
|
126
|
+
lines.push('| Rank | ID | Name | Code | Obligation |');
|
|
127
|
+
lines.push('|:-----|:---|:-----|:-----|:-----------|');
|
|
128
|
+
result.results.forEach((r, i) => {
|
|
129
|
+
const amt = r.amount !== undefined ? `$${r.amount.toLocaleString()}` : 'N/A';
|
|
130
|
+
lines.push(`| ${i + 1} | ${r.id ?? 'N/A'} | ${r.name ?? 'N/A'} | ${r.code ?? 'N/A'} | ${amt} |`);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return [{ type: 'text', text: lines.join('\n') }];
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
//# sourceMappingURL=spending-by-category.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spending-by-category.tool.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/spending-by-category.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAC;AACtF,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC,kCAAkC,EAAE;IAC7E,KAAK,EAAE,sBAAsB;IAC7B,WAAW,EACT,uWAAuW;IACzW,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE;IAE9E,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;QACd,QAAQ,EAAE,CAAC;aACR,IAAI,CAAC;YACJ,OAAO;YACP,KAAK;YACL,iBAAiB;YACjB,oBAAoB;YACpB,gBAAgB;YAChB,mBAAmB;YACnB,MAAM;YACN,gBAAgB;YAChB,uBAAuB;SACxB,CAAC;aACD,QAAQ,CACP,iNAAiN,CAClN;QACH,OAAO,EAAE,CAAC;aACP,MAAM,CAAC;YACN,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,2BAA2B,CAAC;YAC9E,gBAAgB,EAAE,CAAC;iBAChB,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;iBACjB,QAAQ,EAAE;iBACV,Q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AO,EAAE,CAAC,CAAC;QACxD,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACf,KAAK,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;YACvD,KAAK,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;YACvD,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;gBAC9B,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;gBAC7E,KAAK,CAAC,IAAI,CACR,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,KAAK,MAAM,CAAC,CAAC,IAAI,IAAI,KAAK,MAAM,CAAC,CAAC,IAAI,IAAI,KAAK,MAAM,GAAG,IAAI,CACrF,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Tool to aggregate federal spending by state, county, or congressional district.
|
|
3
|
+
* @module mcp-server/tools/definitions/spending-by-geography.tool
|
|
4
|
+
*/
|
|
5
|
+
import { z } from '@cyanheads/mcp-ts-core';
|
|
6
|
+
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
7
|
+
export declare const spendingByGeographyTool: import("@cyanheads/mcp-ts-core").ToolDefinition<z.ZodObject<{
|
|
8
|
+
scope: z.ZodEnum<{
|
|
9
|
+
place_of_performance: "place_of_performance";
|
|
10
|
+
recipient_location: "recipient_location";
|
|
11
|
+
}>;
|
|
12
|
+
geo_layer: z.ZodEnum<{
|
|
13
|
+
state: "state";
|
|
14
|
+
county: "county";
|
|
15
|
+
district: "district";
|
|
16
|
+
}>;
|
|
17
|
+
filters: z.ZodOptional<z.ZodObject<{
|
|
18
|
+
keywords: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
19
|
+
award_type_codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
20
|
+
agency_name: z.ZodOptional<z.ZodString>;
|
|
21
|
+
recipient_id: z.ZodOptional<z.ZodString>;
|
|
22
|
+
naics_codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
23
|
+
time_period_start: z.ZodOptional<z.ZodString>;
|
|
24
|
+
time_period_end: z.ZodOptional<z.ZodString>;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
subawards: z.ZodDefault<z.ZodBoolean>;
|
|
27
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
28
|
+
scope: z.ZodString;
|
|
29
|
+
geo_layer: z.ZodString;
|
|
30
|
+
results: z.ZodArray<z.ZodObject<{
|
|
31
|
+
shape_code: z.ZodOptional<z.ZodString>;
|
|
32
|
+
display_name: z.ZodOptional<z.ZodString>;
|
|
33
|
+
aggregated_amount: z.ZodOptional<z.ZodNumber>;
|
|
34
|
+
population: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
per_capita: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
award_count: z.ZodOptional<z.ZodNumber>;
|
|
37
|
+
}, z.core.$strip>>;
|
|
38
|
+
total: z.ZodNumber;
|
|
39
|
+
}, z.core.$strip>, readonly [{
|
|
40
|
+
readonly reason: "no_data";
|
|
41
|
+
readonly code: JsonRpcErrorCode.NotFound;
|
|
42
|
+
readonly when: "No spending data matched the filters for the selected geography.";
|
|
43
|
+
readonly recovery: "Broaden filters, try a different scope or geo_layer, or widen the time period.";
|
|
44
|
+
}, {
|
|
45
|
+
readonly reason: "api_unavailable";
|
|
46
|
+
readonly code: JsonRpcErrorCode.ServiceUnavailable;
|
|
47
|
+
readonly when: "USAspending.gov API is unreachable or returns an error.";
|
|
48
|
+
readonly retryable: true;
|
|
49
|
+
readonly recovery: "The API may be temporarily down. Retry the request after a few seconds.";
|
|
50
|
+
}]>;
|
|
51
|
+
//# sourceMappingURL=spending-by-geography.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spending-by-geography.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/spending-by-geography.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAQ,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAgCjE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4IlC,CAAC"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Tool to aggregate federal spending by state, county, or congressional district.
|
|
3
|
+
* @module mcp-server/tools/definitions/spending-by-geography.tool
|
|
4
|
+
*/
|
|
5
|
+
import { tool, z } from '@cyanheads/mcp-ts-core';
|
|
6
|
+
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
7
|
+
import { getUSASpendingService } from '../../../services/usaspending/usaspending-service.js';
|
|
8
|
+
import { buildFilters } from './filters.js';
|
|
9
|
+
/** Common filter fields for spending analytics tools */
|
|
10
|
+
const SpendingFiltersSchema = z
|
|
11
|
+
.object({
|
|
12
|
+
keywords: z
|
|
13
|
+
.array(z.string())
|
|
14
|
+
.optional()
|
|
15
|
+
.describe('Full-text keyword filter (e.g., ["cybersecurity", "cloud"])'),
|
|
16
|
+
award_type_codes: z
|
|
17
|
+
.array(z.string())
|
|
18
|
+
.optional()
|
|
19
|
+
.describe('Award type codes: A/B/C/D (contracts), 02–05 (grants), 06/10 (direct payments), 07/08 (loans)'),
|
|
20
|
+
agency_name: z.string().optional().describe('Awarding agency name filter'),
|
|
21
|
+
recipient_id: z.string().optional().describe('Exact recipient hash ID to filter awards'),
|
|
22
|
+
naics_codes: z.array(z.string()).optional().describe('NAICS industry codes to include'),
|
|
23
|
+
time_period_start: z
|
|
24
|
+
.string()
|
|
25
|
+
.optional()
|
|
26
|
+
.describe('Start of time period in ISO 8601 format (YYYY-MM-DD)'),
|
|
27
|
+
time_period_end: z
|
|
28
|
+
.string()
|
|
29
|
+
.optional()
|
|
30
|
+
.describe('End of time period in ISO 8601 format (YYYY-MM-DD)'),
|
|
31
|
+
})
|
|
32
|
+
.optional()
|
|
33
|
+
.describe('Optional filters to scope the spending aggregation');
|
|
34
|
+
export const spendingByGeographyTool = tool('usaspending_spending_by_geography', {
|
|
35
|
+
title: 'Spending by Geography',
|
|
36
|
+
description: 'Aggregate federal spending by state, county, or congressional district. Useful for per-capita analysis, regional comparisons, and mapping federal investment patterns. Geographic filters accept FIPS codes and 2-letter state abbreviations — NOT place names. Resolve place names to FIPS codes using a geocoding server (Census or OpenStreetMap) before applying location filters. Chain per-capita results with Census population data for meaningful comparisons.',
|
|
37
|
+
annotations: { readOnlyHint: true, openWorldHint: true, idempotentHint: true },
|
|
38
|
+
input: z.object({
|
|
39
|
+
scope: z
|
|
40
|
+
.enum(['place_of_performance', 'recipient_location'])
|
|
41
|
+
.describe('Which location to aggregate by: place_of_performance (where work is done) or recipient_location (where the recipient is based)'),
|
|
42
|
+
geo_layer: z
|
|
43
|
+
.enum(['state', 'county', 'district'])
|
|
44
|
+
.describe('Geographic granularity: state (50 states), county (county-level), or district (congressional district)'),
|
|
45
|
+
filters: SpendingFiltersSchema,
|
|
46
|
+
subawards: z
|
|
47
|
+
.boolean()
|
|
48
|
+
.default(false)
|
|
49
|
+
.describe('Include subaward data instead of prime award data'),
|
|
50
|
+
}),
|
|
51
|
+
output: z.object({
|
|
52
|
+
scope: z.string().describe('Location scope used for aggregation'),
|
|
53
|
+
geo_layer: z.string().describe('Geographic granularity used'),
|
|
54
|
+
results: z
|
|
55
|
+
.array(z
|
|
56
|
+
.object({
|
|
57
|
+
shape_code: z
|
|
58
|
+
.string()
|
|
59
|
+
.optional()
|
|
60
|
+
.describe('Geographic identifier (FIPS state code, county FIPS, or district code)'),
|
|
61
|
+
display_name: z
|
|
62
|
+
.string()
|
|
63
|
+
.optional()
|
|
64
|
+
.describe('Human-readable name for the geographic area'),
|
|
65
|
+
aggregated_amount: z
|
|
66
|
+
.number()
|
|
67
|
+
.optional()
|
|
68
|
+
.describe('Total obligation amount in USD for this geographic area'),
|
|
69
|
+
population: z
|
|
70
|
+
.number()
|
|
71
|
+
.optional()
|
|
72
|
+
.describe('Population of the geographic area (when available)'),
|
|
73
|
+
per_capita: z
|
|
74
|
+
.number()
|
|
75
|
+
.optional()
|
|
76
|
+
.describe('Per-capita obligation amount in USD (aggregated_amount / population)'),
|
|
77
|
+
award_count: z.number().optional().describe('Number of awards in this area'),
|
|
78
|
+
})
|
|
79
|
+
.describe('Geographic area with spending totals and optional per-capita data'))
|
|
80
|
+
.describe('Spending totals by geographic area'),
|
|
81
|
+
total: z.number().describe('Number of geographic areas returned'),
|
|
82
|
+
}),
|
|
83
|
+
errors: [
|
|
84
|
+
{
|
|
85
|
+
reason: 'no_data',
|
|
86
|
+
code: JsonRpcErrorCode.NotFound,
|
|
87
|
+
when: 'No spending data matched the filters for the selected geography.',
|
|
88
|
+
recovery: 'Broaden filters, try a different scope or geo_layer, or widen the time period.',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
reason: 'api_unavailable',
|
|
92
|
+
code: JsonRpcErrorCode.ServiceUnavailable,
|
|
93
|
+
when: 'USAspending.gov API is unreachable or returns an error.',
|
|
94
|
+
retryable: true,
|
|
95
|
+
recovery: 'The API may be temporarily down. Retry the request after a few seconds.',
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
async handler(input, ctx) {
|
|
99
|
+
ctx.log.info('usaspending_spending_by_geography', {
|
|
100
|
+
scope: input.scope,
|
|
101
|
+
geo_layer: input.geo_layer,
|
|
102
|
+
});
|
|
103
|
+
const svc = getUSASpendingService();
|
|
104
|
+
const filters = buildFilters(input.filters);
|
|
105
|
+
const data = await svc.spendingByGeography({
|
|
106
|
+
scope: input.scope,
|
|
107
|
+
geo_layer: input.geo_layer,
|
|
108
|
+
filters,
|
|
109
|
+
subawards: input.subawards,
|
|
110
|
+
}, ctx);
|
|
111
|
+
const results = (data.results ?? []).map((r) => ({
|
|
112
|
+
...(r.shape_code ? { shape_code: r.shape_code } : {}),
|
|
113
|
+
...(r.display_name ? { display_name: r.display_name } : {}),
|
|
114
|
+
...(typeof r.aggregated_amount === 'number'
|
|
115
|
+
? { aggregated_amount: r.aggregated_amount }
|
|
116
|
+
: {}),
|
|
117
|
+
...(typeof r.population === 'number' ? { population: r.population } : {}),
|
|
118
|
+
...(typeof r.per_capita === 'number' ? { per_capita: r.per_capita } : {}),
|
|
119
|
+
...(typeof r.award_count === 'number' ? { award_count: r.award_count } : {}),
|
|
120
|
+
}));
|
|
121
|
+
if (results.length === 0) {
|
|
122
|
+
throw ctx.fail('no_data', 'No spending data matched the filters for the selected geography', {
|
|
123
|
+
recovery: {
|
|
124
|
+
hint: 'Try broader filters, a different scope (place_of_performance vs recipient_location), or remove the time period constraint.',
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
scope: input.scope,
|
|
130
|
+
geo_layer: input.geo_layer,
|
|
131
|
+
results,
|
|
132
|
+
total: results.length,
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
format: (result) => {
|
|
136
|
+
const lines = [
|
|
137
|
+
`## Federal Spending by Geography`,
|
|
138
|
+
`**Scope:** ${result.scope} | **Layer:** ${result.geo_layer} | **Areas:** ${result.total}`,
|
|
139
|
+
'',
|
|
140
|
+
'| Area | Code | Obligation | Population | Per Capita | Awards |',
|
|
141
|
+
'|:-----|:-----|:-----------|:-----------|:-----------|:-------|',
|
|
142
|
+
];
|
|
143
|
+
for (const r of result.results) {
|
|
144
|
+
const amt = r.aggregated_amount !== undefined ? `$${r.aggregated_amount.toLocaleString()}` : 'N/A';
|
|
145
|
+
const pop = r.population !== undefined ? r.population.toLocaleString() : 'N/A';
|
|
146
|
+
const perCap = r.per_capita !== undefined ? `$${r.per_capita.toLocaleString()}` : 'N/A';
|
|
147
|
+
const awards = r.award_count !== undefined ? String(r.award_count) : 'N/A';
|
|
148
|
+
lines.push(`| ${r.display_name ?? 'N/A'} | ${r.shape_code ?? 'N/A'} | ${amt} | ${pop} | ${perCap} | ${awards} |`);
|
|
149
|
+
}
|
|
150
|
+
return [{ type: 'text', text: lines.join('\n') }];
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
//# sourceMappingURL=spending-by-geography.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spending-by-geography.tool.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/spending-by-geography.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAC;AACtF,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,wDAAwD;AACxD,MAAM,qBAAqB,GAAG,CAAC;KAC5B,MAAM,CAAC;IACN,QAAQ,EAAE,CAAC;SACR,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;SACjB,QAAQ,EAAE;SACV,QAAQ,CAAC,6DAA6D,CAAC;IAC1E,gBAAgB,EAAE,CAAC;SAChB,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;SACjB,QAAQ,EAAE;SACV,QAAQ,CACP,+FAA+F,CAChG;IACH,WAAW,E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