@pipeworx/mcp-alphavantage 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,34 @@
1
+ # mcp-alphavantage
2
+
3
+ Alpha Vantage MCP — Stock market data, fundamentals, and earnings
4
+
5
+ Part of the [Pipeworx](https://pipeworx.io) open MCP gateway.
6
+
7
+ ## Tools
8
+
9
+ | Tool | Description |
10
+ |------|-------------|
11
+
12
+ ## Quick Start
13
+
14
+ Add to your MCP client config:
15
+
16
+ ```json
17
+ {
18
+ "mcpServers": {
19
+ "alphavantage": {
20
+ "url": "https://gateway.pipeworx.io/alphavantage/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or use the CLI:
27
+
28
+ ```bash
29
+ npx pipeworx use alphavantage
30
+ ```
31
+
32
+ ## License
33
+
34
+ MIT
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@pipeworx/mcp-alphavantage",
3
+ "version": "0.1.0",
4
+ "description": "Alpha Vantage MCP — Stock market data, fundamentals, and earnings",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "alphavantage"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-alphavantage"
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/alphavantage",
4
+ "title": "alphavantage",
5
+ "description": "Alpha Vantage MCP — Stock market data, fundamentals, and earnings",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/alphavantage",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-alphavantage",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/alphavantage/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,402 @@
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
+ }
15
+
16
+ /**
17
+ * Alpha Vantage MCP — Stock market data, fundamentals, and earnings
18
+ *
19
+ * BYO key: requires a free Alpha Vantage API key from https://www.alphavantage.co/support/#api-key
20
+ * Passed via _apiKey parameter. Free tier: 25 requests/day.
21
+ *
22
+ * Tools:
23
+ * - av_quote: get real-time stock quote
24
+ * - av_daily: get daily time series (price history)
25
+ * - av_overview: get company overview/fundamentals
26
+ * - av_income_statement: get income statement (annual + quarterly)
27
+ * - av_balance_sheet: get balance sheet (annual + quarterly)
28
+ * - av_earnings: get earnings data + EPS
29
+ */
30
+
31
+
32
+ const BASE = 'https://www.alphavantage.co/query';
33
+
34
+ // ── Helpers ───────────────────────────────────────────────────────────
35
+
36
+ function extractKey(args: Record<string, unknown>): string {
37
+ const key = args._apiKey as string;
38
+ delete args._apiKey;
39
+ if (!key) throw new Error('Alpha Vantage API key required. Get one free at https://www.alphavantage.co/support/#api-key and pass via _apiKey.');
40
+ return key;
41
+ }
42
+
43
+ async function avGet(apiKey: string, params: Record<string, string>): Promise<unknown> {
44
+ const url = new URL(BASE);
45
+ for (const [k, v] of Object.entries(params)) {
46
+ url.searchParams.set(k, v);
47
+ }
48
+ url.searchParams.set('apikey', apiKey);
49
+
50
+ const res = await fetch(url.toString(), {
51
+ headers: { Accept: 'application/json' },
52
+ });
53
+ if (!res.ok) {
54
+ const text = await res.text();
55
+ throw new Error(`Alpha Vantage API error (${res.status}): ${text}`);
56
+ }
57
+
58
+ const data = (await res.json()) as Record<string, unknown>;
59
+
60
+ // Alpha Vantage returns error messages in the response body
61
+ if (data['Error Message']) {
62
+ throw new Error(`Alpha Vantage error: ${data['Error Message']}`);
63
+ }
64
+ if (data['Note']) {
65
+ throw new Error(`Alpha Vantage rate limit: ${data['Note']}`);
66
+ }
67
+ if (data['Information']) {
68
+ throw new Error(`Alpha Vantage: ${data['Information']}`);
69
+ }
70
+
71
+ return data;
72
+ }
73
+
74
+ // ── Tool definitions ──────────────────────────────────────────────────
75
+
76
+ const tools: McpToolExport['tools'] = [
77
+ {
78
+ name: 'av_quote',
79
+ description:
80
+ 'Get a real-time stock quote including price, change, change percent, volume, and latest trading day.',
81
+ inputSchema: {
82
+ type: 'object' as const,
83
+ properties: {
84
+ _apiKey: { type: 'string', description: 'Alpha Vantage API key' },
85
+ symbol: {
86
+ type: 'string',
87
+ description: 'Stock ticker symbol (e.g., "SOFI", "AFRM", "SQ", "PYPL")',
88
+ },
89
+ },
90
+ required: ['_apiKey', 'symbol'],
91
+ },
92
+ },
93
+ {
94
+ name: 'av_daily',
95
+ description:
96
+ 'Get daily time series (open, high, low, close, volume) for a stock. Returns up to 100 recent trading days by default, or 20+ years of full history.',
97
+ inputSchema: {
98
+ type: 'object' as const,
99
+ properties: {
100
+ _apiKey: { type: 'string', description: 'Alpha Vantage API key' },
101
+ symbol: {
102
+ type: 'string',
103
+ description: 'Stock ticker symbol (e.g., "AAPL", "MSFT")',
104
+ },
105
+ outputsize: {
106
+ type: 'string',
107
+ description: '"compact" for last 100 data points (default), "full" for 20+ years of data',
108
+ },
109
+ },
110
+ required: ['_apiKey', 'symbol'],
111
+ },
112
+ },
113
+ {
114
+ name: 'av_overview',
115
+ description:
116
+ 'Get company overview and fundamentals including description, sector, market cap, P/E ratio, EPS, dividend yield, 52-week range, and more.',
117
+ inputSchema: {
118
+ type: 'object' as const,
119
+ properties: {
120
+ _apiKey: { type: 'string', description: 'Alpha Vantage API key' },
121
+ symbol: {
122
+ type: 'string',
123
+ description: 'Stock ticker symbol (e.g., "AAPL", "GOOGL")',
124
+ },
125
+ },
126
+ required: ['_apiKey', 'symbol'],
127
+ },
128
+ },
129
+ {
130
+ name: 'av_income_statement',
131
+ description:
132
+ 'Get income statement data for a company, including both annual and quarterly reports. Shows revenue, gross profit, operating income, net income, EBITDA, and more.',
133
+ inputSchema: {
134
+ type: 'object' as const,
135
+ properties: {
136
+ _apiKey: { type: 'string', description: 'Alpha Vantage API key' },
137
+ symbol: {
138
+ type: 'string',
139
+ description: 'Stock ticker symbol (e.g., "AAPL", "MSFT")',
140
+ },
141
+ },
142
+ required: ['_apiKey', 'symbol'],
143
+ },
144
+ },
145
+ {
146
+ name: 'av_balance_sheet',
147
+ description:
148
+ 'Get balance sheet data for a company, including both annual and quarterly reports. Shows total assets, liabilities, equity, cash, debt, and more.',
149
+ inputSchema: {
150
+ type: 'object' as const,
151
+ properties: {
152
+ _apiKey: { type: 'string', description: 'Alpha Vantage API key' },
153
+ symbol: {
154
+ type: 'string',
155
+ description: 'Stock ticker symbol (e.g., "AAPL", "TSLA")',
156
+ },
157
+ },
158
+ required: ['_apiKey', 'symbol'],
159
+ },
160
+ },
161
+ {
162
+ name: 'av_earnings',
163
+ description:
164
+ 'Get earnings data for a company, including annual and quarterly EPS (reported and estimated), surprise amount, and surprise percentage.',
165
+ inputSchema: {
166
+ type: 'object' as const,
167
+ properties: {
168
+ _apiKey: { type: 'string', description: 'Alpha Vantage API key' },
169
+ symbol: {
170
+ type: 'string',
171
+ description: 'Stock ticker symbol (e.g., "AAPL", "NVDA")',
172
+ },
173
+ },
174
+ required: ['_apiKey', 'symbol'],
175
+ },
176
+ },
177
+ ];
178
+
179
+ // ── callTool dispatcher ───────────────────────────────────────────────
180
+
181
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
182
+ const key = extractKey(args);
183
+
184
+ switch (name) {
185
+ case 'av_quote':
186
+ return getQuote(key, args.symbol as string);
187
+ case 'av_daily':
188
+ return getDaily(key, args.symbol as string, (args.outputsize as string) ?? 'compact');
189
+ case 'av_overview':
190
+ return getOverview(key, args.symbol as string);
191
+ case 'av_income_statement':
192
+ return getIncomeStatement(key, args.symbol as string);
193
+ case 'av_balance_sheet':
194
+ return getBalanceSheet(key, args.symbol as string);
195
+ case 'av_earnings':
196
+ return getEarnings(key, args.symbol as string);
197
+ default:
198
+ throw new Error(`Unknown tool: ${name}`);
199
+ }
200
+ }
201
+
202
+ // ── Tool implementations ─────────────────────────────────────────────
203
+
204
+ async function getQuote(apiKey: string, symbol: string) {
205
+ const data = (await avGet(apiKey, {
206
+ function: 'GLOBAL_QUOTE',
207
+ symbol,
208
+ })) as { 'Global Quote': Record<string, string> };
209
+
210
+ const q = data['Global Quote'];
211
+ if (!q || Object.keys(q).length === 0) {
212
+ throw new Error(`No quote data found for symbol: ${symbol}`);
213
+ }
214
+
215
+ return {
216
+ symbol: q['01. symbol'] ?? symbol,
217
+ open: q['02. open'] ?? null,
218
+ high: q['03. high'] ?? null,
219
+ low: q['04. low'] ?? null,
220
+ price: q['05. price'] ?? null,
221
+ volume: q['06. volume'] ?? null,
222
+ latest_trading_day: q['07. latest trading day'] ?? null,
223
+ previous_close: q['08. previous close'] ?? null,
224
+ change: q['09. change'] ?? null,
225
+ change_percent: q['10. change percent'] ?? null,
226
+ };
227
+ }
228
+
229
+ async function getDaily(apiKey: string, symbol: string, outputsize: string) {
230
+ const data = (await avGet(apiKey, {
231
+ function: 'TIME_SERIES_DAILY',
232
+ symbol,
233
+ outputsize,
234
+ })) as {
235
+ 'Meta Data': Record<string, string>;
236
+ 'Time Series (Daily)': Record<string, Record<string, string>>;
237
+ };
238
+
239
+ const meta = data['Meta Data'] ?? {};
240
+ const timeSeries = data['Time Series (Daily)'] ?? {};
241
+
242
+ const dates = Object.keys(timeSeries).sort().reverse();
243
+
244
+ return {
245
+ symbol: meta['2. Symbol'] ?? symbol,
246
+ last_refreshed: meta['3. Last Refreshed'] ?? null,
247
+ outputsize,
248
+ data_points: dates.length,
249
+ time_series: dates.map((date) => {
250
+ const day = timeSeries[date];
251
+ return {
252
+ date,
253
+ open: day['1. open'] ?? null,
254
+ high: day['2. high'] ?? null,
255
+ low: day['3. low'] ?? null,
256
+ close: day['4. close'] ?? null,
257
+ volume: day['5. volume'] ?? null,
258
+ };
259
+ }),
260
+ };
261
+ }
262
+
263
+ async function getOverview(apiKey: string, symbol: string) {
264
+ const data = (await avGet(apiKey, {
265
+ function: 'OVERVIEW',
266
+ symbol,
267
+ })) as Record<string, string>;
268
+
269
+ if (!data.Symbol && !data.Name) {
270
+ throw new Error(`No overview data found for symbol: ${symbol}`);
271
+ }
272
+
273
+ return {
274
+ symbol: data.Symbol ?? symbol,
275
+ name: data.Name ?? null,
276
+ description: data.Description ?? null,
277
+ exchange: data.Exchange ?? null,
278
+ currency: data.Currency ?? null,
279
+ country: data.Country ?? null,
280
+ sector: data.Sector ?? null,
281
+ industry: data.Industry ?? null,
282
+ market_cap: data.MarketCapitalization ?? null,
283
+ pe_ratio: data.PERatio ?? null,
284
+ peg_ratio: data.PEGRatio ?? null,
285
+ book_value: data.BookValue ?? null,
286
+ dividend_per_share: data.DividendPerShare ?? null,
287
+ dividend_yield: data.DividendYield ?? null,
288
+ eps: data.EPS ?? null,
289
+ revenue_per_share: data.RevenuePerShareTTM ?? null,
290
+ profit_margin: data.ProfitMargin ?? null,
291
+ operating_margin: data.OperatingMarginTTM ?? null,
292
+ return_on_assets: data.ReturnOnAssetsTTM ?? null,
293
+ return_on_equity: data.ReturnOnEquityTTM ?? null,
294
+ revenue_ttm: data.RevenueTTM ?? null,
295
+ gross_profit_ttm: data.GrossProfitTTM ?? null,
296
+ ebitda: data.EBITDA ?? null,
297
+ beta: data.Beta ?? null,
298
+ week_52_high: data['52WeekHigh'] ?? null,
299
+ week_52_low: data['52WeekLow'] ?? null,
300
+ moving_average_50: data['50DayMovingAverage'] ?? null,
301
+ moving_average_200: data['200DayMovingAverage'] ?? null,
302
+ shares_outstanding: data.SharesOutstanding ?? null,
303
+ fiscal_year_end: data.FiscalYearEnd ?? null,
304
+ latest_quarter: data.LatestQuarter ?? null,
305
+ };
306
+ }
307
+
308
+ async function getIncomeStatement(apiKey: string, symbol: string) {
309
+ const data = (await avGet(apiKey, {
310
+ function: 'INCOME_STATEMENT',
311
+ symbol,
312
+ })) as {
313
+ symbol: string;
314
+ annualReports: Record<string, string>[];
315
+ quarterlyReports: Record<string, string>[];
316
+ };
317
+
318
+ return {
319
+ symbol: data.symbol ?? symbol,
320
+ annual_reports: (data.annualReports ?? []).map(formatIncomeReport),
321
+ quarterly_reports: (data.quarterlyReports ?? []).slice(0, 8).map(formatIncomeReport),
322
+ };
323
+ }
324
+
325
+ function formatIncomeReport(r: Record<string, string>) {
326
+ return {
327
+ fiscal_date: r.fiscalDateEnding ?? null,
328
+ reported_currency: r.reportedCurrency ?? null,
329
+ total_revenue: r.totalRevenue ?? null,
330
+ cost_of_revenue: r.costOfRevenue ?? null,
331
+ gross_profit: r.grossProfit ?? null,
332
+ operating_expenses: r.operatingExpenses ?? null,
333
+ operating_income: r.operatingIncome ?? null,
334
+ net_income: r.netIncome ?? null,
335
+ ebitda: r.ebitda ?? null,
336
+ interest_expense: r.interestExpense ?? null,
337
+ income_tax_expense: r.incomeTaxExpense ?? null,
338
+ research_and_development: r.researchAndDevelopment ?? null,
339
+ };
340
+ }
341
+
342
+ async function getBalanceSheet(apiKey: string, symbol: string) {
343
+ const data = (await avGet(apiKey, {
344
+ function: 'BALANCE_SHEET',
345
+ symbol,
346
+ })) as {
347
+ symbol: string;
348
+ annualReports: Record<string, string>[];
349
+ quarterlyReports: Record<string, string>[];
350
+ };
351
+
352
+ return {
353
+ symbol: data.symbol ?? symbol,
354
+ annual_reports: (data.annualReports ?? []).map(formatBalanceReport),
355
+ quarterly_reports: (data.quarterlyReports ?? []).slice(0, 8).map(formatBalanceReport),
356
+ };
357
+ }
358
+
359
+ function formatBalanceReport(r: Record<string, string>) {
360
+ return {
361
+ fiscal_date: r.fiscalDateEnding ?? null,
362
+ reported_currency: r.reportedCurrency ?? null,
363
+ total_assets: r.totalAssets ?? null,
364
+ total_current_assets: r.totalCurrentAssets ?? null,
365
+ cash_and_equivalents: r.cashAndCashEquivalentsAtCarryingValue ?? null,
366
+ total_liabilities: r.totalLiabilities ?? null,
367
+ total_current_liabilities: r.totalCurrentLiabilities ?? null,
368
+ long_term_debt: r.longTermDebt ?? null,
369
+ total_shareholder_equity: r.totalShareholderEquity ?? null,
370
+ retained_earnings: r.retainedEarnings ?? null,
371
+ common_stock_shares_outstanding: r.commonStockSharesOutstanding ?? null,
372
+ };
373
+ }
374
+
375
+ async function getEarnings(apiKey: string, symbol: string) {
376
+ const data = (await avGet(apiKey, {
377
+ function: 'EARNINGS',
378
+ symbol,
379
+ })) as {
380
+ symbol: string;
381
+ annualEarnings: Record<string, string>[];
382
+ quarterlyEarnings: Record<string, string>[];
383
+ };
384
+
385
+ return {
386
+ symbol: data.symbol ?? symbol,
387
+ annual_earnings: (data.annualEarnings ?? []).map((r) => ({
388
+ fiscal_date: r.fiscalDateEnding ?? null,
389
+ reported_eps: r.reportedEPS ?? null,
390
+ })),
391
+ quarterly_earnings: (data.quarterlyEarnings ?? []).slice(0, 12).map((r) => ({
392
+ fiscal_date: r.fiscalDateEnding ?? null,
393
+ reported_date: r.reportedDate ?? null,
394
+ reported_eps: r.reportedEPS ?? null,
395
+ estimated_eps: r.estimatedEPS ?? null,
396
+ surprise: r.surprise ?? null,
397
+ surprise_percentage: r.surprisePercentage ?? null,
398
+ })),
399
+ };
400
+ }
401
+
402
+ export default { tools, callTool, meter: { credits: 10 }, provider: 'alphavantage' } 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
+ }