a-calc 3.0.0-beta.20260121 → 3.0.0-beta.20260124.2

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.
@@ -0,0 +1,204 @@
1
+ # a-calc MCP Server
2
+
3
+ 为 [a-calc](https://github.com/Autumn-one/a-calc-old) 库提供的 MCP (Model Context Protocol) 服务器,让 AI 助手能够使用 a-calc 进行精确的数字计算和格式化。
4
+
5
+ ## 功能特性
6
+
7
+ ### Tools (工具)
8
+
9
+ | 工具名 | 描述 |
10
+ |--------|------|
11
+ | `calc` | 核心计算函数 - 支持表达式计算、变量填充、格式化 |
12
+ | `fmt` | 专用格式化函数 - 跳过表达式解析,性能更优 |
13
+ | `calc_sum` | 聚合计算函数 - 对数组数据批量计算并求和 |
14
+ | `basic_calc` | 基础运算函数 - 直接进行精确的数学运算 |
15
+ | `get_acalc_guide` | 获取使用指南和最佳实践 |
16
+
17
+ ### Resources (资源)
18
+
19
+ | 资源 URI | 描述 |
20
+ |----------|------|
21
+ | `acalc://api/overview` | API 完整参考文档 |
22
+ | `acalc://guide/formatting` | 格式化规则详解 |
23
+ | `acalc://guide/best-practices` | 最佳实践指南 |
24
+ | `acalc://examples/common` | 常见使用示例 |
25
+
26
+ ### Prompts (提示模板)
27
+
28
+ | 提示名 | 描述 |
29
+ |--------|------|
30
+ | `financial_calculation` | 金融计算场景 - 价格、税费、折扣等 |
31
+ | `data_formatting` | 数据格式化场景 - 千分位、百分比等 |
32
+ | `batch_calculation` | 批量计算场景 - 数组聚合、报表统计 |
33
+ | `code_review` | 代码审查 - 检查数字计算是否可优化 |
34
+
35
+ ## 安装
36
+
37
+ a-calc MCP 服务器已集成到 a-calc 主包中。
38
+
39
+ **推荐:项目本地安装**
40
+
41
+ ```bash
42
+ npm install a-calc
43
+ ```
44
+
45
+ ## 使用方法
46
+
47
+ ### 配置 Claude Desktop
48
+
49
+ 在 Claude Desktop 配置文件中添加:
50
+
51
+ **配置文件位置:**
52
+ - **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
53
+ - **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
54
+ - **Linux**: `~/.config/claude/claude_desktop_config.json`
55
+
56
+ **配置:**
57
+
58
+ ```json
59
+ {
60
+ "mcpServers": {
61
+ "a-calc": {
62
+ "command": "npx",
63
+ "args": ["a-calc-mcp"]
64
+ }
65
+ }
66
+ }
67
+ ```
68
+
69
+ > 💡 **说明:**
70
+ > - Claude Desktop 默认工作目录为项目根目录,会自动使用项目本地安装的 a-calc(如果有)
71
+ > - 如果项目未安装 a-calc,npx 会自动下载最新版本
72
+
73
+ ### 故障排除
74
+
75
+ 如果 MCP 服务器无法正常运行,请按以下顺序尝试:
76
+
77
+ **1. 添加 `cwd` 配置项**
78
+
79
+ 某些 MCP 客户端(如 Trae)可能需要显式指定工作目录:
80
+
81
+ ```json
82
+ {
83
+ "mcpServers": {
84
+ "a-calc": {
85
+ "command": "npx",
86
+ "args": ["a-calc-mcp"],
87
+ "cwd": "${workspaceFolder}"
88
+ }
89
+ }
90
+ }
91
+ ```
92
+
93
+ **2. 全局安装**
94
+
95
+ 如果还是不生效,可以尝试全局安装:
96
+
97
+ ```bash
98
+ npm install -g a-calc
99
+ ```
100
+
101
+ 然后使用:
102
+
103
+ ```json
104
+ {
105
+ "mcpServers": {
106
+ "a-calc": {
107
+ "command": "a-calc-mcp"
108
+ }
109
+ }
110
+ }
111
+ ```
112
+
113
+ **3. Windows 平台特殊说明**
114
+
115
+ 如果在 Windows 上遇到 `Windows requires 'cmd /c' wrapper to execute npx` 错误,将 `npx` 改为 `cmd /c npx`:
116
+
117
+ ```json
118
+ {
119
+ "mcpServers": {
120
+ "a-calc": {
121
+ "command": "cmd",
122
+ "args": ["/c", "npx", "a-calc-mcp"]
123
+ }
124
+ }
125
+ }
126
+ ```
127
+
128
+ ### 配置其他 MCP 客户端
129
+
130
+ 对于其他支持 MCP 的客户端,使用 stdio 传输方式连接:
131
+
132
+ ```bash
133
+ # 使用 npx(推荐)
134
+ npx a-calc-mcp
135
+
136
+ # 全局安装后
137
+ a-calc-mcp
138
+ ```
139
+
140
+ ## 使用示例
141
+
142
+ ### 在 AI 对话中使用
143
+
144
+ ```
145
+ 用户:帮我计算 0.1 + 0.2 的精确结果
146
+
147
+ AI:[调用 calc 工具]
148
+ 结果:0.3
149
+ ```
150
+
151
+ ```
152
+ 用户:把 1234567.89 格式化为千分位显示,保留2位小数
153
+
154
+ AI:[调用 fmt 工具]
155
+ 结果:1,234,567.89
156
+ ```
157
+
158
+ ```
159
+ 用户:计算这些订单的总金额:
160
+ - 商品A:单价 99.9,数量 2
161
+ - 商品B:单价 49.9,数量 3
162
+
163
+ AI:[调用 calc_sum 工具]
164
+ 结果:349.50
165
+ ```
166
+
167
+ ### 获取使用指南
168
+
169
+ ```
170
+ 用户:如何使用 a-calc 进行金额计算?
171
+
172
+ AI:[调用 get_acalc_guide 工具,topic: "best_practices"]
173
+ [返回最佳实践文档]
174
+ ```
175
+
176
+ ## 开发
177
+
178
+ ### 目录结构
179
+
180
+ ```
181
+ mcp-server/
182
+ ├── src/
183
+ │ └── index.js # 主入口文件
184
+ ├── package.json
185
+ └── README.md
186
+ ```
187
+
188
+ ### 添加新工具
189
+
190
+ 在 `src/index.js` 中的 `TOOLS` 数组添加新工具定义,并在 `execute_tool` 函数中实现对应逻辑。
191
+
192
+ ### 添加新资源
193
+
194
+ 在 `RESOURCES` 数组添加资源定义,在 `RESOURCE_CONTENTS` 对象添加资源内容。
195
+
196
+ ## 相关链接
197
+
198
+ - [a-calc GitHub](https://github.com/Autumn-one/a-calc-old)
199
+ - [a-calc npm](https://www.npmjs.com/package/a-calc)
200
+ - [MCP 协议文档](https://modelcontextprotocol.io/)
201
+
202
+ ## License
203
+
204
+ MIT
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "a-calc-mcp-server",
3
+ "version": "1.0.0",
4
+ "description": "MCP server for a-calc - a powerful number precision calculation and formatting library",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "bin": {
8
+ "a-calc-mcp": "./src/index.js"
9
+ },
10
+ "scripts": {
11
+ "start": "node src/index.js",
12
+ "dev": "node --watch src/index.js"
13
+ },
14
+ "keywords": [
15
+ "mcp",
16
+ "a-calc",
17
+ "calculation",
18
+ "formatting",
19
+ "precision"
20
+ ],
21
+ "author": "Autumn",
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "@modelcontextprotocol/sdk": "^1.0.0"
25
+ }
26
+ }