@mrfentmen/murex-mcp 0.0.0-stage → 1.0.1
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 +55 -2
- package/dist/_xml.d.ts +11 -0
- package/dist/_xml.js +62 -0
- package/dist/core.d.ts +3 -0
- package/dist/core.js +343 -0
- package/dist/format.d.ts +2 -0
- package/dist/format.js +81 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +13 -0
- package/dist/run.d.ts +17 -0
- package/dist/run.js +15 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +9 -0
- package/dist/types.d.ts +31 -0
- package/dist/types.js +1 -0
- package/package.json +44 -4
- package/server.json +20 -0
package/README.md
CHANGED
|
@@ -1,3 +1,56 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Murex MCP
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Murex MCP: parse trade export XML, validate ids, amounts and currencies.
|
|
4
|
+
|
|
5
|
+
No network calls. Files are parsed locally and nothing leaves the machine.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx -y @mrfentmen/murex-mcp
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or in an MCP client:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"mcpServers": {
|
|
18
|
+
"murex-mcp": {
|
|
19
|
+
"command": "npx",
|
|
20
|
+
"args": ["-y", "@mrfentmen/murex-mcp"]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Tools
|
|
27
|
+
|
|
28
|
+
| Tool | What it does |
|
|
29
|
+
|---|---|
|
|
30
|
+
| `detect_files` | Find Murex files in a directory tree. |
|
|
31
|
+
| `read_file` | Read a file or line range. |
|
|
32
|
+
| `write_file` | Write a file, with overwrite protection. |
|
|
33
|
+
| `parse` | Parse into records, fields and metadata. |
|
|
34
|
+
| `validate` | Check structural rules and report issues by line. |
|
|
35
|
+
| `summarize` | Record counts, kinds and document metadata. |
|
|
36
|
+
| `list_records` | List record ids and kinds. |
|
|
37
|
+
| `get_record` | Full fields for one record. |
|
|
38
|
+
| `search` | Plain text or regex search across records. |
|
|
39
|
+
| `stats` | Numeric min/max/mean per field. |
|
|
40
|
+
| `format_reference` | Compact spec reference. |
|
|
41
|
+
| `sample` | A small valid example document. |
|
|
42
|
+
| `diff` | Compare two documents. |
|
|
43
|
+
| `to_json` | Export every record as JSON. |
|
|
44
|
+
|
|
45
|
+
## Safety
|
|
46
|
+
|
|
47
|
+
This server reads and writes local files. Treat file paths as trusted input.
|
|
48
|
+
Invalid documents are reported, never silently repaired.
|
|
49
|
+
|
|
50
|
+
## Run locally
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install
|
|
54
|
+
npm run build
|
|
55
|
+
node dist/index.js
|
|
56
|
+
```
|
package/dist/_xml.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Issue } from "./types.js";
|
|
2
|
+
export interface XmlTag {
|
|
3
|
+
name: string;
|
|
4
|
+
attrs: Record<string, string>;
|
|
5
|
+
close: boolean;
|
|
6
|
+
selfClose: boolean;
|
|
7
|
+
line: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function scanTags(text: string): XmlTag[];
|
|
10
|
+
export declare function readRoot(text: string): string;
|
|
11
|
+
export declare function validateXml(text: string, root: string, displayName: string, issues: Issue[]): void;
|
package/dist/_xml.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export function scanTags(text) {
|
|
2
|
+
const tags = [];
|
|
3
|
+
const re = /<(\/?)([A-Za-z_][\w.:-]*)([^>]*?)(\/?)>/g;
|
|
4
|
+
let match;
|
|
5
|
+
let cursor = 0;
|
|
6
|
+
let line = 1;
|
|
7
|
+
while ((match = re.exec(text)) !== null) {
|
|
8
|
+
line += (text.slice(cursor, match.index).match(/\n/g) ?? []).length;
|
|
9
|
+
cursor = match.index;
|
|
10
|
+
const attrs = {};
|
|
11
|
+
for (const attr of match[3].matchAll(/([\w.:-]+)\s*=\s*"([^"]*)"/g))
|
|
12
|
+
attrs[attr[1]] = attr[2];
|
|
13
|
+
tags.push({ name: match[2], attrs, close: match[1] === "/", selfClose: match[4] === "/", line });
|
|
14
|
+
}
|
|
15
|
+
return tags;
|
|
16
|
+
}
|
|
17
|
+
export function readRoot(text) {
|
|
18
|
+
const declaration = text.replace(/^\s*<\?xml[^>]*\?>/, "");
|
|
19
|
+
const match = /<\s*([A-Za-z_][\w.:-]*)/.exec(declaration);
|
|
20
|
+
return match ? match[1] : "";
|
|
21
|
+
}
|
|
22
|
+
export function validateXml(text, root, displayName, issues) {
|
|
23
|
+
if (text.trim().length === 0) {
|
|
24
|
+
issues.push({ code: "empty", severity: "error", message: "Document is empty" });
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const tags = scanTags(text);
|
|
28
|
+
if (tags.length === 0) {
|
|
29
|
+
issues.push({ code: "no-tags", severity: "error", message: "No XML elements found" });
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const found = readRoot(text);
|
|
33
|
+
if (found !== root) {
|
|
34
|
+
issues.push({ code: "bad-root", severity: "error", message: `Root element must be ${root}, found ${found || "nothing"}` });
|
|
35
|
+
}
|
|
36
|
+
const stack = [];
|
|
37
|
+
for (const tag of tags) {
|
|
38
|
+
if (tag.selfClose)
|
|
39
|
+
continue;
|
|
40
|
+
if (tag.close) {
|
|
41
|
+
const open = stack.pop();
|
|
42
|
+
if (!open) {
|
|
43
|
+
issues.push({ code: "unmatched-close", severity: "error", message: `Closing </${tag.name}> has no opening tag`, line: tag.line });
|
|
44
|
+
}
|
|
45
|
+
else if (open.name !== tag.name) {
|
|
46
|
+
issues.push({
|
|
47
|
+
code: "mismatched-tag",
|
|
48
|
+
severity: "error",
|
|
49
|
+
message: `</${tag.name}> closes <${open.name}> from line ${open.line}`,
|
|
50
|
+
line: tag.line,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
stack.push(tag);
|
|
56
|
+
}
|
|
57
|
+
for (const open of stack.slice(-3)) {
|
|
58
|
+
issues.push({ code: "unclosed-tag", severity: "error", message: `<${open.name}> is never closed`, line: open.line });
|
|
59
|
+
}
|
|
60
|
+
if (!root)
|
|
61
|
+
issues.push({ code: "no-root", severity: "error", message: `${displayName} has no root element` });
|
|
62
|
+
}
|
package/dist/core.d.ts
ADDED
package/dist/core.js
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { errorMessage, fail, text, ToolError } from "./run.js";
|
|
5
|
+
const MAX_INPUT = 4_000_000;
|
|
6
|
+
const SKIP_DIRS = new Set([".git", "node_modules", "dist", "build", ".mcp-build"]);
|
|
7
|
+
async function readInput(input) {
|
|
8
|
+
if (input.path && input.content !== undefined)
|
|
9
|
+
throw new ToolError("Use path or content, not both");
|
|
10
|
+
if (input.content !== undefined) {
|
|
11
|
+
if (input.content.length > MAX_INPUT)
|
|
12
|
+
throw new ToolError(`Input is larger than ${MAX_INPUT} characters`);
|
|
13
|
+
return { body: input.content };
|
|
14
|
+
}
|
|
15
|
+
if (!input.path)
|
|
16
|
+
throw new ToolError("Provide a path or content");
|
|
17
|
+
if (input.path.includes("\0"))
|
|
18
|
+
throw new ToolError("Path contains a null byte");
|
|
19
|
+
const file = path.isAbsolute(input.path) ? input.path : path.resolve(input.cwd ? path.resolve(input.cwd) : process.cwd(), input.path);
|
|
20
|
+
const stat = await fs.stat(file);
|
|
21
|
+
if (!stat.isFile())
|
|
22
|
+
throw new ToolError(`Not a file: ${file}`);
|
|
23
|
+
if (stat.size > MAX_INPUT)
|
|
24
|
+
throw new ToolError(`File is larger than ${MAX_INPUT} bytes`);
|
|
25
|
+
return { body: await fs.readFile(file, "utf8"), file };
|
|
26
|
+
}
|
|
27
|
+
function parseOrThrow(format, body) {
|
|
28
|
+
const parsed = format.parse(body);
|
|
29
|
+
const errors = parsed.issues.filter((issue) => issue.severity === "error");
|
|
30
|
+
if (errors.length > 0) {
|
|
31
|
+
const first = errors.slice(0, 5).map((issue) => (issue.line ? `line ${issue.line}: ${issue.message}` : issue.message));
|
|
32
|
+
throw new ToolError(`${format.displayName} could not be parsed:\n${first.join("\n")}`);
|
|
33
|
+
}
|
|
34
|
+
return parsed;
|
|
35
|
+
}
|
|
36
|
+
function numericStats(records) {
|
|
37
|
+
const out = {};
|
|
38
|
+
for (const record of records) {
|
|
39
|
+
for (const [key, value] of Object.entries(record.fields)) {
|
|
40
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
41
|
+
continue;
|
|
42
|
+
const current = out[key];
|
|
43
|
+
if (!current) {
|
|
44
|
+
out[key] = { count: 1, min: value, max: value, mean: value, sum: value };
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
current.count += 1;
|
|
48
|
+
current.sum += value;
|
|
49
|
+
current.min = Math.min(current.min, value);
|
|
50
|
+
current.max = Math.max(current.max, value);
|
|
51
|
+
current.mean = current.sum / current.count;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
function round(value) {
|
|
58
|
+
return Number.isFinite(value) ? Math.round(value * 1000) / 1000 : value;
|
|
59
|
+
}
|
|
60
|
+
export function registerFormatTools(server, format) {
|
|
61
|
+
const sourceArgs = {
|
|
62
|
+
path: z.string().min(1).max(2_000).optional(),
|
|
63
|
+
content: z.string().max(MAX_INPUT).optional(),
|
|
64
|
+
cwd: z.string().min(1).max(2_000).optional(),
|
|
65
|
+
};
|
|
66
|
+
server.tool("detect_files", `Find ${format.displayName} files (${format.extensions.join(", ")}) in a directory tree.`, {
|
|
67
|
+
path: z.string().min(1).max(2_000).default("."),
|
|
68
|
+
maxDepth: z.number().int().min(0).max(8).default(4),
|
|
69
|
+
}, async (a) => {
|
|
70
|
+
try {
|
|
71
|
+
const root = path.resolve(a.path);
|
|
72
|
+
const stat = await fs.stat(root);
|
|
73
|
+
if (!stat.isDirectory())
|
|
74
|
+
throw new ToolError(`Not a directory: ${root}`);
|
|
75
|
+
const found = [];
|
|
76
|
+
let scanned = 0;
|
|
77
|
+
async function walk(dir, depth) {
|
|
78
|
+
if (depth > a.maxDepth || found.length >= 500)
|
|
79
|
+
return;
|
|
80
|
+
let entries;
|
|
81
|
+
try {
|
|
82
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
for (const entry of entries) {
|
|
88
|
+
if (entry.name.startsWith("."))
|
|
89
|
+
continue;
|
|
90
|
+
const full = path.join(dir, entry.name);
|
|
91
|
+
if (entry.isDirectory()) {
|
|
92
|
+
if (SKIP_DIRS.has(entry.name))
|
|
93
|
+
continue;
|
|
94
|
+
await walk(full, depth + 1);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (!entry.isFile())
|
|
98
|
+
continue;
|
|
99
|
+
scanned += 1;
|
|
100
|
+
if (!format.extensions.includes(path.extname(entry.name).toLowerCase()))
|
|
101
|
+
continue;
|
|
102
|
+
found.push(path.relative(root, full));
|
|
103
|
+
if (found.length >= 500)
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
await walk(root, 0);
|
|
108
|
+
return text(JSON.stringify({ format: format.displayName, root, filesScanned: scanned, matches: found.length, files: found }, null, 2));
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
return fail(errorMessage(error));
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
server.tool("read_file", `Read a ${format.displayName} file, optionally a line range.`, {
|
|
115
|
+
path: z.string().min(1).max(2_000),
|
|
116
|
+
startLine: z.number().int().min(1).default(1),
|
|
117
|
+
endLine: z.number().int().min(1).optional(),
|
|
118
|
+
cwd: z.string().min(1).max(2_000).optional(),
|
|
119
|
+
}, async (a) => {
|
|
120
|
+
try {
|
|
121
|
+
const { body } = await readInput({ path: a.path, cwd: a.cwd });
|
|
122
|
+
const lines = body.split(/\r?\n/);
|
|
123
|
+
const end = Math.min(a.endLine ?? lines.length, lines.length);
|
|
124
|
+
return text(lines.slice(a.startLine - 1, end).join("\n"));
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
return fail(errorMessage(error));
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
server.tool("write_file", `Write a ${format.displayName} file. Refuses to overwrite unless overwrite is true.`, {
|
|
131
|
+
path: z.string().min(1).max(2_000),
|
|
132
|
+
content: z.string().max(MAX_INPUT),
|
|
133
|
+
overwrite: z.boolean().default(false),
|
|
134
|
+
cwd: z.string().min(1).max(2_000).optional(),
|
|
135
|
+
}, async (a) => {
|
|
136
|
+
try {
|
|
137
|
+
const file = path.isAbsolute(a.path) ? a.path : path.resolve(a.cwd ? path.resolve(a.cwd) : process.cwd(), a.path);
|
|
138
|
+
if (!a.overwrite) {
|
|
139
|
+
const exists = await fs.stat(file).then(() => true).catch(() => false);
|
|
140
|
+
if (exists)
|
|
141
|
+
throw new ToolError(`File already exists: ${file}. Set overwrite=true to replace it.`);
|
|
142
|
+
}
|
|
143
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
144
|
+
await fs.writeFile(file, a.content, "utf8");
|
|
145
|
+
return text(`Wrote ${Buffer.byteLength(a.content)} bytes to ${file}`);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
return fail(errorMessage(error));
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
server.tool("parse", `Parse ${format.displayName} into records, fields and document metadata.`, { ...sourceArgs }, async (a) => {
|
|
152
|
+
try {
|
|
153
|
+
const { body, file } = await readInput(a);
|
|
154
|
+
const parsed = parseOrThrow(format, body);
|
|
155
|
+
return text(JSON.stringify({
|
|
156
|
+
file: file ?? null,
|
|
157
|
+
format: parsed.format,
|
|
158
|
+
meta: parsed.meta,
|
|
159
|
+
records: parsed.records.length,
|
|
160
|
+
kinds: parsed.records.reduce((acc, record) => {
|
|
161
|
+
acc[record.kind] = (acc[record.kind] ?? 0) + 1;
|
|
162
|
+
return acc;
|
|
163
|
+
}, {}),
|
|
164
|
+
issues: parsed.issues,
|
|
165
|
+
}, null, 2));
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
return fail(errorMessage(error));
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
server.tool("validate", `Validate ${format.displayName} against its structural rules and report every issue with a line number.`, { ...sourceArgs }, async (a) => {
|
|
172
|
+
try {
|
|
173
|
+
const { body } = await readInput(a);
|
|
174
|
+
const parsed = format.parse(body);
|
|
175
|
+
const errors = parsed.issues.filter((issue) => issue.severity === "error").length;
|
|
176
|
+
const warnings = parsed.issues.length - errors;
|
|
177
|
+
return text(JSON.stringify({
|
|
178
|
+
format: parsed.format,
|
|
179
|
+
valid: errors === 0,
|
|
180
|
+
errors,
|
|
181
|
+
warnings,
|
|
182
|
+
issues: parsed.issues,
|
|
183
|
+
}, null, 2));
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
return fail(errorMessage(error));
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
server.tool("summarize", `Summarize a ${format.displayName} document: metadata, record counts and per-kind totals.`, { ...sourceArgs }, async (a) => {
|
|
190
|
+
try {
|
|
191
|
+
const { body } = await readInput(a);
|
|
192
|
+
const parsed = parseOrThrow(format, body);
|
|
193
|
+
const kinds = parsed.records.reduce((acc, record) => {
|
|
194
|
+
acc[record.kind] = (acc[record.kind] ?? 0) + 1;
|
|
195
|
+
return acc;
|
|
196
|
+
}, {});
|
|
197
|
+
const lines = [
|
|
198
|
+
`${format.displayName} document`,
|
|
199
|
+
`records: ${parsed.records.length}`,
|
|
200
|
+
...Object.entries(kinds).map(([kind, count]) => ` ${kind}: ${count}`),
|
|
201
|
+
...Object.entries(parsed.meta).map(([key, value]) => `${key}: ${String(value)}`),
|
|
202
|
+
`issues: ${parsed.issues.length}`,
|
|
203
|
+
];
|
|
204
|
+
return text(lines.join("\n"));
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
return fail(errorMessage(error));
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
server.tool("list_records", `List ${format.displayName} record ids and kinds, with a limit.`, {
|
|
211
|
+
...sourceArgs,
|
|
212
|
+
limit: z.number().int().min(1).max(1_000).default(50),
|
|
213
|
+
}, async (a) => {
|
|
214
|
+
try {
|
|
215
|
+
const { body } = await readInput(a);
|
|
216
|
+
const parsed = parseOrThrow(format, body);
|
|
217
|
+
const rows = parsed.records.slice(0, a.limit).map((record) => `${record.kind}\t${record.id}`);
|
|
218
|
+
const rest = parsed.records.length - rows.length;
|
|
219
|
+
return text(rows.join("\n") + (rest > 0 ? `\n... ${rest} more` : ""));
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
return fail(errorMessage(error));
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
server.tool("get_record", `Return one ${format.displayName} record by id, with all parsed fields.`, {
|
|
226
|
+
...sourceArgs,
|
|
227
|
+
id: z.string().min(1).max(300),
|
|
228
|
+
}, async (a) => {
|
|
229
|
+
try {
|
|
230
|
+
const { body } = await readInput(a);
|
|
231
|
+
const parsed = parseOrThrow(format, body);
|
|
232
|
+
const record = parsed.records.find((item) => item.id === a.id);
|
|
233
|
+
if (!record)
|
|
234
|
+
throw new ToolError(`No record with id ${a.id}. Use list_records to see available ids.`);
|
|
235
|
+
return text(JSON.stringify(record, null, 2));
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
return fail(errorMessage(error));
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
server.tool("search", `Search ${format.displayName} records by plain text or regular expression.`, {
|
|
242
|
+
...sourceArgs,
|
|
243
|
+
query: z.string().min(1).max(500),
|
|
244
|
+
regex: z.boolean().default(false),
|
|
245
|
+
limit: z.number().int().min(1).max(500).default(50),
|
|
246
|
+
}, async (a) => {
|
|
247
|
+
try {
|
|
248
|
+
const { body } = await readInput(a);
|
|
249
|
+
const parsed = parseOrThrow(format, body);
|
|
250
|
+
let test;
|
|
251
|
+
if (a.regex) {
|
|
252
|
+
let pattern;
|
|
253
|
+
try {
|
|
254
|
+
pattern = new RegExp(a.query, "i");
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
throw new ToolError(`Invalid regular expression: ${a.query}`);
|
|
258
|
+
}
|
|
259
|
+
test = (value) => pattern.test(value);
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
const needle = a.query.toLowerCase();
|
|
263
|
+
test = (value) => value.toLowerCase().includes(needle);
|
|
264
|
+
}
|
|
265
|
+
const matches = parsed.records.filter((record) => test(`${record.id} ${record.kind} ${JSON.stringify(record.fields)}`));
|
|
266
|
+
const rows = matches.slice(0, a.limit).map((record) => `${record.kind}\t${record.id}`);
|
|
267
|
+
return text(`${matches.length} match(es)\n${rows.join("\n")}`.trim());
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
return fail(errorMessage(error));
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
server.tool("stats", `Numeric statistics for ${format.displayName} fields across all records.`, {
|
|
274
|
+
...sourceArgs,
|
|
275
|
+
field: z.string().min(1).max(120).optional(),
|
|
276
|
+
}, async (a) => {
|
|
277
|
+
try {
|
|
278
|
+
const { body } = await readInput(a);
|
|
279
|
+
const parsed = parseOrThrow(format, body);
|
|
280
|
+
const stats = numericStats(parsed.records);
|
|
281
|
+
if (a.field) {
|
|
282
|
+
const one = stats[a.field];
|
|
283
|
+
if (!one)
|
|
284
|
+
throw new ToolError(`Field ${a.field} has no numeric values. Numeric fields: ${Object.keys(stats).join(", ") || "none"}`);
|
|
285
|
+
return text(JSON.stringify({ [a.field]: { ...one, mean: round(one.mean) } }, null, 2));
|
|
286
|
+
}
|
|
287
|
+
const rounded = Object.fromEntries(Object.entries(stats).map(([key, value]) => [key, { ...value, mean: round(value.mean) }]));
|
|
288
|
+
return text(JSON.stringify(rounded, null, 2));
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
return fail(errorMessage(error));
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
server.tool("to_json", `Export every parsed ${format.displayName} record as JSON.`, { ...sourceArgs }, async (a) => {
|
|
295
|
+
try {
|
|
296
|
+
const { body, file } = await readInput(a);
|
|
297
|
+
const parsed = parseOrThrow(format, body);
|
|
298
|
+
return text(JSON.stringify({
|
|
299
|
+
file: file ?? null,
|
|
300
|
+
format: parsed.format,
|
|
301
|
+
meta: parsed.meta,
|
|
302
|
+
issues: parsed.issues,
|
|
303
|
+
records: parsed.records,
|
|
304
|
+
}, null, 2));
|
|
305
|
+
}
|
|
306
|
+
catch (error) {
|
|
307
|
+
return fail(errorMessage(error));
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
server.tool("diff", `Compare two ${format.displayName} documents: added, removed and changed records.`, {
|
|
311
|
+
leftPath: z.string().min(1).max(2_000).optional(),
|
|
312
|
+
leftContent: z.string().max(MAX_INPUT).optional(),
|
|
313
|
+
rightPath: z.string().min(1).max(2_000).optional(),
|
|
314
|
+
rightContent: z.string().max(MAX_INPUT).optional(),
|
|
315
|
+
cwd: z.string().min(1).max(2_000).optional(),
|
|
316
|
+
}, async (a) => {
|
|
317
|
+
try {
|
|
318
|
+
const left = await readInput({ path: a.leftPath, content: a.leftContent, cwd: a.cwd });
|
|
319
|
+
const right = await readInput({ path: a.rightPath, content: a.rightContent, cwd: a.cwd });
|
|
320
|
+
const before = parseOrThrow(format, left.body);
|
|
321
|
+
const after = parseOrThrow(format, right.body);
|
|
322
|
+
const beforeFields = new Map(before.records.map((record) => [record.id, JSON.stringify(record.fields)]));
|
|
323
|
+
const afterFields = new Map(after.records.map((record) => [record.id, JSON.stringify(record.fields)]));
|
|
324
|
+
const added = [...afterFields.keys()].filter((id) => !beforeFields.has(id));
|
|
325
|
+
const removed = [...beforeFields.keys()].filter((id) => !afterFields.has(id));
|
|
326
|
+
const changed = [...afterFields.keys()].filter((id) => beforeFields.has(id) && beforeFields.get(id) !== afterFields.get(id));
|
|
327
|
+
return text(JSON.stringify({
|
|
328
|
+
format: before.format,
|
|
329
|
+
added: added.length,
|
|
330
|
+
removed: removed.length,
|
|
331
|
+
changed: changed.length,
|
|
332
|
+
unchanged: afterFields.size - added.length - changed.length,
|
|
333
|
+
records: { added, removed, changed },
|
|
334
|
+
issues: { left: before.issues.length, right: after.issues.length },
|
|
335
|
+
}, null, 2));
|
|
336
|
+
}
|
|
337
|
+
catch (error) {
|
|
338
|
+
return fail(errorMessage(error));
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
server.tool("format_reference", `Return a compact ${format.displayName} reference: structure, required fields and common pitfalls.`, {}, async () => text(format.reference));
|
|
342
|
+
server.tool("sample", `Return a small but valid ${format.displayName} example document.`, {}, async () => text(format.sample()));
|
|
343
|
+
}
|
package/dist/format.d.ts
ADDED
package/dist/format.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { readRoot, scanTags, validateXml } from "./_xml.js";
|
|
2
|
+
function parse(text) {
|
|
3
|
+
const issues = [];
|
|
4
|
+
const root = readRoot(text);
|
|
5
|
+
validateXml(text, root, "Murex export", issues);
|
|
6
|
+
const tags = scanTags(text);
|
|
7
|
+
const records = [];
|
|
8
|
+
const ids = new Set();
|
|
9
|
+
const currencies = new Set();
|
|
10
|
+
let total = 0;
|
|
11
|
+
for (const tag of tags) {
|
|
12
|
+
if (tag.close || !/^trade$/i.test(tag.name))
|
|
13
|
+
continue;
|
|
14
|
+
const id = tag.attrs.id ?? tag.attrs.tradeId ?? "";
|
|
15
|
+
if (!id) {
|
|
16
|
+
issues.push({ code: "trade-without-id", severity: "error", message: "Trade has no id", line: tag.line });
|
|
17
|
+
}
|
|
18
|
+
else if (ids.has(id)) {
|
|
19
|
+
issues.push({ code: "duplicate-trade", severity: "error", message: `Trade ${id} appears twice`, line: tag.line });
|
|
20
|
+
}
|
|
21
|
+
ids.add(id);
|
|
22
|
+
const amountText = tag.attrs.amount ?? tag.attrs.notional ?? "";
|
|
23
|
+
let amount = 0;
|
|
24
|
+
if (amountText) {
|
|
25
|
+
amount = Number(amountText.replace(/,/g, ""));
|
|
26
|
+
if (!Number.isFinite(amount)) {
|
|
27
|
+
issues.push({ code: "bad-amount", severity: "error", message: `Trade ${id || tag.line} amount is not numeric: ${amountText}`, line: tag.line });
|
|
28
|
+
amount = 0;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
issues.push({ code: "missing-amount", severity: "warning", message: `Trade ${id || tag.line} has no amount`, line: tag.line });
|
|
33
|
+
}
|
|
34
|
+
const currency = tag.attrs.currency ?? "";
|
|
35
|
+
if (currency)
|
|
36
|
+
currencies.add(currency);
|
|
37
|
+
total += amount;
|
|
38
|
+
records.push({ id: `trade:${id || tag.line}`, kind: "trade", fields: { id, amount, currency, line: tag.line } });
|
|
39
|
+
}
|
|
40
|
+
if (records.length === 0) {
|
|
41
|
+
issues.push({ code: "no-trades", severity: "error", message: "Export contains no Trade element" });
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
format: "Murex",
|
|
45
|
+
records,
|
|
46
|
+
meta: {
|
|
47
|
+
root,
|
|
48
|
+
trades: records.length,
|
|
49
|
+
currencies: currencies.size,
|
|
50
|
+
totalAmount: Number(total.toFixed(2)),
|
|
51
|
+
},
|
|
52
|
+
issues,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const reference = [
|
|
56
|
+
"Murex trade export (XML)",
|
|
57
|
+
"",
|
|
58
|
+
"<MurexExport>",
|
|
59
|
+
" <Trade id=\"T1\" amount=\"1000000\" currency=\"EUR\"/>",
|
|
60
|
+
" <Trade id=\"T2\" amount=\"250000\" currency=\"USD\"/>",
|
|
61
|
+
"</MurexExport>",
|
|
62
|
+
"",
|
|
63
|
+
"Each Trade carries a unique id, a numeric amount and a currency.",
|
|
64
|
+
"amount or notional is accepted for the cash amount.",
|
|
65
|
+
"The root element is reported, not enforced.",
|
|
66
|
+
].join("\n");
|
|
67
|
+
export const format = {
|
|
68
|
+
slug: "murex",
|
|
69
|
+
displayName: "Murex",
|
|
70
|
+
extensions: [".murex"],
|
|
71
|
+
description: "Parse Murex trade export XML, validate trade ids, amounts and currencies.",
|
|
72
|
+
reference,
|
|
73
|
+
parse,
|
|
74
|
+
sample: () => [
|
|
75
|
+
'<?xml version="1.0"?>',
|
|
76
|
+
"<MurexExport>",
|
|
77
|
+
' <Trade id="T1" amount="1000000" currency="EUR"/>',
|
|
78
|
+
' <Trade id="T2" amount="250000" currency="USD"/>',
|
|
79
|
+
"</MurexExport>",
|
|
80
|
+
].join("\n") + "\n",
|
|
81
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { createServer } from "./server.js";
|
|
4
|
+
async function main() {
|
|
5
|
+
const server = createServer();
|
|
6
|
+
const transport = new StdioServerTransport();
|
|
7
|
+
await server.connect(transport);
|
|
8
|
+
}
|
|
9
|
+
main().catch((error) => {
|
|
10
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
11
|
+
process.stderr.write(`${message}\n`);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
});
|
package/dist/run.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class ToolError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare function errorMessage(error: unknown): string;
|
|
5
|
+
export declare function text(value: string): {
|
|
6
|
+
content: {
|
|
7
|
+
type: "text";
|
|
8
|
+
text: string;
|
|
9
|
+
}[];
|
|
10
|
+
};
|
|
11
|
+
export declare function fail(message: string): {
|
|
12
|
+
isError: boolean;
|
|
13
|
+
content: {
|
|
14
|
+
type: "text";
|
|
15
|
+
text: string;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
package/dist/run.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class ToolError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = "ToolError";
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export function errorMessage(error) {
|
|
8
|
+
return error instanceof Error ? error.message : String(error);
|
|
9
|
+
}
|
|
10
|
+
export function text(value) {
|
|
11
|
+
return { content: [{ type: "text", text: value }] };
|
|
12
|
+
}
|
|
13
|
+
export function fail(message) {
|
|
14
|
+
return { isError: true, content: [{ type: "text", text: message }] };
|
|
15
|
+
}
|
package/dist/server.d.ts
ADDED
package/dist/server.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { format } from "./format.js";
|
|
3
|
+
import { registerFormatTools } from "./core.js";
|
|
4
|
+
export const VERSION = "1.0.0";
|
|
5
|
+
export function createServer() {
|
|
6
|
+
const server = new McpServer({ name: `${format.slug}-mcp`, version: VERSION });
|
|
7
|
+
registerFormatTools(server, format);
|
|
8
|
+
return server;
|
|
9
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type Severity = "error" | "warning";
|
|
2
|
+
export interface Issue {
|
|
3
|
+
code: string;
|
|
4
|
+
severity: Severity;
|
|
5
|
+
message: string;
|
|
6
|
+
line?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ParsedRecord {
|
|
9
|
+
id: string;
|
|
10
|
+
kind: string;
|
|
11
|
+
fields: Record<string, string | number | boolean | null>;
|
|
12
|
+
}
|
|
13
|
+
export interface Parsed {
|
|
14
|
+
format: string;
|
|
15
|
+
records: ParsedRecord[];
|
|
16
|
+
meta: Record<string, string | number | boolean | null>;
|
|
17
|
+
issues: Issue[];
|
|
18
|
+
}
|
|
19
|
+
export interface FormatModule {
|
|
20
|
+
slug: string;
|
|
21
|
+
displayName: string;
|
|
22
|
+
extensions: string[];
|
|
23
|
+
description: string;
|
|
24
|
+
reference: string;
|
|
25
|
+
parse(text: string): Parsed;
|
|
26
|
+
sample(): string;
|
|
27
|
+
regressions?: Array<{
|
|
28
|
+
doc: string;
|
|
29
|
+
expectError: string;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrfentmen/murex-mcp",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Murex MCP: parse trade export XML, validate ids, amounts and currencies.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"mcpName": "io.github.mrfentmen/murex-mcp",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/mrfentmen/awesome-servers.git"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"murex-mcp": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"server.json",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -p tsconfig.json",
|
|
22
|
+
"start": "node dist/index.js",
|
|
23
|
+
"test": "npm run build && node --test tests/tools.test.mjs"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"mcp",
|
|
27
|
+
"model-context-protocol",
|
|
28
|
+
"murex",
|
|
29
|
+
"trading",
|
|
30
|
+
"capital-markets",
|
|
31
|
+
"risk",
|
|
32
|
+
"xml"
|
|
33
|
+
],
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@modelcontextprotocol/sdk": "^1.0.4",
|
|
37
|
+
"zod": "^3.23.8"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^22.0.0",
|
|
41
|
+
"typescript": "^5.6.0"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=20"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/server.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.mrfentmen/murex-mcp",
|
|
4
|
+
"description": "Murex MCP: parse trade export XML, validate ids, amounts and currencies.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"url": "https://github.com/mrfentmen/awesome-servers",
|
|
7
|
+
"source": "github"
|
|
8
|
+
},
|
|
9
|
+
"version": "1.0.1",
|
|
10
|
+
"packages": [
|
|
11
|
+
{
|
|
12
|
+
"registryType": "npm",
|
|
13
|
+
"identifier": "@mrfentmen/murex-mcp",
|
|
14
|
+
"version": "1.0.1",
|
|
15
|
+
"transport": {
|
|
16
|
+
"type": "stdio"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|