@cliwant/mcp-sam-gov 0.2.1 → 0.3.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.
- package/README.md +55 -5
- package/dist/cache.d.ts +40 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +60 -0
- package/dist/cache.js.map +1 -0
- package/dist/ecfr.d.ts.map +1 -1
- package/dist/ecfr.js +18 -16
- package/dist/ecfr.js.map +1 -1
- package/dist/errors.d.ts +76 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +179 -0
- package/dist/errors.js.map +1 -0
- package/dist/federal-register.d.ts.map +1 -1
- package/dist/federal-register.js +17 -16
- package/dist/federal-register.js.map +1 -1
- package/dist/grants.d.ts.map +1 -1
- package/dist/grants.js +3 -5
- package/dist/grants.js.map +1 -1
- package/dist/server.js +14 -5
- package/dist/server.js.map +1 -1
- package/dist/usaspending.d.ts.map +1 -1
- package/dist/usaspending.js +95 -87
- package/dist/usaspending.js.map +1 -1
- package/package.json +1 -1
- package/src/cache.ts +68 -0
- package/src/ecfr.ts +134 -127
- package/src/errors.ts +220 -0
- package/src/federal-register.ts +197 -191
- package/src/grants.ts +158 -155
- package/src/server.ts +14 -5
- package/src/usaspending.ts +948 -925
package/src/federal-register.ts
CHANGED
|
@@ -1,191 +1,197 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Federal Register API v1 wrappers (keyless, no registration).
|
|
3
|
-
*
|
|
4
|
-
* Federal Register is the daily journal of the US federal government —
|
|
5
|
-
* proposed rules, final rules, presidential documents, public notices.
|
|
6
|
-
* Critical context for any federal contracting question that touches
|
|
7
|
-
* regulation, set-aside policy, or new acquisition guidance.
|
|
8
|
-
*
|
|
9
|
-
* Endpoints:
|
|
10
|
-
* - documents.json — search across documents (filters: agencies,
|
|
11
|
-
* conditions, type, date range)
|
|
12
|
-
* - documents/{number}.json — single document detail (full body URL,
|
|
13
|
-
* abstract, citation, effective date)
|
|
14
|
-
* - agencies.json — agency reference list
|
|
15
|
-
*
|
|
16
|
-
* All endpoints are public + keyless (no API key, no registration).
|
|
17
|
-
* Rate-limit: documented as ~1000 req/hour per IP (informal).
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
| "
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Federal Register API v1 wrappers (keyless, no registration).
|
|
3
|
+
*
|
|
4
|
+
* Federal Register is the daily journal of the US federal government —
|
|
5
|
+
* proposed rules, final rules, presidential documents, public notices.
|
|
6
|
+
* Critical context for any federal contracting question that touches
|
|
7
|
+
* regulation, set-aside policy, or new acquisition guidance.
|
|
8
|
+
*
|
|
9
|
+
* Endpoints:
|
|
10
|
+
* - documents.json — search across documents (filters: agencies,
|
|
11
|
+
* conditions, type, date range)
|
|
12
|
+
* - documents/{number}.json — single document detail (full body URL,
|
|
13
|
+
* abstract, citation, effective date)
|
|
14
|
+
* - agencies.json — agency reference list
|
|
15
|
+
*
|
|
16
|
+
* All endpoints are public + keyless (no API key, no registration).
|
|
17
|
+
* Rate-limit: documented as ~1000 req/hour per IP (informal).
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { fetchWithRetry } from "./errors.js";
|
|
21
|
+
import { memoize } from "./cache.js";
|
|
22
|
+
|
|
23
|
+
const FED_REG = "https://www.federalregister.gov/api/v1";
|
|
24
|
+
|
|
25
|
+
async function fetchJson<T>(url: string): Promise<T> {
|
|
26
|
+
const r = await fetchWithRetry(
|
|
27
|
+
url,
|
|
28
|
+
{
|
|
29
|
+
headers: { Accept: "application/json" },
|
|
30
|
+
signal: AbortSignal.timeout(15_000),
|
|
31
|
+
},
|
|
32
|
+
`federal-register:${url.split("/api/v1/")[1] ?? url}`,
|
|
33
|
+
);
|
|
34
|
+
return (await r.json()) as T;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type FedRegDocumentType =
|
|
38
|
+
| "RULE"
|
|
39
|
+
| "PRORULE"
|
|
40
|
+
| "NOTICE"
|
|
41
|
+
| "PRESDOCU"
|
|
42
|
+
| "UNKNOWN";
|
|
43
|
+
|
|
44
|
+
const TYPE_MAP: Record<string, FedRegDocumentType> = {
|
|
45
|
+
Rule: "RULE",
|
|
46
|
+
"Proposed Rule": "PRORULE",
|
|
47
|
+
Notice: "NOTICE",
|
|
48
|
+
"Presidential Document": "PRESDOCU",
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export async function searchDocuments(args: {
|
|
52
|
+
query?: string;
|
|
53
|
+
agencySlugs?: string[]; // e.g. ["veterans-affairs-department", "defense-department"]
|
|
54
|
+
type?: "RULE" | "PRORULE" | "NOTICE" | "PRESDOCU";
|
|
55
|
+
publicationDateFrom?: string; // YYYY-MM-DD
|
|
56
|
+
publicationDateTo?: string;
|
|
57
|
+
effectiveDateFrom?: string;
|
|
58
|
+
perPage?: number;
|
|
59
|
+
}) {
|
|
60
|
+
const url = new URL(`${FED_REG}/documents.json`);
|
|
61
|
+
url.searchParams.set("per_page", String(args.perPage ?? 10));
|
|
62
|
+
if (args.query) {
|
|
63
|
+
url.searchParams.set("conditions[term]", args.query);
|
|
64
|
+
}
|
|
65
|
+
for (const slug of args.agencySlugs ?? []) {
|
|
66
|
+
url.searchParams.append("conditions[agencies][]", slug);
|
|
67
|
+
}
|
|
68
|
+
if (args.type) {
|
|
69
|
+
url.searchParams.append("conditions[type][]", args.type);
|
|
70
|
+
}
|
|
71
|
+
if (args.publicationDateFrom) {
|
|
72
|
+
url.searchParams.set(
|
|
73
|
+
"conditions[publication_date][gte]",
|
|
74
|
+
args.publicationDateFrom,
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
if (args.publicationDateTo) {
|
|
78
|
+
url.searchParams.set(
|
|
79
|
+
"conditions[publication_date][lte]",
|
|
80
|
+
args.publicationDateTo,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
if (args.effectiveDateFrom) {
|
|
84
|
+
url.searchParams.set(
|
|
85
|
+
"conditions[effective_date][gte]",
|
|
86
|
+
args.effectiveDateFrom,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
type Resp = {
|
|
91
|
+
count?: number;
|
|
92
|
+
total_pages?: number;
|
|
93
|
+
results?: {
|
|
94
|
+
title?: string;
|
|
95
|
+
type?: string;
|
|
96
|
+
abstract?: string;
|
|
97
|
+
document_number?: string;
|
|
98
|
+
html_url?: string;
|
|
99
|
+
pdf_url?: string;
|
|
100
|
+
publication_date?: string;
|
|
101
|
+
effective_on?: string;
|
|
102
|
+
agencies?: { name?: string; slug?: string }[];
|
|
103
|
+
}[];
|
|
104
|
+
};
|
|
105
|
+
const json = await fetchJson<Resp>(url.toString());
|
|
106
|
+
return {
|
|
107
|
+
totalRecords: json.count ?? 0,
|
|
108
|
+
totalPages: json.total_pages ?? 0,
|
|
109
|
+
documents: (json.results ?? []).map((d) => ({
|
|
110
|
+
documentNumber: d.document_number ?? "",
|
|
111
|
+
title: d.title ?? "",
|
|
112
|
+
type: TYPE_MAP[d.type ?? ""] ?? "UNKNOWN",
|
|
113
|
+
typeDisplay: d.type ?? "",
|
|
114
|
+
abstract: d.abstract ?? "",
|
|
115
|
+
htmlUrl: d.html_url ?? "",
|
|
116
|
+
pdfUrl: d.pdf_url,
|
|
117
|
+
publicationDate: d.publication_date ?? "",
|
|
118
|
+
effectiveDate: d.effective_on,
|
|
119
|
+
agencies: (d.agencies ?? []).map((a) => ({
|
|
120
|
+
name: a.name ?? "",
|
|
121
|
+
slug: a.slug ?? "",
|
|
122
|
+
})),
|
|
123
|
+
})),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export async function getDocument(documentNumber: string) {
|
|
128
|
+
type Resp = {
|
|
129
|
+
title?: string;
|
|
130
|
+
type?: string;
|
|
131
|
+
abstract?: string;
|
|
132
|
+
document_number?: string;
|
|
133
|
+
html_url?: string;
|
|
134
|
+
pdf_url?: string;
|
|
135
|
+
body_html_url?: string;
|
|
136
|
+
publication_date?: string;
|
|
137
|
+
effective_on?: string;
|
|
138
|
+
citation?: string;
|
|
139
|
+
page_length?: number;
|
|
140
|
+
raw_text_url?: string;
|
|
141
|
+
agencies?: { name?: string; slug?: string }[];
|
|
142
|
+
cfr_references?: { title?: string; part?: string; chapter?: string }[];
|
|
143
|
+
};
|
|
144
|
+
const json = await fetchJson<Resp>(
|
|
145
|
+
`${FED_REG}/documents/${encodeURIComponent(documentNumber)}.json`,
|
|
146
|
+
);
|
|
147
|
+
return {
|
|
148
|
+
documentNumber: json.document_number ?? "",
|
|
149
|
+
title: json.title ?? "",
|
|
150
|
+
type: TYPE_MAP[json.type ?? ""] ?? "UNKNOWN",
|
|
151
|
+
typeDisplay: json.type ?? "",
|
|
152
|
+
abstract: json.abstract ?? "",
|
|
153
|
+
htmlUrl: json.html_url ?? "",
|
|
154
|
+
pdfUrl: json.pdf_url,
|
|
155
|
+
rawTextUrl: json.raw_text_url,
|
|
156
|
+
publicationDate: json.publication_date ?? "",
|
|
157
|
+
effectiveDate: json.effective_on,
|
|
158
|
+
citation: json.citation,
|
|
159
|
+
pageCount: json.page_length,
|
|
160
|
+
agencies: (json.agencies ?? []).map((a) => ({
|
|
161
|
+
name: a.name ?? "",
|
|
162
|
+
slug: a.slug ?? "",
|
|
163
|
+
})),
|
|
164
|
+
cfrReferences: (json.cfr_references ?? []).map((c) => ({
|
|
165
|
+
title: c.title ?? "",
|
|
166
|
+
part: c.part,
|
|
167
|
+
chapter: c.chapter,
|
|
168
|
+
})),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export async function listAgencies(args: { perPage?: number }) {
|
|
173
|
+
return memoize(`fedreg:agencies:${args.perPage ?? 100}`, async () => {
|
|
174
|
+
type Resp = Array<{
|
|
175
|
+
id?: number;
|
|
176
|
+
name?: string;
|
|
177
|
+
short_name?: string;
|
|
178
|
+
slug?: string;
|
|
179
|
+
description?: string;
|
|
180
|
+
parent_id?: number | null;
|
|
181
|
+
json_url?: string;
|
|
182
|
+
}>;
|
|
183
|
+
const json = await fetchJson<Resp>(
|
|
184
|
+
`${FED_REG}/agencies.json?per_page=${args.perPage ?? 100}`,
|
|
185
|
+
);
|
|
186
|
+
return {
|
|
187
|
+
agencies: (json ?? []).map((a) => ({
|
|
188
|
+
id: a.id ?? 0,
|
|
189
|
+
name: a.name ?? "",
|
|
190
|
+
shortName: a.short_name,
|
|
191
|
+
slug: a.slug ?? "",
|
|
192
|
+
description: a.description ?? "",
|
|
193
|
+
parentId: a.parent_id,
|
|
194
|
+
})),
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
}
|