chaimi-keep-mcp 3.1.44-beta.2 → 3.1.44-beta.4

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 -1
  2. package/package.json +1 -1
  3. package/server.js +53 -33
package/README.md CHANGED
@@ -141,7 +141,19 @@ AI 会自动调用 `save_income` 工具记录收入。
141
141
 
142
142
  ## 更新日志
143
143
 
144
- ### v3.1.44-beta.1 (2026-04-20)
144
+ ### v3.1.44-beta.4 (2026-04-21)
145
+ - **优化** 统一字段命名规范
146
+ - 将 `mcp_version` 改为 `mcpVersion`,统一使用驼峰命名法
147
+ - 符合项目 JavaScript 代码规范
148
+
149
+ ### v3.1.44-beta.3 (2026-04-21)
150
+ - **修复** MCP 调用日志字段缺失问题(完整修复)
151
+ - 修复所有日志记录阶段(request_received/cloud_calling/cloud_success/cloud_failed/validation_failed/mcp_error)
152
+ - 补充缺失字段:agentType、apiProvider、mcp_version、params
153
+ - 修改 callMcpHubWithLogging 函数签名,添加 agentType/apiProvider 参数
154
+ - 更新所有调用处(8处),正确传递元数据字段
155
+
156
+ ### v3.1.44-beta.2 (2026-04-20)
145
157
  - **重构** `get_text_parse_prompt` 工具改为云端实现
146
158
  - 新增 `mcpPrompt` 云函数 `getTextParsePrompt` 工具
147
159
  - Prompt 包含43个标准分类(与手动记账分类完全一致)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chaimi-keep-mcp",
3
- "version": "3.1.44-beta.2",
3
+ "version": "3.1.44-beta.4",
4
4
  "description": "柴米记账 MCP Server - 支持 Claude、Cursor、OpenClaw、WorkBuddy 等 AI 工具直接记账",
5
5
  "main": "server.js",
6
6
  "bin": {
package/server.js CHANGED
@@ -170,7 +170,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
170
170
  agentType: { type: 'string', description: '【必填】Agent类型,如:claude-desktop、cursor、openclaw、workbuddy、trae' },
171
171
  apiProvider: { type: 'string', description: '【必填】AI服务提供商,如:anthropic、openai、doubao、aliyun' },
172
172
  rawInput: { type: 'string', description: '【必填】用户的原始输入内容,用于记录用户原始请求' },
173
- mcp_version: { type: 'string', description: 'MCP Server 版本号(自动填充)' },
173
+ mcpVersion: { type: 'string', description: 'MCP Server 版本号(自动填充)' },
174
174
  },
175
175
  required: ['name', 'amount', 'category', 'agentType', 'apiProvider', 'rawInput'],
176
176
  },
@@ -214,7 +214,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
214
214
  agentType: { type: 'string', description: '【必填】Agent类型:claude-desktop、cursor、openclaw、workbuddy、trae' },
215
215
  apiProvider: { type: 'string', description: '【必填】AI服务提供商:anthropic、openai、doubao、aliyun' },
216
216
  rawInput: { type: 'string', description: '【必填】用户的原始输入内容' },
217
- mcp_version: { type: 'string', description: '【自动填充】MCP Server版本号' },
217
+ mcpVersion: { type: 'string', description: '【自动填充】MCP Server版本号' },
218
218
  },
219
219
  required: ['store', 'items', 'storeCategory', 'storeSubCategory', 'agentType', 'apiProvider', 'rawInput'],
220
220
  },
@@ -315,7 +315,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
315
315
  agentType: { type: 'string', description: '【必填】Agent类型,如:claude-desktop、cursor、openclaw、workbuddy、trae' },
316
316
  apiProvider: { type: 'string', description: '【必填】AI服务提供商,如:anthropic、openai、doubao、aliyun' },
317
317
  rawInput: { type: 'string', description: '【必填】用户的原始输入内容,用于记录用户原始请求' },
318
- mcp_version: { type: 'string', description: 'MCP Server 版本号(自动填充)' },
318
+ mcpVersion: { type: 'string', description: 'MCP Server 版本号(自动填充)' },
319
319
  },
320
320
  required: ['name', 'amount', 'category', 'agentType', 'apiProvider', 'rawInput'],
321
321
  },
@@ -538,16 +538,20 @@ function getOSInfo() {
538
538
  }
539
539
 
540
540
  // 调用 mcpHub 云函数(带日志和链路追踪)
541
- async function callMcpHubWithLogging(tool, params, token, traceId, startTime, osInfo) {
541
+ async function callMcpHubWithLogging(tool, params, token, traceId, startTime, osInfo, agentType, apiProvider) {
542
542
  // 记录即将调用云函数
543
543
  logMcpCall({
544
544
  traceId,
545
545
  stage: 'cloud_calling',
546
546
  toolName: tool,
547
- timestamp: new Date().toISOString(),
548
- logSource: 'mcp',
547
+ params: sanitizeLogParams(params),
548
+ agentType: agentType || '',
549
+ apiProvider: apiProvider || '',
550
+ mcpVersion: MCP_VERSION,
549
551
  osType: osInfo?.osType,
550
- osVersion: osInfo?.osVersion
552
+ osVersion: osInfo?.osVersion,
553
+ timestamp: new Date().toISOString(),
554
+ logSource: 'mcp'
551
555
  });
552
556
 
553
557
  try {
@@ -559,10 +563,13 @@ async function callMcpHubWithLogging(tool, params, token, traceId, startTime, os
559
563
  stage: 'cloud_success',
560
564
  toolName: tool,
561
565
  duration: Date.now() - startTime,
562
- timestamp: new Date().toISOString(),
563
- logSource: 'mcp',
566
+ agentType: agentType || '',
567
+ apiProvider: apiProvider || '',
568
+ mcpVersion: MCP_VERSION,
564
569
  osType: osInfo?.osType,
565
- osVersion: osInfo?.osVersion
570
+ osVersion: osInfo?.osVersion,
571
+ timestamp: new Date().toISOString(),
572
+ logSource: 'mcp'
566
573
  });
567
574
 
568
575
  return result;
@@ -574,10 +581,13 @@ async function callMcpHubWithLogging(tool, params, token, traceId, startTime, os
574
581
  toolName: tool,
575
582
  error: cloudErr.message,
576
583
  duration: Date.now() - startTime,
577
- timestamp: new Date().toISOString(),
578
- logSource: 'mcp',
584
+ agentType: agentType || '',
585
+ apiProvider: apiProvider || '',
586
+ mcpVersion: MCP_VERSION,
579
587
  osType: osInfo?.osType,
580
- osVersion: osInfo?.osVersion
588
+ osVersion: osInfo?.osVersion,
589
+ timestamp: new Date().toISOString(),
590
+ logSource: 'mcp'
581
591
  });
582
592
  throw cloudErr;
583
593
  }
@@ -659,6 +669,10 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
659
669
  const startTime = Date.now();
660
670
  const traceId = generateTraceId();
661
671
  const osInfo = getOSInfo();
672
+
673
+ // 提取元数据字段
674
+ const agentType = args.agentType || process.env.AGENT_TYPE || process.env.MCP_AGENT_TYPE || '';
675
+ const apiProvider = args.apiProvider || process.env.API_PROVIDER || process.env.MCP_API_PROVIDER || '';
662
676
 
663
677
  // 记录请求到达
664
678
  logMcpCall({
@@ -668,7 +682,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
668
682
  params: sanitizeLogParams(args),
669
683
  agentType: args.agentType || process.env.AGENT_TYPE || process.env.MCP_AGENT_TYPE || '',
670
684
  apiProvider: args.apiProvider || process.env.API_PROVIDER || process.env.MCP_API_PROVIDER || '',
671
- mcp_version: MCP_VERSION,
685
+ mcpVersion: MCP_VERSION,
672
686
  osType: osInfo.osType,
673
687
  osVersion: osInfo.osVersion,
674
688
  timestamp: new Date().toISOString(),
@@ -687,10 +701,13 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
687
701
  toolName: name,
688
702
  error: 'SKILL_NOT_READ',
689
703
  duration: Date.now() - startTime,
690
- timestamp: new Date().toISOString(),
691
- logSource: 'mcp',
704
+ agentType: args.agentType || process.env.AGENT_TYPE || process.env.MCP_AGENT_TYPE || '',
705
+ apiProvider: args.apiProvider || process.env.API_PROVIDER || process.env.MCP_API_PROVIDER || '',
706
+ mcpVersion: MCP_VERSION,
692
707
  osType: osInfo.osType,
693
- osVersion: osInfo.osVersion
708
+ osVersion: osInfo.osVersion,
709
+ timestamp: new Date().toISOString(),
710
+ logSource: 'mcp'
694
711
  });
695
712
  return {
696
713
  content: [
@@ -831,7 +848,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
831
848
  }
832
849
 
833
850
  const mcpParams = convertParams('save_expense', processedArgs);
834
- result = await callMcpHubWithLogging('addExpense', mcpParams, token, traceId, startTime, osInfo);
851
+ result = await callMcpHubWithLogging('addExpense', mcpParams, token, traceId, startTime, osInfo, agentType, apiProvider);
835
852
 
836
853
  if (result.success) {
837
854
  const displayName = processedArgs.name || '未知商品';
@@ -1098,7 +1115,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1098
1115
  }
1099
1116
 
1100
1117
  const mcpParams = convertParams('save_receipt', processedArgs);
1101
- result = await callMcpHubWithLogging('addReceipt', mcpParams, token, traceId, startTime, osInfo);
1118
+ result = await callMcpHubWithLogging('addReceipt', mcpParams, token, traceId, startTime, osInfo, agentType, apiProvider);
1102
1119
 
1103
1120
  if (result.success) {
1104
1121
  const totalAmount = processedArgs.totalAmount || processedArgs.items?.reduce((sum, item) => sum + (item.amount || 0), 0) || 0;
@@ -1140,7 +1157,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1140
1157
  case 'get_receipt_list': {
1141
1158
  const toolName = toolMapping[name];
1142
1159
  const mcpParams = convertParams(name, processedArgs);
1143
- result = await callMcpHubWithLogging(toolName, mcpParams, token, traceId, startTime, osInfo);
1160
+ result = await callMcpHubWithLogging(toolName, mcpParams, token, traceId, startTime, osInfo, agentType, apiProvider);
1144
1161
 
1145
1162
  if (result.success) {
1146
1163
  const total = result.data?.total || 0;
@@ -1181,7 +1198,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1181
1198
  case 'get_statistics': {
1182
1199
  const toolName = toolMapping[name];
1183
1200
  const mcpParams = convertParams(name, processedArgs);
1184
- result = await callMcpHubWithLogging(toolName, mcpParams, token, traceId, startTime, osInfo);
1201
+ result = await callMcpHubWithLogging(toolName, mcpParams, token, traceId, startTime, osInfo, agentType, apiProvider);
1185
1202
 
1186
1203
  if (result.success) {
1187
1204
  const data = result.data || {};
@@ -1229,7 +1246,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1229
1246
  case 'get_insights': {
1230
1247
  const toolName = toolMapping[name];
1231
1248
  const mcpParams = convertParams(name, processedArgs);
1232
- result = await callMcpHubWithLogging(toolName, mcpParams, token, traceId, startTime, osInfo);
1249
+ result = await callMcpHubWithLogging(toolName, mcpParams, token, traceId, startTime, osInfo, agentType, apiProvider);
1233
1250
 
1234
1251
  if (result.success) {
1235
1252
  const data = result.data || {};
@@ -1275,7 +1292,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1275
1292
  case 'export_data': {
1276
1293
  const toolName = toolMapping[name];
1277
1294
  const mcpParams = convertParams(name, processedArgs);
1278
- result = await callMcpHubWithLogging(toolName, mcpParams, token, traceId, startTime, osInfo);
1295
+ result = await callMcpHubWithLogging(toolName, mcpParams, token, traceId, startTime, osInfo, agentType, apiProvider);
1279
1296
 
1280
1297
  if (result.success) {
1281
1298
  const summary = result.data?.summary || {};
@@ -1329,7 +1346,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1329
1346
  }
1330
1347
 
1331
1348
  const mcpParams = convertParams('save_income', processedArgs);
1332
- result = await callMcpHubWithLogging('addIncome', mcpParams, token, traceId, startTime, osInfo);
1349
+ result = await callMcpHubWithLogging('addIncome', mcpParams, token, traceId, startTime, osInfo, agentType, apiProvider);
1333
1350
 
1334
1351
  if (result.success) {
1335
1352
  const displayName = processedArgs.name || '未知收入';
@@ -1397,11 +1414,11 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1397
1414
  context: processedArgs.context || '',
1398
1415
  agentType: processedArgs.agentType || '',
1399
1416
  apiProvider: processedArgs.apiProvider || '',
1400
- mcp_version: MCP_VERSION,
1417
+ mcpVersion: MCP_VERSION,
1401
1418
  userAgent: request.headers?.['user-agent'] || ''
1402
1419
  };
1403
1420
 
1404
- result = await callMcpHubWithLogging('addFeedback', feedbackData, token, traceId, startTime, osInfo);
1421
+ result = await callMcpHubWithLogging('addFeedback', feedbackData, token, traceId, startTime, osInfo, agentType, apiProvider);
1405
1422
 
1406
1423
  if (result.success) {
1407
1424
  const typeText = {
@@ -1430,7 +1447,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1430
1447
  const fullResponse = {
1431
1448
  userMessage: userMessage,
1432
1449
  result: result,
1433
- mcp_version: MCP_VERSION
1450
+ mcpVersion: MCP_VERSION
1434
1451
  };
1435
1452
 
1436
1453
  return {
@@ -1449,10 +1466,13 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1449
1466
  toolName: name,
1450
1467
  error: error.message,
1451
1468
  duration: Date.now() - startTime,
1452
- timestamp: new Date().toISOString(),
1453
- logSource: 'mcp',
1469
+ agentType: agentType || '',
1470
+ apiProvider: apiProvider || '',
1471
+ mcpVersion: MCP_VERSION,
1454
1472
  osType: osInfo.osType,
1455
- osVersion: osInfo.osVersion
1473
+ osVersion: osInfo.osVersion,
1474
+ timestamp: new Date().toISOString(),
1475
+ logSource: 'mcp'
1456
1476
  });
1457
1477
 
1458
1478
  // 处理授权错误
@@ -1689,7 +1709,7 @@ function convertParams(toolName, args) {
1689
1709
  rawInput: sanitizeString(args.rawInput, 1000) || '',
1690
1710
  agentType: args.agentType || '',
1691
1711
  apiProvider: args.apiProvider || '',
1692
- mcp_version: args.mcp_version || MCP_VERSION,
1712
+ mcpVersion: MCP_VERSION,
1693
1713
  source: 'mcp_txt_expense',
1694
1714
  };
1695
1715
  }
@@ -1743,7 +1763,7 @@ function convertParams(toolName, args) {
1743
1763
  rawInput: sanitizeString(args.rawInput, 2000),
1744
1764
  agentType: args.agentType || '',
1745
1765
  apiProvider: args.apiProvider || '',
1746
- mcp_version: args.mcp_version || MCP_VERSION,
1766
+ mcpVersion: MCP_VERSION,
1747
1767
  source: 'mcp_receipt',
1748
1768
  storeCategory: sanitizeString(args.storeCategory, 50) || '其他',
1749
1769
  storeSubCategory: sanitizeString(args.storeSubCategory, 50) || '其他',
@@ -1775,7 +1795,7 @@ function convertParams(toolName, args) {
1775
1795
  rawInput: sanitizeString(args.rawInput, 1000),
1776
1796
  agentType: args.agentType || '',
1777
1797
  apiProvider: args.apiProvider || '',
1778
- mcp_version: args.mcp_version || MCP_VERSION,
1798
+ mcpVersion: MCP_VERSION,
1779
1799
  source: 'mcp_txt_income',
1780
1800
  };
1781
1801