@cyanheads/calculator-mcp-server 0.2.0 → 0.3.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/AGENTS.md +2 -2
- package/CLAUDE.md +2 -2
- package/README.md +1 -1
- package/dist/mcp-server/tools/definitions/calculate.tool.d.ts +4 -4
- package/dist/mcp-server/tools/definitions/calculate.tool.js +12 -12
- package/dist/mcp-server/tools/definitions/calculate.tool.js.map +1 -1
- package/dist/services/math/math-service.d.ts +16 -0
- package/dist/services/math/math-service.d.ts.map +1 -1
- package/dist/services/math/math-service.js +70 -5
- package/dist/services/math/math-service.js.map +1 -1
- package/package.json +1 -1
- package/server.json +3 -3
package/AGENTS.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Agent Protocol
|
|
2
2
|
|
|
3
3
|
**Server:** calculator-mcp-server
|
|
4
|
-
**Version:** 0.
|
|
4
|
+
**Version:** 0.3.0
|
|
5
5
|
**Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.9.16`
|
|
6
6
|
**Engines:** Bun ≥1.3.0, Node ≥24.0.0
|
|
7
7
|
**MCP SDK:** `@modelcontextprotocol/sdk` 1.29.0
|
|
@@ -20,7 +20,7 @@ A publicly-hosted calculator MCP server that lets any LLM verify mathematical co
|
|
|
20
20
|
|
|
21
21
|
### Security Model
|
|
22
22
|
|
|
23
|
-
MathService wraps a **hardened math.js instance** — dangerous functions (`import`, `createUnit`, `evaluate`, `parse`, `compile`, `chain`, `config`, `resolve`, `reviver`, `parser`) are disabled in the expression scope. `simplify` and `derivative` are also disabled in expressions but called programmatically by the tool handler. Evaluation runs inside `vm.runInNewContext()` with a timeout. Input length is capped. Expression separators (semicolons and newlines) are rejected — single expression per call only. Variable scope accepts `z.record(z.number())` only with prototype-polluting keys blocked. Result types are validated (functions, parsers, and result sets rejected). Result size is capped via `CALC_MAX_RESULT_LENGTH`. The math.js `version` constant is redacted to prevent fingerprinting.
|
|
23
|
+
MathService wraps a **hardened math.js instance** — dangerous functions (`import`, `createUnit`, `evaluate`, `parse`, `compile`, `chain`, `config`, `resolve`, `reviver`, `parser`) are disabled in the expression scope. `simplify` and `derivative` are also disabled in expressions but called programmatically by the tool handler. Evaluation runs inside `vm.runInNewContext()` with a timeout. Input length is capped. Expression separators (semicolons and newlines) are rejected — single expression per call only (the separator scan is string-literal-aware so `;` inside `"..."` is not treated as a statement break). Variable scope accepts `z.record(z.number())` only with prototype-polluting keys blocked. Result types are validated (functions, parsers, and result sets rejected). `.toString()` / `.toLocaleString()` access on any value is rejected at parse time via an AST check — these method calls on function-valued identifiers would otherwise bypass the result-type guard by returning source as a plain string. Result size is capped via `CALC_MAX_RESULT_LENGTH`. The math.js `version` constant is redacted to prevent fingerprinting.
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
package/CLAUDE.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Agent Protocol
|
|
2
2
|
|
|
3
3
|
**Server:** calculator-mcp-server
|
|
4
|
-
**Version:** 0.
|
|
4
|
+
**Version:** 0.3.0
|
|
5
5
|
**Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.9.16`
|
|
6
6
|
**Engines:** Bun ≥1.3.0, Node ≥24.0.0
|
|
7
7
|
**MCP SDK:** `@modelcontextprotocol/sdk` 1.29.0
|
|
@@ -20,7 +20,7 @@ A publicly-hosted calculator MCP server that lets any LLM verify mathematical co
|
|
|
20
20
|
|
|
21
21
|
### Security Model
|
|
22
22
|
|
|
23
|
-
MathService wraps a **hardened math.js instance** — dangerous functions (`import`, `createUnit`, `evaluate`, `parse`, `compile`, `chain`, `config`, `resolve`, `reviver`, `parser`) are disabled in the expression scope. `simplify` and `derivative` are also disabled in expressions but called programmatically by the tool handler. Evaluation runs inside `vm.runInNewContext()` with a timeout. Input length is capped. Expression separators (semicolons and newlines) are rejected — single expression per call only. Variable scope accepts `z.record(z.number())` only with prototype-polluting keys blocked. Result types are validated (functions, parsers, and result sets rejected). Result size is capped via `CALC_MAX_RESULT_LENGTH`. The math.js `version` constant is redacted to prevent fingerprinting.
|
|
23
|
+
MathService wraps a **hardened math.js instance** — dangerous functions (`import`, `createUnit`, `evaluate`, `parse`, `compile`, `chain`, `config`, `resolve`, `reviver`, `parser`) are disabled in the expression scope. `simplify` and `derivative` are also disabled in expressions but called programmatically by the tool handler. Evaluation runs inside `vm.runInNewContext()` with a timeout. Input length is capped. Expression separators (semicolons and newlines) are rejected — single expression per call only (the separator scan is string-literal-aware so `;` inside `"..."` is not treated as a statement break). Variable scope accepts `z.record(z.number())` only with prototype-polluting keys blocked. Result types are validated (functions, parsers, and result sets rejected). `.toString()` / `.toLocaleString()` access on any value is rejected at parse time via an AST check — these method calls on function-valued identifiers would otherwise bypass the result-type guard by returning source as a plain string. Result size is capped via `CALC_MAX_RESULT_LENGTH`. The math.js `version` constant is redacted to prevent fingerprinting.
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
<div align="center">
|
|
9
9
|
|
|
10
|
-
[](./CHANGELOG.md) [](./LICENSE) [](https://github.com/users/cyanheads/packages/container/package/calculator-mcp-server) [](https://modelcontextprotocol.io/) [](https://www.npmjs.com/package/@cyanheads/calculator-mcp-server) [](https://www.typescriptlang.org/) [](https://bun.sh/)
|
|
11
11
|
|
|
12
12
|
</div>
|
|
13
13
|
|
|
@@ -24,8 +24,8 @@ export declare const calculateTool: import("@cyanheads/mcp-ts-core").ToolDefinit
|
|
|
24
24
|
simplify: "simplify";
|
|
25
25
|
derivative: "derivative";
|
|
26
26
|
}>;
|
|
27
|
-
scopeVars: z.
|
|
28
|
-
precisionUsed: z.
|
|
27
|
+
scopeVars: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
28
|
+
precisionUsed: z.ZodOptional<z.ZodNumber>;
|
|
29
29
|
}, z.core.$strip>, readonly [{
|
|
30
30
|
readonly reason: "empty_expression";
|
|
31
31
|
readonly code: JsonRpcErrorCode.ValidationError;
|
|
@@ -49,8 +49,8 @@ export declare const calculateTool: import("@cyanheads/mcp-ts-core").ToolDefinit
|
|
|
49
49
|
}, {
|
|
50
50
|
readonly reason: "disallowed_result_type";
|
|
51
51
|
readonly code: JsonRpcErrorCode.ValidationError;
|
|
52
|
-
readonly when: "Result
|
|
53
|
-
readonly recovery: "Rewrite the expression to produce a value (number, matrix, unit) instead of a function or
|
|
52
|
+
readonly when: "Result is a function, parser, or multi-expression ResultSet, or the expression converts a function to a string (e.g. `cos.toString()`) — security guard.";
|
|
53
|
+
readonly recovery: "Rewrite the expression to produce a value (number, matrix, unit) instead of a function or its source.";
|
|
54
54
|
}, {
|
|
55
55
|
readonly reason: "result_too_large";
|
|
56
56
|
readonly code: JsonRpcErrorCode.ValidationError;
|
|
@@ -56,12 +56,12 @@ export const calculateTool = tool('calculate', {
|
|
|
56
56
|
.describe('The operation that was applied.'),
|
|
57
57
|
scopeVars: z
|
|
58
58
|
.array(z.string())
|
|
59
|
-
.
|
|
60
|
-
.describe('Keys from the scope that were active during evaluation
|
|
59
|
+
.optional()
|
|
60
|
+
.describe('Keys from the scope that were active during evaluation. Omitted when no scope was provided. Values are omitted to keep output compact.'),
|
|
61
61
|
precisionUsed: z
|
|
62
62
|
.number()
|
|
63
|
-
.
|
|
64
|
-
.describe('Significant-digit precision
|
|
63
|
+
.optional()
|
|
64
|
+
.describe('Significant-digit precision applied to the result. Omitted when full precision was used or the operation is symbolic.'),
|
|
65
65
|
}),
|
|
66
66
|
errors: [
|
|
67
67
|
{
|
|
@@ -91,8 +91,8 @@ export const calculateTool = tool('calculate', {
|
|
|
91
91
|
{
|
|
92
92
|
reason: 'disallowed_result_type',
|
|
93
93
|
code: JsonRpcErrorCode.ValidationError,
|
|
94
|
-
when: 'Result
|
|
95
|
-
recovery: 'Rewrite the expression to produce a value (number, matrix, unit) instead of a function or
|
|
94
|
+
when: 'Result is a function, parser, or multi-expression ResultSet, or the expression converts a function to a string (e.g. `cos.toString()`) — security guard.',
|
|
95
|
+
recovery: 'Rewrite the expression to produce a value (number, matrix, unit) instead of a function or its source.',
|
|
96
96
|
},
|
|
97
97
|
{
|
|
98
98
|
reason: 'result_too_large',
|
|
@@ -138,29 +138,29 @@ export const calculateTool = tool('calculate', {
|
|
|
138
138
|
...math.evaluateExpression(expression, ctx, scope, precision),
|
|
139
139
|
expression,
|
|
140
140
|
operation,
|
|
141
|
-
|
|
142
|
-
precisionUsed
|
|
141
|
+
// Omit context fields that carry no signal: scopeVars only when a scope
|
|
142
|
+
// was supplied, precisionUsed only when a precision was applied (#14).
|
|
143
|
+
...(scope ? { scopeVars: Object.keys(scope) } : {}),
|
|
144
|
+
...(precision !== undefined ? { precisionUsed: precision } : {}),
|
|
143
145
|
};
|
|
144
146
|
case 'simplify':
|
|
145
147
|
ctx.log.info('Simplified expression', { expression });
|
|
148
|
+
// Symbolic operations never carry scope/precision context — omit both.
|
|
146
149
|
return {
|
|
147
150
|
...math.simplifyExpression(expression, ctx),
|
|
148
151
|
expression,
|
|
149
152
|
operation,
|
|
150
|
-
scopeVars: null,
|
|
151
|
-
precisionUsed: null,
|
|
152
153
|
};
|
|
153
154
|
case 'derivative':
|
|
154
155
|
if (!variable) {
|
|
155
156
|
throw ctx.fail('derivative_missing_variable', "The 'variable' parameter is required when operation is 'derivative'.", { ...ctx.recoveryFor('derivative_missing_variable') });
|
|
156
157
|
}
|
|
157
158
|
ctx.log.info('Differentiated expression', { expression, variable });
|
|
159
|
+
// Symbolic operations never carry scope/precision context — omit both.
|
|
158
160
|
return {
|
|
159
161
|
...math.differentiateExpression(expression, variable, ctx),
|
|
160
162
|
expression,
|
|
161
163
|
operation,
|
|
162
|
-
scopeVars: null,
|
|
163
|
-
precisionUsed: null,
|
|
164
164
|
};
|
|
165
165
|
default:
|
|
166
166
|
throw new Error(`Unhandled operation: ${operation}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculate.tool.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/calculate.tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjE,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,EAAE;IAC7C,WAAW,EACT,0NAA0N;IAC5N,WAAW,EAAE;QACX,YAAY,EAAE,IAAI;QAClB,cAAc,EAAE,IAAI;QACpB,aAAa,EAAE,KAAK;KACrB;IACD,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;QACd,UAAU,EAAE,CAAC;aACV,MAAM,EAAE;aACR,GAAG,CAAC,CAAC,CAAC;aACN,QAAQ,CACP,+dAA+d,CAChe;QACH,SAAS,EAAE,CAAC;aACT,IAAI,CAAC,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;aAC5C,OAAO,CAAC,UAAU,CAAC;aACnB,QAAQ,CACP,+RAA+R,CAChS;QACH,QAAQ,EAAE,CAAC;aACR,KAAK,CAAC;YACL,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,oCAAoC,CAAC;YAC5D,CAAC;iBACE,MAAM,EAAE;iBACR,GAAG,CAAC,EAAE,CAAC;iBACP,KAAK,CACJ,0BAA0B,EAC1B,wDAAwD,CACzD;iBACA,QAAQ,CAAC,mEAAmE,CAAC;SACjF,CAAC;aACD,QAAQ,EAAE;aACV,QAAQ,CACP,uIAAuI,CACxI;QACH,KAAK,EAAE,CAAC;aACL,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;aAC9B,QAAQ,EAAE;aACV,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AM,EAAE,EAAE;QACjB,MAAM,SAAS,GACb,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QACzF,MAAM,SAAS,GAAG,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC;QACjD,OAAO;YACL;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,qBAAqB,MAAM,CAAC,UAAU,sBAAsB,MAAM,CAAC,SAAS,iBAAiB,MAAM,CAAC,MAAM,eAAe,MAAM,CAAC,UAAU,0BAA0B,SAAS,oBAAoB,SAAS,EAAE;aACnN;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -9,6 +9,7 @@ import type { ServerConfig } from '../../config/server-config.js';
|
|
|
9
9
|
import type { MathResult } from './types.js';
|
|
10
10
|
export declare class MathService {
|
|
11
11
|
private readonly evaluate;
|
|
12
|
+
private readonly parse;
|
|
12
13
|
private readonly simplify;
|
|
13
14
|
private readonly derivative;
|
|
14
15
|
private readonly simplifyRules;
|
|
@@ -33,6 +34,21 @@ export declare class MathService {
|
|
|
33
34
|
private validateFinite;
|
|
34
35
|
/** Reject results that exceed the configured maximum size. */
|
|
35
36
|
private validateResultSize;
|
|
37
|
+
/**
|
|
38
|
+
* Reject expressions that access `.toString` / `.toLocaleString` on any value.
|
|
39
|
+
* math.js permits these methods on function-valued identifiers (`cos.toString()`,
|
|
40
|
+
* `import.toString()`), returning the function's source as a plain string — which
|
|
41
|
+
* slips past {@link validateResultType}, whose function defense only inspects the
|
|
42
|
+
* value AFTER stringification. The check is parse-time and AST-based rather than a
|
|
43
|
+
* runtime `Function.prototype` patch: math.js itself calls `toString` on functions
|
|
44
|
+
* internally while evaluating units, statistics, and complex results, so patching
|
|
45
|
+
* the prototype would reject legitimate expressions. No real calculator expression
|
|
46
|
+
* needs `.toString()`/`.toLocaleString()`, so blocking the accessor outright (dot
|
|
47
|
+
* or bracket form, on any operand) is both sufficient and side-effect-free. String
|
|
48
|
+
* literals that merely contain the text "toString" parse as ConstantNodes, not
|
|
49
|
+
* accessors, so they are unaffected.
|
|
50
|
+
*/
|
|
51
|
+
private validateNoFunctionStringification;
|
|
36
52
|
/** Runs a synchronous function inside a vm sandbox with timeout protection. */
|
|
37
53
|
private runWithTimeout;
|
|
38
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math-service.d.ts","sourceRoot":"","sources":["../../../src/services/math/math-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAGtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"math-service.d.ts","sourceRoot":"","sources":["../../../src/services/math/math-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAGtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA0L7C,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA4D;IACrF,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA6B;IACnD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmE;IAC5F,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA6D;IACxF,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAC/C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAGX;IACZ,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6B;IACpD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;gBAE1B,MAAM,EAAE,YAAY;IAiChC,6EAA6E;IAC7E,kBAAkB,CAChB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,OAAO,EACZ,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,SAAS,CAAC,EAAE,MAAM,GACjB,UAAU;IAuBb,qDAAqD;IACrD,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,UAAU;IAYhE,mFAAmF;IACnF,uBAAuB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,UAAU;IASvF,qFAAqF;IACrF,cAAc,IAAI,MAAM;IAIxB,OAAO,CAAC,aAAa;IAqBrB,uEAAuE;IACvE,OAAO,CAAC,aAAa;IAWrB,iGAAiG;IACjG,OAAO,CAAC,kBAAkB;IAS1B,2HAA2H;IAC3H,OAAO,CAAC,cAAc;IAStB,8DAA8D;IAC9D,OAAO,CAAC,kBAAkB;IAS1B;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,iCAAiC;IAyBzC,+EAA+E;IAC/E,OAAO,CAAC,cAAc;CAoBvB;AAMD,qEAAqE;AACrE,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAE1D;AAED,iDAAiD;AACjD,wBAAgB,cAAc,IAAI,WAAW,CAG5C"}
|
|
@@ -76,6 +76,14 @@ const REDACTED_CONSTANTS = {
|
|
|
76
76
|
* ResultSet indicates multi-expression evaluation (newline bypass).
|
|
77
77
|
*/
|
|
78
78
|
const BLOCKED_RESULT_TYPES = new Set(['function', 'Function', 'ResultSet', 'Parser']);
|
|
79
|
+
/**
|
|
80
|
+
* Method names that coerce a value to a string. Blocked at parse time on any
|
|
81
|
+
* accessor: `.toString()` / `.toLocaleString()` on a function-valued identifier
|
|
82
|
+
* (e.g. `cos.toString()`) otherwise returns internal source as a plain string,
|
|
83
|
+
* slipping past {@link BLOCKED_RESULT_TYPES} (which only sees the value after
|
|
84
|
+
* stringification). See {@link MathService.validateNoFunctionStringification}.
|
|
85
|
+
*/
|
|
86
|
+
const STRINGIFYING_METHODS = new Set(['toString', 'toLocaleString']);
|
|
79
87
|
/**
|
|
80
88
|
* Scope key names that could pollute the object prototype chain or shadow
|
|
81
89
|
* critical Object.prototype methods. Validated before passing to math.js.
|
|
@@ -96,14 +104,35 @@ const BLOCKED_SCOPE_KEYS = new Set([
|
|
|
96
104
|
'toLocaleString',
|
|
97
105
|
]);
|
|
98
106
|
/**
|
|
99
|
-
* Check for expression separators
|
|
100
|
-
*
|
|
101
|
-
*
|
|
107
|
+
* Check for expression separators (`;` or newline) that split the input into
|
|
108
|
+
* multiple statements. Three contexts are NOT separators and are skipped:
|
|
109
|
+
* - `;` inside `[...]` — a matrix row separator (`[1, 2; 3, 4]`).
|
|
110
|
+
* - `;` or a newline inside a double-quoted string literal — part of the data,
|
|
111
|
+
* not a statement break (`"a;b"`, `concat("a;b", "c")`).
|
|
112
|
+
* - `[` / `]` inside a string literal — they must not shift the bracket depth,
|
|
113
|
+
* or a string such as `"]"` would let a later top-level `;` slip past.
|
|
114
|
+
*
|
|
115
|
+
* Single quotes are NOT string delimiters in math.js — `'` is the transpose
|
|
116
|
+
* operator (`A'`) — so only `"` opens a string span, and a backslash escapes the
|
|
117
|
+
* next character within it (`"\""` stays open). The scan is intentionally
|
|
118
|
+
* lexical rather than a full parse: it only has to recognize quoted spans, and a
|
|
119
|
+
* genuine multi-statement input (`1+2; 3+4`) is still caught at depth 0.
|
|
102
120
|
*/
|
|
103
121
|
function hasExpressionSeparator(expr) {
|
|
104
122
|
let depth = 0;
|
|
105
|
-
|
|
106
|
-
|
|
123
|
+
let inString = false;
|
|
124
|
+
for (let i = 0; i < expr.length; i++) {
|
|
125
|
+
const ch = expr[i];
|
|
126
|
+
if (inString) {
|
|
127
|
+
if (ch === '\\')
|
|
128
|
+
i++;
|
|
129
|
+
else if (ch === '"')
|
|
130
|
+
inString = false;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (ch === '"')
|
|
134
|
+
inString = true;
|
|
135
|
+
else if (ch === '[')
|
|
107
136
|
depth++;
|
|
108
137
|
else if (ch === ']')
|
|
109
138
|
depth--;
|
|
@@ -160,6 +189,7 @@ function normalizeNotation(expression) {
|
|
|
160
189
|
}
|
|
161
190
|
export class MathService {
|
|
162
191
|
evaluate;
|
|
192
|
+
parse;
|
|
163
193
|
simplify;
|
|
164
194
|
derivative;
|
|
165
195
|
simplifyRules;
|
|
@@ -172,6 +202,7 @@ export class MathService {
|
|
|
172
202
|
const math = create(all);
|
|
173
203
|
// Save references before overriding — these bypass the expression scope restrictions
|
|
174
204
|
this.evaluate = math.evaluate.bind(math);
|
|
205
|
+
this.parse = math.parse.bind(math);
|
|
175
206
|
this.simplify = math.simplify.bind(math);
|
|
176
207
|
this.derivative = math.derivative.bind(math);
|
|
177
208
|
this.simplifyRules = [...math.simplify.rules, ...TRIG_SIMPLIFY_RULES];
|
|
@@ -200,6 +231,7 @@ export class MathService {
|
|
|
200
231
|
if (scope)
|
|
201
232
|
this.validateScope(scope, ctx);
|
|
202
233
|
const normalized = normalizeNotation(expression);
|
|
234
|
+
this.validateNoFunctionStringification(normalized, ctx);
|
|
203
235
|
const raw = this.runWithTimeout(() => (scope ? this.evaluate(normalized, scope) : this.evaluate(normalized)), ctx);
|
|
204
236
|
const resultType = this.typeOf(raw);
|
|
205
237
|
this.validateResultType(resultType, ctx);
|
|
@@ -276,6 +308,39 @@ export class MathService {
|
|
|
276
308
|
throw validationError(`Result exceeds maximum size (${this.config.maxResultLength} characters). Reduce matrix dimensions or simplify the expression.`, { reason: 'result_too_large', ...ctx.recoveryFor('result_too_large') });
|
|
277
309
|
}
|
|
278
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* Reject expressions that access `.toString` / `.toLocaleString` on any value.
|
|
313
|
+
* math.js permits these methods on function-valued identifiers (`cos.toString()`,
|
|
314
|
+
* `import.toString()`), returning the function's source as a plain string — which
|
|
315
|
+
* slips past {@link validateResultType}, whose function defense only inspects the
|
|
316
|
+
* value AFTER stringification. The check is parse-time and AST-based rather than a
|
|
317
|
+
* runtime `Function.prototype` patch: math.js itself calls `toString` on functions
|
|
318
|
+
* internally while evaluating units, statistics, and complex results, so patching
|
|
319
|
+
* the prototype would reject legitimate expressions. No real calculator expression
|
|
320
|
+
* needs `.toString()`/`.toLocaleString()`, so blocking the accessor outright (dot
|
|
321
|
+
* or bracket form, on any operand) is both sufficient and side-effect-free. String
|
|
322
|
+
* literals that merely contain the text "toString" parse as ConstantNodes, not
|
|
323
|
+
* accessors, so they are unaffected.
|
|
324
|
+
*/
|
|
325
|
+
validateNoFunctionStringification(expr, ctx) {
|
|
326
|
+
let ast;
|
|
327
|
+
try {
|
|
328
|
+
ast = this.parse(expr);
|
|
329
|
+
}
|
|
330
|
+
catch {
|
|
331
|
+
// Let the evaluate path surface parse errors with full mathjs context.
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const accessesStringifier = ast.filter((node) => {
|
|
335
|
+
if (node.type !== 'IndexNode')
|
|
336
|
+
return false;
|
|
337
|
+
const { dimensions } = node;
|
|
338
|
+
return dimensions.some((dim) => dim.type === 'ConstantNode' && STRINGIFYING_METHODS.has(String(dim.value)));
|
|
339
|
+
});
|
|
340
|
+
if (accessesStringifier.length > 0) {
|
|
341
|
+
throw validationError('Converting a function to a string is not allowed — it would expose internal source. Only numeric, string, matrix, complex, unit, and boolean results are allowed.', { reason: 'disallowed_result_type', ...ctx.recoveryFor('disallowed_result_type') });
|
|
342
|
+
}
|
|
343
|
+
}
|
|
279
344
|
/** Runs a synchronous function inside a vm sandbox with timeout protection. */
|
|
280
345
|
runWithTimeout(fn, ctx) {
|
|
281
346
|
const sandbox = { fn, result: undefined };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math-service.js","sourceRoot":"","sources":["../../../src/services/math/math-service.ts"],"names":[],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YACjE,MAAM,eAAe,CAAC,uBAAuB,OAAO,EAAE,EAAE;gBACtD,MAAM,EAAE,cAAc;gBACtB,GAAG,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC;aACnC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AAED,gCAAgC;AAEhC,IAAI,QAAiC,CAAC;AAEtC,qEAAqE;AACrE,MAAM,UAAU,eAAe,CAAC,MAAoB;IAClD,QAAQ,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,cAAc;IAC5B,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;IAClG,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,uBAAuB;AAEvB,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkGpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyanheads/calculator-mcp-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Evaluate, simplify, and differentiate mathematical expressions via MCP. STDIO or Streamable HTTP.",
|
|
5
5
|
"mcpName": "io.github.cyanheads/calculator-mcp-server",
|
|
6
6
|
"type": "module",
|
package/server.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"url": "https://github.com/cyanheads/calculator-mcp-server",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.3.0",
|
|
10
10
|
"remotes": [
|
|
11
11
|
{
|
|
12
12
|
"type": "streamable-http",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"registryBaseUrl": "https://registry.npmjs.org",
|
|
20
20
|
"identifier": "@cyanheads/calculator-mcp-server",
|
|
21
21
|
"runtimeHint": "bun",
|
|
22
|
-
"version": "0.
|
|
22
|
+
"version": "0.3.0",
|
|
23
23
|
"packageArguments": [
|
|
24
24
|
{
|
|
25
25
|
"type": "positional",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"registryBaseUrl": "https://registry.npmjs.org",
|
|
70
70
|
"identifier": "@cyanheads/calculator-mcp-server",
|
|
71
71
|
"runtimeHint": "bun",
|
|
72
|
-
"version": "0.
|
|
72
|
+
"version": "0.3.0",
|
|
73
73
|
"packageArguments": [
|
|
74
74
|
{
|
|
75
75
|
"type": "positional",
|