a-calc 2.2.14 → 3.0.0-beta.20250123
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 +83 -393
- package/a-calc.versions.js +5 -1
- package/browser/index.js +10 -1
- package/calc.d.ts +541 -81
- package/cjs/index.js +10 -1
- package/es/index.js +10 -1
- package/mcp-server/README.md +165 -0
- package/mcp-server/package.json +26 -0
- package/mcp-server/src/index.js +1046 -0
- package/package.json +34 -10
|
@@ -0,0 +1,1046 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
4
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
|
+
import {
|
|
6
|
+
CallToolRequestSchema,
|
|
7
|
+
ListToolsRequestSchema,
|
|
8
|
+
ListResourcesRequestSchema,
|
|
9
|
+
ReadResourceRequestSchema,
|
|
10
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
calc,
|
|
14
|
+
calc_sum,
|
|
15
|
+
calc_wrap,
|
|
16
|
+
fmt,
|
|
17
|
+
add,
|
|
18
|
+
sub,
|
|
19
|
+
mul,
|
|
20
|
+
div,
|
|
21
|
+
mod,
|
|
22
|
+
pow,
|
|
23
|
+
idiv,
|
|
24
|
+
abs,
|
|
25
|
+
neg,
|
|
26
|
+
sqrt,
|
|
27
|
+
ln,
|
|
28
|
+
exp,
|
|
29
|
+
cadd,
|
|
30
|
+
csub,
|
|
31
|
+
cmul,
|
|
32
|
+
cdiv,
|
|
33
|
+
set_config,
|
|
34
|
+
get_config,
|
|
35
|
+
} from "../../es/index.js";
|
|
36
|
+
|
|
37
|
+
// ==================== Tools 定义 ====================
|
|
38
|
+
|
|
39
|
+
const TOOLS = [
|
|
40
|
+
{
|
|
41
|
+
name: "calc",
|
|
42
|
+
description: `a-calc 核心计算函数 - 支持表达式计算、变量填充、格式化
|
|
43
|
+
|
|
44
|
+
功能特点:
|
|
45
|
+
- 高精度计算,避免 JavaScript 浮点数精度问题
|
|
46
|
+
- 支持运算符: + - * / % ** //
|
|
47
|
+
- 支持变量填充和单位计算
|
|
48
|
+
- 支持条件表达式: a > b ? x : y
|
|
49
|
+
- 支持比较运算: > < >= <= == !=
|
|
50
|
+
- 支持逻辑运算: && || !
|
|
51
|
+
- 支持链式比较: 1 < x < 10
|
|
52
|
+
- 支持内置数学函数: sqrt, sin, cos, pow, max, min 等
|
|
53
|
+
- 支持丰富的格式化选项
|
|
54
|
+
|
|
55
|
+
使用示例:
|
|
56
|
+
- calc("0.1 + 0.2") → "0.3"
|
|
57
|
+
- calc("a + b", {a: 1, b: 2}) → "3"
|
|
58
|
+
- calc("10 / 3 | =2") → "3.33"
|
|
59
|
+
- calc("1000000 | ,") → "1,000,000"
|
|
60
|
+
- calc("100元 + 50元", {_unit: true}) → "150元"
|
|
61
|
+
- calc("score >= 60 ? '及格' : '不及格'", {score: 75}) → "及格"
|
|
62
|
+
- calc("sqrt(16) + pow(2, 3)") → "12"`,
|
|
63
|
+
inputSchema: {
|
|
64
|
+
type: "object",
|
|
65
|
+
properties: {
|
|
66
|
+
expr: {
|
|
67
|
+
type: "string",
|
|
68
|
+
description: "计算表达式,支持变量名和格式化(用 | 分隔)",
|
|
69
|
+
},
|
|
70
|
+
options: {
|
|
71
|
+
type: "object",
|
|
72
|
+
description: "配置选项和变量数据",
|
|
73
|
+
properties: {
|
|
74
|
+
_error: {
|
|
75
|
+
type: ["string", "number", "null"],
|
|
76
|
+
description: "错误时的返回值,默认会抛出异常",
|
|
77
|
+
},
|
|
78
|
+
_unit: {
|
|
79
|
+
type: "boolean",
|
|
80
|
+
description: "是否启用单位计算,如 '100元 + 50元'",
|
|
81
|
+
},
|
|
82
|
+
_fmt: {
|
|
83
|
+
type: "string",
|
|
84
|
+
description: "默认格式化字符串",
|
|
85
|
+
},
|
|
86
|
+
_mode: {
|
|
87
|
+
type: "string",
|
|
88
|
+
enum: ["normal", "space", "space-all"],
|
|
89
|
+
description: "解析模式",
|
|
90
|
+
},
|
|
91
|
+
_debug: {
|
|
92
|
+
type: "boolean",
|
|
93
|
+
description: "是否启用调试模式",
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
additionalProperties: true,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
required: ["expr"],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: "fmt",
|
|
104
|
+
description: `a-calc 专用格式化函数 - 跳过表达式解析,性能更优
|
|
105
|
+
|
|
106
|
+
格式化规则:
|
|
107
|
+
- 小数位: =N(精确N位), <=N(最多N位), >=N(至少N位)
|
|
108
|
+
- 舍入: ~-(截断), ~+(进位), ~5(四舍五入), ~6(银行家舍入)
|
|
109
|
+
- 千分位: , (如 1,234,567)
|
|
110
|
+
- 百分比: % (如 12.34%)
|
|
111
|
+
- 科学计数: !e (如 1.23e+8)
|
|
112
|
+
- 正负号: + (如 +100)
|
|
113
|
+
- 返回数字: !n (返回 number 类型而非 string)
|
|
114
|
+
- 交易量缩写: !v (如 1.23M, 1.23万)
|
|
115
|
+
- 千分位预设: !t:us, !t:eu, !t:indian, !t:cn4
|
|
116
|
+
|
|
117
|
+
使用示例:
|
|
118
|
+
- fmt(100, "=2") → "100.00"
|
|
119
|
+
- fmt(1234567, ",") → "1,234,567"
|
|
120
|
+
- fmt(0.1234, "%=2") → "12.34%"
|
|
121
|
+
- fmt(123456789, "!e=2") → "1.23e+8"
|
|
122
|
+
- fmt(1234567, "!v") → "1.23M"
|
|
123
|
+
- fmt(1234567.89, "!t:eu") → "1.234.567,89"`,
|
|
124
|
+
inputSchema: {
|
|
125
|
+
type: "object",
|
|
126
|
+
properties: {
|
|
127
|
+
value: {
|
|
128
|
+
type: ["number", "string"],
|
|
129
|
+
description: "要格式化的数值",
|
|
130
|
+
},
|
|
131
|
+
format_str: {
|
|
132
|
+
type: "string",
|
|
133
|
+
description: "格式化字符串",
|
|
134
|
+
},
|
|
135
|
+
options: {
|
|
136
|
+
type: "object",
|
|
137
|
+
description: "格式化选项",
|
|
138
|
+
additionalProperties: true,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
required: ["value"],
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: "calc_sum",
|
|
146
|
+
description: `a-calc 聚合计算函数 - 对数组数据进行批量计算并求和
|
|
147
|
+
|
|
148
|
+
适用场景:
|
|
149
|
+
- 计算订单总价
|
|
150
|
+
- 统计销售额
|
|
151
|
+
- 汇总报表数据
|
|
152
|
+
|
|
153
|
+
使用示例:
|
|
154
|
+
- calc_sum("a + b", [{a:1,b:2}, {a:3,b:4}]) → "10"
|
|
155
|
+
- calc_sum("price * qty | =2", [{price:99.9,qty:2}, {price:49.9,qty:1}]) → "249.70"`,
|
|
156
|
+
inputSchema: {
|
|
157
|
+
type: "object",
|
|
158
|
+
properties: {
|
|
159
|
+
expr: {
|
|
160
|
+
type: "string",
|
|
161
|
+
description: "计算表达式",
|
|
162
|
+
},
|
|
163
|
+
data_array: {
|
|
164
|
+
type: "array",
|
|
165
|
+
description: "数据源数组",
|
|
166
|
+
items: {
|
|
167
|
+
type: "object",
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
required: ["expr", "data_array"],
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
name: "basic_calc",
|
|
176
|
+
description: `a-calc 基础运算函数 - 直接进行精确的数学运算,性能最优
|
|
177
|
+
|
|
178
|
+
支持的运算:
|
|
179
|
+
- add: 加法 (支持多参数)
|
|
180
|
+
- sub: 减法 (支持多参数)
|
|
181
|
+
- mul: 乘法 (支持多参数)
|
|
182
|
+
- div: 除法 (支持多参数)
|
|
183
|
+
- mod: 取模
|
|
184
|
+
- pow: 幂运算
|
|
185
|
+
- idiv: 整除
|
|
186
|
+
- abs: 绝对值
|
|
187
|
+
- neg: 取负
|
|
188
|
+
- sqrt: 平方根
|
|
189
|
+
- ln: 自然对数
|
|
190
|
+
- exp: e的幂
|
|
191
|
+
|
|
192
|
+
使用示例:
|
|
193
|
+
- add(0.1, 0.2) → "0.3"
|
|
194
|
+
- mul(0.1, 0.2, 0.3) → "0.006"
|
|
195
|
+
- div(1, 3) → "0.333..."
|
|
196
|
+
- sqrt(16) → "4"`,
|
|
197
|
+
inputSchema: {
|
|
198
|
+
type: "object",
|
|
199
|
+
properties: {
|
|
200
|
+
operation: {
|
|
201
|
+
type: "string",
|
|
202
|
+
enum: ["add", "sub", "mul", "div", "mod", "pow", "idiv", "abs", "neg", "sqrt", "ln", "exp"],
|
|
203
|
+
description: "运算类型",
|
|
204
|
+
},
|
|
205
|
+
args: {
|
|
206
|
+
type: "array",
|
|
207
|
+
description: "运算参数",
|
|
208
|
+
items: {
|
|
209
|
+
type: ["number", "string"],
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
required: ["operation", "args"],
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
name: "chain_calc",
|
|
218
|
+
description: `a-calc 链式计算函数 - 流式 API 风格的连续运算
|
|
219
|
+
|
|
220
|
+
链式函数:
|
|
221
|
+
- cadd: 加法起始
|
|
222
|
+
- csub: 减法起始
|
|
223
|
+
- cmul: 乘法起始
|
|
224
|
+
- cdiv: 除法起始
|
|
225
|
+
|
|
226
|
+
链上方法: .add() .sub() .mul() .div() .mod() .pow() .idiv()
|
|
227
|
+
最后调用 () 或 (格式化字符串) 获取结果
|
|
228
|
+
|
|
229
|
+
使用示例:
|
|
230
|
+
- cadd(100, 200).mul(0.8).sub(50)() → "190"
|
|
231
|
+
- cmul(10, 20, 30).div(100)("=2") → "60.00"
|
|
232
|
+
- cadd(99.9, 199, 49.5).mul(0.9).sub(20)("=2,") → "296.33"`,
|
|
233
|
+
inputSchema: {
|
|
234
|
+
type: "object",
|
|
235
|
+
properties: {
|
|
236
|
+
start_op: {
|
|
237
|
+
type: "string",
|
|
238
|
+
enum: ["cadd", "csub", "cmul", "cdiv"],
|
|
239
|
+
description: "起始运算类型",
|
|
240
|
+
},
|
|
241
|
+
start_args: {
|
|
242
|
+
type: "array",
|
|
243
|
+
description: "起始运算参数",
|
|
244
|
+
items: {
|
|
245
|
+
type: ["number", "string"],
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
chain_ops: {
|
|
249
|
+
type: "array",
|
|
250
|
+
description: "链式操作序列",
|
|
251
|
+
items: {
|
|
252
|
+
type: "object",
|
|
253
|
+
properties: {
|
|
254
|
+
op: {
|
|
255
|
+
type: "string",
|
|
256
|
+
enum: ["add", "sub", "mul", "div", "mod", "pow", "idiv"],
|
|
257
|
+
},
|
|
258
|
+
args: {
|
|
259
|
+
type: "array",
|
|
260
|
+
items: {
|
|
261
|
+
type: ["number", "string"],
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
required: ["op", "args"],
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
format: {
|
|
269
|
+
type: "string",
|
|
270
|
+
description: "最终格式化字符串(可选)",
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
required: ["start_op", "start_args"],
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
name: "get_acalc_guide",
|
|
278
|
+
description: `获取 a-calc 库的使用指南和最佳实践
|
|
279
|
+
|
|
280
|
+
可获取的内容:
|
|
281
|
+
- api: API 完整参考
|
|
282
|
+
- formatting: 格式化规则详解
|
|
283
|
+
- functions: 内置数学函数
|
|
284
|
+
- conditional: 条件表达式和比较运算
|
|
285
|
+
- chain: 链式计算
|
|
286
|
+
- examples: 常见使用示例
|
|
287
|
+
- all: 获取全部内容`,
|
|
288
|
+
inputSchema: {
|
|
289
|
+
type: "object",
|
|
290
|
+
properties: {
|
|
291
|
+
topic: {
|
|
292
|
+
type: "string",
|
|
293
|
+
enum: ["api", "formatting", "functions", "conditional", "chain", "examples", "all"],
|
|
294
|
+
description: "要获取的主题",
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
required: ["topic"],
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
];
|
|
301
|
+
|
|
302
|
+
// ==================== Resources 定义 ====================
|
|
303
|
+
|
|
304
|
+
const RESOURCES = [
|
|
305
|
+
{
|
|
306
|
+
uri: "acalc://api/overview",
|
|
307
|
+
name: "a-calc API 概览",
|
|
308
|
+
description: "a-calc 库的完整 API 参考文档",
|
|
309
|
+
mimeType: "text/markdown",
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
uri: "acalc://guide/formatting",
|
|
313
|
+
name: "格式化规则指南",
|
|
314
|
+
description: "详细的格式化规则和选项说明",
|
|
315
|
+
mimeType: "text/markdown",
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
uri: "acalc://guide/functions",
|
|
319
|
+
name: "内置数学函数",
|
|
320
|
+
description: "支持的数学函数列表和用法",
|
|
321
|
+
mimeType: "text/markdown",
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
uri: "acalc://guide/conditional",
|
|
325
|
+
name: "条件表达式",
|
|
326
|
+
description: "条件表达式、比较运算、逻辑运算",
|
|
327
|
+
mimeType: "text/markdown",
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
uri: "acalc://examples/common",
|
|
331
|
+
name: "常见示例",
|
|
332
|
+
description: "常见使用场景的代码示例",
|
|
333
|
+
mimeType: "text/markdown",
|
|
334
|
+
},
|
|
335
|
+
];
|
|
336
|
+
|
|
337
|
+
// ==================== Resource Contents ====================
|
|
338
|
+
|
|
339
|
+
const RESOURCE_CONTENTS = {
|
|
340
|
+
"acalc://api/overview": `# a-calc API 完整参考
|
|
341
|
+
|
|
342
|
+
## 核心函数
|
|
343
|
+
|
|
344
|
+
### calc(expr, options?)
|
|
345
|
+
核心计算函数,支持表达式计算、变量填充、格式化。
|
|
346
|
+
|
|
347
|
+
**参数:**
|
|
348
|
+
- \`expr\`: string | number - 计算表达式
|
|
349
|
+
- \`options\`: object - 配置选项和变量数据
|
|
350
|
+
|
|
351
|
+
**返回:** string | number
|
|
352
|
+
|
|
353
|
+
**示例:**
|
|
354
|
+
\`\`\`javascript
|
|
355
|
+
calc("0.1 + 0.2") // "0.3"
|
|
356
|
+
calc("a + b", {a: 1, b: 2}) // "3"
|
|
357
|
+
calc("10 / 3 | =2") // "3.33"
|
|
358
|
+
\`\`\`
|
|
359
|
+
|
|
360
|
+
### fmt(value, format?, options?)
|
|
361
|
+
专用格式化函数,跳过表达式解析,性能更优。
|
|
362
|
+
|
|
363
|
+
**参数:**
|
|
364
|
+
- \`value\`: number | string - 要格式化的数值
|
|
365
|
+
- \`format\`: string - 格式化字符串
|
|
366
|
+
- \`options\`: object - 配置选项
|
|
367
|
+
|
|
368
|
+
**返回:** string | number
|
|
369
|
+
|
|
370
|
+
**示例:**
|
|
371
|
+
\`\`\`javascript
|
|
372
|
+
fmt(100, "=2") // "100.00"
|
|
373
|
+
fmt(1234567, ",") // "1,234,567"
|
|
374
|
+
\`\`\`
|
|
375
|
+
|
|
376
|
+
### calc_sum(expr, data_array)
|
|
377
|
+
聚合计算函数,对数组数据批量计算并求和。
|
|
378
|
+
|
|
379
|
+
**参数:**
|
|
380
|
+
- \`expr\`: string - 计算表达式
|
|
381
|
+
- \`data_array\`: array - 数据源数组
|
|
382
|
+
|
|
383
|
+
**返回:** string | number
|
|
384
|
+
|
|
385
|
+
**示例:**
|
|
386
|
+
\`\`\`javascript
|
|
387
|
+
calc_sum("a + b", [{a:1,b:2}, {a:3,b:4}]) // "10"
|
|
388
|
+
\`\`\`
|
|
389
|
+
|
|
390
|
+
## 基础运算函数
|
|
391
|
+
|
|
392
|
+
支持多参数运算,返回 number 类型:
|
|
393
|
+
|
|
394
|
+
- \`add(...nums)\` - 加法
|
|
395
|
+
- \`sub(...nums)\` - 减法
|
|
396
|
+
- \`mul(...nums)\` - 乘法
|
|
397
|
+
- \`div(...nums)\` - 除法
|
|
398
|
+
- \`mod(a, b)\` - 取模
|
|
399
|
+
- \`pow(base, exp)\` - 幂运算
|
|
400
|
+
- \`idiv(a, b)\` - 整除
|
|
401
|
+
- \`abs(value)\` - 绝对值
|
|
402
|
+
- \`neg(value)\` - 取负
|
|
403
|
+
- \`sqrt(value)\` - 平方根
|
|
404
|
+
- \`ln(value)\` - 自然对数
|
|
405
|
+
- \`exp(value)\` - e的幂
|
|
406
|
+
|
|
407
|
+
## 链式计算函数
|
|
408
|
+
|
|
409
|
+
流式 API 风格的连续运算:
|
|
410
|
+
|
|
411
|
+
- \`cadd(...nums)\` - 加法起始
|
|
412
|
+
- \`csub(first, ...rest)\` - 减法起始
|
|
413
|
+
- \`cmul(...nums)\` - 乘法起始
|
|
414
|
+
- \`cdiv(first, ...rest)\` - 除法起始
|
|
415
|
+
|
|
416
|
+
链上方法:\`.add()\` \`.sub()\` \`.mul()\` \`.div()\` \`.mod()\` \`.pow()\` \`.idiv()\`
|
|
417
|
+
|
|
418
|
+
**示例:**
|
|
419
|
+
\`\`\`javascript
|
|
420
|
+
cadd(100, 200).mul(0.8).sub(50)() // "190"
|
|
421
|
+
\`\`\`
|
|
422
|
+
`,
|
|
423
|
+
|
|
424
|
+
"acalc://guide/formatting": `# 格式化规则详解
|
|
425
|
+
|
|
426
|
+
## 小数位控制
|
|
427
|
+
|
|
428
|
+
- \`=N\` - 精确N位小数
|
|
429
|
+
- \`<=N\` - 最多N位小数
|
|
430
|
+
- \`>=N\` - 至少N位小数
|
|
431
|
+
- \`>=M<=N\` - M到N位小数范围
|
|
432
|
+
|
|
433
|
+
**示例:**
|
|
434
|
+
\`\`\`javascript
|
|
435
|
+
calc("10 / 3 | =2") // "3.33"
|
|
436
|
+
calc("3.14159 | <=2") // "3.14"
|
|
437
|
+
calc("3.1 | >=3") // "3.100"
|
|
438
|
+
\`\`\`
|
|
439
|
+
|
|
440
|
+
## 舍入规则
|
|
441
|
+
|
|
442
|
+
- \`~-\` - 截断(默认)
|
|
443
|
+
- \`~+\` - 进位
|
|
444
|
+
- \`~5\` - 四舍五入
|
|
445
|
+
- \`~6\` - 银行家舍入
|
|
446
|
+
|
|
447
|
+
**示例:**
|
|
448
|
+
\`\`\`javascript
|
|
449
|
+
calc("1.125 | ~5=2") // "1.13"
|
|
450
|
+
calc("1.125 | ~6=2") // "1.12"
|
|
451
|
+
calc("1.124 | ~+=2") // "1.13"
|
|
452
|
+
\`\`\`
|
|
453
|
+
|
|
454
|
+
## 千分位
|
|
455
|
+
|
|
456
|
+
- \`,\` - 千分位分隔符
|
|
457
|
+
- \`!t:us\` - 美式千分位 (1,234.56)
|
|
458
|
+
- \`!t:eu\` - 欧式千分位 (1.234,56)
|
|
459
|
+
- \`!t:indian\` - 印度式千分位 (12,34,567)
|
|
460
|
+
- \`!t:cn4\` - 中文四位分隔 (1234,5678)
|
|
461
|
+
|
|
462
|
+
**示例:**
|
|
463
|
+
\`\`\`javascript
|
|
464
|
+
calc("1234567 | ,") // "1,234,567"
|
|
465
|
+
fmt(1234567.89, "!t:eu") // "1.234.567,89"
|
|
466
|
+
\`\`\`
|
|
467
|
+
|
|
468
|
+
## 百分比
|
|
469
|
+
|
|
470
|
+
- \`%\` - 转换为百分比
|
|
471
|
+
|
|
472
|
+
**示例:**
|
|
473
|
+
\`\`\`javascript
|
|
474
|
+
calc("0.1234 | %=2") // "12.34%"
|
|
475
|
+
\`\`\`
|
|
476
|
+
|
|
477
|
+
## 科学计数法
|
|
478
|
+
|
|
479
|
+
- \`!e\` - 科学计数法输出
|
|
480
|
+
|
|
481
|
+
**示例:**
|
|
482
|
+
\`\`\`javascript
|
|
483
|
+
calc("123456789 | !e=2") // "1.23e+8"
|
|
484
|
+
\`\`\`
|
|
485
|
+
|
|
486
|
+
## 正负号
|
|
487
|
+
|
|
488
|
+
- \`+\` - 正数显示 + 号
|
|
489
|
+
|
|
490
|
+
**示例:**
|
|
491
|
+
\`\`\`javascript
|
|
492
|
+
calc("100 | +") // "+100"
|
|
493
|
+
\`\`\`
|
|
494
|
+
|
|
495
|
+
## 返回数字类型
|
|
496
|
+
|
|
497
|
+
- \`!n\` - 返回 number 类型而非 string
|
|
498
|
+
|
|
499
|
+
**示例:**
|
|
500
|
+
\`\`\`javascript
|
|
501
|
+
calc("1 + 1 | !n") // 2 (number)
|
|
502
|
+
\`\`\`
|
|
503
|
+
|
|
504
|
+
## 交易量格式化
|
|
505
|
+
|
|
506
|
+
- \`!v\` - 交易量缩写 (1.23M, 1.23B)
|
|
507
|
+
- \`!v:wan\` - 中文单位 (1.23万)
|
|
508
|
+
|
|
509
|
+
**示例:**
|
|
510
|
+
\`\`\`javascript
|
|
511
|
+
calc("1234567 | !v") // "1.23M"
|
|
512
|
+
calc("12345 | !v:wan") // "1.23万"
|
|
513
|
+
\`\`\`
|
|
514
|
+
|
|
515
|
+
## 组合使用
|
|
516
|
+
|
|
517
|
+
格式化参数可以组合使用:
|
|
518
|
+
|
|
519
|
+
\`\`\`javascript
|
|
520
|
+
calc("0.1234 | %=2+") // "+12.34%"
|
|
521
|
+
calc("1234567.89 | ,=2") // "1,234,567.89"
|
|
522
|
+
calc("price * qty | ~5=2,", {price: 99.9, qty: 3}) // "299.70"
|
|
523
|
+
\`\`\`
|
|
524
|
+
`,
|
|
525
|
+
|
|
526
|
+
"acalc://guide/functions": `# 内置数学函数
|
|
527
|
+
|
|
528
|
+
a-calc 支持在表达式中直接使用数学函数。
|
|
529
|
+
|
|
530
|
+
## 基础数学函数
|
|
531
|
+
|
|
532
|
+
- \`sqrt(x)\` - 平方根
|
|
533
|
+
- \`cbrt(x)\` - 立方根
|
|
534
|
+
- \`abs(x)\` - 绝对值
|
|
535
|
+
- \`pow(x, y)\` - x 的 y 次方
|
|
536
|
+
- \`exp(x)\` - e 的 x 次方
|
|
537
|
+
- \`ln(x)\` - 自然对数
|
|
538
|
+
- \`log(x)\` - 常用对数(以10为底)
|
|
539
|
+
- \`log2(x)\` - 以2为底的对数
|
|
540
|
+
- \`log10(x)\` - 以10为底的对数
|
|
541
|
+
|
|
542
|
+
## 三角函数
|
|
543
|
+
|
|
544
|
+
- \`sin(x)\` - 正弦
|
|
545
|
+
- \`cos(x)\` - 余弦
|
|
546
|
+
- \`tan(x)\` - 正切
|
|
547
|
+
- \`asin(x)\` - 反正弦
|
|
548
|
+
- \`acos(x)\` - 反余弦
|
|
549
|
+
- \`atan(x)\` - 反正切
|
|
550
|
+
|
|
551
|
+
## 双曲函数
|
|
552
|
+
|
|
553
|
+
- \`sinh(x)\` - 双曲正弦
|
|
554
|
+
- \`cosh(x)\` - 双曲余弦
|
|
555
|
+
- \`tanh(x)\` - 双曲正切
|
|
556
|
+
- \`asinh(x)\` - 反双曲正弦
|
|
557
|
+
- \`acosh(x)\` - 反双曲余弦
|
|
558
|
+
- \`atanh(x)\` - 反双曲正切
|
|
559
|
+
|
|
560
|
+
## 取整函数
|
|
561
|
+
|
|
562
|
+
- \`floor(x)\` - 向下取整
|
|
563
|
+
- \`ceil(x)\` - 向上取整
|
|
564
|
+
- \`trunc(x)\` - 截断小数
|
|
565
|
+
- \`round(x)\` - 四舍五入
|
|
566
|
+
|
|
567
|
+
## 比较函数
|
|
568
|
+
|
|
569
|
+
- \`max(x, y, ...)\` - 最大值
|
|
570
|
+
- \`min(x, y, ...)\` - 最小值
|
|
571
|
+
|
|
572
|
+
## 使用示例
|
|
573
|
+
|
|
574
|
+
\`\`\`javascript
|
|
575
|
+
calc("sqrt(16) + pow(2, 3)") // "12"
|
|
576
|
+
calc("sin(0) + cos(0)") // "1"
|
|
577
|
+
calc("max(10, 20, 30)") // "30"
|
|
578
|
+
calc("floor(3.7) + ceil(3.2)") // "7"
|
|
579
|
+
calc("ln(exp(1))") // "1"
|
|
580
|
+
\`\`\`
|
|
581
|
+
|
|
582
|
+
## 函数嵌套
|
|
583
|
+
|
|
584
|
+
函数可以嵌套使用:
|
|
585
|
+
|
|
586
|
+
\`\`\`javascript
|
|
587
|
+
calc("sqrt(pow(3, 2) + pow(4, 2))") // "5" (勾股定理)
|
|
588
|
+
calc("round(sqrt(2) * 100) / 100") // "1.41"
|
|
589
|
+
\`\`\`
|
|
590
|
+
`,
|
|
591
|
+
|
|
592
|
+
"acalc://guide/conditional": `# 条件表达式和运算符
|
|
593
|
+
|
|
594
|
+
## 条件表达式
|
|
595
|
+
|
|
596
|
+
a-calc 支持三元条件表达式:
|
|
597
|
+
|
|
598
|
+
\`\`\`javascript
|
|
599
|
+
calc("score >= 60 ? '及格' : '不及格'", {score: 75}) // "及格"
|
|
600
|
+
calc("age >= 18 ? 'adult' : 'minor'", {age: 20}) // "adult"
|
|
601
|
+
\`\`\`
|
|
602
|
+
|
|
603
|
+
## 比较运算符
|
|
604
|
+
|
|
605
|
+
- \`>\` - 大于
|
|
606
|
+
- \`<\` - 小于
|
|
607
|
+
- \`>=\` - 大于等于
|
|
608
|
+
- \`<=\` - 小于等于
|
|
609
|
+
- \`==\` - 等于
|
|
610
|
+
- \`!=\` - 不等于
|
|
611
|
+
|
|
612
|
+
**示例:**
|
|
613
|
+
\`\`\`javascript
|
|
614
|
+
calc("10 > 5") // "1" (true)
|
|
615
|
+
calc("10 < 5") // "0" (false)
|
|
616
|
+
calc("10 == 10") // "1"
|
|
617
|
+
calc("10 != 5") // "1"
|
|
618
|
+
\`\`\`
|
|
619
|
+
|
|
620
|
+
## 逻辑运算符
|
|
621
|
+
|
|
622
|
+
- \`&&\` - 逻辑与
|
|
623
|
+
- \`||\` - 逻辑或
|
|
624
|
+
- \`!\` - 逻辑非
|
|
625
|
+
|
|
626
|
+
**示例:**
|
|
627
|
+
\`\`\`javascript
|
|
628
|
+
calc("(10 > 5) && (20 > 10)") // "1" (true)
|
|
629
|
+
calc("(10 > 5) || (20 < 10)") // "1" (true)
|
|
630
|
+
calc("!(10 > 5)") // "0" (false)
|
|
631
|
+
\`\`\`
|
|
632
|
+
|
|
633
|
+
## 链式比较
|
|
634
|
+
|
|
635
|
+
a-calc 支持链式比较表达式:
|
|
636
|
+
|
|
637
|
+
\`\`\`javascript
|
|
638
|
+
calc("1 < x < 10", {x: 5}) // "1" (true)
|
|
639
|
+
calc("0 <= score <= 100", {score: 85}) // "1" (true)
|
|
640
|
+
\`\`\`
|
|
641
|
+
|
|
642
|
+
## 复杂条件
|
|
643
|
+
|
|
644
|
+
可以组合使用条件和逻辑运算:
|
|
645
|
+
|
|
646
|
+
\`\`\`javascript
|
|
647
|
+
calc("(score >= 90) ? 'A' : (score >= 80) ? 'B' : (score >= 60) ? 'C' : 'D'", {score: 85})
|
|
648
|
+
// "B"
|
|
649
|
+
|
|
650
|
+
calc("(age >= 18 && hasLicense) ? 'can drive' : 'cannot drive'", {
|
|
651
|
+
age: 20,
|
|
652
|
+
hasLicense: 1
|
|
653
|
+
}) // "can drive"
|
|
654
|
+
\`\`\`
|
|
655
|
+
`,
|
|
656
|
+
|
|
657
|
+
"acalc://examples/common": `# 常见使用示例
|
|
658
|
+
|
|
659
|
+
## 金融计算
|
|
660
|
+
|
|
661
|
+
### 价格计算
|
|
662
|
+
\`\`\`javascript
|
|
663
|
+
// 含税价格
|
|
664
|
+
calc("price * (1 + taxRate) | =2", {price: 100, taxRate: 0.13}) // "113.00"
|
|
665
|
+
|
|
666
|
+
// 折扣价格
|
|
667
|
+
calc("price * discount | =2", {price: 199.9, discount: 0.8}) // "159.92"
|
|
668
|
+
|
|
669
|
+
// 订单总价
|
|
670
|
+
calc("price * qty + shipping | =2,", {
|
|
671
|
+
price: 99.9,
|
|
672
|
+
qty: 3,
|
|
673
|
+
shipping: 15
|
|
674
|
+
}) // "314.70"
|
|
675
|
+
\`\`\`
|
|
676
|
+
|
|
677
|
+
### 利率计算
|
|
678
|
+
\`\`\`javascript
|
|
679
|
+
// 单利
|
|
680
|
+
calc("principal * rate * time | =2", {
|
|
681
|
+
principal: 10000,
|
|
682
|
+
rate: 0.05,
|
|
683
|
+
time: 2
|
|
684
|
+
}) // "1000.00"
|
|
685
|
+
|
|
686
|
+
// 复利
|
|
687
|
+
calc("principal * pow(1 + rate, time) - principal | =2", {
|
|
688
|
+
principal: 10000,
|
|
689
|
+
rate: 0.05,
|
|
690
|
+
time: 2
|
|
691
|
+
}) // "1025.00"
|
|
692
|
+
\`\`\`
|
|
693
|
+
|
|
694
|
+
## 电商场景
|
|
695
|
+
|
|
696
|
+
### 购物车计算
|
|
697
|
+
\`\`\`javascript
|
|
698
|
+
const items = [
|
|
699
|
+
{price: 99.9, qty: 2},
|
|
700
|
+
{price: 49.9, qty: 3},
|
|
701
|
+
{price: 199, qty: 1}
|
|
702
|
+
]
|
|
703
|
+
|
|
704
|
+
calc_sum("price * qty | =2", items) // "548.50"
|
|
705
|
+
\`\`\`
|
|
706
|
+
|
|
707
|
+
### 优惠券计算
|
|
708
|
+
\`\`\`javascript
|
|
709
|
+
calc("total > 200 ? total * 0.9 : total | =2", {total: 250}) // "225.00"
|
|
710
|
+
\`\`\`
|
|
711
|
+
|
|
712
|
+
## 数据格式化
|
|
713
|
+
|
|
714
|
+
### 金额显示
|
|
715
|
+
\`\`\`javascript
|
|
716
|
+
fmt(1234567.89, ",=2") // "1,234,567.89"
|
|
717
|
+
fmt(1234567, "!v") // "1.23M"
|
|
718
|
+
\`\`\`
|
|
719
|
+
|
|
720
|
+
### 百分比显示
|
|
721
|
+
\`\`\`javascript
|
|
722
|
+
fmt(0.1234, "%=2") // "12.34%"
|
|
723
|
+
fmt(0.0523, "%=2+") // "+5.23%" (涨跌幅)
|
|
724
|
+
\`\`\`
|
|
725
|
+
|
|
726
|
+
### 科学计数法
|
|
727
|
+
\`\`\`javascript
|
|
728
|
+
fmt(123456789, "!e=2") // "1.23e+8"
|
|
729
|
+
\`\`\`
|
|
730
|
+
|
|
731
|
+
## 统计计算
|
|
732
|
+
|
|
733
|
+
### 平均值
|
|
734
|
+
\`\`\`javascript
|
|
735
|
+
const values = [10, 20, 30, 40, 50]
|
|
736
|
+
const sum = add(...values) // 150
|
|
737
|
+
const avg = div(sum, values.length) // 30
|
|
738
|
+
\`\`\`
|
|
739
|
+
|
|
740
|
+
### 标准差
|
|
741
|
+
\`\`\`javascript
|
|
742
|
+
import { add, div, sqrt, sub, mul } from 'a-calc'
|
|
743
|
+
|
|
744
|
+
const values = [10, 20, 30, 40, 50]
|
|
745
|
+
const avg = 30
|
|
746
|
+
const variance = div(
|
|
747
|
+
add(...values.map(v => mul(sub(v, avg), sub(v, avg)))),
|
|
748
|
+
values.length
|
|
749
|
+
) // 200
|
|
750
|
+
const stdDev = sqrt(variance) // 14.142...
|
|
751
|
+
\`\`\`
|
|
752
|
+
|
|
753
|
+
## 单位计算
|
|
754
|
+
|
|
755
|
+
### 带单位的计算
|
|
756
|
+
\`\`\`javascript
|
|
757
|
+
calc("100元 + 50元", {_unit: true}) // "150元"
|
|
758
|
+
calc("10% + 5%", {_unit: true}) // "15%"
|
|
759
|
+
calc("1.5kg * 2", {_unit: true}) // "3kg"
|
|
760
|
+
\`\`\`
|
|
761
|
+
|
|
762
|
+
## 链式计算
|
|
763
|
+
|
|
764
|
+
### 复杂运算
|
|
765
|
+
\`\`\`javascript
|
|
766
|
+
// (100 + 200) * 0.8 - 50
|
|
767
|
+
cadd(100, 200).mul(0.8).sub(50)("=2") // "190.00"
|
|
768
|
+
|
|
769
|
+
// 价格计算链
|
|
770
|
+
cmul(99.9, 3) // 单价 * 数量
|
|
771
|
+
.mul(0.9) // 打9折
|
|
772
|
+
.add(15) // 加运费
|
|
773
|
+
("=2,") // "284.73"
|
|
774
|
+
\`\`\`
|
|
775
|
+
`
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
// ==================== Server Setup ====================
|
|
779
|
+
|
|
780
|
+
const server = new Server(
|
|
781
|
+
{
|
|
782
|
+
name: "a-calc-mcp-server",
|
|
783
|
+
version: "1.0.0",
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
capabilities: {
|
|
787
|
+
tools: {},
|
|
788
|
+
resources: {},
|
|
789
|
+
},
|
|
790
|
+
}
|
|
791
|
+
);
|
|
792
|
+
|
|
793
|
+
// ==================== Tool Handlers ====================
|
|
794
|
+
|
|
795
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
796
|
+
return { tools: TOOLS };
|
|
797
|
+
});
|
|
798
|
+
|
|
799
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
800
|
+
const { name, arguments: args } = request.params;
|
|
801
|
+
|
|
802
|
+
try {
|
|
803
|
+
switch (name) {
|
|
804
|
+
case "calc": {
|
|
805
|
+
const { expr, options = {} } = args;
|
|
806
|
+
const result = calc(expr, options);
|
|
807
|
+
return {
|
|
808
|
+
content: [
|
|
809
|
+
{
|
|
810
|
+
type: "text",
|
|
811
|
+
text: JSON.stringify({ result, type: typeof result }),
|
|
812
|
+
},
|
|
813
|
+
],
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
case "fmt": {
|
|
818
|
+
const { value, format_str, options = {} } = args;
|
|
819
|
+
const result = fmt(value, format_str, options);
|
|
820
|
+
return {
|
|
821
|
+
content: [
|
|
822
|
+
{
|
|
823
|
+
type: "text",
|
|
824
|
+
text: JSON.stringify({ result, type: typeof result }),
|
|
825
|
+
},
|
|
826
|
+
],
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
case "calc_sum": {
|
|
831
|
+
const { expr, data_array } = args;
|
|
832
|
+
const result = calc_sum(expr, data_array);
|
|
833
|
+
return {
|
|
834
|
+
content: [
|
|
835
|
+
{
|
|
836
|
+
type: "text",
|
|
837
|
+
text: JSON.stringify({ result, type: typeof result }),
|
|
838
|
+
},
|
|
839
|
+
],
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
case "basic_calc": {
|
|
844
|
+
const { operation, args: calcArgs } = args;
|
|
845
|
+
let result;
|
|
846
|
+
|
|
847
|
+
switch (operation) {
|
|
848
|
+
case "add":
|
|
849
|
+
result = add(...calcArgs);
|
|
850
|
+
break;
|
|
851
|
+
case "sub":
|
|
852
|
+
result = sub(...calcArgs);
|
|
853
|
+
break;
|
|
854
|
+
case "mul":
|
|
855
|
+
result = mul(...calcArgs);
|
|
856
|
+
break;
|
|
857
|
+
case "div":
|
|
858
|
+
result = div(...calcArgs);
|
|
859
|
+
break;
|
|
860
|
+
case "mod":
|
|
861
|
+
result = mod(...calcArgs);
|
|
862
|
+
break;
|
|
863
|
+
case "pow":
|
|
864
|
+
result = pow(...calcArgs);
|
|
865
|
+
break;
|
|
866
|
+
case "idiv":
|
|
867
|
+
result = idiv(...calcArgs);
|
|
868
|
+
break;
|
|
869
|
+
case "abs":
|
|
870
|
+
result = abs(calcArgs[0]);
|
|
871
|
+
break;
|
|
872
|
+
case "neg":
|
|
873
|
+
result = neg(calcArgs[0]);
|
|
874
|
+
break;
|
|
875
|
+
case "sqrt":
|
|
876
|
+
result = sqrt(calcArgs[0]);
|
|
877
|
+
break;
|
|
878
|
+
case "ln":
|
|
879
|
+
result = ln(calcArgs[0]);
|
|
880
|
+
break;
|
|
881
|
+
case "exp":
|
|
882
|
+
result = exp(calcArgs[0]);
|
|
883
|
+
break;
|
|
884
|
+
default:
|
|
885
|
+
throw new Error(`Unknown operation: ${operation}`);
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
return {
|
|
889
|
+
content: [
|
|
890
|
+
{
|
|
891
|
+
type: "text",
|
|
892
|
+
text: JSON.stringify({ result, type: typeof result }),
|
|
893
|
+
},
|
|
894
|
+
],
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
case "chain_calc": {
|
|
899
|
+
const { start_op, start_args, chain_ops = [], format } = args;
|
|
900
|
+
|
|
901
|
+
let chainFn;
|
|
902
|
+
switch (start_op) {
|
|
903
|
+
case "cadd":
|
|
904
|
+
chainFn = cadd(...start_args);
|
|
905
|
+
break;
|
|
906
|
+
case "csub":
|
|
907
|
+
chainFn = csub(...start_args);
|
|
908
|
+
break;
|
|
909
|
+
case "cmul":
|
|
910
|
+
chainFn = cmul(...start_args);
|
|
911
|
+
break;
|
|
912
|
+
case "cdiv":
|
|
913
|
+
chainFn = cdiv(...start_args);
|
|
914
|
+
break;
|
|
915
|
+
default:
|
|
916
|
+
throw new Error(`Unknown start operation: ${start_op}`);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
for (const { op, args: opArgs } of chain_ops) {
|
|
920
|
+
switch (op) {
|
|
921
|
+
case "add":
|
|
922
|
+
chainFn = chainFn.add(...opArgs);
|
|
923
|
+
break;
|
|
924
|
+
case "sub":
|
|
925
|
+
chainFn = chainFn.sub(...opArgs);
|
|
926
|
+
break;
|
|
927
|
+
case "mul":
|
|
928
|
+
chainFn = chainFn.mul(...opArgs);
|
|
929
|
+
break;
|
|
930
|
+
case "div":
|
|
931
|
+
chainFn = chainFn.div(...opArgs);
|
|
932
|
+
break;
|
|
933
|
+
case "mod":
|
|
934
|
+
chainFn = chainFn.mod(...opArgs);
|
|
935
|
+
break;
|
|
936
|
+
case "pow":
|
|
937
|
+
chainFn = chainFn.pow(...opArgs);
|
|
938
|
+
break;
|
|
939
|
+
case "idiv":
|
|
940
|
+
chainFn = chainFn.idiv(...opArgs);
|
|
941
|
+
break;
|
|
942
|
+
default:
|
|
943
|
+
throw new Error(`Unknown chain operation: ${op}`);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
const result = format ? chainFn(format) : chainFn();
|
|
948
|
+
return {
|
|
949
|
+
content: [
|
|
950
|
+
{
|
|
951
|
+
type: "text",
|
|
952
|
+
text: JSON.stringify({ result, type: typeof result }),
|
|
953
|
+
},
|
|
954
|
+
],
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
case "get_acalc_guide": {
|
|
959
|
+
const { topic } = args;
|
|
960
|
+
let content = "";
|
|
961
|
+
|
|
962
|
+
if (topic === "all") {
|
|
963
|
+
content = Object.values(RESOURCE_CONTENTS).join("\n\n---\n\n");
|
|
964
|
+
} else {
|
|
965
|
+
const resourceMap = {
|
|
966
|
+
api: "acalc://api/overview",
|
|
967
|
+
formatting: "acalc://guide/formatting",
|
|
968
|
+
functions: "acalc://guide/functions",
|
|
969
|
+
conditional: "acalc://guide/conditional",
|
|
970
|
+
chain: "acalc://api/overview",
|
|
971
|
+
examples: "acalc://examples/common",
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
const uri = resourceMap[topic];
|
|
975
|
+
if (uri && RESOURCE_CONTENTS[uri]) {
|
|
976
|
+
content = RESOURCE_CONTENTS[uri];
|
|
977
|
+
} else {
|
|
978
|
+
throw new Error(`Unknown topic: ${topic}`);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
return {
|
|
983
|
+
content: [
|
|
984
|
+
{
|
|
985
|
+
type: "text",
|
|
986
|
+
text: content,
|
|
987
|
+
},
|
|
988
|
+
],
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
default:
|
|
993
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
994
|
+
}
|
|
995
|
+
} catch (error) {
|
|
996
|
+
return {
|
|
997
|
+
content: [
|
|
998
|
+
{
|
|
999
|
+
type: "text",
|
|
1000
|
+
text: JSON.stringify({
|
|
1001
|
+
error: error.message,
|
|
1002
|
+
stack: error.stack,
|
|
1003
|
+
}),
|
|
1004
|
+
},
|
|
1005
|
+
],
|
|
1006
|
+
isError: true,
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
1010
|
+
|
|
1011
|
+
// ==================== Resource Handlers ====================
|
|
1012
|
+
|
|
1013
|
+
server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
1014
|
+
return { resources: RESOURCES };
|
|
1015
|
+
});
|
|
1016
|
+
|
|
1017
|
+
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
1018
|
+
const { uri } = request.params;
|
|
1019
|
+
|
|
1020
|
+
if (RESOURCE_CONTENTS[uri]) {
|
|
1021
|
+
return {
|
|
1022
|
+
contents: [
|
|
1023
|
+
{
|
|
1024
|
+
uri,
|
|
1025
|
+
mimeType: "text/markdown",
|
|
1026
|
+
text: RESOURCE_CONTENTS[uri],
|
|
1027
|
+
},
|
|
1028
|
+
],
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
throw new Error(`Resource not found: ${uri}`);
|
|
1033
|
+
});
|
|
1034
|
+
|
|
1035
|
+
// ==================== Start Server ====================
|
|
1036
|
+
|
|
1037
|
+
async function main() {
|
|
1038
|
+
const transport = new StdioServerTransport();
|
|
1039
|
+
await server.connect(transport);
|
|
1040
|
+
console.error("a-calc MCP Server running on stdio");
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
main().catch((error) => {
|
|
1044
|
+
console.error("Fatal error:", error);
|
|
1045
|
+
process.exit(1);
|
|
1046
|
+
});
|