ofw-mcp 2.21.0 → 2.23.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 +50 -1
- package/dist/bundle.js +942 -349
- package/dist/index.js +2 -1
- package/dist/timestamps.js +19 -0
- package/dist/tools/_confirm.js +17 -9
- package/dist/tools/_shared.js +6 -4
- package/dist/tools/attachments.js +21 -1
- package/dist/tools/calendar-ics.js +250 -0
- package/dist/tools/calendar.js +122 -10
- package/dist/tools/expense-reimbursement.js +117 -0
- package/dist/tools/expenses.js +3 -0
- package/dist/tools/messages.js +4 -18
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/server.json +3 -3
- package/skills/ofw/SKILL.md +24 -1
|
@@ -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/tools/messages.js
CHANGED
|
@@ -6,10 +6,10 @@ import { FOLDER_TYPE, newDraftKey, persistFolderIds, probeIds, resolveDraftKey }
|
|
|
6
6
|
import { CONFIRM_NOTE, confirmTokenParam, confirmWrite } from './_confirm.js';
|
|
7
7
|
import { getFolderVerifiedAt } from '../sync.js';
|
|
8
8
|
import { buildInlineDelivery, tryExtract } from './delivery.js';
|
|
9
|
-
import {
|
|
9
|
+
import { resolveDownloadMime, resolveSaveDest } from './attachments.js';
|
|
10
10
|
import { getAllowMarkRead, getAttachmentsDir, getAutoRefreshStaleReads, getDefaultInlineAttachments, getFetchUnreadBodies, getSyncMaxRequests, getWriteMode, } from '../config.js';
|
|
11
|
-
import { basename,
|
|
12
|
-
import { ApiRecipientSchema, deriveRead,
|
|
11
|
+
import { basename, resolve } from 'node:path';
|
|
12
|
+
import { ApiRecipientSchema, deriveRead, hasRealView, jsonErrorResponse, jsonResponse, jsonText, mapRecipients, notedJsonResponse, postMessageAndRefetch, reportsThreaded, UnconfirmedWriteError, reportsUnthreaded, threadedReplyTo, verifyWriteLanded, withReadState } from './_shared.js';
|
|
13
13
|
import { parseLenient } from '@chrischall/mcp-utils';
|
|
14
14
|
import { pageState } from './pagination.js';
|
|
15
15
|
import { MESSAGE_VIEWS, viewDrafts, viewMessages, viewOne } from './project.js';
|
|
@@ -1664,7 +1664,6 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1664
1664
|
diskAvailable: attachmentIO.supportsDisk,
|
|
1665
1665
|
});
|
|
1666
1666
|
}
|
|
1667
|
-
let dest;
|
|
1668
1667
|
// The filename comes from OFW file metadata — i.e. it is controlled by the
|
|
1669
1668
|
// co-parent who uploaded the attachment. basename() it before interpolating
|
|
1670
1669
|
// into a path so a crafted `../…` name can't escape the target directory
|
|
@@ -1675,20 +1674,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
|
|
|
1675
1674
|
// — reachable through an instruction injected into a message body — must
|
|
1676
1675
|
// be impossible, not merely discouraged.
|
|
1677
1676
|
const root = resolve(getAttachmentsDir());
|
|
1678
|
-
|
|
1679
|
-
// Treat saveTo as a directory if it ends with a separator; otherwise as a full path.
|
|
1680
|
-
const isDirArg = args.saveTo.endsWith('/') || args.saveTo.endsWith('\\');
|
|
1681
|
-
// expandPath resolves a relative path against the process cwd; resolve
|
|
1682
|
-
// it against the attachments dir instead, and only expand a leading ~.
|
|
1683
|
-
const abs = resolve(root, args.saveTo.startsWith('~') ? expandPath(args.saveTo) : args.saveTo);
|
|
1684
|
-
dest = isDirArg ? join(abs, `${fileId}-${safeName}`) : abs;
|
|
1685
|
-
if (!isWithin(root, dest)) {
|
|
1686
|
-
throw new Error(`Refusing to save to ${dest}: it is outside the attachments directory (${root}). Downloads can only be written inside it — pass a path or subdirectory under it, or set OFW_ATTACHMENTS_DIR to move it.`);
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
else {
|
|
1690
|
-
dest = join(root, `${fileId}-${safeName}`);
|
|
1691
|
-
}
|
|
1677
|
+
const dest = resolveSaveDest(root, args.saveTo, `${fileId}-${safeName}`);
|
|
1692
1678
|
// Disk mode extracts only on request: the caller already has a real file to
|
|
1693
1679
|
// open, so extraction is an add-on here rather than the point.
|
|
1694
1680
|
const extractOnDisk = args.extract === true;
|
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.23.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.23.0",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "ofw-mcp",
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.23.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
|
@@ -107,7 +107,8 @@ Always pass `--config ~/.mcporter/mcporter.json` unless a local `config/mcporter
|
|
|
107
107
|
### Calendar
|
|
108
108
|
| Tool | Notes |
|
|
109
109
|
|------|-------|
|
|
110
|
-
| `ofw_list_events(startDate, endDate, detailed?)` | Dates as `YYYY-MM-DD` |
|
|
110
|
+
| `ofw_list_events(startDate, endDate, detailed?, types?, timeZone?, format?)` | Dates as `YYYY-MM-DD`. `types` keeps only `EVENT`/`CONNECTED_EVENT`/`TRANSITION` (custody handoffs)/`SCHEDULE` (the per-day custody grid — heavy; omit unless needed). `timeZone` is the account's IANA zone when it differs from the server's. `format:"ics"` returns a summary then iCalendar text |
|
|
111
|
+
| `ofw_save_calendar_ics(startDate, endDate, types?, timeZone?, saveTo?, linkMinutes?)` | The `.ics` as a file: a private download link that expires (hosted) or a path in the attachments directory (local). Each custody period becomes a "Parenting time" event. A snapshot — it does not update |
|
|
111
112
|
| `ofw_create_event(title, startDate, endDate, ...)` | `startDate`/`endDate` as ISO datetime |
|
|
112
113
|
| `ofw_update_event(eventId, ...)` | Partial update — only pass fields to change |
|
|
113
114
|
| `ofw_delete_event(eventId)` | Permanent delete |
|
|
@@ -124,8 +125,30 @@ When `OFW_EXPENSE_ONLY=true`, only the healthcheck and expense tools exist. When
|
|
|
124
125
|
| `ofw_list_expense_categories` | Category ids and split metadata (use the id in create/update) |
|
|
125
126
|
| `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
127
|
| `ofw_create_expense(title, amount, purchaseDate, categoryId, payerId, children, description?, privateExpense?, receiptFileId?)` | Log a new expense; confirm-gated; optionally private with one receipt |
|
|
128
|
+
| `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
129
|
| `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
130
|
|
|
131
|
+
### Recording reimbursement (not sending money)
|
|
132
|
+
|
|
133
|
+
Use `ofw_mark_expense_reimbursed` only after the user explicitly says the FULL
|
|
134
|
+
remaining balance was reimbursed outside OFW. Require `expectedRemainingAmount`
|
|
135
|
+
in currency units and exact cents, matching `amount.leftToPay`, not `amount.total`
|
|
136
|
+
or a guessed half. Show the tool's complete preview and irreversible warning,
|
|
137
|
+
confirm the author/payer ids refer to the intended parents, and wait for explicit
|
|
138
|
+
approval before returning the single-use `confirmToken` with identical args.
|
|
139
|
+
This is a status-only record: it never pays anyone or accesses payment/bank
|
|
140
|
+
endpoints and supports no partial reimbursement. It is absent in upload-only
|
|
141
|
+
mode and in write modes `none`/`drafts`.
|
|
142
|
+
|
|
143
|
+
The tool refuses pending/unknown statuses or unreadable financial details, binds
|
|
144
|
+
the full current detail to confirmation, re-GETs immediately before writing, and
|
|
145
|
+
verifies paid/zero/external-marker plus unchanged expense fields afterward. An
|
|
146
|
+
already paid zero balance is a no-op, not a new reimbursement. On
|
|
147
|
+
`EXPENSE_REIMBURSEMENT_UNCONFIRMED` (`mayHaveLanded=true`), inspect the expense in
|
|
148
|
+
the OFW web app; never automatically replay or roll back. Pre-write checks are
|
|
149
|
+
best-effort, not atomic against concurrent edits. See README's external
|
|
150
|
+
reimbursement section for the exact endpoint and verification contract.
|
|
151
|
+
|
|
129
152
|
### Journal
|
|
130
153
|
| Tool | Notes |
|
|
131
154
|
|------|-------|
|