opc-finance-mcp 0.8.0 → 0.9.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 (3) hide show
  1. package/README.md +20 -0
  2. package/package.json +1 -1
  3. package/src/index.js +101 -0
package/README.md CHANGED
@@ -96,6 +96,26 @@ npm run inspect
96
96
  | `finance_import_bank_flow` | 导入一批流水到核对清单(按指纹去重) | 可写 |
97
97
  | `finance_suggest_voucher` | **起草凭证建议**:给发票或流水算出分录,**不写账** | 只读 |
98
98
 
99
+ | `finance_get_attachment_url` | 取原件短期签名地址(图片交视觉模型读) | 只读 |
100
+ | `finance_month_checklist` | 月度工作清单:还差什么才能结账 | 只读 |
101
+ | `finance_prepare_closing` | 算结转损益分录(草案,不记账) | 只读 |
102
+ | `finance_mark_tax_filed` | 标记申报完成 / 退回草稿 | 可写 |
103
+ | `finance_get_attachment_text` | 把 PDF 原件转成文本(读票用) | 只读 |
104
+ | `finance_import_invoices` | 批量导入发票(含挂原件) | 可写 |
105
+ | `finance_link_invoice_attachment` | 给发票挂原件 | 可写 |
106
+ | `finance_reconcile_documents` | 自动对账:找「可能已经记过的那张凭证」 | 只读 |
107
+ | `finance_link_documents` | 把单据关联到已有凭证(不新建凭证) | 可写 |
108
+
109
+ > 0.9.0 起「读截图 → 月度清单 → 结转 → 结账」也是一条闭环:
110
+ > `finance_get_attachment_url` 拿到签名地址交给视觉模型读图片(PDF 仍用 `finance_get_attachment_text`),
111
+ > 干完活先 `finance_month_checklist` 看还差什么,缺结转就用 `finance_prepare_closing` 拿草案,
112
+ > 确认后过账、`finance_close_period` 结账,最后 `finance_mark_tax_filed` 标记申报。
113
+
114
+ > 0.8.0 的「读票 → 导入 → 对账」是一条闭环:`finance_get_attachment_text` 取文本,
115
+ > 模型认出票面字段后 `finance_import_invoices` 入库,再用 `finance_reconcile_documents`
116
+ > 判断这张票是不是已经记过账 —— 已经记过就 `finance_link_documents` 关联,没记过才起草新凭证。
117
+ > 这样不会因为「先按流水记了、票后来才到」而重复入账。
118
+
99
119
  > 0.7.0 起多了「读票、读流水、起草」四件工具。它们刻意停在建议那一步:
100
120
  > AI 可以算出借贷,但过账仍然要走 `finance_create_voucher` 并由用户确认。
101
121
  > 依据依次是「同一对手方的历史记法 → 摘要关键词 → 收入/费用兜底」,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opc-finance-mcp",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "OPC智能财务 MCP Server —— 让 AI 客户端直接查账、记账、传票",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
package/src/index.js CHANGED
@@ -1327,6 +1327,107 @@ tool('finance_link_documents', {
1327
1327
  return ok(`✅ 已关联 ${d.linked} 条${d.skipped ? `,${d.skipped} 条跳过(凭证不存在)` : ''}。`);
1328
1328
  });
1329
1329
 
1330
+ tool('finance_get_attachment_url', {
1331
+ title: '取票据原件的可读地址(读图用)',
1332
+ description: '返回票据原件的一个短期签名 URL(10 分钟有效),交给视觉模型直接读图。'
1333
+ + 'PDF 优先用 finance_get_attachment_text 取文字;图片(发票照片、银行回单截图、扫描件)用这个 URL 让视觉读。'
1334
+ + '返回里 readWith 会告诉你是 text 还是 vision。',
1335
+ inputSchema: {
1336
+ attach_id: z.number().int().positive().describe('附件 id(来自 finance_list_attachments)'),
1337
+ },
1338
+ }, async ({ attach_id }) => {
1339
+ const d = await request('/api/attach/' + attach_id + '/url');
1340
+ return ok([
1341
+ `# ${d.title || d.filename}(attach_id=${d.id})`,
1342
+ `类型 ${d.mime || '未知'}|${d.size ? (d.size / 1024).toFixed(0) + ' KB' : ''}|归档 ${d.folder || '—'}`,
1343
+ '',
1344
+ `URL(${d.expiresIn} 秒内有效):`,
1345
+ d.url,
1346
+ '',
1347
+ `读法:${d.hint}`,
1348
+ d.readWith === 'vision'
1349
+ ? '把上面的 URL 交给视觉模型,读出:发票号、开票日期、购销方名称、不含税金额、税额、价税合计;读不准就只报能确认的字段,不要编。'
1350
+ : '',
1351
+ ].filter(Boolean).join('\n'));
1352
+ });
1353
+
1354
+ tool('finance_month_checklist', {
1355
+ title: '月度工作清单(月结前先看这个)',
1356
+ description: '一次答完「这个月还差什么」:凭证数、待入账发票/流水、损益是否结转、工资做没做、申报状态、'
1357
+ + '以及按顺序该做的下一步。只读,不改任何数据。给用户做月结或验收 AI 记账结果时先调它。',
1358
+ inputSchema: {
1359
+ period: z.string().describe('期间 YYYY-MM,如 2026-10'),
1360
+ },
1361
+ }, async ({ period }) => {
1362
+ const d = await request('/api/month-checklist' + qs({ period }));
1363
+ const line = (k, v) => `- ${k}:${v}`;
1364
+ const out = [
1365
+ `# ${d.period} 工作清单(期间状态:${d.statusLabel})`,
1366
+ line('凭证', `${d.voucher.count} 张,金额 ${fmt(d.voucher.amount)}`),
1367
+ line('待入账发票', d.invoice.pending ? `${d.invoice.pending} 张,价税合计 ${fmt(d.invoice.amount)}` : '无'),
1368
+ line('待处理流水', d.flow.pending ? `${d.flow.pending} 条,金额 ${fmt(d.flow.amount)}` : '无'),
1369
+ line('工资', d.payroll
1370
+ ? `已算(${d.payroll.status})${d.payroll.accrued ? '、已出计提凭证' : '、未出计提凭证'}${d.payroll.paid ? '、已出发放凭证' : ''}`
1371
+ : '本月没有工资表'),
1372
+ line('损益结转', d.plResidual.count
1373
+ ? `${d.plResidual.count} 个科目未结平,合计 ${fmt(d.plResidual.total)}`
1374
+ : '已结平'),
1375
+ line('申报', `${d.tax.quarter} 状态:${d.tax.status === 'missing' ? '还没建申报期' : d.tax.status === 'filed' ? '已申报' : '草稿'}`),
1376
+ '',
1377
+ d.todos.length ? '## 还差这些' : '## 可以结账了',
1378
+ ...d.todos.map(t => `- ${t}`),
1379
+ ];
1380
+ if (d.plResidual.accounts.length) {
1381
+ out.push('', '## 未结平的损益科目', '| 科目 | 名称 | 余额 |', '| --- | --- | --- |',
1382
+ ...d.plResidual.accounts.map(a => `| ${a.code} | ${a.name} | ${a.side} ${fmt(Math.abs(a.net))} |`));
1383
+ out.push('', '用 finance_prepare_closing 拿结转分录草案。');
1384
+ }
1385
+ return ok(out.join('\n'));
1386
+ });
1387
+
1388
+ tool('finance_prepare_closing', {
1389
+ title: '计算结转损益分录(不记账)',
1390
+ description: '按「截至期末各损益科目余额」算出结转分录草案,对方科目取报表映射里的「本年利润」。'
1391
+ + '只返回建议,不写账。拿到后念给用户确认,再用 finance_create_voucher 入账(日期用期末最后一天)。',
1392
+ inputSchema: {
1393
+ period: z.string().describe('期间 YYYY-MM,如 2026-10'),
1394
+ },
1395
+ }, async ({ period }) => {
1396
+ const d = await request('/api/closing/prepare' + qs({ period }));
1397
+ if (!d.entries.length) return ok(d.message || `${period} 不需要结转。`);
1398
+ const out = [
1399
+ `# ${period} 结转损益草案(尚未入账)`,
1400
+ `对方科目:${d.closeTo.code} ${d.closeTo.name}`,
1401
+ '',
1402
+ '| 科目 | 名称 | 借方 | 贷方 |',
1403
+ '| --- | --- | --- | --- |',
1404
+ ...d.entries.map(e => `| ${e.account_code} | ${e.account_name} | `
1405
+ + `${e.debit ? fmt(e.debit) : ''} | ${e.credit ? fmt(e.credit) : ''} |`),
1406
+ '',
1407
+ `合计:借 ${fmt(d.debitTotal)}|贷 ${fmt(d.creditTotal)}${d.balanced ? '(平)' : '(不平,勿提交)'}`,
1408
+ `结转后本年利润${d.profit >= 0 ? '增加' : '减少'} ${fmt(Math.abs(d.profit))}`,
1409
+ '',
1410
+ '把上面每一行念给用户确认,再用 finance_create_voucher 提交;凭证日期填该月最后一天,摘要「结转${period}损益」。',
1411
+ ];
1412
+ return ok(out.join('\n'));
1413
+ });
1414
+
1415
+ tool('finance_mark_tax_filed', {
1416
+ title: '标记申报完成/撤销',
1417
+ description: '把某个申报期标成「已申报」或退回「草稿」。⚠️ 会写状态(不是记账)。'
1418
+ + '只在用户确认已经在电子税务局报完之后调用;备注里写申报表上的应纳税额,方便日后对账。',
1419
+ inputSchema: {
1420
+ period: z.string().describe('申报期,如 2026-Q3'),
1421
+ status: z.enum(['filed', 'draft']).describe('filed = 已申报,draft = 退回草稿'),
1422
+ note: z.string().optional().describe('备注,如「增值税 1,234.56,所得税 0」'),
1423
+ },
1424
+ }, async ({ period, status, note }) => {
1425
+ const d = await request('/api/tax/status', { method: 'POST', body: { period, status, note } });
1426
+ return ok(status === 'filed'
1427
+ ? `✅ ${period} 已标记为「已申报」${note ? `(备注:${note})` : ''}。`
1428
+ : `↩️ ${period} 已退回「草稿」。`);
1429
+ });
1430
+
1330
1431
  /* ================================================================
1331
1432
  * 启动
1332
1433
  * ================================================================ */