ofw-mcp 2.22.0 → 2.24.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.
@@ -6,15 +6,15 @@ 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 { isWithin, resolveDownloadMime } from './attachments.js';
10
- import { getAllowMarkRead, getAttachmentsDir, getAutoRefreshStaleReads, getDefaultInlineAttachments, getFetchUnreadBodies, getSyncMaxRequests, getWriteMode, } from '../config.js';
11
- import { basename, join, resolve } from 'node:path';
12
- import { ApiRecipientSchema, deriveRead, expandPath, hasRealView, jsonErrorResponse, jsonResponse, jsonText, mapRecipients, notedJsonResponse, postMessageAndRefetch, reportsThreaded, UnconfirmedWriteError, reportsUnthreaded, threadedReplyTo, verifyWriteLanded, withReadState } from './_shared.js';
9
+ import { resolveDownloadMime, resolveSaveDest } from './attachments.js';
10
+ import { getAllowMarkRead, getConfirmMarkRead, getAttachmentsDir, getAutoRefreshStaleReads, getDefaultInlineAttachments, getFetchUnreadBodies, getSyncMaxRequests, getWriteMode, } from '../config.js';
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
- import { MESSAGE_VIEWS, viewDrafts, viewMessages, viewOne } from './project.js';
15
+ import { MESSAGE_VIEWS, senderOf, viewDrafts, viewMessages, viewOne } from './project.js';
16
16
  import { resolveView, viewParam } from '@chrischall/mcp-utils';
17
- import { nowNaiveWallClock, toNaiveWallClock } from '../timestamps.js';
17
+ import { normalizeTimestampsInValue, nowNaiveWallClock, toNaiveWallClock } from '../timestamps.js';
18
18
  import { readingBlockedToday } from '../read-days.js';
19
19
  // Schemas for the load-bearing fields of each /pub/v3 response this file
20
20
  // reads (issue #83). Loose: unknown keys pass through into cached listData.
@@ -205,12 +205,62 @@ function unverifiedEmptyResponse(input) {
205
205
  });
206
206
  }
207
207
  /**
208
- * Whether ANY tool may mark a message read right now: the OFW_ALLOW_MARK_READ
209
- * ceiling, AND today being a reading day (OFW_READ_DAYS / OFW_NO_READ_DAYS).
210
- * Both are deployment settings a per-call argument cannot raise.
208
+ * Whether a BULK path may mark messages read right now (sync's
209
+ * fetchUnreadBodies, the allowMarkRead probes): the OFW_ALLOW_MARK_READ
210
+ * ceiling, today being a reading day (OFW_READ_DAYS / OFW_NO_READ_DAYS), and
211
+ * OFW_CONFIRM_MARK_READ being off — those paths stamp many messages without
212
+ * looking at any of them, so they have nothing to put in front of the user.
213
+ * With confirmation on, ofw_get_message (which asks) is the one way in. All
214
+ * are deployment settings a per-call argument cannot raise.
211
215
  */
212
216
  function markReadPermitted() {
213
- return getAllowMarkRead() && readingBlockedToday() === null;
217
+ return getAllowMarkRead() && readingBlockedToday() === null && !getConfirmMarkRead();
218
+ }
219
+ /**
220
+ * OFW_CONFIRM_MARK_READ: before `ofw_get_message` fetches a body that would
221
+ * mark an unread inbox message read, show the user which message it is and
222
+ * ask. Called only after markReadVerdict let the fetch through, so the
223
+ * OFW_ALLOW_MARK_READ ceiling and allowMarkRead:false have already refused.
224
+ *
225
+ * Returns undefined to proceed with the fetch, otherwise the result to return.
226
+ */
227
+ async function confirmMarkRead(ctx, cached, args) {
228
+ if (!getConfirmMarkRead())
229
+ return undefined;
230
+ // Same "would this stamp?" rule as markReadVerdict: a sent or already-read
231
+ // message changes nothing on OFW, so there is nothing to ask about.
232
+ if (cached !== null && !(cached.folder === 'inbox' && !deriveRead(cached)))
233
+ return undefined;
234
+ if (cached === null) {
235
+ // Nothing to show: the subject and time live only behind the request that
236
+ // would stamp it. A prompt reading "open message 123?" is not a choice.
237
+ return jsonErrorResponse({
238
+ error: 'MARK_READ_CONFIRMATION_UNAVAILABLE',
239
+ messageId: Number(args.messageId),
240
+ reason: 'This server asks before opening an unread message (OFW_CONFIRM_MARK_READ), but this id is not in the cache, so there is no subject or time to show — and fetching them is the request that would mark it read.',
241
+ hint: 'Run ofw_sync_messages first: it walks list pages, not bodies, so it learns the subject and sent time without marking anything read. Then call ofw_get_message again.',
242
+ });
243
+ }
244
+ // The preview never passes through jsonResponse, so normalize here: sentAt
245
+ // gains its explicit offset and a weekday-first sentAtDisplay.
246
+ const when = normalizeTimestampsInValue({ sentAt: cached.sentAt });
247
+ return confirmWrite(ctx, {
248
+ args,
249
+ tool: 'ofw_get_message',
250
+ action: 'ofw.message.mark_read',
251
+ message: `Open this unread OurFamilyWizard message and mark it read? "${cached.subject}" — ${when.sentAtDisplay ?? cached.sentAt}. Opening it stamps a "First Viewed" time your co-parent can see; that cannot be undone.`,
252
+ target: `message:${cached.id}`,
253
+ payload: { messageId: cached.id, markRead: true },
254
+ preview: {
255
+ action: 'Open unread OurFamilyWizard message (marks it READ)',
256
+ warning: 'Opening this message marks it read on OurFamilyWizard and stamps a "First Viewed" time your co-parent can see. It is part of the record and cannot be undone.',
257
+ messageId: cached.id,
258
+ subject: cached.subject,
259
+ from: senderOf(cached),
260
+ ...when,
261
+ },
262
+ confirmToken: args.confirmToken,
263
+ });
214
264
  }
215
265
  /**
216
266
  * A message row with its content removed, for a no-read day. The body goes,
@@ -469,7 +519,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
469
519
  return jsonResponse(payload);
470
520
  });
471
521
  server.registerTool('ofw_get_message', {
472
- description: 'Get a single OurFamilyWizard message OR draft by ID. Reads from local cache when available; otherwise fetches from OFW — and for an UNREAD INBOX message that fetch marks it read and stamps a "First Viewed" time the co-parent can see, which is part of the record and cannot be undone. Pass allowMarkRead:false to refuse such a fetch instead (cached bodies, sent messages and already-read messages are unaffected, because none of them stamp anything). For ids that match a draft (in the drafts cache), the response carries folder="drafts" and the body/subject/recipients reflect the drafts cache (which ofw_sync_messages keeps fresh) — drafts have no `fromUser`, and `sentAt`/`fetchedBodyAt` mirror the draft\'s `modifiedAt`. For inbox/sent messages, folder is "inbox" or "sent" as before. On a server-configured no-read day (OFW_READ_DAYS / OFW_NO_READ_DAYS) inbox/sent bodies are withheld (body:null, bodyWithheld:true, readingBlocked says when reading resumes) and OFW is never contacted.',
522
+ description: 'Get a single OurFamilyWizard message OR draft by ID. Reads from local cache when available; otherwise fetches from OFW — and for an UNREAD INBOX message that fetch marks it read and stamps a "First Viewed" time the co-parent can see, which is part of the record and cannot be undone. Pass allowMarkRead:false to refuse such a fetch instead (cached bodies, sent messages and already-read messages are unaffected, because none of them stamp anything). For ids that match a draft (in the drafts cache), the response carries folder="drafts" and the body/subject/recipients reflect the drafts cache (which ofw_sync_messages keeps fresh) — drafts have no `fromUser`, and `sentAt`/`fetchedBodyAt` mirror the draft\'s `modifiedAt`. For inbox/sent messages, folder is "inbox" or "sent" as before. On a server-configured no-read day (OFW_READ_DAYS / OFW_NO_READ_DAYS) inbox/sent bodies are withheld (body:null, bodyWithheld:true, readingBlocked says when reading resumes) and OFW is never contacted. When the server runs with OFW_CONFIRM_MARK_READ=true, opening an unread inbox message first shows its subject, sender and sent time and asks the user to confirm marking it read: a confirmation prompt where the client supports one; otherwise the first call fetches NOTHING and returns that preview plus a confirmToken, and only a repeat call with that token opens the message (see MCP_CONFIRM_MODE). Show the user the preview and wait for their yes before repeating the call.',
473
523
  annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true },
474
524
  inputSchema: z.object({
475
525
  messageId: z.string().describe('Message ID (also accepts draft IDs — drafts are routed via the drafts cache)'),
@@ -477,8 +527,9 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
477
527
  view: viewParam(MESSAGE_VIEWS, {
478
528
  note: 'compact omits OurFamilyWizard\'s raw `listData` echo, which duplicates this record\'s own id, subject, sentAt, recipients and read flag; the sender is promoted to `from`, and `files`/`replied` are kept. Pass "full" for the echo.',
479
529
  }),
530
+ confirmToken: confirmTokenParam,
480
531
  }),
481
- }, async (args) => {
532
+ }, async (args, ctx) => {
482
533
  const id = Number(args.messageId);
483
534
  const view = resolveView(args.view, MESSAGE_VIEWS);
484
535
  const cache = cacheProvider();
@@ -615,6 +666,9 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
615
666
  const markReadCheck = markReadVerdict(cached, args.allowMarkRead);
616
667
  if (markReadCheck !== null)
617
668
  return markReadCheck;
669
+ const confirmGate = await confirmMarkRead(ctx, cached, args);
670
+ if (confirmGate)
671
+ return confirmGate;
618
672
  const detail = parseLenient(MessageDetailSchema, await client.request('GET', `/pub/v3/messages/${encodeURIComponent(args.messageId)}`), { label: 'ofw-mcp', context: 'GET /pub/v3/messages/{id} (ofw_get_message)' });
619
673
  // Derive the folder for a live-fetched message. A cached row (reached here
620
674
  // only when its body was NULL) already knows its folder, so keep it.
@@ -1664,7 +1718,6 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
1664
1718
  diskAvailable: attachmentIO.supportsDisk,
1665
1719
  });
1666
1720
  }
1667
- let dest;
1668
1721
  // The filename comes from OFW file metadata — i.e. it is controlled by the
1669
1722
  // co-parent who uploaded the attachment. basename() it before interpolating
1670
1723
  // into a path so a crafted `../…` name can't escape the target directory
@@ -1675,20 +1728,7 @@ export function registerMessageTools(server, client, cacheProvider, attachmentIO
1675
1728
  // — reachable through an instruction injected into a message body — must
1676
1729
  // be impossible, not merely discouraged.
1677
1730
  const root = resolve(getAttachmentsDir());
1678
- if (args.saveTo) {
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
- }
1731
+ const dest = resolveSaveDest(root, args.saveTo, `${fileId}-${safeName}`);
1692
1732
  // Disk mode extracts only on request: the caller already has a real file to
1693
1733
  // open, so extraction is an add-on here rather than the point.
1694
1734
  const extractOnDisk = args.extract === true;
@@ -45,7 +45,7 @@ function asRecord(value) {
45
45
  * it would have taken the sender's name off every message, and compact is
46
46
  * where a field that has never worked starts working.
47
47
  */
48
- function senderOf(row) {
48
+ export function senderOf(row) {
49
49
  if (typeof row.fromUser === 'string' && row.fromUser !== '')
50
50
  return row.fromUser;
51
51
  const author = asRecord(asRecord(row.listData)?.author);
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.22.0'; // x-release-please-version
7
+ export const VERSION = '2.24.0'; // x-release-please-version
package/mint.yaml CHANGED
@@ -78,6 +78,13 @@ env:
78
78
  on OurFamilyWizard - reading a body for the first time stamps a
79
79
  co-parent-visible "First Viewed" time that cannot be undone. A ceiling: no
80
80
  per-call argument can raise it.
81
+ - name: OFW_CONFIRM_MARK_READ
82
+ required: false
83
+ help: >-
84
+ Default "false". Set "true" to show an unread message's subject, sender
85
+ and sent time and ask for confirmation before opening it marks it read on
86
+ OurFamilyWizard. Also disables the bulk mark-read paths (sync
87
+ fetchUnreadBodies, allowMarkRead probes), which cannot ask per message.
81
88
  - name: OFW_FETCH_UNREAD_BODIES
82
89
  required: false
83
90
  help: >-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ofw-mcp",
3
- "version": "2.22.0",
3
+ "version": "2.24.0",
4
4
  "license": "MIT",
5
5
  "mcpName": "io.github.chrischall/ofw-mcp",
6
6
  "description": "OurFamilyWizard MCP server for Claude — developed and maintained by AI (Claude Code)",
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.22.0",
9
+ "version": "2.24.0",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "ofw-mcp",
14
- "version": "2.22.0",
14
+ "version": "2.24.0",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },
@@ -47,6 +47,12 @@
47
47
  "isRequired": false,
48
48
  "format": "string"
49
49
  },
50
+ {
51
+ "name": "OFW_CONFIRM_MARK_READ",
52
+ "description": "Default \"false\". Set \"true\" to show an unread message's subject, sender and sent time and ask for confirmation before opening it marks it read. Also disables the bulk mark-read paths (sync fetchUnreadBodies, allowMarkRead probes).",
53
+ "isRequired": false,
54
+ "format": "string"
55
+ },
50
56
  {
51
57
  "name": "OFW_FETCH_UNREAD_BODIES",
52
58
  "description": "Default \"false\". Whether ofw_sync_messages fetches unread inbox bodies by default (each fetch stamps a First Viewed time). Capped by OFW_ALLOW_MARK_READ.",
@@ -93,7 +93,7 @@ Always pass `--config ~/.mcporter/mcporter.json` unless a local `config/mcporter
93
93
  | `ofw_sync_messages(folders?, deep?, fetchUnreadBodies?)` | Sync OFW → local cache. **Call first if the cache might be stale.** Returns unread inbox hints (bodies not fetched, to avoid mark-as-read). |
94
94
  | `ofw_list_message_folders` | List OFW folders with unread counts. Most reads use the cache; this is mainly for folder IDs and live unread counts. |
95
95
  | `ofw_list_messages(folderId?, since?, until?, q?, sort?, page?, size?, autoRefresh?, view?)` | Cache-backed list. Supports folder ("inbox"/"sent"/"both"), date range, and substring search. `sort:"oldest"` starts at the old end of a range instead of paging to it (default `"newest"`). Returns `complete` for the RESULT SET plus **`nextPage`** (null when done) — and the paging keys come FIRST in the JSON, before `messages`. `returned` carries the record count as a scalar, beside `total`. An **empty** result from a non-fresh cache is refused (`UNVERIFIED_EMPTY`) — pass `autoRefresh:true` to sync and answer instead. |
96
- | `ofw_get_message(messageId, allowMarkRead?, view?)` | Read a message OR draft body. Cache-first. Ids in the drafts cache return `folder: "drafts"`. ⚠️ Falls through to OFW for unread inbox messages, which marks them read AND stamps a "First Viewed" time the co-parent can see — irreversible. Pass `allowMarkRead:false` to refuse that fetch instead; cached, sent and already-read messages are unaffected. On a server-configured no-read day (`readingBlocked` / `READING_BLOCKED` in the response) the body is withheld (`bodyWithheld: true`) — report the sender, date and subject, say when `nextReadableDay` is, and do not try to work around it. |
96
+ | `ofw_get_message(messageId, allowMarkRead?, view?)` | Read a message OR draft body. Cache-first. Ids in the drafts cache return `folder: "drafts"`. ⚠️ Falls through to OFW for unread inbox messages, which marks them read AND stamps a "First Viewed" time the co-parent can see — irreversible. Pass `allowMarkRead:false` to refuse that fetch instead; cached, sent and already-read messages are unaffected. If the server runs with `OFW_CONFIRM_MARK_READ`, the first call returns a preview (subject, sender, sent time) instead of the body: show it to the user and repeat the call with its `confirmToken` only after they say yes. On a server-configured no-read day (`readingBlocked` / `READING_BLOCKED` in the response) the body is withheld (`bodyWithheld: true`) — report the sender, date and subject, say when `nextReadableDay` is, and do not try to work around it. |
97
97
  | `ofw_send_message(draftId?, subject?, body?, recipientIds?, replyToId?, expectedRevision?, deleteDraftOnSuccess?, myFileIDs?, force?)` | Send a message — **the one irreversible operation**. Preferred path: pass `draftId` (+ `expectedRevision`) to send an existing draft **as it exists on the server** — the tool re-reads it from OFW first and refuses if it changed since you read it (or was already sent/deleted); `subject`/`body` become optional overrides. `recipientIds` is usually still required: OFW does not store recipients on drafts. After a **confirmed** send the draft is auto-deleted (`deleteDraftOnSuccess:false` to keep it); on any failure or ambiguity it is retained and the response says why (`draftRetained`). Response leads with `sentMessageId`, `draftKey`, `threaded`, `draftDeleted`. Compose from scratch by passing `subject`/`body`/`recipientIds` with no `draftId`. |
98
98
  | `ofw_get_unread_sent(page?, size?, autoRefresh?)` | Sent messages your co-parent hasn't read yet (from cache). Leads with `complete`/`hasMore`/`nextPage`, then `scanned`/`total`, then `unread`; an empty sent cache that is not fresh is refused rather than reported as "nothing sent". |
99
99
  | `ofw_list_drafts(page?, size?, verify?, autoRefresh?, view?)` | Leads with `complete`/`hasMore`/`nextPage`; `drafts` comes last. List saved drafts, **auto-verified**: when the cache is not verified-fresh a cheap drafts sync runs first (default `verify:true`), so one call answers server-confirmed. `verify:false` serves straight from cache. Each draft carries `serverConfirmed`, `revision` and `draftKey`. Returns `complete` — **check it before saying "you have N drafts"**. See [Freshness](#freshness). |
@@ -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 |