@vinkius-core/mcp-fusion 2.12.0 → 2.13.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.
Files changed (52) hide show
  1. package/dist/core/builder/FluentToolBuilder.d.ts +30 -0
  2. package/dist/core/builder/FluentToolBuilder.d.ts.map +1 -1
  3. package/dist/core/builder/FluentToolBuilder.js +43 -0
  4. package/dist/core/builder/FluentToolBuilder.js.map +1 -1
  5. package/dist/core/builder/GroupedToolBuilder.d.ts +27 -0
  6. package/dist/core/builder/GroupedToolBuilder.d.ts.map +1 -1
  7. package/dist/core/builder/GroupedToolBuilder.js +33 -0
  8. package/dist/core/builder/GroupedToolBuilder.js.map +1 -1
  9. package/dist/core/index.d.ts +1 -0
  10. package/dist/core/index.d.ts.map +1 -1
  11. package/dist/core/index.js.map +1 -1
  12. package/dist/core/initFusion.d.ts +37 -0
  13. package/dist/core/initFusion.d.ts.map +1 -1
  14. package/dist/core/initFusion.js +8 -0
  15. package/dist/core/initFusion.js.map +1 -1
  16. package/dist/core/response.d.ts +2 -1
  17. package/dist/core/response.d.ts.map +1 -1
  18. package/dist/core/response.js +3 -2
  19. package/dist/core/response.js.map +1 -1
  20. package/dist/core/serialization/JsonSerializer.d.ts +71 -0
  21. package/dist/core/serialization/JsonSerializer.d.ts.map +1 -0
  22. package/dist/core/serialization/JsonSerializer.js +192 -0
  23. package/dist/core/serialization/JsonSerializer.js.map +1 -0
  24. package/dist/core/serialization/index.d.ts +7 -0
  25. package/dist/core/serialization/index.d.ts.map +1 -0
  26. package/dist/core/serialization/index.js +7 -0
  27. package/dist/core/serialization/index.js.map +1 -0
  28. package/dist/index.d.ts +10 -1
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +7 -0
  31. package/dist/index.js.map +1 -1
  32. package/dist/presenter/Presenter.d.ts +1 -0
  33. package/dist/presenter/Presenter.d.ts.map +1 -1
  34. package/dist/presenter/Presenter.js +6 -1
  35. package/dist/presenter/Presenter.js.map +1 -1
  36. package/dist/presenter/ResponseBuilder.d.ts +2 -1
  37. package/dist/presenter/ResponseBuilder.d.ts.map +1 -1
  38. package/dist/presenter/ResponseBuilder.js +3 -2
  39. package/dist/presenter/ResponseBuilder.js.map +1 -1
  40. package/dist/sandbox/SandboxEngine.d.ts +202 -0
  41. package/dist/sandbox/SandboxEngine.d.ts.map +1 -0
  42. package/dist/sandbox/SandboxEngine.js +343 -0
  43. package/dist/sandbox/SandboxEngine.js.map +1 -0
  44. package/dist/sandbox/SandboxGuard.d.ts +47 -0
  45. package/dist/sandbox/SandboxGuard.d.ts.map +1 -0
  46. package/dist/sandbox/SandboxGuard.js +90 -0
  47. package/dist/sandbox/SandboxGuard.js.map +1 -0
  48. package/dist/sandbox/index.d.ts +23 -0
  49. package/dist/sandbox/index.d.ts.map +1 -0
  50. package/dist/sandbox/index.js +26 -0
  51. package/dist/sandbox/index.js.map +1 -0
  52. package/package.json +13 -1
@@ -0,0 +1,90 @@
1
+ /**
2
+ * SandboxGuard — Fail-Fast Syntax Checker for LLM-Provided Code
3
+ *
4
+ * Provides quick feedback BEFORE sending code to the isolated-vm engine.
5
+ * This is NOT a security boundary — security comes from the empty V8
6
+ * Context (no `process`, `require`, `fs`, or `globalThis` injected).
7
+ *
8
+ * Purpose:
9
+ * - Validate that the code is syntactically valid JavaScript
10
+ * - Check that it looks like a function expression / arrow function
11
+ * - Provide fast, descriptive error messages to the LLM
12
+ *
13
+ * Properties:
14
+ * - Zero runtime dependencies (pure string analysis)
15
+ * - Fail-fast: rejects obviously broken code before V8 boot
16
+ * - NOT a security gate (LLMs can obfuscate; the Isolate is the real wall)
17
+ *
18
+ * @module
19
+ * @internal
20
+ */
21
+ // ── Constants ────────────────────────────────────────────
22
+ /**
23
+ * Patterns that indicate the code is NOT a pure function.
24
+ * These are fail-fast hints, not security barriers.
25
+ * The V8 Isolate with an empty Context is the real security wall.
26
+ */
27
+ const SUSPICIOUS_PATTERNS = [
28
+ { pattern: /\bimport\s*\(/, reason: 'Dynamic import() is not available in the sandbox.' },
29
+ { pattern: /\bimport\s+/, reason: 'ES module imports are not available in the sandbox.' },
30
+ { pattern: /\brequire\s*\(/, reason: 'require() is not available in the sandbox.' },
31
+ ];
32
+ /**
33
+ * The code must start with one of these patterns to be recognized
34
+ * as a function expression or arrow function.
35
+ */
36
+ const FUNCTION_PATTERNS = [
37
+ /^\s*\(.*\)\s*=>/s, // (x) => ...
38
+ /^\s*[a-zA-Z_$]\w*\s*=>/, // x => ...
39
+ /^\s*function\s*\(/, // function(x) { ... }
40
+ /^\s*function\s+\w+\s*\(/, // function name(x) { ... }
41
+ /^\s*async\s+\(.*\)\s*=>/s, // async (x) => ...
42
+ /^\s*async\s+function\s*\(/, // async function(x) { ... }
43
+ /^\s*async\s+[a-zA-Z_$]\w*\s*=>/, // async x => ...
44
+ ];
45
+ // ── Guard Implementation ─────────────────────────────────
46
+ /**
47
+ * Validate LLM-provided code before sending it to the sandbox.
48
+ *
49
+ * Performs two checks:
50
+ * 1. **Shape check**: The code must look like a function expression
51
+ * 2. **Suspicious pattern check**: Fail-fast for obviously unsandboxable patterns
52
+ *
53
+ * @param code - The JavaScript code string from the LLM
54
+ * @returns A `GuardResult` indicating whether the code passed
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * const result = validateSandboxCode('(data) => data.filter(d => d.x > 5)');
59
+ * // { ok: true }
60
+ *
61
+ * const bad = validateSandboxCode('require("fs").readFileSync("/etc/passwd")');
62
+ * // { ok: false, violation: 'Code must be a function expression...' }
63
+ * ```
64
+ */
65
+ export function validateSandboxCode(code) {
66
+ if (!code || typeof code !== 'string') {
67
+ return { ok: false, violation: 'Code must be a non-empty string.' };
68
+ }
69
+ const trimmed = code.trim();
70
+ if (trimmed.length === 0) {
71
+ return { ok: false, violation: 'Code must be a non-empty string.' };
72
+ }
73
+ // Shape check: must look like a function
74
+ const looksLikeFunction = FUNCTION_PATTERNS.some(p => p.test(trimmed));
75
+ if (!looksLikeFunction) {
76
+ return {
77
+ ok: false,
78
+ violation: 'Code must be a function expression or arrow function. ' +
79
+ 'Example: (data) => data.filter(d => d.value > 10)',
80
+ };
81
+ }
82
+ // Suspicious pattern check (fail-fast hints, not security)
83
+ for (const { pattern, reason } of SUSPICIOUS_PATTERNS) {
84
+ if (pattern.test(trimmed)) {
85
+ return { ok: false, violation: reason };
86
+ }
87
+ }
88
+ return { ok: true };
89
+ }
90
+ //# sourceMappingURL=SandboxGuard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SandboxGuard.js","sourceRoot":"","sources":["../../src/sandbox/SandboxGuard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAWH,4DAA4D;AAE5D;;;;GAIG;AACH,MAAM,mBAAmB,GAAuD;IAC5E,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,mDAAmD,EAAE;IACzF,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,qDAAqD,EAAE;IACzF,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,4CAA4C,EAAE;CACtF,CAAC;AAEF;;;GAGG;AACH,MAAM,iBAAiB,GAA0B;IAC7C,kBAAkB,EAAe,aAAa;IAC9C,wBAAwB,EAAQ,WAAW;IAC3C,mBAAmB,EAAc,sBAAsB;IACvD,yBAAyB,EAAQ,2BAA2B;IAC5D,0BAA0B,EAAO,mBAAmB;IACpD,2BAA2B,EAAM,4BAA4B;IAC7D,gCAAgC,EAAE,iBAAiB;CACtD,CAAC;AAEF,4DAA4D;AAE5D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC5C,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,kCAAkC,EAAE,CAAC;IACxE,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAE5B,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,kCAAkC,EAAE,CAAC;IACxE,CAAC;IAED,yCAAyC;IACzC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACvE,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACrB,OAAO;YACH,EAAE,EAAE,KAAK;YACT,SAAS,EACL,wDAAwD;gBACxD,mDAAmD;SAC1D,CAAC;IACN,CAAC;IAED,2DAA2D;IAC3D,KAAK,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,mBAAmB,EAAE,CAAC;QACpD,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACxB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;QAC5C,CAAC;IACL,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AACxB,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Sandbox — Barrel Export
3
+ *
4
+ * Zero-Trust Computation Delegation via isolated-vm.
5
+ * Allows LLMs to send JavaScript functions to be executed
6
+ * in a sealed V8 isolate on the client's machine.
7
+ *
8
+ * The `isolated-vm` package is an optional peerDependency.
9
+ * The framework works fully without it — sandbox is a power add-on.
10
+ */
11
+ export { SandboxEngine } from './SandboxEngine.js';
12
+ export type { SandboxConfig, SandboxResult, SandboxErrorCode } from './SandboxEngine.js';
13
+ export { validateSandboxCode } from './SandboxGuard.js';
14
+ export type { GuardResult } from './SandboxGuard.js';
15
+ /**
16
+ * System instruction auto-injected into the tool description
17
+ * when `.sandboxed()` is used. Teaches the LLM how to send
18
+ * JavaScript functions for server-side computation delegation.
19
+ *
20
+ * @internal
21
+ */
22
+ export declare const SANDBOX_SYSTEM_INSTRUCTION: string;
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,QAKiC,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Sandbox — Barrel Export
3
+ *
4
+ * Zero-Trust Computation Delegation via isolated-vm.
5
+ * Allows LLMs to send JavaScript functions to be executed
6
+ * in a sealed V8 isolate on the client's machine.
7
+ *
8
+ * The `isolated-vm` package is an optional peerDependency.
9
+ * The framework works fully without it — sandbox is a power add-on.
10
+ */
11
+ export { SandboxEngine } from './SandboxEngine.js';
12
+ export { validateSandboxCode } from './SandboxGuard.js';
13
+ // ── HATEOAS Auto-Prompting Instruction ───────────────────
14
+ /**
15
+ * System instruction auto-injected into the tool description
16
+ * when `.sandboxed()` is used. Teaches the LLM how to send
17
+ * JavaScript functions for server-side computation delegation.
18
+ *
19
+ * @internal
20
+ */
21
+ export const SANDBOX_SYSTEM_INSTRUCTION = '\n\n[SYSTEM: This tool supports Zero-Trust Compute. ' +
22
+ 'You MUST pass a valid, pure, synchronous JavaScript arrow function as a string ' +
23
+ 'to filter/map the data on the server before receiving it. ' +
24
+ 'E.g.: (data) => data.filter(d => d.value > 10). ' +
25
+ 'Do not use markdown formatting, async/await, or external imports.]';
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAGxD,4DAA4D;AAE5D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,0BAA0B,GACnC,sDAAsD;IACtD,iFAAiF;IACjF,4DAA4D;IAC5D,kDAAkD;IAClD,oEAAoE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vinkius-core/mcp-fusion",
3
- "version": "2.12.0",
3
+ "version": "2.13.1",
4
4
  "description": "MVA (Model-View-Agent) framework for the Model Context Protocol. Structured perception packages with Presenters, cognitive guardrails, self-healing errors, action consolidation, and tRPC-style type safety — so AI agents perceive and act on your data deterministically.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -52,6 +52,10 @@
52
52
  "./introspection": {
53
53
  "import": "./dist/introspection/index.js",
54
54
  "types": "./dist/introspection/index.d.ts"
55
+ },
56
+ "./sandbox": {
57
+ "import": "./dist/sandbox/index.js",
58
+ "types": "./dist/sandbox/index.d.ts"
55
59
  }
56
60
  },
57
61
  "scripts": {
@@ -108,11 +112,19 @@
108
112
  },
109
113
  "peerDependencies": {
110
114
  "@modelcontextprotocol/sdk": "^1.12.1",
115
+ "fast-json-stringify": "^6.0.0",
116
+ "isolated-vm": "^5.0.4",
111
117
  "zod": "^3.25.1 || ^4.0.0"
112
118
  },
113
119
  "peerDependenciesMeta": {
114
120
  "zod": {
115
121
  "optional": true
122
+ },
123
+ "isolated-vm": {
124
+ "optional": true
125
+ },
126
+ "fast-json-stringify": {
127
+ "optional": true
116
128
  }
117
129
  },
118
130
  "license": "Apache-2.0"