@pipeworx/mcp-newton 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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -0
  3. package/package.json +18 -0
  4. package/src/index.ts +128 -0
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,32 @@
1
+ # @pipeworx/mcp-newton
2
+
3
+ MCP server for symbolic math operations via the [Newton API](https://newton.vercel.app/). Free, no authentication required.
4
+
5
+ ## Tools
6
+
7
+ | Tool | Description |
8
+ |------|-------------|
9
+ | `simplify` | Simplify a mathematical expression |
10
+ | `derive` | Compute the derivative of an expression with respect to x |
11
+ | `integrate` | Compute the indefinite integral of an expression |
12
+ | `factor` | Factor a polynomial expression |
13
+
14
+ ## Quickstart via Pipeworx Gateway
15
+
16
+ ```bash
17
+ curl -X POST https://gateway.pipeworx.io/mcp \
18
+ -H "Content-Type: application/json" \
19
+ -d '{
20
+ "jsonrpc": "2.0",
21
+ "method": "tools/call",
22
+ "params": {
23
+ "name": "newton__derive",
24
+ "arguments": { "expression": "x^3+2x^2+x" }
25
+ },
26
+ "id": 1
27
+ }'
28
+ ```
29
+
30
+ ## License
31
+
32
+ MIT
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@pipeworx/mcp-newton",
3
+ "version": "0.1.0",
4
+ "description": "MCP server for symbolic math (simplify, derive, integrate, factor) via Newton API",
5
+ "main": "src/index.ts",
6
+ "types": "src/index.ts",
7
+ "files": ["src"],
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "check": "tsc --noEmit"
11
+ },
12
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "newton", "math", "calculus", "algebra"],
13
+ "author": "Pipeworx",
14
+ "license": "MIT",
15
+ "devDependencies": {
16
+ "typescript": "^5.0.0"
17
+ }
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Newton MCP — wraps the Newton math solver API (free, no auth)
3
+ *
4
+ * Tools:
5
+ * - simplify: simplify a mathematical expression
6
+ * - derive: find the derivative of an expression with respect to x
7
+ * - integrate: find the indefinite integral of an expression
8
+ * - factor: factor a polynomial expression
9
+ */
10
+
11
+ interface McpToolDefinition {
12
+ name: string;
13
+ description: string;
14
+ inputSchema: {
15
+ type: 'object';
16
+ properties: Record<string, unknown>;
17
+ required?: string[];
18
+ };
19
+ }
20
+
21
+ interface McpToolExport {
22
+ tools: McpToolDefinition[];
23
+ callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
24
+ }
25
+
26
+ const BASE_URL = 'https://newton.vercel.app/api/v2';
27
+
28
+ const tools: McpToolExport['tools'] = [
29
+ {
30
+ name: 'simplify',
31
+ description:
32
+ 'Simplify a mathematical expression (e.g., "2^2+2(2)" → "8"). Supports standard algebraic notation.',
33
+ inputSchema: {
34
+ type: 'object' as const,
35
+ properties: {
36
+ expression: {
37
+ type: 'string',
38
+ description: 'Mathematical expression to simplify (e.g., "2^2+2(2)", "x^2+2x+1")',
39
+ },
40
+ },
41
+ required: ['expression'],
42
+ },
43
+ },
44
+ {
45
+ name: 'derive',
46
+ description:
47
+ 'Compute the derivative of a mathematical expression with respect to x (e.g., "x^2" → "2 x")',
48
+ inputSchema: {
49
+ type: 'object' as const,
50
+ properties: {
51
+ expression: {
52
+ type: 'string',
53
+ description: 'Expression to differentiate (e.g., "x^2", "sin(x)", "x^3+2x^2+x")',
54
+ },
55
+ },
56
+ required: ['expression'],
57
+ },
58
+ },
59
+ {
60
+ name: 'integrate',
61
+ description:
62
+ 'Compute the indefinite integral of a mathematical expression with respect to x (e.g., "x^2" → "(1/3)x^3")',
63
+ inputSchema: {
64
+ type: 'object' as const,
65
+ properties: {
66
+ expression: {
67
+ type: 'string',
68
+ description: 'Expression to integrate (e.g., "x^2", "cos(x)", "x^3+x")',
69
+ },
70
+ },
71
+ required: ['expression'],
72
+ },
73
+ },
74
+ {
75
+ name: 'factor',
76
+ description:
77
+ 'Factor a polynomial expression (e.g., "x^2-1" → "(x-1)(x+1)", "x^2+3x+2" → "(x+1)(x+2)")',
78
+ inputSchema: {
79
+ type: 'object' as const,
80
+ properties: {
81
+ expression: {
82
+ type: 'string',
83
+ description: 'Polynomial expression to factor (e.g., "x^2-1", "x^2+3x+2")',
84
+ },
85
+ },
86
+ required: ['expression'],
87
+ },
88
+ },
89
+ ];
90
+
91
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
92
+ const expression = args.expression as string;
93
+ switch (name) {
94
+ case 'simplify':
95
+ return callNewton('simplify', expression);
96
+ case 'derive':
97
+ return callNewton('derive', expression);
98
+ case 'integrate':
99
+ return callNewton('integrate', expression);
100
+ case 'factor':
101
+ return callNewton('factor', expression);
102
+ default:
103
+ throw new Error(`Unknown tool: ${name}`);
104
+ }
105
+ }
106
+
107
+ async function callNewton(operation: string, expression: string) {
108
+ const encodedExpr = encodeURIComponent(expression);
109
+ const res = await fetch(`${BASE_URL}/${operation}/${encodedExpr}`);
110
+ if (!res.ok) throw new Error(`Newton API error: ${res.status} ${res.statusText}`);
111
+
112
+ const data = (await res.json()) as {
113
+ operation?: string;
114
+ expression?: string;
115
+ result?: string;
116
+ error?: string;
117
+ };
118
+
119
+ if (data.error) throw new Error(`Newton error: ${data.error}`);
120
+
121
+ return {
122
+ operation: data.operation ?? operation,
123
+ input: data.expression ?? expression,
124
+ result: data.result ?? null,
125
+ };
126
+ }
127
+
128
+ export default { tools, callTool } satisfies McpToolExport;