@pipeworx/mcp-mic 0.1.0 → 0.2.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/README.md +17 -12
- package/bin/cli.js +55 -11
- package/lib/index.js +333 -0
- package/package.json +17 -16
- package/server.json +1 -1
- package/tools.json +56 -0
- package/src/index.ts +0 -261
- package/src/mic-index-data.ts +0 -2910
- package/src/server.ts +0 -49
- package/tsconfig.json +0 -18
package/src/index.ts
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
interface McpToolDefinition {
|
|
2
|
-
name: string;
|
|
3
|
-
description: string;
|
|
4
|
-
/** Human-facing one-liner (fleet #1967). Optional; consumers fall back to
|
|
5
|
-
* description. Kept in step with shared/src/types.ts — scripts/lib/
|
|
6
|
-
* check-inlined-types.mjs reports drift at publish time. */
|
|
7
|
-
summary?: string;
|
|
8
|
-
inputSchema: {
|
|
9
|
-
type: 'object';
|
|
10
|
-
properties: Record<string, unknown>;
|
|
11
|
-
required?: string[];
|
|
12
|
-
anyOf?: Array<{ required: string[] }>;
|
|
13
|
-
oneOf?: Array<{ required: string[] }>;
|
|
14
|
-
allOf?: Array<{ required: string[] }>;
|
|
15
|
-
};
|
|
16
|
-
outputSchema?: Record<string, unknown>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface McpToolExport {
|
|
20
|
-
tools: McpToolDefinition[];
|
|
21
|
-
callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
22
|
-
meter?: { credits: number };
|
|
23
|
-
cost?: Record<string, unknown>;
|
|
24
|
-
provider?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* MIC — ISO 10383 Market Identifier Code decoder (fleet #3261)
|
|
29
|
-
*
|
|
30
|
-
* Decodes the 4-character venue code openfigi returns as `exchCode` on a
|
|
31
|
-
* security's exchange listing (and that most market-data feeds use the same
|
|
32
|
-
* way) to the trading venue's own name, legal operator, country, city and
|
|
33
|
-
* status, per ANNA's Market Identifier Code registry — the Registration
|
|
34
|
-
* Authority for ISO 10383.
|
|
35
|
-
*
|
|
36
|
-
* SHAPE. ANNA publishes the registry as a downloadable file only (checked
|
|
37
|
-
* live 2026-10-17: the registry's own listing page links straight to the
|
|
38
|
-
* file; there is no query API, keyed or otherwise), so this pack answers
|
|
39
|
-
* from a baked table rather than a live per-call fetch — the same "local
|
|
40
|
-
* copy when live fails" shape as every other baked-index pack in this repo
|
|
41
|
-
* (mcps/south-dakota-code is the worked example). The table is uploaded to
|
|
42
|
-
* KV at deploy and injected by the gateway as `args._bakedIndex` on the
|
|
43
|
-
* first call into this pack — see ensureIndex() below and
|
|
44
|
-
* workers/gateway/src/pack-baked-indexes.json. Refresh path:
|
|
45
|
-
* scripts/bake-index.mjs, re-run on a schedule (ANNA updates the registry on
|
|
46
|
-
* an ongoing basis).
|
|
47
|
-
*
|
|
48
|
-
* Two MIC "kinds" (per ISO 10383 itself): an OPERATING MIC names the venue
|
|
49
|
-
* operator as a whole (e.g. "XNYS", the New York Stock Exchange); a SEGMENT
|
|
50
|
-
* MIC names one specific market/order book under that operator (e.g.
|
|
51
|
-
* "ARCX", NYSE Arca, operates under XNYS). decode_mic reports which kind a
|
|
52
|
-
* code is and, for an operating MIC, how many segments sit under it.
|
|
53
|
-
*
|
|
54
|
-
* Tools:
|
|
55
|
-
* - decode_mic: one MIC -> venue name, operator, country, city, status
|
|
56
|
-
* - search_mics: filter the registry by country, operator, status, name
|
|
57
|
-
*/
|
|
58
|
-
import type { MicRow } from './mic-index-data.js';
|
|
59
|
-
|
|
60
|
-
const tools: McpToolExport['tools'] = [
|
|
61
|
-
{
|
|
62
|
-
name: 'decode_mic',
|
|
63
|
-
description:
|
|
64
|
-
'Decode an ISO 10383 Market Identifier Code (MIC) — the 4-character venue code openfigi returns as `exchCode` ' +
|
|
65
|
-
'on an exchange listing, and the code most market-data feeds use the same way — to the trading venue\'s own ' +
|
|
66
|
-
'name, legal operator, country, city, website and registry status. Reports whether the code is an OPERATING ' +
|
|
67
|
-
'MIC (the operator as a whole, e.g. "XNYS") or a SEGMENT MIC (one specific market under an operator, e.g. ' +
|
|
68
|
-
'"ARCX" under "XNYS"); an operating MIC also carries segment_count — call search_mics with operating_mic to list them.',
|
|
69
|
-
summary: 'The venue name, operator, country and status behind an ISO 10383 Market Identifier Code.',
|
|
70
|
-
inputSchema: {
|
|
71
|
-
type: 'object',
|
|
72
|
-
properties: {
|
|
73
|
-
code: { type: 'string', description: '4-character ISO 10383 MIC, e.g. "XNYS" (NYSE) or "XLON" (London Stock Exchange).' },
|
|
74
|
-
},
|
|
75
|
-
required: ['code'],
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
name: 'search_mics',
|
|
80
|
-
description:
|
|
81
|
-
'Filter the ISO 10383 Market Identifier Code registry by country, operating MIC, status and/or a name fragment. ' +
|
|
82
|
-
'Returns aggregate counts first (total matched, by_status, by_country) and a page of rows after. Use operating_mic ' +
|
|
83
|
-
'to list every segment market under one venue operator (e.g. every segment under "XNYS").',
|
|
84
|
-
summary: 'Trading venues in the ISO 10383 Market Identifier Code registry, filtered by country, operator, status or name.',
|
|
85
|
-
inputSchema: {
|
|
86
|
-
type: 'object',
|
|
87
|
-
properties: {
|
|
88
|
-
country: { type: 'string', description: 'ISO 3166-1 alpha-2 country code of the venue, e.g. "US", "GB", "JP".' },
|
|
89
|
-
operating_mic: { type: 'string', description: 'List every market (segment or operating) under this operating MIC, e.g. "XNYS" to list NYSE\'s own segments.' },
|
|
90
|
-
status: { type: 'string', description: 'Registry status.', enum: ['ACTIVE', 'UPDATED', 'EXPIRED'] },
|
|
91
|
-
name_contains: { type: 'string', description: 'Case-insensitive fragment of the market name, legal entity name or acronym, e.g. "nasdaq".' },
|
|
92
|
-
limit: { type: 'number', description: 'Rows per page, 1-500 (default 50).' },
|
|
93
|
-
offset: { type: 'number', description: 'Rows to skip for paging (default 0).' },
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
];
|
|
98
|
-
|
|
99
|
-
// fleet #2754: a pack registered in pack-baked-indexes.json must never VALUE
|
|
100
|
-
// import its data module — the whole table would then be evaluated at
|
|
101
|
-
// module scope in every gateway isolate, including ones that never serve
|
|
102
|
-
// this pack. `MicRow` above is a type-only import (erased at build time);
|
|
103
|
-
// the actual rows arrive at runtime via args._bakedIndex, injected by the
|
|
104
|
-
// gateway from KV on the first call into this pack and adopted for the
|
|
105
|
-
// isolate's life.
|
|
106
|
-
let MIC_ROWS: MicRow[] = [];
|
|
107
|
-
let MIC_INDEX_CAPTURED_AT = '';
|
|
108
|
-
|
|
109
|
-
function ensureIndex(args: Record<string, unknown>): void {
|
|
110
|
-
if (MIC_ROWS.length) return;
|
|
111
|
-
const idx = args._bakedIndex as Record<string, unknown> | null | undefined;
|
|
112
|
-
const rows = idx?.MIC_ROWS;
|
|
113
|
-
const capturedAt = idx?.MIC_INDEX_CAPTURED_AT;
|
|
114
|
-
if (!Array.isArray(rows) || rows.length === 0 || typeof capturedAt !== 'string') {
|
|
115
|
-
// Loud on purpose: answering from an empty table would read as "no such
|
|
116
|
-
// MIC" / "no match" — a silent wrong answer indistinguishable from a
|
|
117
|
-
// real miss (docs/silent-zero-policy.md).
|
|
118
|
-
throw new Error(
|
|
119
|
-
`mic: the baked MIC index is unavailable (${idx == null ? 'not injected' : 'malformed'}). ` +
|
|
120
|
-
'The gateway loads it from KV on the first call into this pack; this is a server-side fault, not an unknown code — retry shortly.',
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
MIC_ROWS = rows as MicRow[];
|
|
124
|
-
MIC_INDEX_CAPTURED_AT = capturedAt;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Tuple field indices — see mic-index-data.ts's own header for the full list.
|
|
128
|
-
const F = {
|
|
129
|
-
mic: 0, operatingMic: 1, type: 2, marketName: 3, legalEntityName: 4, lei: 5,
|
|
130
|
-
marketCategoryCode: 6, acronym: 7, countryCode: 8, city: 9, website: 10,
|
|
131
|
-
status: 11, creationDate: 12, lastUpdateDate: 13, lastValidationDate: 14,
|
|
132
|
-
expiryDate: 15, comments: 16,
|
|
133
|
-
} as const;
|
|
134
|
-
|
|
135
|
-
function toRecord(r: MicRow) {
|
|
136
|
-
return {
|
|
137
|
-
mic: r[F.mic],
|
|
138
|
-
operating_mic: r[F.operatingMic] || null,
|
|
139
|
-
type: r[F.type] === 'OPRT' ? 'operating' : r[F.type] === 'SGMT' ? 'segment' : r[F.type] || null,
|
|
140
|
-
market_name: r[F.marketName] || null,
|
|
141
|
-
legal_entity_name: r[F.legalEntityName] || null,
|
|
142
|
-
lei: r[F.lei] || null,
|
|
143
|
-
market_category_code: r[F.marketCategoryCode] || null,
|
|
144
|
-
acronym: r[F.acronym] || null,
|
|
145
|
-
country_code: r[F.countryCode] || null,
|
|
146
|
-
city: r[F.city] || null,
|
|
147
|
-
website: r[F.website] || null,
|
|
148
|
-
status: r[F.status] || null,
|
|
149
|
-
creation_date: r[F.creationDate] || null,
|
|
150
|
-
last_update_date: r[F.lastUpdateDate] || null,
|
|
151
|
-
last_validation_date: r[F.lastValidationDate] || null,
|
|
152
|
-
expiry_date: r[F.expiryDate] || null,
|
|
153
|
-
comments: r[F.comments] || null,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function decodeMic(args: Record<string, unknown>) {
|
|
158
|
-
ensureIndex(args);
|
|
159
|
-
const raw = args.code;
|
|
160
|
-
if (typeof raw !== 'string' || !raw.trim()) {
|
|
161
|
-
throw new Error('Required argument "code" is missing or empty. Pass a 4-character MIC like "XNYS" or "XLON".');
|
|
162
|
-
}
|
|
163
|
-
const code = raw.trim().toUpperCase();
|
|
164
|
-
const row = MIC_ROWS.find((r) => r[F.mic] === code);
|
|
165
|
-
if (!row) {
|
|
166
|
-
throw new Error(
|
|
167
|
-
`user_error: "${code}" is not a MIC in the ISO 10383 registry (${MIC_ROWS.length} codes, as of ${MIC_INDEX_CAPTURED_AT}). ` +
|
|
168
|
-
'Verify the code, or use search_mics to browse by name or country rather than guessing one.',
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
const decoded = toRecord(row);
|
|
172
|
-
const segments =
|
|
173
|
-
decoded.type === 'operating'
|
|
174
|
-
? MIC_ROWS.filter((r) => r[F.operatingMic] === code && r[F.mic] !== code)
|
|
175
|
-
: [];
|
|
176
|
-
return {
|
|
177
|
-
found: true,
|
|
178
|
-
data_as_of: MIC_INDEX_CAPTURED_AT,
|
|
179
|
-
...decoded,
|
|
180
|
-
...(decoded.type === 'operating'
|
|
181
|
-
? {
|
|
182
|
-
segment_count: segments.length,
|
|
183
|
-
...(segments.length
|
|
184
|
-
? { note: `This is an operating MIC with ${segments.length} segment market(s) under it — call search_mics with operating_mic: "${code}" to list them.` }
|
|
185
|
-
: {}),
|
|
186
|
-
}
|
|
187
|
-
: {}),
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function searchMics(args: Record<string, unknown>) {
|
|
192
|
-
ensureIndex(args);
|
|
193
|
-
const country = typeof args.country === 'string' && args.country.trim() ? args.country.trim().toUpperCase() : null;
|
|
194
|
-
const operatingMic = typeof args.operating_mic === 'string' && args.operating_mic.trim() ? args.operating_mic.trim().toUpperCase() : null;
|
|
195
|
-
const status = typeof args.status === 'string' && args.status.trim() ? args.status.trim().toUpperCase() : null;
|
|
196
|
-
const nameContains = typeof args.name_contains === 'string' && args.name_contains.trim() ? args.name_contains.trim().toLowerCase() : null;
|
|
197
|
-
const limit = Math.min(500, Math.max(1, Math.round((args.limit as number) ?? 50)));
|
|
198
|
-
const offset = Math.max(0, Math.round((args.offset as number) ?? 0));
|
|
199
|
-
|
|
200
|
-
if (status && status !== 'ACTIVE' && status !== 'UPDATED' && status !== 'EXPIRED') {
|
|
201
|
-
throw new Error(`user_error: unknown status "${args.status}". Use ACTIVE, UPDATED or EXPIRED.`);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const filtersTried: string[] = [];
|
|
205
|
-
if (country) filtersTried.push(`country=${country}`);
|
|
206
|
-
if (operatingMic) filtersTried.push(`operating_mic=${operatingMic}`);
|
|
207
|
-
if (status) filtersTried.push(`status=${status}`);
|
|
208
|
-
if (nameContains) filtersTried.push(`name_contains="${nameContains}"`);
|
|
209
|
-
|
|
210
|
-
const matched = MIC_ROWS.filter((r) => {
|
|
211
|
-
if (country && r[F.countryCode] !== country) return false;
|
|
212
|
-
if (operatingMic && r[F.operatingMic] !== operatingMic) return false;
|
|
213
|
-
if (status && r[F.status] !== status) return false;
|
|
214
|
-
if (nameContains) {
|
|
215
|
-
const hay = `${r[F.marketName]} ${r[F.legalEntityName]} ${r[F.acronym]}`.toLowerCase();
|
|
216
|
-
if (!hay.includes(nameContains)) return false;
|
|
217
|
-
}
|
|
218
|
-
return true;
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
const byStatus: Record<string, number> = {};
|
|
222
|
-
const byCountry: Record<string, number> = {};
|
|
223
|
-
for (const r of matched) {
|
|
224
|
-
byStatus[r[F.status]] = (byStatus[r[F.status]] ?? 0) + 1;
|
|
225
|
-
if (r[F.countryCode]) byCountry[r[F.countryCode]] = (byCountry[r[F.countryCode]] ?? 0) + 1;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const page = matched.slice(offset, offset + limit).map(toRecord);
|
|
229
|
-
|
|
230
|
-
return {
|
|
231
|
-
found: matched.length > 0,
|
|
232
|
-
data_as_of: MIC_INDEX_CAPTURED_AT,
|
|
233
|
-
total: matched.length,
|
|
234
|
-
by_status: byStatus,
|
|
235
|
-
by_country: byCountry,
|
|
236
|
-
returned: page.length,
|
|
237
|
-
offset,
|
|
238
|
-
...(offset + page.length < matched.length ? { next_offset: offset + page.length } : {}),
|
|
239
|
-
...(matched.length === 0
|
|
240
|
-
? {
|
|
241
|
-
note: filtersTried.length
|
|
242
|
-
? `No MIC in the registry (${MIC_ROWS.length} codes, as of ${MIC_INDEX_CAPTURED_AT}) matches: ${filtersTried.join(', ')}. That is a real zero, not an error.`
|
|
243
|
-
: `No filters were given and the registry is unexpectedly empty — this should never happen; treat as a server fault.`,
|
|
244
|
-
}
|
|
245
|
-
: {}),
|
|
246
|
-
rows: page,
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
251
|
-
switch (name) {
|
|
252
|
-
case 'decode_mic':
|
|
253
|
-
return decodeMic(args);
|
|
254
|
-
case 'search_mics':
|
|
255
|
-
return searchMics(args);
|
|
256
|
-
default:
|
|
257
|
-
throw new Error(`Unknown tool: ${name}`);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
export default { tools, callTool } satisfies McpToolExport;
|