ofw-mcp 2.21.0 → 2.22.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.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +48 -0
- package/dist/bundle.js +431 -265
- package/dist/tools/_confirm.js +17 -9
- package/dist/tools/expense-reimbursement.js +117 -0
- package/dist/tools/expenses.js +3 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/server.json +3 -3
- package/skills/ofw/SKILL.md +22 -0
package/dist/tools/_confirm.js
CHANGED
|
@@ -12,8 +12,10 @@ export const CONFIRM_NOTE = 'Asks the user to confirm first: a confirmation prom
|
|
|
12
12
|
* docs/CLIENT-BEHAVIOUR.md) gets the two-phase token flow governed by
|
|
13
13
|
* `MCP_CONFIRM_MODE`: phase 1 performs no write and returns the preview plus a
|
|
14
14
|
* `confirmToken`; only a repeat call with that token proceeds. The token is
|
|
15
|
-
* bound to this tool, the target, its revision
|
|
16
|
-
* single-use and
|
|
15
|
+
* bound to this tool/action, the target, its revision, exact payload, preview
|
|
16
|
+
* and caller arguments on BOTH rails. The fallback token is single-use and
|
|
17
|
+
* expires (`MCP_CONFIRM_TTL_SECONDS`); elicitation state uses the same TTL.
|
|
18
|
+
* Outstanding approvals minted before this binding change must be renewed.
|
|
17
19
|
*
|
|
18
20
|
* Call it on EVERY invocation with the freshly-built payload and a freshly
|
|
19
21
|
* read revision — the caller's own re-read is what makes a stale token fail.
|
|
@@ -24,6 +26,17 @@ export const CONFIRM_NOTE = 'Asks the user to confirm first: a confirmation prom
|
|
|
24
26
|
* return unchanged.
|
|
25
27
|
*/
|
|
26
28
|
export function confirmWrite(ctx, opts) {
|
|
29
|
+
// mcp-utils binds elicitation acceptance to args, NOT subject(). Carry the
|
|
30
|
+
// effective approval state into both rails; caller args alone omit fields
|
|
31
|
+
// inherited from fresh reads. Strip the phase-2 token before nesting args
|
|
32
|
+
// (the helper only strips a top-level confirmToken).
|
|
33
|
+
const { confirmToken: _confirmToken, ...args } = opts.args;
|
|
34
|
+
const subject = {
|
|
35
|
+
target: opts.target,
|
|
36
|
+
...(opts.revision !== undefined ? { revision: opts.revision } : {}),
|
|
37
|
+
payload: opts.payload,
|
|
38
|
+
preview: opts.preview,
|
|
39
|
+
};
|
|
27
40
|
return requireConfirmationWithFallback(ctx, confirmationFromEnv({
|
|
28
41
|
action: opts.action,
|
|
29
42
|
message: opts.message,
|
|
@@ -33,14 +46,9 @@ export function confirmWrite(ctx, opts) {
|
|
|
33
46
|
// One OFW account per process (OFW_USERNAME / the captured session), so
|
|
34
47
|
// there is no principal to distinguish; mcp-utils 3 makes saying so explicit.
|
|
35
48
|
account: undefined,
|
|
36
|
-
args: opts.args,
|
|
49
|
+
args: { tool: opts.tool, action: opts.action, args, ...subject },
|
|
37
50
|
confirmToken: opts.confirmToken,
|
|
38
|
-
subject: () =>
|
|
39
|
-
target: opts.target,
|
|
40
|
-
...(opts.revision !== undefined ? { revision: opts.revision } : {}),
|
|
41
|
-
payload: opts.payload,
|
|
42
|
-
preview: opts.preview,
|
|
43
|
-
}),
|
|
51
|
+
subject: () => subject,
|
|
44
52
|
}));
|
|
45
53
|
}
|
|
46
54
|
/**
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { parseLenient } from '@chrischall/mcp-utils';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { CONFIRM_NOTE, confirmTokenParam, confirmWrite, stateRevision } from './_confirm.js';
|
|
4
|
+
import { jsonErrorResponse, jsonResponse, requestWrite, UnconfirmedWriteError, unconfirmedWriteResponse } from './_shared.js';
|
|
5
|
+
// Allow ordinary binary floating point representations of exact cents, but
|
|
6
|
+
// never round a genuinely fractional cent or accept an unsafe monetary value.
|
|
7
|
+
const money = z.number().nonnegative().refine((v) => Number.isSafeInteger(Math.round(v * 100))
|
|
8
|
+
&& v === Math.round(v * 100) / 100, 'Must be an exact, safe cent amount');
|
|
9
|
+
const id = z.number().int().positive();
|
|
10
|
+
const detailSchema = z.looseObject({
|
|
11
|
+
id, title: z.string().min(1).refine((v) => v.trim().length > 0), author: z.looseObject({ userId: id }),
|
|
12
|
+
payer: z.looseObject({ userId: id }), private: z.boolean(), paymentType: z.string(),
|
|
13
|
+
amount: z.looseObject({ total: money.refine((v) => v > 0), totalOwed: money, leftToPay: money }),
|
|
14
|
+
status: z.string().min(1), statusInfo: z.looseObject({ baseStatus: z.string(), subStatus: z.literal('NONE') }),
|
|
15
|
+
category: z.looseObject({ id, split: z.looseObject({ parentSplit: z.string(), coparentSplit: z.string() }) }),
|
|
16
|
+
children: z.array(z.looseObject({ userId: id })).min(1),
|
|
17
|
+
}).refine((d) => d.amount.leftToPay <= d.amount.totalOwed && d.amount.totalOwed <= d.amount.total, 'Inconsistent expense balances');
|
|
18
|
+
// All fields outside the expected status/balance transition stay protected.
|
|
19
|
+
// OFW's amount display fields describe the current balance and legitimately
|
|
20
|
+
// change with settlement; the numeric purchase/owed totals remain immutable.
|
|
21
|
+
// Unknown fields outside these known derived displays remain protected too.
|
|
22
|
+
function immutableRevision(d) {
|
|
23
|
+
const { status: _status, statusInfo: _info, paymentType: _type, amount, ...rest } = d;
|
|
24
|
+
const { leftToPay: _balance, leftToPayFmt: _balanceFmt, description: _description, color: _color, ...amountRest } = amount;
|
|
25
|
+
return stateRevision({ ...rest, amount: amountRest });
|
|
26
|
+
}
|
|
27
|
+
/** Registered only by the full expense surface in write mode all. */
|
|
28
|
+
export function registerExpenseReimbursementTool(server, client) {
|
|
29
|
+
server.registerTool('ofw_mark_expense_reimbursed', {
|
|
30
|
+
description: 'Irreversibly mark the FULL remaining expense balance reimbursed externally. Records an already completed outside-OFW reimbursement only: does NOT send money or use bank/payment endpoints; no partial amounts. Requires expectedRemainingAmount (currency units, positive exact cents) matching the current leftToPay, NOT the full expense total. Reads the current expense, binds the entire detail to confirmation, rechecks immediately before writing, then verifies paid status and unchanged fields. Cannot be undone. On EXPENSE_REIMBURSEMENT_UNCONFIRMED, mayHaveLanded=true: inspect the OFW Expenses log before any retry; never replay blindly. ' + CONFIRM_NOTE,
|
|
31
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true },
|
|
32
|
+
inputSchema: z.object({
|
|
33
|
+
expenseId: id.describe('Existing expense entity id'),
|
|
34
|
+
expectedRemainingAmount: money.refine((v) => v > 0, 'Must be positive').describe('Full remaining external reimbursement in currency units (e.g. 48.50); must match leftToPay, not the expense total'),
|
|
35
|
+
confirmToken: confirmTokenParam,
|
|
36
|
+
}),
|
|
37
|
+
}, async (args, ctx) => {
|
|
38
|
+
const path = `/pub/v2/expense/expenses/${args.expenseId}`;
|
|
39
|
+
const read = async () => {
|
|
40
|
+
const d = parseLenient(detailSchema, await client.request('GET', path), { label: 'ofw-mcp', context: `GET ${path} (mark reimbursed)`, mode: 'strict' });
|
|
41
|
+
if (d.id !== args.expenseId)
|
|
42
|
+
throw new Error('Expense id does not match the requested expense');
|
|
43
|
+
return d;
|
|
44
|
+
};
|
|
45
|
+
let current;
|
|
46
|
+
try {
|
|
47
|
+
current = await read();
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return jsonErrorResponse({ result: 'EXPENSE_REIMBURSEMENT_REFUSED', expenseId: args.expenseId,
|
|
51
|
+
reason: 'Could not safely read the expense identity, status, parties and balances. Nothing was sent.' });
|
|
52
|
+
}
|
|
53
|
+
const base = current.statusInfo.baseStatus;
|
|
54
|
+
if (base === 'PAID' && current.amount.leftToPay === 0) {
|
|
55
|
+
return jsonResponse({ result: 'ALREADY_PAID', expenseId: args.expenseId, changed: false,
|
|
56
|
+
note: 'OFW already reports paid with zero remaining balance. No write or money transfer was performed.' });
|
|
57
|
+
}
|
|
58
|
+
if (!['OPEN', 'APPROVED', 'PARTIAL'].includes(base) || current.amount.leftToPay <= 0) {
|
|
59
|
+
return jsonErrorResponse({ result: 'EXPENSE_REIMBURSEMENT_REFUSED', expenseId: args.expenseId,
|
|
60
|
+
reason: 'Only OPEN, APPROVED or PARTIAL expenses with subStatus NONE and positive remaining balance are supported. Nothing was sent.' });
|
|
61
|
+
}
|
|
62
|
+
if (Math.round(current.amount.leftToPay * 100) !== Math.round(args.expectedRemainingAmount * 100)) {
|
|
63
|
+
return jsonErrorResponse({ result: 'EXPENSE_REMAINING_AMOUNT_MISMATCH', expenseId: args.expenseId,
|
|
64
|
+
expectedRemainingAmount: args.expectedRemainingAmount, remainingAmount: current.amount.leftToPay,
|
|
65
|
+
total: current.amount.total, reason: 'Approve the full remaining balance, not the original expense total or a partial payment. Nothing was sent.' });
|
|
66
|
+
}
|
|
67
|
+
const payload = { status: 'MARKED_REIMBURSED' };
|
|
68
|
+
const revision = stateRevision(current);
|
|
69
|
+
const gate = await confirmWrite(ctx, {
|
|
70
|
+
args, tool: 'ofw_mark_expense_reimbursed', action: 'ofw.expense.mark-reimbursed',
|
|
71
|
+
target: `expense:${args.expenseId}`, revision, payload, confirmToken: args.confirmToken,
|
|
72
|
+
message: `Mark "${current.title}" fully reimbursed externally (${current.amount.leftToPay}). This cannot be undone and does not transfer money.`,
|
|
73
|
+
preview: { expenseId: args.expenseId, title: current.title, authorUserId: current.author.userId,
|
|
74
|
+
payerUserId: current.payer.userId, category: current.category, children: current.children,
|
|
75
|
+
private: current.private, total: current.amount.total, totalOwed: current.amount.totalOwed,
|
|
76
|
+
remainingAmount: current.amount.leftToPay, status: current.status, statusInfo: current.statusInfo,
|
|
77
|
+
paymentType: current.paymentType,
|
|
78
|
+
warning: 'Mark the FULL remaining balance reimbursed outside OFW. This cannot be undone. No money is transferred; no bank/payment action is performed.' },
|
|
79
|
+
});
|
|
80
|
+
if (gate)
|
|
81
|
+
return gate;
|
|
82
|
+
try {
|
|
83
|
+
if (stateRevision(await read()) !== revision) {
|
|
84
|
+
return jsonErrorResponse({ result: 'EXPENSE_CHANGED', expenseId: args.expenseId,
|
|
85
|
+
reason: 'The expense changed after confirmation. Nothing was sent. Review it again before confirming.' });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return jsonErrorResponse({ result: 'EXPENSE_REIMBURSEMENT_REFUSED', expenseId: args.expenseId,
|
|
90
|
+
reason: 'The immediate pre-write check failed. Nothing was sent.' });
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
await requestWrite(client, 'PUT', `${path}/status`, payload);
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
if (!(e instanceof UnconfirmedWriteError))
|
|
97
|
+
throw e;
|
|
98
|
+
return unconfirmedWriteResponse(e, { result: 'EXPENSE_REIMBURSEMENT_UNCONFIRMED',
|
|
99
|
+
what: `mark expense ${args.expenseId} reimbursed`, checkWith: 'the Expenses log on ourfamilywizard.com' });
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const after = await read();
|
|
103
|
+
if (after.statusInfo.baseStatus !== 'PAID' || after.amount.leftToPay !== 0
|
|
104
|
+
|| after.paymentType !== 'Marked reimbursed' || immutableRevision(after) !== immutableRevision(current)) {
|
|
105
|
+
throw new Error('Paid status, external reimbursement marker, zero balance or unchanged expense fields could not be verified');
|
|
106
|
+
}
|
|
107
|
+
return jsonResponse({ result: 'EXPENSE_MARKED_REIMBURSED', expenseId: args.expenseId,
|
|
108
|
+
verified: true, reimbursedAmount: current.amount.leftToPay, remainingAmount: 0, moneyTransferred: false });
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
return unconfirmedWriteResponse(new UnconfirmedWriteError(args.expenseId, e), {
|
|
112
|
+
result: 'EXPENSE_REIMBURSEMENT_UNCONFIRMED', what: `verify reimbursement of expense ${args.expenseId}`,
|
|
113
|
+
checkWith: 'the Expenses log on ourfamilywizard.com'
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
package/dist/tools/expenses.js
CHANGED
|
@@ -6,6 +6,7 @@ import { readUpstreamPaging } from './pagination.js';
|
|
|
6
6
|
import { getExpenseUploadOnly, getWriteMode } from '../config.js';
|
|
7
7
|
import { parseLenient } from '@chrischall/mcp-utils';
|
|
8
8
|
import { RECEIPT_HOST_SUFFIX } from '../protocol.js';
|
|
9
|
+
import { registerExpenseReimbursementTool } from './expense-reimbursement.js';
|
|
9
10
|
const UploadedExpenseFileSchema = z.looseObject({
|
|
10
11
|
fileId: z.number(),
|
|
11
12
|
fileName: z.string().optional(),
|
|
@@ -202,6 +203,8 @@ export function registerExpenseTools(server, client, attachmentIO) {
|
|
|
202
203
|
? 'the Expenses log on ourfamilywizard.com (ofw_list_expenses is not available in this deployment)'
|
|
203
204
|
: 'ofw_list_expenses';
|
|
204
205
|
const allowWrites = writeMode === 'all';
|
|
206
|
+
if (allowWrites && !uploadOnly)
|
|
207
|
+
registerExpenseReimbursementTool(server, client);
|
|
205
208
|
// The receipt is uploaded SHARED (the only share class OFW accepts in an
|
|
206
209
|
// expense's fileIds), and a SHARED My Files entry is co-parent-visible at
|
|
207
210
|
// once — so, like ofw_upload_attachment's SHARED path, it needs mode 'all'.
|
package/dist/version.js
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
// package.json drift. Importing these instead of package.json keeps the whole
|
|
5
5
|
// manifest — npm scripts included — out of dist/bundle.js.
|
|
6
6
|
export const SERVER_NAME = 'ofw-mcp';
|
|
7
|
-
export const VERSION = '2.
|
|
7
|
+
export const VERSION = '2.22.0'; // x-release-please-version
|
package/package.json
CHANGED
package/server.json
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
"url": "https://github.com/chrischall/ofw-mcp",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "2.
|
|
9
|
+
"version": "2.22.0",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "ofw-mcp",
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.22.0",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
},
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
87
|
"name": "OFW_EXPENSE_UPLOAD_ONLY",
|
|
88
|
-
"description": "Set true for strict reimbursement upload mode: only healthcheck, ofw_upload_expense_pdf, ofw_create_expense, and ofw_update_expense register. Implies OFW_EXPENSE_ONLY.",
|
|
88
|
+
"description": "Set true for strict reimbursement upload mode: only healthcheck, ofw_upload_expense_pdf, ofw_create_expense, and ofw_update_expense register. Excludes ofw_mark_expense_reimbursed. Implies OFW_EXPENSE_ONLY.",
|
|
89
89
|
"isRequired": false,
|
|
90
90
|
"format": "string"
|
|
91
91
|
},
|
package/skills/ofw/SKILL.md
CHANGED
|
@@ -124,8 +124,30 @@ When `OFW_EXPENSE_ONLY=true`, only the healthcheck and expense tools exist. When
|
|
|
124
124
|
| `ofw_list_expense_categories` | Category ids and split metadata (use the id in create/update) |
|
|
125
125
|
| `ofw_upload_expense_pdf(path \| url, fileName?, label?, description?)` | Upload one receipt PDF to My Files (SHARED, co-parent-visible even on a private expense) for later attachment; confirm-gated; mode `all` only |
|
|
126
126
|
| `ofw_create_expense(title, amount, purchaseDate, categoryId, payerId, children, description?, privateExpense?, receiptFileId?)` | Log a new expense; confirm-gated; optionally private with one receipt |
|
|
127
|
+
| `ofw_mark_expense_reimbursed(expenseId, expectedRemainingAmount, confirmToken?)` | Confirm-gated, irreversible FULL remaining external reimbursement only; no money transfer or partial amount. Mode `all`, never upload-only. |
|
|
127
128
|
| `ofw_update_expense(expenseId, …only the fields to change…)` | Reads the expense and keeps every field you omit; `privateExpense:false` publishes a private expense; `receiptFileId` replaces all receipts, `null` clears it or `description`; refuses as `EXPENSE_FIELDS_UNREADABLE` (naming the fields) rather than erase one it can't read; confirm-gated |
|
|
128
129
|
|
|
130
|
+
### Recording reimbursement (not sending money)
|
|
131
|
+
|
|
132
|
+
Use `ofw_mark_expense_reimbursed` only after the user explicitly says the FULL
|
|
133
|
+
remaining balance was reimbursed outside OFW. Require `expectedRemainingAmount`
|
|
134
|
+
in currency units and exact cents, matching `amount.leftToPay`, not `amount.total`
|
|
135
|
+
or a guessed half. Show the tool's complete preview and irreversible warning,
|
|
136
|
+
confirm the author/payer ids refer to the intended parents, and wait for explicit
|
|
137
|
+
approval before returning the single-use `confirmToken` with identical args.
|
|
138
|
+
This is a status-only record: it never pays anyone or accesses payment/bank
|
|
139
|
+
endpoints and supports no partial reimbursement. It is absent in upload-only
|
|
140
|
+
mode and in write modes `none`/`drafts`.
|
|
141
|
+
|
|
142
|
+
The tool refuses pending/unknown statuses or unreadable financial details, binds
|
|
143
|
+
the full current detail to confirmation, re-GETs immediately before writing, and
|
|
144
|
+
verifies paid/zero/external-marker plus unchanged expense fields afterward. An
|
|
145
|
+
already paid zero balance is a no-op, not a new reimbursement. On
|
|
146
|
+
`EXPENSE_REIMBURSEMENT_UNCONFIRMED` (`mayHaveLanded=true`), inspect the expense in
|
|
147
|
+
the OFW web app; never automatically replay or roll back. Pre-write checks are
|
|
148
|
+
best-effort, not atomic against concurrent edits. See README's external
|
|
149
|
+
reimbursement section for the exact endpoint and verification contract.
|
|
150
|
+
|
|
129
151
|
### Journal
|
|
130
152
|
| Tool | Notes |
|
|
131
153
|
|------|-------|
|