@pipeworx/mcp-open-fec 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pipeworx
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # mcp-open-fec
2
+
3
+ OpenFEC MCP — Federal Election Commission campaign finance data
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 965+ live data sources.
6
+
7
+ ## Tools
8
+
9
+ | Tool | Description |
10
+ |------|-------------|
11
+
12
+ ## Quick Start
13
+
14
+ Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
15
+
16
+ ```json
17
+ {
18
+ "mcpServers": {
19
+ "open-fec": {
20
+ "url": "https://gateway.pipeworx.io/open-fec/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or connect to the full Pipeworx gateway for access to all 965+ data sources:
27
+
28
+ ```json
29
+ {
30
+ "mcpServers": {
31
+ "pipeworx": {
32
+ "url": "https://gateway.pipeworx.io/mcp"
33
+ }
34
+ }
35
+ }
36
+ ```
37
+
38
+ ## Using with ask_pipeworx
39
+
40
+ Instead of calling tools directly, you can ask questions in plain English:
41
+
42
+ ```
43
+ ask_pipeworx({ question: "your question about Open Fec data" })
44
+ ```
45
+
46
+ The gateway picks the right tool and fills the arguments automatically.
47
+
48
+ ## More
49
+
50
+ - [All tools and guides](https://github.com/pipeworx-io/examples)
51
+ - [pipeworx.io](https://pipeworx.io)
52
+
53
+ ## License
54
+
55
+ MIT
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@pipeworx/mcp-open-fec",
3
+ "version": "0.1.0",
4
+ "description": "OpenFEC MCP — Federal Election Commission campaign finance data",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "open-fec"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-open-fec"
13
+ },
14
+ "scripts": {
15
+ "typecheck": "tsc --noEmit"
16
+ },
17
+ "devDependencies": {
18
+ "typescript": "^5.7.0"
19
+ }
20
+ }
package/server.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.pipeworx-io/open-fec",
4
+ "title": "Open Fec",
5
+ "description": "OpenFEC MCP — Federal Election Commission campaign finance data",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/open-fec",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-open-fec",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/open-fec/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,403 @@
1
+ interface McpToolDefinition {
2
+ name: string;
3
+ description: string;
4
+ inputSchema: {
5
+ type: 'object';
6
+ properties: Record<string, unknown>;
7
+ required?: string[];
8
+ };
9
+ }
10
+
11
+ interface McpToolExport {
12
+ tools: McpToolDefinition[];
13
+ callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
14
+ meter?: { credits: number };
15
+ cost?: Record<string, unknown>;
16
+ provider?: string;
17
+ }
18
+
19
+ /**
20
+ * OpenFEC MCP — Federal Election Commission campaign finance data
21
+ *
22
+ * BYO key: requires a free API key from https://api.open.fec.gov/developers/
23
+ * Passed via _apiKey parameter. Rate limit: 1,000 requests/hour.
24
+ *
25
+ * Tools:
26
+ * - search_candidates: search federal election candidates
27
+ * - candidate_financials: get financial summary for a candidate
28
+ * - search_committees: search political committees (PACs, party committees, etc.)
29
+ * - committee_financials: get financial summary for a committee/PAC
30
+ * - search_contributions: itemized individual contributions ("follow the money")
31
+ */
32
+
33
+
34
+ const BASE = 'https://api.open.fec.gov/v1';
35
+
36
+ // ── Helpers ───────────────────────────────────────────────────────────
37
+
38
+ function extractKey(args: Record<string, unknown>): string {
39
+ const key = args._apiKey as string;
40
+ delete args._apiKey;
41
+ if (!key) throw new Error('OpenFEC API key required. Get one free at https://api.open.fec.gov/developers/ and pass via _apiKey.');
42
+ return key;
43
+ }
44
+
45
+ async function fecGet(apiKey: string, path: string, params: Record<string, string>): Promise<unknown> {
46
+ const url = new URL(`${BASE}${path}`);
47
+ for (const [k, v] of Object.entries(params)) {
48
+ url.searchParams.set(k, v);
49
+ }
50
+ url.searchParams.set('api_key', apiKey);
51
+
52
+ const res = await fetch(url.toString(), {
53
+ headers: { Accept: 'application/json' },
54
+ });
55
+ if (!res.ok) {
56
+ const text = await res.text();
57
+ throw new Error(`OpenFEC API error (${res.status}): ${text}`);
58
+ }
59
+ return res.json();
60
+ }
61
+
62
+ // ── Types ─────────────────────────────────────────────────────────────
63
+
64
+ type FECCandidate = {
65
+ candidate_id?: string | null;
66
+ name?: string | null;
67
+ party_full?: string | null;
68
+ party?: string | null;
69
+ state?: string | null;
70
+ district?: string | null;
71
+ office_full?: string | null;
72
+ office?: string | null;
73
+ incumbent_challenge_full?: string | null;
74
+ candidate_status?: string | null;
75
+ election_years?: number[] | null;
76
+ cycles?: number[] | null;
77
+ has_raised_funds?: boolean | null;
78
+ federal_funds_flag?: boolean | null;
79
+ };
80
+
81
+ type FECFinancials = {
82
+ candidate_id?: string | null;
83
+ candidate_name?: string | null;
84
+ cycle?: number | null;
85
+ coverage_start_date?: string | null;
86
+ coverage_end_date?: string | null;
87
+ total_receipts?: number | null;
88
+ total_disbursements?: number | null;
89
+ cash_on_hand_end_period?: number | null;
90
+ debts_owed_by_committee?: number | null;
91
+ total_individual_contributions?: number | null;
92
+ total_contributions?: number | null;
93
+ other_political_committee_contributions?: number | null;
94
+ candidate_contribution?: number | null;
95
+ total_loans?: number | null;
96
+ operating_expenditures?: number | null;
97
+ };
98
+
99
+ type FECCommittee = {
100
+ committee_id?: string | null;
101
+ name?: string | null;
102
+ committee_type_full?: string | null;
103
+ committee_type?: string | null;
104
+ designation_full?: string | null;
105
+ party_full?: string | null;
106
+ state?: string | null;
107
+ treasurer_name?: string | null;
108
+ organization_type_full?: string | null;
109
+ filing_frequency?: string | null;
110
+ cycles?: number[] | null;
111
+ candidate_ids?: string[] | null;
112
+ sponsor_candidate_ids?: string[] | null;
113
+ };
114
+
115
+ type FECResponse<T> = {
116
+ pagination?: { count?: number; pages?: number; per_page?: number; page?: number };
117
+ results: T[];
118
+ };
119
+
120
+ function formatCandidate(c: FECCandidate) {
121
+ return {
122
+ candidate_id: c.candidate_id ?? null,
123
+ name: c.name ?? null,
124
+ party: c.party_full ?? c.party ?? null,
125
+ state: c.state ?? null,
126
+ district: c.district ?? null,
127
+ office: c.office_full ?? c.office ?? null,
128
+ incumbent_challenge: c.incumbent_challenge_full ?? null,
129
+ status: c.candidate_status ?? null,
130
+ election_years: c.election_years ?? [],
131
+ has_raised_funds: c.has_raised_funds ?? null,
132
+ };
133
+ }
134
+
135
+ function formatFinancials(f: FECFinancials) {
136
+ return {
137
+ candidate_id: f.candidate_id ?? null,
138
+ candidate_name: f.candidate_name ?? null,
139
+ cycle: f.cycle ?? null,
140
+ coverage_start: f.coverage_start_date ?? null,
141
+ coverage_end: f.coverage_end_date ?? null,
142
+ total_receipts: f.total_receipts ?? null,
143
+ total_disbursements: f.total_disbursements ?? null,
144
+ cash_on_hand: f.cash_on_hand_end_period ?? null,
145
+ debts_owed: f.debts_owed_by_committee ?? null,
146
+ individual_contributions: f.total_individual_contributions ?? null,
147
+ total_contributions: f.total_contributions ?? null,
148
+ pac_contributions: f.other_political_committee_contributions ?? null,
149
+ candidate_contribution: f.candidate_contribution ?? null,
150
+ total_loans: f.total_loans ?? null,
151
+ operating_expenditures: f.operating_expenditures ?? null,
152
+ };
153
+ }
154
+
155
+ function formatCommittee(c: FECCommittee) {
156
+ return {
157
+ committee_id: c.committee_id ?? null,
158
+ name: c.name ?? null,
159
+ type: c.committee_type_full ?? c.committee_type ?? null,
160
+ designation: c.designation_full ?? null,
161
+ party: c.party_full ?? null,
162
+ state: c.state ?? null,
163
+ treasurer: c.treasurer_name ?? null,
164
+ organization_type: c.organization_type_full ?? null,
165
+ filing_frequency: c.filing_frequency ?? null,
166
+ cycles: c.cycles ?? [],
167
+ candidate_ids: c.candidate_ids ?? [],
168
+ };
169
+ }
170
+
171
+ // ── Tool definitions ──────────────────────────────────────────────────
172
+
173
+ const tools: McpToolExport['tools'] = [
174
+ {
175
+ name: 'search_candidates',
176
+ description:
177
+ 'Search federal election candidates by name, state, or party. Returns candidate ID, name, party, office, state, district, and election years. Example: search_candidates("Biden", state="DE", party="DEM")',
178
+ inputSchema: {
179
+ type: 'object' as const,
180
+ properties: {
181
+ _apiKey: { type: 'string', description: 'OpenFEC API key' },
182
+ query: { type: 'string', description: 'Candidate name to search (e.g., "Sanders")' },
183
+ state: { type: 'string', description: 'Two-letter state code (e.g., "CA", "NY")' },
184
+ party: { type: 'string', description: 'Party code: "DEM", "REP", "LIB", "GRE", etc.' },
185
+ },
186
+ required: ['_apiKey', 'query'],
187
+ },
188
+ },
189
+ {
190
+ name: 'candidate_financials',
191
+ description:
192
+ 'Get campaign finance summary for a candidate by their FEC candidate ID (e.g., "P80001571"). Returns total receipts, disbursements, cash on hand, individual contributions, PAC contributions, and loans. Use search_candidates first to find the candidate ID.',
193
+ inputSchema: {
194
+ type: 'object' as const,
195
+ properties: {
196
+ _apiKey: { type: 'string', description: 'OpenFEC API key' },
197
+ candidate_id: { type: 'string', description: 'FEC candidate ID (e.g., "P80001571")' },
198
+ cycle: { type: 'number', description: 'Election cycle year (e.g., 2024). Defaults to most recent.' },
199
+ },
200
+ required: ['_apiKey', 'candidate_id'],
201
+ },
202
+ },
203
+ {
204
+ name: 'search_committees',
205
+ description:
206
+ 'Search political committees (PACs, Super PACs, party committees) by name. Returns committee ID, name, type, designation, party, treasurer, and associated candidates. Example: search_committees("ActBlue")',
207
+ inputSchema: {
208
+ type: 'object' as const,
209
+ properties: {
210
+ _apiKey: { type: 'string', description: 'OpenFEC API key' },
211
+ query: { type: 'string', description: 'Committee name to search (e.g., "Americans for Prosperity")' },
212
+ },
213
+ required: ['_apiKey', 'query'],
214
+ },
215
+ },
216
+ {
217
+ name: 'committee_financials',
218
+ description:
219
+ 'Get campaign-finance totals for a committee / PAC by its FEC committee ID (e.g., "C00401224"). Returns receipts, disbursements, cash on hand, and independent expenditures by cycle. Use search_committees first to find the committee ID.',
220
+ inputSchema: {
221
+ type: 'object' as const,
222
+ properties: {
223
+ _apiKey: { type: 'string', description: 'OpenFEC API key' },
224
+ committee_id: { type: 'string', description: 'FEC committee ID (e.g., "C00401224")' },
225
+ cycle: { type: 'number', description: 'Election cycle year (e.g., 2024). Defaults to most recent.' },
226
+ },
227
+ required: ['_apiKey', 'committee_id'],
228
+ },
229
+ },
230
+ {
231
+ name: 'search_contributions',
232
+ description:
233
+ 'Search itemized individual contributions ("follow the money") — who donated, how much, employer/occupation, city/state, and date. Filter by recipient committee, donor name, employer, state, minimum amount, and cycle. PREFER for "who donated to <committee>", "<person>\'s political donations", "donations from <employer> employees". Requires at least one of committee_id or contributor_name.',
234
+ inputSchema: {
235
+ type: 'object' as const,
236
+ properties: {
237
+ _apiKey: { type: 'string', description: 'OpenFEC API key' },
238
+ committee_id: { type: 'string', description: 'Recipient committee ID (from search_committees).' },
239
+ contributor_name: { type: 'string', description: 'Donor name to search (e.g. "Musk").' },
240
+ contributor_employer: { type: 'string', description: 'Donor employer filter (e.g. "Google").' },
241
+ state: { type: 'string', description: 'Two-letter donor state (e.g. "CA").' },
242
+ min_amount: { type: 'number', description: 'Minimum contribution amount in USD.' },
243
+ cycle: { type: 'number', description: 'Two-year transaction period / cycle (even year, e.g. 2024).' },
244
+ },
245
+ required: ['_apiKey'],
246
+ },
247
+ },
248
+ ];
249
+
250
+ // ── callTool dispatcher ───────────────────────────────────────────────
251
+
252
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
253
+ const key = extractKey(args);
254
+
255
+ switch (name) {
256
+ case 'search_candidates':
257
+ return searchCandidates(key, args);
258
+ case 'candidate_financials':
259
+ return candidateFinancials(key, args);
260
+ case 'search_committees':
261
+ return searchCommittees(key, args.query as string);
262
+ case 'committee_financials':
263
+ return committeeFinancials(key, args);
264
+ case 'search_contributions':
265
+ return searchContributions(key, args);
266
+ default:
267
+ throw new Error(`Unknown tool: ${name}`);
268
+ }
269
+ }
270
+
271
+ // ── Tool implementations ─────────────────────────────────────────────
272
+
273
+ async function searchCandidates(apiKey: string, args: Record<string, unknown>) {
274
+ const params: Record<string, string> = {
275
+ q: args.query as string,
276
+ per_page: '20',
277
+ sort: '-election_years',
278
+ };
279
+ if (args.state) params.state = args.state as string;
280
+ if (args.party) params.party = args.party as string;
281
+
282
+ const data = (await fecGet(apiKey, '/candidates/search/', params)) as FECResponse<FECCandidate>;
283
+
284
+ return {
285
+ total: data.pagination?.count ?? data.results.length,
286
+ returned: data.results.length,
287
+ candidates: data.results.map(formatCandidate),
288
+ };
289
+ }
290
+
291
+ async function candidateFinancials(apiKey: string, args: Record<string, unknown>) {
292
+ const candidateId = args.candidate_id as string;
293
+ const params: Record<string, string> = {
294
+ per_page: '5',
295
+ sort: '-cycle',
296
+ };
297
+ if (args.cycle) params.cycle = String(args.cycle);
298
+
299
+ const data = (await fecGet(apiKey, `/candidate/${candidateId}/totals/`, params)) as FECResponse<FECFinancials>;
300
+
301
+ if (data.results.length === 0) {
302
+ throw new Error(`No financial data found for candidate ${candidateId}`);
303
+ }
304
+
305
+ return {
306
+ candidate_id: candidateId,
307
+ cycles: data.results.map(formatFinancials),
308
+ };
309
+ }
310
+
311
+ async function searchCommittees(apiKey: string, query: string) {
312
+ const params: Record<string, string> = {
313
+ q: query,
314
+ per_page: '20',
315
+ };
316
+
317
+ const data = (await fecGet(apiKey, '/committees/', params)) as FECResponse<FECCommittee>;
318
+
319
+ return {
320
+ query,
321
+ total: data.pagination?.count ?? data.results.length,
322
+ returned: data.results.length,
323
+ committees: data.results.map(formatCommittee),
324
+ };
325
+ }
326
+
327
+ type FECCommitteeTotals = {
328
+ cycle?: number | null;
329
+ receipts?: number | null;
330
+ disbursements?: number | null;
331
+ last_cash_on_hand_end_period?: number | null;
332
+ independent_expenditures?: number | null;
333
+ contributions?: number | null;
334
+ contribution_refunds?: number | null;
335
+ };
336
+
337
+ async function committeeFinancials(apiKey: string, args: Record<string, unknown>) {
338
+ const committeeId = String(args.committee_id ?? '').trim();
339
+ if (!committeeId) throw new Error('committee_id is required (use search_committees to find it).');
340
+ const params: Record<string, string> = { per_page: '5', sort: '-cycle' };
341
+ if (args.cycle) params.cycle = String(args.cycle);
342
+
343
+ const data = (await fecGet(apiKey, `/committee/${encodeURIComponent(committeeId)}/totals/`, params)) as FECResponse<FECCommitteeTotals>;
344
+ if (data.results.length === 0) {
345
+ throw new Error(`No financial data found for committee ${committeeId}`);
346
+ }
347
+ return {
348
+ committee_id: committeeId,
349
+ cycles: data.results.map((r) => ({
350
+ cycle: r.cycle ?? null,
351
+ receipts: r.receipts ?? null,
352
+ disbursements: r.disbursements ?? null,
353
+ cash_on_hand: r.last_cash_on_hand_end_period ?? null,
354
+ contributions: r.contributions ?? null,
355
+ independent_expenditures: r.independent_expenditures ?? null,
356
+ })),
357
+ };
358
+ }
359
+
360
+ type FECContribution = {
361
+ contributor_name?: string | null;
362
+ contribution_receipt_amount?: number | null;
363
+ contribution_receipt_date?: string | null;
364
+ contributor_employer?: string | null;
365
+ contributor_occupation?: string | null;
366
+ contributor_city?: string | null;
367
+ contributor_state?: string | null;
368
+ committee_name?: string | null;
369
+ committee?: { name?: string | null } | null;
370
+ };
371
+
372
+ async function searchContributions(apiKey: string, args: Record<string, unknown>) {
373
+ const committeeId = String(args.committee_id ?? '').trim();
374
+ const contributorName = String(args.contributor_name ?? '').trim();
375
+ if (!committeeId && !contributorName) {
376
+ throw new Error('Provide at least one of "committee_id" or "contributor_name".');
377
+ }
378
+ const params: Record<string, string> = { per_page: '20', sort: '-contribution_receipt_amount' };
379
+ if (committeeId) params.committee_id = committeeId;
380
+ if (contributorName) params.contributor_name = contributorName;
381
+ if (args.contributor_employer) params.contributor_employer = String(args.contributor_employer);
382
+ if (args.state) params.contributor_state = String(args.state).toUpperCase();
383
+ if (args.min_amount) params.min_amount = String(args.min_amount);
384
+ if (args.cycle) params.two_year_transaction_period = String(args.cycle);
385
+
386
+ const data = (await fecGet(apiKey, '/schedules/schedule_a/', params)) as FECResponse<FECContribution>;
387
+ return {
388
+ total: data.pagination?.count ?? data.results.length,
389
+ returned: data.results.length,
390
+ contributions: data.results.map((c) => ({
391
+ contributor: c.contributor_name ?? null,
392
+ amount: c.contribution_receipt_amount ?? null,
393
+ date: c.contribution_receipt_date ?? null,
394
+ employer: c.contributor_employer ?? null,
395
+ occupation: c.contributor_occupation ?? null,
396
+ city: c.contributor_city ?? null,
397
+ state: c.contributor_state ?? null,
398
+ recipient: c.committee_name ?? c.committee?.name ?? null,
399
+ })),
400
+ };
401
+ }
402
+
403
+ export default { tools, callTool, meter: { credits: 5 } } satisfies McpToolExport;
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "outDir": "dist",
10
+ "rootDir": "src",
11
+ "declaration": true
12
+ },
13
+ "include": ["src"]
14
+ }