@pipeworx/mcp-stooq 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-stooq
2
+
3
+ Stooq market-quotes MCP.
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 697+ 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
+ "stooq": {
20
+ "url": "https://gateway.pipeworx.io/stooq/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or connect to the full Pipeworx gateway for access to all 697+ 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 Stooq 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-stooq",
3
+ "version": "0.1.0",
4
+ "description": "Stooq market-quotes MCP.",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "stooq"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-stooq"
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/stooq",
4
+ "title": "Stooq",
5
+ "description": "Stooq market-quotes MCP.",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/stooq",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-stooq",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/stooq/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,206 @@
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
+ * Stooq market-quotes MCP.
21
+ *
22
+ * Keyless. Pulls free, real-time-ish stock, index, forex and commodity quotes from
23
+ * stooq.com's public CSV endpoint and parses the CSV into clean JSON.
24
+ *
25
+ * Stooq is a free community data source — no API key, but also NO SLA: it can be slow,
26
+ * rate-limit, or briefly return no data. Treat it as best-effort.
27
+ *
28
+ * Symbol conventions (use symbol_guide for the full list):
29
+ * - US stocks: lowercase ticker + ".us" e.g. aapl.us, msft.us, brk-b.us
30
+ * - Indices: "^" prefix e.g. ^spx (S&P 500), ^dji (Dow), ^ndq (Nasdaq)
31
+ * - Forex: 6-letter pair, no separator e.g. eurusd, gbpusd, usdjpy
32
+ * - Crypto: pair vs fiat e.g. btcusd, ethusd
33
+ * - Futures: root + ".f" e.g. gc.f (gold), cl.f (crude oil), si.f (silver)
34
+ * - Non-US equities use country suffixes too (e.g. .uk, .de, .jp).
35
+ *
36
+ * Implementation notes:
37
+ * - Only the latest-quote endpoint (/q/l/) is keyless. Stooq's historical CSV endpoint
38
+ * (/q/d/l/) now requires an apikey + captcha, so this pack does not offer history.
39
+ * - Multiple symbols MUST be joined with "+" on the wire (comma yields a malformed row);
40
+ * callers may pass an array or a comma/space/plus-separated string — we normalize.
41
+ * - Unknown/invalid symbols come back as a row of "N/D" values; those are filtered into
42
+ * a `notFound` list rather than emitted as bogus quotes.
43
+ */
44
+
45
+
46
+ const BASE = 'https://stooq.com/q/l/';
47
+ const UA = 'pipeworx-mcp-stooq/1.0 (+https://pipeworx.io)';
48
+
49
+ /** Field spec: Symbol, Date, Time, OHLC, Volume — plus header row (h). */
50
+ const FIELDS = 'sd2t2ohlcv';
51
+
52
+ const SYMBOL_EXAMPLES = [
53
+ { kind: 'US stock', example: 'aapl.us', note: 'lowercase ticker + ".us" suffix' },
54
+ { kind: 'index', example: '^spx', note: '"^" prefix; also ^dji (Dow), ^ndq (Nasdaq Composite)' },
55
+ { kind: 'forex pair', example: 'eurusd', note: '6-letter pair, no separator; e.g. gbpusd, usdjpy' },
56
+ { kind: 'crypto', example: 'btcusd', note: 'pair vs fiat; e.g. ethusd' },
57
+ { kind: 'futures', example: 'gc.f', note: 'root + ".f"; e.g. cl.f (crude), si.f (silver)' },
58
+ { kind: 'non-US equity', example: 'vod.uk', note: 'country suffix (.uk, .de, .jp, ...)' },
59
+ ];
60
+
61
+ const tools: McpToolExport['tools'] = [
62
+ {
63
+ name: 'quote',
64
+ description:
65
+ 'Latest market quote (OHLCV + date/time) for one or more symbols from Stooq, a free community data ' +
66
+ 'source (no key, no SLA — best-effort, may rate-limit). Parsed from Stooq CSV into clean JSON. ' +
67
+ 'Covers US stocks (aapl.us), indices (^spx, ^dji, ^ndq), forex pairs (eurusd), crypto (btcusd), ' +
68
+ 'and futures (gc.f, cl.f). See symbol_guide for conventions. Unknown symbols are returned in a ' +
69
+ 'separate notFound list. Volume is often empty for forex/futures.',
70
+ inputSchema: {
71
+ type: 'object',
72
+ properties: {
73
+ symbols: {
74
+ description:
75
+ 'One or more Stooq symbols. Accepts an array ["aapl.us","^spx"] or a comma/space/plus-separated ' +
76
+ 'string ("aapl.us, msft.us"). US stocks use ".us"; indices use "^"; forex like "eurusd"; futures like "gc.f".',
77
+ oneOf: [{ type: 'string' }, { type: 'array', items: { type: 'string' } }],
78
+ },
79
+ },
80
+ required: ['symbols'],
81
+ },
82
+ },
83
+ {
84
+ name: 'symbol_guide',
85
+ description:
86
+ 'Explain Stooq symbol conventions (US ".us", indices "^", forex pairs, crypto, futures ".f") with ' +
87
+ 'worked examples, so you can construct the right symbol before calling quote.',
88
+ inputSchema: { type: 'object', properties: {} },
89
+ },
90
+ ];
91
+
92
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
93
+ switch (name) {
94
+ case 'symbol_guide':
95
+ return {
96
+ source: 'Stooq (stooq.com) — free community market data, keyless, no SLA.',
97
+ conventions: SYMBOL_EXAMPLES,
98
+ note: 'Symbols are case-insensitive. Pass multiple symbols to quote at once. ' +
99
+ 'Historical/daily data requires a Stooq apikey and is not available through this pack.',
100
+ };
101
+
102
+ case 'quote': {
103
+ const symbols = parseSymbols(args.symbols);
104
+ if (symbols.length === 0) {
105
+ throw new Error('Required argument "symbols" is missing. Pass e.g. "aapl.us" or ["aapl.us","^spx"].');
106
+ }
107
+ // Stooq requires "+" between symbols on the wire; comma yields a malformed single row.
108
+ const s = symbols.join('+');
109
+ const url = `${BASE}?s=${encodeURIComponent(s)}&f=${FIELDS}&h&e=csv`;
110
+ const res = await fetch(url, { headers: { Accept: 'text/csv', 'User-Agent': UA } });
111
+ const body = await res.text();
112
+ if (!res.ok) throw new Error(`Stooq: ${res.status} ${body.slice(0, 200)}`);
113
+ return parseQuotes(body);
114
+ }
115
+
116
+ default:
117
+ throw new Error(`Unknown tool: ${name}`);
118
+ }
119
+ }
120
+
121
+ interface Quote {
122
+ symbol: string;
123
+ date: string | null;
124
+ time: string | null;
125
+ open: number | null;
126
+ high: number | null;
127
+ low: number | null;
128
+ close: number | null;
129
+ volume: number | null;
130
+ }
131
+
132
+ /**
133
+ * Stooq /q/l/ CSV with f=sd2t2ohlcv&h (verified):
134
+ * Symbol,Date,Time,Open,High,Low,Close,Volume
135
+ * AAPL.US,2026-06-02,20:59:27,307.46,315.45,306.72,314.69,21713232
136
+ * Unknown symbols return a row whose fields are all "N/D".
137
+ * Volume can be empty (forex/futures) — emitted as null.
138
+ */
139
+ function parseQuotes(csv: string): { quotes: Quote[]; notFound: string[] } {
140
+ const lines = csv.split(/\r?\n/).filter((l) => l.trim().length > 0);
141
+ const quotes: Quote[] = [];
142
+ const notFound: string[] = [];
143
+ // Drop the header row if present.
144
+ const start = lines.length > 0 && /^symbol\b/i.test(lines[0]) ? 1 : 0;
145
+
146
+ for (let i = start; i < lines.length; i++) {
147
+ const cells = splitCsvLine(lines[i]);
148
+ if (cells.length < 2) continue;
149
+ const symbol = cells[0];
150
+ // No-data row: Date is "N/D".
151
+ if ((cells[1] ?? '').toUpperCase() === 'N/D') {
152
+ notFound.push(symbol);
153
+ continue;
154
+ }
155
+ quotes.push({
156
+ symbol,
157
+ date: cell(cells[1]),
158
+ time: cell(cells[2]),
159
+ open: num(cells[3]),
160
+ high: num(cells[4]),
161
+ low: num(cells[5]),
162
+ close: num(cells[6]),
163
+ volume: num(cells[7]),
164
+ });
165
+ }
166
+ return { quotes, notFound };
167
+ }
168
+
169
+ function splitCsvLine(line: string): string[] {
170
+ // Stooq quote rows contain no embedded commas/quotes; a simple split is safe.
171
+ return line.split(',').map((s) => s.trim());
172
+ }
173
+
174
+ /** Empty or "N/D" -> null; otherwise the trimmed string. */
175
+ function cell(raw: string | undefined): string | null {
176
+ const v = (raw ?? '').trim();
177
+ if (v === '' || v.toUpperCase() === 'N/D') return null;
178
+ return v;
179
+ }
180
+
181
+ /** Parse a numeric cell; empty / "N/D" / non-numeric -> null. */
182
+ function num(raw: string | undefined): number | null {
183
+ const v = cell(raw);
184
+ if (v === null) return null;
185
+ const n = Number(v);
186
+ return Number.isFinite(n) ? n : null;
187
+ }
188
+
189
+ /** Accept an array or a comma/space/plus-separated string of symbols; lowercase, dedupe. */
190
+ function parseSymbols(v: unknown): string[] {
191
+ let parts: string[];
192
+ if (Array.isArray(v)) parts = v.map((x) => String(x));
193
+ else if (typeof v === 'string') parts = v.split(/[\s,+]+/);
194
+ else return [];
195
+ const out: string[] = [];
196
+ const seen = new Set<string>();
197
+ for (const p of parts) {
198
+ const s = p.trim().toLowerCase();
199
+ if (!s || seen.has(s)) continue;
200
+ seen.add(s);
201
+ out.push(s);
202
+ }
203
+ return out;
204
+ }
205
+
206
+ 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
+ }