@pipeworx/mcp-econdata 1.0.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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +34 -0
  3. package/package.json +18 -0
  4. package/src/index.ts +295 -0
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,34 @@
1
+ # mcp-econdata
2
+
3
+ MCP server for US economic data (unemployment, CPI, employment) via the [Bureau of Labor Statistics API](https://api.bls.gov/publicAPI/v2/). No authentication required.
4
+
5
+ ## Tools
6
+
7
+ | Tool | Description |
8
+ |------|-------------|
9
+ | `get_series` | Fetch any BLS time series by series ID |
10
+ | `get_unemployment` | Get the US civilian unemployment rate over time |
11
+ | `get_cpi` | Get the US Consumer Price Index for All Urban Consumers |
12
+ | `get_employment_by_industry` | Get US non-farm payroll employment by industry |
13
+
14
+ ## Quickstart via Pipeworx Gateway
15
+
16
+ Call any tool through the hosted gateway with zero setup:
17
+
18
+ ```bash
19
+ curl -X POST https://gateway.pipeworx.io/mcp \
20
+ -H "Content-Type: application/json" \
21
+ -d '{
22
+ "jsonrpc": "2.0",
23
+ "id": 1,
24
+ "method": "tools/call",
25
+ "params": {
26
+ "name": "econdata_get_unemployment",
27
+ "arguments": { "start_year": "2023", "end_year": "2024" }
28
+ }
29
+ }'
30
+ ```
31
+
32
+ ## License
33
+
34
+ MIT
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@pipeworx/mcp-econdata",
3
+ "version": "1.0.0",
4
+ "description": "MCP server for US economic data (unemployment, CPI, employment) via Bureau of Labor Statistics API",
5
+ "main": "src/index.ts",
6
+ "types": "src/index.ts",
7
+ "files": ["src"],
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "typecheck": "tsc --noEmit"
11
+ },
12
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "econdata", "economics", "bls"],
13
+ "author": "Pipeworx <hello@pipeworx.io>",
14
+ "license": "MIT",
15
+ "devDependencies": {
16
+ "typescript": "^5.0.0"
17
+ }
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,295 @@
1
+ /**
2
+ * Econdata MCP — wraps BLS (Bureau of Labor Statistics) public API v2
3
+ * (https://api.bls.gov/publicAPI/v2/)
4
+ *
5
+ * Tools:
6
+ * - get_series: Fetch any BLS time series by ID
7
+ * - get_unemployment: US unemployment rate (series LNS14000000)
8
+ * - get_cpi: Consumer Price Index (series CUUR0000SA0)
9
+ * - get_employment_by_industry: Non-farm payroll employment by industry
10
+ */
11
+
12
+ interface McpToolDefinition {
13
+ name: string;
14
+ description: string;
15
+ inputSchema: {
16
+ type: 'object';
17
+ properties: Record<string, unknown>;
18
+ required?: string[];
19
+ };
20
+ }
21
+
22
+ interface McpToolExport {
23
+ tools: McpToolDefinition[];
24
+ callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
25
+ }
26
+
27
+ const BASE_URL = 'https://api.bls.gov/publicAPI/v2';
28
+
29
+ // --- Raw API types ---
30
+
31
+ type RawDataPoint = {
32
+ year: string;
33
+ period: string;
34
+ periodName: string;
35
+ value: string;
36
+ footnotes: unknown[];
37
+ };
38
+
39
+ type RawSeries = {
40
+ seriesID: string;
41
+ data: RawDataPoint[];
42
+ };
43
+
44
+ type RawBLSResponse = {
45
+ status: string;
46
+ responseTime: number;
47
+ message: string[];
48
+ Results?: {
49
+ series: RawSeries[];
50
+ };
51
+ };
52
+
53
+ // --- Tool definitions ---
54
+
55
+ const tools: McpToolExport['tools'] = [
56
+ {
57
+ name: 'get_series',
58
+ description:
59
+ 'Fetch a BLS time series by series ID. Returns data points with year, period, and value. Example series IDs: "CUUR0000SA0" (CPI), "LNS14000000" (unemployment rate), "CES0000000001" (total nonfarm employment).',
60
+ inputSchema: {
61
+ type: 'object' as const,
62
+ properties: {
63
+ series_id: {
64
+ type: 'string',
65
+ description: 'BLS series ID (e.g. "CUUR0000SA0" for CPI)',
66
+ },
67
+ start_year: {
68
+ type: 'string',
69
+ description: 'Start year as 4-digit string (e.g. "2020"). Optional.',
70
+ },
71
+ end_year: {
72
+ type: 'string',
73
+ description: 'End year as 4-digit string (e.g. "2024"). Optional.',
74
+ },
75
+ },
76
+ required: ['series_id'],
77
+ },
78
+ },
79
+ {
80
+ name: 'get_unemployment',
81
+ description:
82
+ 'Get the US civilian unemployment rate over time (BLS series LNS14000000). Returns year, month, and rate for each period.',
83
+ inputSchema: {
84
+ type: 'object' as const,
85
+ properties: {
86
+ start_year: {
87
+ type: 'string',
88
+ description: 'Start year as 4-digit string (e.g. "2020"). Optional.',
89
+ },
90
+ end_year: {
91
+ type: 'string',
92
+ description: 'End year as 4-digit string (e.g. "2024"). Optional.',
93
+ },
94
+ },
95
+ required: [],
96
+ },
97
+ },
98
+ {
99
+ name: 'get_cpi',
100
+ description:
101
+ 'Get the US Consumer Price Index for All Urban Consumers (BLS series CUUR0000SA0). Returns year, month, and index value for each period.',
102
+ inputSchema: {
103
+ type: 'object' as const,
104
+ properties: {
105
+ start_year: {
106
+ type: 'string',
107
+ description: 'Start year as 4-digit string (e.g. "2020"). Optional.',
108
+ },
109
+ end_year: {
110
+ type: 'string',
111
+ description: 'End year as 4-digit string (e.g. "2024"). Optional.',
112
+ },
113
+ },
114
+ required: [],
115
+ },
116
+ },
117
+ {
118
+ name: 'get_employment_by_industry',
119
+ description:
120
+ 'Get US non-farm payroll employment figures by industry. Industry options: "total_nonfarm" (default), "manufacturing", "construction", "retail", "financial", "government". Returns employment in thousands.',
121
+ inputSchema: {
122
+ type: 'object' as const,
123
+ properties: {
124
+ industry: {
125
+ type: 'string',
126
+ description:
127
+ 'Industry to retrieve. One of: "total_nonfarm", "manufacturing", "construction", "retail", "financial", "government". Defaults to "total_nonfarm".',
128
+ },
129
+ start_year: {
130
+ type: 'string',
131
+ description: 'Start year as 4-digit string (e.g. "2020"). Optional.',
132
+ },
133
+ end_year: {
134
+ type: 'string',
135
+ description: 'End year as 4-digit string (e.g. "2024"). Optional.',
136
+ },
137
+ },
138
+ required: [],
139
+ },
140
+ },
141
+ ];
142
+
143
+ // --- Industry series ID map ---
144
+
145
+ const INDUSTRY_SERIES: Record<string, string> = {
146
+ total_nonfarm: 'CES0000000001',
147
+ manufacturing: 'CES3000000001',
148
+ construction: 'CES2000000001',
149
+ retail: 'CES4200000001',
150
+ financial: 'CES5500000001',
151
+ government: 'CES9000000001',
152
+ };
153
+
154
+ // --- callTool dispatcher ---
155
+
156
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
157
+ switch (name) {
158
+ case 'get_series':
159
+ return getSeries(
160
+ args.series_id as string,
161
+ args.start_year as string | undefined,
162
+ args.end_year as string | undefined,
163
+ );
164
+ case 'get_unemployment':
165
+ return getUnemployment(
166
+ args.start_year as string | undefined,
167
+ args.end_year as string | undefined,
168
+ );
169
+ case 'get_cpi':
170
+ return getCpi(
171
+ args.start_year as string | undefined,
172
+ args.end_year as string | undefined,
173
+ );
174
+ case 'get_employment_by_industry':
175
+ return getEmploymentByIndustry(
176
+ (args.industry as string | undefined) ?? 'total_nonfarm',
177
+ args.start_year as string | undefined,
178
+ args.end_year as string | undefined,
179
+ );
180
+ default:
181
+ throw new Error(`Unknown tool: ${name}`);
182
+ }
183
+ }
184
+
185
+ // --- Shared fetch helper ---
186
+
187
+ async function fetchSeries(
188
+ seriesId: string,
189
+ startYear?: string,
190
+ endYear?: string,
191
+ ): Promise<RawDataPoint[]> {
192
+ const body: Record<string, unknown> = { seriesid: [seriesId] };
193
+ if (startYear) body.startyear = startYear;
194
+ if (endYear) body.endyear = endYear;
195
+
196
+ const res = await fetch(`${BASE_URL}/timeseries/data/`, {
197
+ method: 'POST',
198
+ headers: { 'Content-Type': 'application/json' },
199
+ body: JSON.stringify(body),
200
+ });
201
+ if (!res.ok) throw new Error(`BLS API error: ${res.status}`);
202
+
203
+ const data = (await res.json()) as RawBLSResponse;
204
+ if (data.status !== 'REQUEST_SUCCEEDED') {
205
+ throw new Error(`BLS API error: ${data.message?.join(', ') ?? data.status}`);
206
+ }
207
+
208
+ return data.Results?.series[0]?.data ?? [];
209
+ }
210
+
211
+ function formatDataPoint(point: RawDataPoint) {
212
+ return {
213
+ year: point.year,
214
+ period: point.period,
215
+ period_name: point.periodName,
216
+ value: Number(point.value),
217
+ };
218
+ }
219
+
220
+ // --- Tool implementations ---
221
+
222
+ async function getSeries(seriesId: string, startYear?: string, endYear?: string) {
223
+ const data = await fetchSeries(seriesId, startYear, endYear);
224
+ return {
225
+ series_id: seriesId,
226
+ start_year: startYear ?? null,
227
+ end_year: endYear ?? null,
228
+ total: data.length,
229
+ data: data.map(formatDataPoint),
230
+ };
231
+ }
232
+
233
+ async function getUnemployment(startYear?: string, endYear?: string) {
234
+ const seriesId = 'LNS14000000';
235
+ const data = await fetchSeries(seriesId, startYear, endYear);
236
+ return {
237
+ series_id: seriesId,
238
+ description: 'Civilian Unemployment Rate (seasonally adjusted)',
239
+ unit: 'percent',
240
+ start_year: startYear ?? null,
241
+ end_year: endYear ?? null,
242
+ total: data.length,
243
+ data: data.map((point) => ({
244
+ year: point.year,
245
+ month: point.periodName,
246
+ period: point.period,
247
+ rate: Number(point.value),
248
+ })),
249
+ };
250
+ }
251
+
252
+ async function getCpi(startYear?: string, endYear?: string) {
253
+ const seriesId = 'CUUR0000SA0';
254
+ const data = await fetchSeries(seriesId, startYear, endYear);
255
+ return {
256
+ series_id: seriesId,
257
+ description: 'CPI for All Urban Consumers (not seasonally adjusted)',
258
+ unit: 'index (1982-84=100)',
259
+ start_year: startYear ?? null,
260
+ end_year: endYear ?? null,
261
+ total: data.length,
262
+ data: data.map((point) => ({
263
+ year: point.year,
264
+ month: point.periodName,
265
+ period: point.period,
266
+ value: Number(point.value),
267
+ })),
268
+ };
269
+ }
270
+
271
+ async function getEmploymentByIndustry(
272
+ industry: string,
273
+ startYear?: string,
274
+ endYear?: string,
275
+ ) {
276
+ const seriesId = INDUSTRY_SERIES[industry] ?? INDUSTRY_SERIES['total_nonfarm'];
277
+ const data = await fetchSeries(seriesId, startYear, endYear);
278
+ return {
279
+ series_id: seriesId,
280
+ industry,
281
+ description: 'All Employees (seasonally adjusted)',
282
+ unit: 'thousands of persons',
283
+ start_year: startYear ?? null,
284
+ end_year: endYear ?? null,
285
+ total: data.length,
286
+ data: data.map((point) => ({
287
+ year: point.year,
288
+ month: point.periodName,
289
+ period: point.period,
290
+ employment_thousands: Number(point.value),
291
+ })),
292
+ };
293
+ }
294
+
295
+ export default { tools, callTool } satisfies McpToolExport;