chaimi-bookkeeping-mcp 3.1.21 → 3.1.22

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 (3) hide show
  1. package/README.md +13 -0
  2. package/package.json +1 -1
  3. package/server.js +45 -19
package/README.md CHANGED
@@ -8,6 +8,15 @@
8
8
  - macOS / Windows / Linux
9
9
  - 微信(已安装"柴米AI记账"小程序)
10
10
 
11
+ ## ⚠️ 重要提示(Agent开发者必读)
12
+
13
+ **如果您是 AI Agent 开发者,请注意:**
14
+
15
+ 1. **不要缓存工具定义**:MCP 工具定义可能会更新,请在每次调用前通过 `mcporter list` 获取最新定义
16
+ 2. **关注版本号**:工具描述中包含版本号(如【v3.1.21】),版本变化时请更新您的 Skill
17
+ 3. **save_receipt 工具要求**:items 数组中每个商品必须包含完整的4个字段:`name`、`amount`、`price`、`quantity`
18
+ 4. **自动填充字段**:`agentType`、`apiProvider`、`rawInput`、`mcp_version` 为自动填充字段,无需用户输入
19
+
11
20
  ## 快速安装
12
21
 
13
22
  ### 方式一:npm 全局安装(推荐)
@@ -134,6 +143,10 @@ AI 会自动调用 `save_income` 工具记录收入。
134
143
 
135
144
  ## 更新日志
136
145
 
146
+ ### v3.1.22 (2026-04-12)
147
+ - **修复** fillDefaults 金额计算逻辑(根据 price × quantity 计算 amount)
148
+ - **修复** 解决辣可可小票价格显示为0元的问题
149
+
137
150
  ### v3.1.21 (2026-04-12)
138
151
  - **修复** 版本号同步更新
139
152
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chaimi-bookkeeping-mcp",
3
- "version": "3.1.21",
3
+ "version": "3.1.22",
4
4
  "description": "柴米记账 MCP Server - 支持 Claude、Cursor、OpenClaw、WorkBuddy 等 AI 工具直接记账",
5
5
  "main": "server.js",
6
6
  "bin": {
package/server.js CHANGED
@@ -118,41 +118,41 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
118
118
  },
119
119
  {
120
120
  name: 'save_receipt',
121
- description: '【图片小票专用】保存购物小票/发票/收据(支持单商品或多商品)。当用户提供图片形式的小票、发票时,无论商品数量多少(1条或多条),都必须使用此接口。可自动识别商家名称、商品明细、金额、优惠等信息。典型场景:超市购物小票、餐厅发票、线上订单截图、手写收据照片等',
121
+ description: '【v3.1.21】【图片小票专用】保存购物小票/发票/收据。⚠️ 重要:items数组中每个商品必须包含完整的4个字段:name(商品名称)、amount(金额=单价×数量)、price(单价)、quantity(数量)。示例:[{"name":"苹果","amount":5.5,"price":5.5,"quantity":1}]',
122
122
  inputSchema: {
123
123
  type: 'object',
124
124
  properties: {
125
- store: { type: 'string', description: '商家名称' },
125
+ store: { type: 'string', description: '商家名称(必填)' },
126
126
  date: { type: 'string', description: '消费时间(ISO 8601 格式,必须包含日期和时间,如:2026-04-10T13:06:21)' },
127
- totalAmount: { type: 'number', description: '总金额' },
128
- originalAmount: { type: 'number', description: '应付金额' },
127
+ totalAmount: { type: 'number', description: '总金额(所有商品amount之和)' },
128
+ originalAmount: { type: 'number', description: '应付金额(优惠前)' },
129
129
  discountAmount: { type: 'number', description: '优惠金额' },
130
- actualAmount: { type: 'number', description: '实付金额' },
131
- paymentMethod: { type: 'string', description: '支付方式' },
130
+ actualAmount: { type: 'number', description: '实付金额(优惠后)' },
131
+ paymentMethod: { type: 'string', description: '支付方式,如:微信支付、支付宝' },
132
132
  receiptNo: { type: 'string', description: '小票编号' },
133
133
  items: {
134
134
  type: 'array',
135
- description: '商品列表,支持两种格式:1) 直接数组:[{"name":"苹果","amount":5.5}] 2) JSON字符串:"[{\"name\":\"苹果\",\"amount\":5.5}]"(部分Agent如Claude Code可能传递JSON字符串)',
135
+ description: '【必填】商品列表,必须是数组格式。每个商品必须包含:nameamount、price、quantity。⚠️ 注意:amount=price×quantity',
136
136
  items: {
137
137
  type: 'object',
138
138
  properties: {
139
- name: { type: 'string', description: '商品名称' },
140
- originalName: { type: 'string', description: '原始商品名称' },
141
- price: { type: 'number', description: '单价' },
142
- quantity: { type: 'number', description: '数量' },
143
- unit: { type: 'string', description: '单位' },
144
- amount: { type: 'number', description: '金额' },
139
+ name: { type: 'string', description: '【必填】商品名称' },
140
+ originalName: { type: 'string', description: '原始商品名称(含规格)' },
141
+ price: { type: 'number', description: '【必填】单价' },
142
+ quantity: { type: 'number', description: '【必填】数量' },
143
+ unit: { type: 'string', description: '单位,如:斤、个、份' },
144
+ amount: { type: 'number', description: '【必填】金额,必须等于 price × quantity' },
145
145
  weight: { type: 'string', description: '重量' },
146
- marketPrice: { type: 'string', description: '市场单价' },
147
- category: { type: 'string', description: '分类' },
146
+ marketPrice: { type: 'string', description: '市场单价(元/500g)' },
147
+ category: { type: 'string', description: '分类,如:餐饮、食品、购物' },
148
148
  },
149
149
  required: ['name', 'amount', 'price', 'quantity'],
150
150
  },
151
151
  },
152
- agentType: { type: 'string', description: '【推荐自动填充】Agent类型,如:claude-desktop、cursor、openclaw、workbuddy、trae' },
153
- apiProvider: { type: 'string', description: '【推荐自动填充】AI服务提供商,如:anthropic、openai、doubao、aliyun' },
154
- rawInput: { type: 'string', description: '【推荐自动填充】用户的原始输入内容,用于记录用户原始请求' },
155
- mcp_version: { type: 'string', description: 'MCP Server 版本号(自动填充)' },
152
+ agentType: { type: 'string', description: '【自动填充】Agent类型:claude-desktop、cursor、openclaw、workbuddy、trae' },
153
+ apiProvider: { type: 'string', description: '【自动填充】AI服务提供商:anthropic、openai、doubao、aliyun' },
154
+ rawInput: { type: 'string', description: '【自动填充】用户的原始输入内容' },
155
+ mcp_version: { type: 'string', description: '【自动填充】MCP Server版本号' },
156
156
  },
157
157
  required: ['store', 'items'],
158
158
  },
@@ -418,6 +418,32 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
418
418
  }
419
419
 
420
420
  case 'save_receipt': {
421
+ // 0. 参数格式强制检查 - 确保 items 中每个商品都有完整的字段
422
+ if (processedArgs.items && Array.isArray(processedArgs.items)) {
423
+ const invalidItems = [];
424
+ processedArgs.items.forEach((item, index) => {
425
+ const missingFields = [];
426
+ if (!item.hasOwnProperty('name')) missingFields.push('name');
427
+ if (!item.hasOwnProperty('amount')) missingFields.push('amount');
428
+ if (!item.hasOwnProperty('price')) missingFields.push('price');
429
+ if (!item.hasOwnProperty('quantity')) missingFields.push('quantity');
430
+
431
+ if (missingFields.length > 0) {
432
+ invalidItems.push(`商品${index + 1}(${item.name || '未命名'})缺少字段: ${missingFields.join(', ')}`);
433
+ }
434
+ });
435
+
436
+ if (invalidItems.length > 0) {
437
+ result = {
438
+ success: false,
439
+ error: `参数格式错误:${invalidItems.join('; ')}。请更新您的 MCP Skill 或检查 items 数组格式。每个商品必须包含:name, amount, price, quantity`,
440
+ code: 400
441
+ };
442
+ userMessage = `❌ 保存失败\n\n错误:商品数据格式不完整\n\n${invalidItems.join('\n')}\n\n💡 解决方案:\n1. 请更新您的柴米记账 MCP Skill\n2. 确保每个商品包含完整的4个字段:name, amount, price, quantity\n3. amount 必须等于 price × quantity`;
443
+ break;
444
+ }
445
+ }
446
+
421
447
  // 1. 调用 parseReceipt 重新提取小票信息(覆盖 Agent 传的数据)
422
448
  if (processedArgs.rawInput) {
423
449
  const parseResult = await callMcpPrompt(