@pipeworx/mcp-market-recap 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-market-recap
2
+
3
+ Market Recap MCP — a one-call 'what happened in markets' snapshot.
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 1225+ 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
+ "market-recap": {
20
+ "url": "https://gateway.pipeworx.io/market-recap/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or connect to the full Pipeworx gateway for access to all 1225+ 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 Market Recap 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-market-recap",
3
+ "version": "0.1.0",
4
+ "description": "Market Recap MCP — a one-call 'what happened in markets' snapshot.",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "market-recap"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-market-recap"
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/market-recap",
4
+ "title": "Market Recap",
5
+ "description": "Market Recap MCP — a one-call 'what happened in markets' snapshot.",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/market-recap",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-market-recap",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/market-recap/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,274 @@
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
+ * Market Recap MCP — a one-call "what happened in markets" snapshot.
21
+ *
22
+ * Serves the recurring demand for an overnight / session market pulse
23
+ * ("what happened in Asia-Pacific / US markets overnight"). Rather than
24
+ * synthesize a narrative server-side, it returns a STRUCTURED, region-grouped
25
+ * snapshot — major indices, rates, FX, commodities, crypto with price + daily
26
+ * % change — so the calling agent writes the recap itself from live numbers.
27
+ *
28
+ * Source: Yahoo Finance v7 spark endpoint (keyless, batches up to 20 symbols
29
+ * per call; the full basket is fetched in ≤2 chunked calls). No API key.
30
+ *
31
+ * Tool: market_snapshot({ region? })
32
+ */
33
+
34
+
35
+ const SPARK = 'https://query1.finance.yahoo.com/v7/finance/spark';
36
+ const UA = 'Mozilla/5.0 (compatible; pipeworx-mcp/1.0; +https://pipeworx.io)';
37
+ const SPARK_MAX = 20; // Yahoo caps spark at 20 symbols/call
38
+
39
+ interface Instrument { symbol: string; name: string }
40
+ interface GroupDef { key: string; label: string; items: Instrument[] }
41
+
42
+ const GROUPS: GroupDef[] = [
43
+ {
44
+ key: 'asia', label: 'Asia-Pacific',
45
+ items: [
46
+ { symbol: '^N225', name: 'Nikkei 225 (Japan)' },
47
+ { symbol: '^HSI', name: 'Hang Seng (Hong Kong)' },
48
+ { symbol: '000001.SS', name: 'Shanghai Composite (China)' },
49
+ { symbol: '^KS11', name: 'KOSPI (South Korea)' },
50
+ { symbol: '^AXJO', name: 'ASX 200 (Australia)' },
51
+ { symbol: '^BSESN', name: 'BSE Sensex (India)' },
52
+ ],
53
+ },
54
+ {
55
+ key: 'europe', label: 'Europe',
56
+ items: [
57
+ { symbol: '^FTSE', name: 'FTSE 100 (UK)' },
58
+ { symbol: '^GDAXI', name: 'DAX (Germany)' },
59
+ { symbol: '^FCHI', name: 'CAC 40 (France)' },
60
+ { symbol: '^STOXX50E', name: 'Euro Stoxx 50' },
61
+ ],
62
+ },
63
+ {
64
+ key: 'us', label: 'United States',
65
+ items: [
66
+ { symbol: '^GSPC', name: 'S&P 500' },
67
+ { symbol: '^IXIC', name: 'Nasdaq Composite' },
68
+ { symbol: '^DJI', name: 'Dow Jones Industrial' },
69
+ { symbol: '^RUT', name: 'Russell 2000' },
70
+ { symbol: 'ES=F', name: 'S&P 500 Futures' },
71
+ ],
72
+ },
73
+ {
74
+ key: 'rates', label: 'US Treasury Yields',
75
+ items: [
76
+ { symbol: '^IRX', name: 'US 13-Week Yield' },
77
+ { symbol: '^FVX', name: 'US 5-Year Yield' },
78
+ { symbol: '^TNX', name: 'US 10-Year Yield' },
79
+ { symbol: '^TYX', name: 'US 30-Year Yield' },
80
+ ],
81
+ },
82
+ {
83
+ key: 'fx', label: 'Foreign Exchange',
84
+ items: [
85
+ { symbol: 'DX-Y.NYB', name: 'US Dollar Index (DXY)' },
86
+ { symbol: 'EURUSD=X', name: 'EUR/USD' },
87
+ { symbol: 'USDJPY=X', name: 'USD/JPY' },
88
+ { symbol: 'GBPUSD=X', name: 'GBP/USD' },
89
+ { symbol: 'USDCNY=X', name: 'USD/CNY' },
90
+ ],
91
+ },
92
+ {
93
+ key: 'commodities', label: 'Commodities',
94
+ items: [
95
+ { symbol: 'CL=F', name: 'WTI Crude Oil' },
96
+ { symbol: 'BZ=F', name: 'Brent Crude Oil' },
97
+ { symbol: 'GC=F', name: 'Gold' },
98
+ { symbol: 'SI=F', name: 'Silver' },
99
+ { symbol: 'NG=F', name: 'Natural Gas' },
100
+ { symbol: 'HG=F', name: 'Copper' },
101
+ ],
102
+ },
103
+ {
104
+ key: 'crypto', label: 'Crypto',
105
+ items: [
106
+ { symbol: 'BTC-USD', name: 'Bitcoin' },
107
+ { symbol: 'ETH-USD', name: 'Ethereum' },
108
+ { symbol: 'SOL-USD', name: 'Solana' },
109
+ ],
110
+ },
111
+ ];
112
+
113
+ // Curated cross-region "overnight recap" set — the default. One spark call.
114
+ const HEADLINE_SYMBOLS = [
115
+ '^N225', '^HSI', '000001.SS', '^FTSE', '^GDAXI',
116
+ 'ES=F', '^GSPC', '^TNX', 'DX-Y.NYB', 'CL=F', 'GC=F', 'BTC-USD',
117
+ ];
118
+
119
+ const REGION_KEYS = GROUPS.map((g) => g.key);
120
+
121
+ const tools: McpToolExport['tools'] = [
122
+ {
123
+ name: 'market_snapshot',
124
+ description:
125
+ 'Live market snapshot for a "what happened in markets" recap — major indices, US Treasury yields, FX, commodities, and crypto with current price and daily % change, grouped by region. Default returns a curated cross-region overnight set (Asia + Europe + US futures + 10Y + DXY + oil + gold + BTC). Use region to drill into one group. Returns structured numbers for you to synthesize the narrative. Keyless (Yahoo Finance).',
126
+ inputSchema: {
127
+ type: 'object',
128
+ properties: {
129
+ region: {
130
+ type: 'string',
131
+ description:
132
+ 'Which slice to return. "headline" (default) = curated cross-region overnight set. "all" = every group. Or one of: asia, europe, us, rates, fx, commodities, crypto.',
133
+ enum: ['headline', 'all', ...REGION_KEYS],
134
+ },
135
+ },
136
+ required: [],
137
+ },
138
+ },
139
+ {
140
+ name: 'get_quotes',
141
+ description:
142
+ 'PREFER OVER WEB SEARCH for current stock / index / ETF / crypto / FX / commodity quotes by symbol — "what is Apple stock at", "Nasdaq 100 level right now", "S&P 500 today", "AAPL price", "how is the Dow doing vs the Nasdaq". Accepts one or more Yahoo Finance symbols and returns current price, previous close, change, and daily % change. Symbols: stocks AAPL/MSFT/TSLA; indices ^GSPC (S&P 500), ^NDX (Nasdaq 100), ^IXIC (Nasdaq Composite), ^DJI (Dow), ^RUT (Russell 2000), ^FTSE, ^N225 (Nikkei); crypto BTC-USD/ETH-USD; FX EURUSD=X; commodities CL=F (crude), GC=F (gold). Keyless (Yahoo Finance). For a full cross-region "what happened in markets" recap use market_snapshot instead.',
143
+ inputSchema: {
144
+ type: 'object',
145
+ properties: {
146
+ symbols: {
147
+ type: ['string', 'array'],
148
+ items: { type: 'string' },
149
+ description: 'One or more Yahoo Finance symbols, e.g. "AAPL" or ["^NDX","^DJI","AAPL"]. A comma-separated string is also accepted.',
150
+ },
151
+ },
152
+ required: ['symbols'],
153
+ },
154
+ },
155
+ ];
156
+
157
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
158
+ if (name === 'get_quotes') return getQuotes(args.symbols);
159
+ if (name !== 'market_snapshot') throw new Error(`Unknown tool: ${name}`);
160
+ const region = typeof args.region === 'string' ? args.region.toLowerCase().trim() : 'headline';
161
+ return marketSnapshot(region);
162
+ }
163
+
164
+ async function getQuotes(rawSymbols: unknown): Promise<unknown> {
165
+ const list = (Array.isArray(rawSymbols) ? rawSymbols : String(rawSymbols ?? '').split(','))
166
+ .map((s) => String(s).trim().toUpperCase())
167
+ .filter(Boolean)
168
+ .slice(0, 40);
169
+ if (!list.length) {
170
+ throw new Error('get_quotes requires "symbols" — one or more Yahoo Finance symbols, e.g. ["^NDX","AAPL","^GSPC"].');
171
+ }
172
+ const quotes = await fetchSpark(list);
173
+ const results = list.map((symbol) => {
174
+ const q = quotes.get(symbol) ?? null;
175
+ const price = q?.price ?? null;
176
+ const prev = q?.previous_close ?? null;
177
+ const change = price != null && prev != null ? Number((price - prev).toFixed(4)) : null;
178
+ const change_pct = price != null && prev ? Number((((price - prev) / prev) * 100).toFixed(2)) : null;
179
+ return { symbol, price, previous_close: prev, change, change_pct, found: q != null && price != null };
180
+ });
181
+ return { requested: list.length, found: results.filter((r) => r.found).length, quotes: results };
182
+ }
183
+
184
+ interface Quote { price: number | null; previous_close: number | null }
185
+
186
+ async function fetchSpark(symbols: string[]): Promise<Map<string, Quote>> {
187
+ const out = new Map<string, Quote>();
188
+ // chunk into ≤20 per call, fetch chunks in parallel
189
+ const chunks: string[][] = [];
190
+ for (let i = 0; i < symbols.length; i += SPARK_MAX) chunks.push(symbols.slice(i, i + SPARK_MAX));
191
+
192
+ const results = await Promise.allSettled(
193
+ chunks.map(async (chunk) => {
194
+ const url = `${SPARK}?symbols=${chunk.map(encodeURIComponent).join(',')}&range=1d&interval=1d`;
195
+ const controller = new AbortController();
196
+ const t = setTimeout(() => controller.abort(), 10000);
197
+ try {
198
+ const res = await fetch(url, { headers: { 'User-Agent': UA, Accept: 'application/json' }, signal: controller.signal });
199
+ if (!res.ok) throw new Error(`Yahoo spark HTTP ${res.status}`);
200
+ const j = (await res.json()) as {
201
+ spark?: { result?: { symbol?: string; response?: { meta?: { symbol?: string; regularMarketPrice?: number; chartPreviousClose?: number; previousClose?: number } }[] }[] };
202
+ };
203
+ for (const r of j.spark?.result ?? []) {
204
+ const meta = r.response?.[0]?.meta;
205
+ const sym = meta?.symbol ?? r.symbol;
206
+ if (!sym) continue;
207
+ out.set(sym, {
208
+ price: meta?.regularMarketPrice ?? null,
209
+ previous_close: meta?.chartPreviousClose ?? meta?.previousClose ?? null,
210
+ });
211
+ }
212
+ } finally {
213
+ clearTimeout(t);
214
+ }
215
+ }),
216
+ );
217
+ if (results.length > 0 && results.every((r) => r.status === 'rejected')) {
218
+ const first = results.find((r) => r.status === 'rejected') as PromiseRejectedResult | undefined;
219
+ throw new Error(`upstream_down: Yahoo Finance unreachable — ${first?.reason instanceof Error ? first.reason.message : 'all requests failed'}`);
220
+ }
221
+ return out;
222
+ }
223
+
224
+ function selectGroups(region: string): GroupDef[] {
225
+ if (region === 'all') return GROUPS;
226
+ if (region === 'headline' || region === '') {
227
+ const bySym = new Map(GROUPS.flatMap((g) => g.items).map((i) => [i.symbol, i]));
228
+ return [{
229
+ key: 'headline', label: 'Market Snapshot (overnight)',
230
+ items: HEADLINE_SYMBOLS.map((s) => bySym.get(s)).filter((i): i is Instrument => !!i),
231
+ }];
232
+ }
233
+ const g = GROUPS.find((x) => x.key === region);
234
+ if (!g) throw new Error(`Unknown region "${region}". Use one of: headline, all, ${REGION_KEYS.join(', ')}.`);
235
+ return [g];
236
+ }
237
+
238
+ function round(n: number, dp: number): number {
239
+ const f = 10 ** dp;
240
+ return Math.round(n * f) / f;
241
+ }
242
+
243
+ async function marketSnapshot(region: string) {
244
+ const groups = selectGroups(region);
245
+ const symbols = [...new Set(groups.flatMap((g) => g.items.map((i) => i.symbol)))];
246
+ const quotes = await fetchSpark(symbols);
247
+
248
+ const grouped = groups.map((g) => {
249
+ const instruments = g.items.map((i) => {
250
+ const q = quotes.get(i.symbol);
251
+ const price = q?.price ?? null;
252
+ const prev = q?.previous_close ?? null;
253
+ const change = price != null && prev != null ? round(price - prev, 4) : null;
254
+ const change_pct = price != null && prev != null && prev !== 0 ? round(((price - prev) / prev) * 100, 2) : null;
255
+ return { symbol: i.symbol, name: i.name, price, previous_close: prev, change, change_pct };
256
+ });
257
+ const moves = instruments.filter((x) => x.change_pct != null);
258
+ const up = moves.filter((x) => (x.change_pct as number) > 0).length;
259
+ const down = moves.filter((x) => (x.change_pct as number) < 0).length;
260
+ return { region: g.label, key: g.key, advancers: up, decliners: down, instruments };
261
+ });
262
+
263
+ const missing = groups.flatMap((g) => g.items).filter((i) => !quotes.get(i.symbol)?.price).map((i) => i.symbol);
264
+
265
+ return {
266
+ as_of: new Date().toISOString(),
267
+ region,
268
+ note: 'Prices are the latest available from Yahoo Finance; change is vs the previous close. Yields (^TNX etc.) are in percent; FX pairs are exchange rates; futures (ES=F, CL=F…) trade nearly 24h. Synthesize the recap from these numbers.',
269
+ groups: grouped,
270
+ ...(missing.length ? { unavailable_symbols: missing } : {}),
271
+ };
272
+ }
273
+
274
+ export default { tools, callTool, meter: { credits: 1 } } 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
+ }