langmail-mcp 0.0.0 → 0.2.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/LICENSE +1 -1
- package/README.md +89 -169
- package/dist/chunk-0fxfqny0.js +12642 -0
- package/dist/langmail-mcp.js +7 -0
- package/package.json +93 -98
- package/THIRD_PARTY_NOTICES.md +0 -388
- package/dist/attachments/download.js +0 -69
- package/dist/attachments/routes.js +0 -42
- package/dist/attachments/tickets.js +0 -45
- package/dist/attachments/upload-tickets.js +0 -43
- package/dist/attachments/upload.js +0 -136
- package/dist/caldav/account-settings.js +0 -92
- package/dist/caldav/agenda.js +0 -277
- package/dist/caldav/alarm.js +0 -97
- package/dist/caldav/client.js +0 -408
- package/dist/caldav/ical.js +0 -248
- package/dist/caldav/occurrence.js +0 -534
- package/dist/caldav/recurrence.js +0 -313
- package/dist/caldav/rsvp.js +0 -107
- package/dist/caldav/scheduling-handover.js +0 -22
- package/dist/caldav/timezone.js +0 -103
- package/dist/caldav/types.js +0 -5
- package/dist/config.js +0 -219
- package/dist/contacts/address-class.js +0 -79
- package/dist/contacts/birthdays.js +0 -81
- package/dist/contacts/card.js +0 -58
- package/dist/contacts/constants.js +0 -46
- package/dist/contacts/fold.js +0 -309
- package/dist/contacts/index.js +0 -10
- package/dist/contacts/merge.js +0 -388
- package/dist/contacts/observations.js +0 -115
- package/dist/contacts/profile.js +0 -402
- package/dist/contacts/scoring.js +0 -146
- package/dist/contacts/types.js +0 -7
- package/dist/contacts/upsert.js +0 -131
- package/dist/drafts/attachments.js +0 -254
- package/dist/drafts/idempotency.js +0 -60
- package/dist/drafts/send-guard.js +0 -184
- package/dist/email-render/email-viewer.html +0 -143
- package/dist/email-render/image-proxy.js +0 -389
- package/dist/email-render/meta.js +0 -48
- package/dist/email-render/sanitize.js +0 -93
- package/dist/email-render/viewer-resource.js +0 -104
- package/dist/http/bearer.js +0 -30
- package/dist/http/guard.js +0 -57
- package/dist/http/hosts.js +0 -10
- package/dist/http/listener.js +0 -170
- package/dist/http/routes.js +0 -72
- package/dist/ical/ical-parse.js +0 -357
- package/dist/ical/index.js +0 -4
- package/dist/ical/timezone.js +0 -22
- package/dist/ical/windows-zones.js +0 -155
- package/dist/index.js +0 -79
- package/dist/jmap/blob.js +0 -49
- package/dist/jmap/contacts.js +0 -226
- package/dist/jmap/drafts.js +0 -480
- package/dist/jmap/email.js +0 -668
- package/dist/jmap/index.js +0 -12
- package/dist/jmap/keywords.js +0 -22
- package/dist/jmap/live.js +0 -21
- package/dist/jmap/origin.js +0 -113
- package/dist/jmap/patch.js +0 -29
- package/dist/jmap/request.js +0 -37
- package/dist/jmap/session.js +0 -89
- package/dist/jmap/sieve.js +0 -71
- package/dist/jmap/submission.js +0 -107
- package/dist/jmap/timeout.js +0 -30
- package/dist/jmap/types.js +0 -6
- package/dist/logger.js +0 -48
- package/dist/mcp/handler.js +0 -255
- package/dist/mcp/http.js +0 -29
- package/dist/mcp/instructions.js +0 -44
- package/dist/mcp/links.js +0 -64
- package/dist/mcp/test-client.js +0 -43
- package/dist/mcp/tool-logging.js +0 -67
- package/dist/observability/errors.js +0 -41
- package/dist/rules/apply.js +0 -236
- package/dist/rules/rule.js +0 -280
- package/dist/rules/store.js +0 -92
- package/dist/tools/annotations.js +0 -71
- package/dist/tools/archive-emails.js +0 -40
- package/dist/tools/calendar-lookup.js +0 -64
- package/dist/tools/contact-common.js +0 -146
- package/dist/tools/contact-format.js +0 -72
- package/dist/tools/contact-write-through.js +0 -37
- package/dist/tools/create-calendar-event.js +0 -231
- package/dist/tools/create-calendar.js +0 -54
- package/dist/tools/create-contact.js +0 -172
- package/dist/tools/create-draft.js +0 -369
- package/dist/tools/create-mail-rule.js +0 -101
- package/dist/tools/delete-calendar-event.js +0 -165
- package/dist/tools/delete-contact.js +0 -60
- package/dist/tools/delete-draft.js +0 -129
- package/dist/tools/delete-mail-rule.js +0 -38
- package/dist/tools/download-attachment.js +0 -90
- package/dist/tools/download-email.js +0 -112
- package/dist/tools/draft-common.js +0 -600
- package/dist/tools/email-types.js +0 -58
- package/dist/tools/error-detail.js +0 -10
- package/dist/tools/file-emails-common.js +0 -75
- package/dist/tools/format.js +0 -131
- package/dist/tools/forward-message.js +0 -237
- package/dist/tools/forward-quote.js +0 -179
- package/dist/tools/get-draft.js +0 -61
- package/dist/tools/get-email.js +0 -164
- package/dist/tools/get-thread.js +0 -67
- package/dist/tools/keywords.js +0 -43
- package/dist/tools/list-calendar-events.js +0 -180
- package/dist/tools/list-calendars.js +0 -44
- package/dist/tools/list-drafts.js +0 -134
- package/dist/tools/list-mail-rules.js +0 -28
- package/dist/tools/list-unsubscribe.js +0 -152
- package/dist/tools/list-upcoming-birthdays.js +0 -165
- package/dist/tools/mail-rule-common.js +0 -43
- package/dist/tools/mail-rule-format.js +0 -79
- package/dist/tools/mailbox-lookup.js +0 -13
- package/dist/tools/mark-emails.js +0 -78
- package/dist/tools/merge-contacts.js +0 -145
- package/dist/tools/move-calendar-events.js +0 -340
- package/dist/tools/move-emails.js +0 -64
- package/dist/tools/one-click-post.js +0 -275
- package/dist/tools/preview-email.js +0 -204
- package/dist/tools/preview-mail-rule.js +0 -79
- package/dist/tools/reply-quote.js +0 -426
- package/dist/tools/reply-to-message.js +0 -292
- package/dist/tools/respond-to-event.js +0 -110
- package/dist/tools/result.js +0 -9
- package/dist/tools/search-contacts.js +0 -431
- package/dist/tools/search-emails.js +0 -570
- package/dist/tools/send-draft.js +0 -308
- package/dist/tools/trash-emails.js +0 -36
- package/dist/tools/unsubscribe-from-list.js +0 -249
- package/dist/tools/update-calendar-event.js +0 -973
- package/dist/tools/update-calendar.js +0 -100
- package/dist/tools/update-contact.js +0 -382
- package/dist/tools/update-draft.js +0 -714
- package/dist/tools/update-mail-rule.js +0 -103
- package/dist/tools/upload-attachments.js +0 -126
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
// update_mail_rule tool — modify an existing rule in place while preserving
|
|
2
|
-
// its identity (id, createdAt). Only the provided parts change; conditions
|
|
3
|
-
// and actions are replaced wholesale when given (a partial merge of
|
|
4
|
-
// condition fields would be ambiguous about clearing). Optionally applies
|
|
5
|
-
// the updated actions to existing matching mail, same policy as create.
|
|
6
|
-
import { z } from "zod";
|
|
7
|
-
import { LARGE_APPLY_THRESHOLD } from "../rules/apply.js";
|
|
8
|
-
import { hasAnyCondition, normalizeConditions, } from "../rules/rule.js";
|
|
9
|
-
import { OUTWARD_WRITE } from "./annotations.js";
|
|
10
|
-
import { existingMailSchema, existingMailShape, ruleActionsField, ruleConditionsField, ruleMatchField, ruleNameField, ruleTimestamp, } from "./mail-rule-common.js";
|
|
11
|
-
import { formatApplyResult, formatMailRule } from "./mail-rule-format.js";
|
|
12
|
-
import { errorResult, textResult } from "./result.js";
|
|
13
|
-
const updateMailRuleShape = {
|
|
14
|
-
actions: ruleActionsField
|
|
15
|
-
.optional()
|
|
16
|
-
.describe("Replacement action list (replaces all current actions, in order)."),
|
|
17
|
-
conditions: ruleConditionsField
|
|
18
|
-
.optional()
|
|
19
|
-
.describe("Replacement conditions (replace all current conditions; at least one required when given)."),
|
|
20
|
-
enabled: z
|
|
21
|
-
.boolean()
|
|
22
|
-
.optional()
|
|
23
|
-
.describe("Enable (true) or disable (false) the rule without deleting it."),
|
|
24
|
-
existingMail: z
|
|
25
|
-
.object(existingMailShape)
|
|
26
|
-
.optional()
|
|
27
|
-
.describe("Optionally apply the UPDATED rule to existing mail after saving, same policy as create_mail_rule."),
|
|
28
|
-
match: ruleMatchField.optional(),
|
|
29
|
-
name: ruleNameField.optional(),
|
|
30
|
-
ruleId: z
|
|
31
|
-
.string()
|
|
32
|
-
.min(1)
|
|
33
|
-
.describe("The id of the rule to update, as returned by create_mail_rule or list_mail_rules."),
|
|
34
|
-
};
|
|
35
|
-
export const updateMailRuleInput = z
|
|
36
|
-
.object(updateMailRuleShape)
|
|
37
|
-
.refine((v) => v.conditions === undefined || hasAnyCondition(v.conditions), {
|
|
38
|
-
message: "Replacement conditions need at least one of: from, to, subject, bodyContains, hasAttachment.",
|
|
39
|
-
})
|
|
40
|
-
.refine((v) => v.name !== undefined ||
|
|
41
|
-
v.enabled !== undefined ||
|
|
42
|
-
v.match !== undefined ||
|
|
43
|
-
v.conditions !== undefined ||
|
|
44
|
-
v.actions !== undefined, {
|
|
45
|
-
message: "Provide at least one field to update: name, enabled, match, conditions, or actions.",
|
|
46
|
-
});
|
|
47
|
-
export const updateMailRule = async (deps, ctx) => {
|
|
48
|
-
const { args, token } = ctx;
|
|
49
|
-
const existingMail = existingMailSchema.parse(args.existingMail ?? {});
|
|
50
|
-
const rules = await deps.store.load(token);
|
|
51
|
-
const index = rules.findIndex((r) => r.id === args.ruleId);
|
|
52
|
-
const current = rules[index];
|
|
53
|
-
if (!current) {
|
|
54
|
-
return errorResult(`No mail rule with id ${args.ruleId}. Use list_mail_rules to see the current rules and ids.`);
|
|
55
|
-
}
|
|
56
|
-
const updated = {
|
|
57
|
-
...current,
|
|
58
|
-
...(args.name === undefined ? {} : { name: args.name }),
|
|
59
|
-
...(args.enabled === undefined ? {} : { enabled: args.enabled }),
|
|
60
|
-
...(args.match === undefined ? {} : { match: args.match }),
|
|
61
|
-
...(args.conditions === undefined
|
|
62
|
-
? {}
|
|
63
|
-
: { conditions: normalizeConditions(args.conditions) }),
|
|
64
|
-
...(args.actions === undefined ? {} : { actions: args.actions }),
|
|
65
|
-
updatedAt: ruleTimestamp(deps),
|
|
66
|
-
};
|
|
67
|
-
// Same pre-write guard as create: a denied large backfill changes nothing.
|
|
68
|
-
if (existingMail.mode !== "none" && !existingMail.confirmLargeApply) {
|
|
69
|
-
const estimate = await deps.applier.estimate(token, updated, existingMail.scope);
|
|
70
|
-
if (estimate.messages > LARGE_APPLY_THRESHOLD) {
|
|
71
|
-
return errorResult(`Nothing was updated: ${estimate.messages}${estimate.capped ? "+" : ""} existing messages match, which exceeds the confirmation threshold of ${LARGE_APPLY_THRESHOLD}. Confirm the backfill with the user, then re-call with existingMail.confirmLargeApply: true — or with existingMail.mode "none" to update the rule without touching existing mail.`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const next = [...rules];
|
|
75
|
-
next[index] = updated;
|
|
76
|
-
await deps.store.save(token, next);
|
|
77
|
-
const lines = ["Mail rule updated:", "", formatMailRule(index + 1, updated)];
|
|
78
|
-
if (existingMail.mode !== "none") {
|
|
79
|
-
const applied = await deps.applier.applyToExisting(token, updated, existingMail.mode, existingMail.scope);
|
|
80
|
-
lines.push("", formatApplyResult(applied));
|
|
81
|
-
}
|
|
82
|
-
return textResult(lines.join("\n"));
|
|
83
|
-
};
|
|
84
|
-
// --- MCP registration ----------------------------------------------------
|
|
85
|
-
export const registerUpdateMailRule = (server, deps, getToken) => {
|
|
86
|
-
server.registerTool("update_mail_rule", {
|
|
87
|
-
annotations: OUTWARD_WRITE,
|
|
88
|
-
description: "Update an existing mail rule while keeping its id and history: rename it, enable or " +
|
|
89
|
-
"disable it, change how conditions combine (match), or replace its conditions or " +
|
|
90
|
-
"actions. Only the provided fields change; conditions/actions replace the current " +
|
|
91
|
-
"ones wholesale when given. Optionally applies the updated rule to existing mail via " +
|
|
92
|
-
"existingMail (same confirmation policy as create_mail_rule). Find the id with " +
|
|
93
|
-
"list_mail_rules.",
|
|
94
|
-
inputSchema: z.object(updateMailRuleShape),
|
|
95
|
-
title: "Update mail rule",
|
|
96
|
-
}, (args) => {
|
|
97
|
-
const parsed = updateMailRuleInput.safeParse(args);
|
|
98
|
-
if (!parsed.success) {
|
|
99
|
-
return errorResult(parsed.error.issues.map((i) => i.message).join(" "));
|
|
100
|
-
}
|
|
101
|
-
return updateMailRule(deps, { args: parsed.data, token: getToken() });
|
|
102
|
-
});
|
|
103
|
-
};
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
// upload_attachments tool — mint short-lived, single-use URLs the agent PUTs
|
|
2
|
-
// local files to. The mirror of download_attachment: the bytes go the agent's
|
|
3
|
-
// disk → MCP server → Stalwart's blob store via PUT /attachments/uploads/:token,
|
|
4
|
-
// never through the model context, and each PUT answers with the blobId
|
|
5
|
-
// create_draft / update_draft already accept.
|
|
6
|
-
//
|
|
7
|
-
// One step, no confirm call: the blobId only exists once Stalwart has the
|
|
8
|
-
// bytes (it is content-derived), so the upload response carries it rather
|
|
9
|
-
// than this tool, and nothing has to resolve a staged reference later.
|
|
10
|
-
//
|
|
11
|
-
// Batched, because "attach these three scans" is the normal request: one call
|
|
12
|
-
// mints a URL per file, up to the number of attachments a draft can carry.
|
|
13
|
-
import { z } from "zod";
|
|
14
|
-
import { attachEntry, UNREFERENCED_BLOB_TTL_MINUTES, } from "../attachments/upload.js";
|
|
15
|
-
import { UPLOAD_TICKET_TTL_MINUTES, } from "../attachments/upload-tickets.js";
|
|
16
|
-
import { MAX_ATTACHMENT_BYTES, MAX_ATTACHMENTS, mimeTypeFor, } from "../drafts/attachments.js";
|
|
17
|
-
import { authorizationHeader } from "../jmap/index.js";
|
|
18
|
-
import { ACCOUNT_WRITE } from "./annotations.js";
|
|
19
|
-
import { formatSize } from "./format.js";
|
|
20
|
-
import { errorResult, textResult } from "./result.js";
|
|
21
|
-
const MAX_MB = MAX_ATTACHMENT_BYTES / (1024 * 1024);
|
|
22
|
-
const MEDIA_TYPE_RE = /^[\w.+-]+\/[\w.+-]+$/u;
|
|
23
|
-
const fileSchema = z.object({
|
|
24
|
-
filename: z
|
|
25
|
-
.string()
|
|
26
|
-
.min(1)
|
|
27
|
-
.max(255)
|
|
28
|
-
.describe('Name the recipient will see, e.g. "Bescheid-2025.pdf". Pass the same name to create_draft.'),
|
|
29
|
-
mimeType: z
|
|
30
|
-
.string()
|
|
31
|
-
.max(255)
|
|
32
|
-
// It becomes the blob's Content-Type header, so refuse anything that is
|
|
33
|
-
// not `type/subtype` here, before a URL is spent on it.
|
|
34
|
-
.regex(MEDIA_TYPE_RE, 'Expected a media type such as "application/pdf".')
|
|
35
|
-
.optional()
|
|
36
|
-
.describe('Media type, e.g. "application/pdf". Guessed from the filename extension when omitted.'),
|
|
37
|
-
sizeBytes: z
|
|
38
|
-
.number()
|
|
39
|
-
.int()
|
|
40
|
-
.nonnegative()
|
|
41
|
-
.optional()
|
|
42
|
-
.describe(`The file's size in bytes, if you know it — a file over ${MAX_MB} MB is refused before you upload.`),
|
|
43
|
-
});
|
|
44
|
-
const uploadAttachmentsShape = {
|
|
45
|
-
files: z
|
|
46
|
-
.array(fileSchema)
|
|
47
|
-
.min(1)
|
|
48
|
-
.max(MAX_ATTACHMENTS)
|
|
49
|
-
.describe(`The local files to upload, at most ${MAX_ATTACHMENTS} per call. Each gets its own URL.`),
|
|
50
|
-
};
|
|
51
|
-
export const uploadAttachmentsInput = z.object(uploadAttachmentsShape);
|
|
52
|
-
export const uploadAttachments = async (deps, ctx) => {
|
|
53
|
-
const { args, token } = ctx;
|
|
54
|
-
// Per file, like the other batch tools: an oversized file is named and
|
|
55
|
-
// skipped, the rest still get URLs. Only a batch where nothing fits is an error.
|
|
56
|
-
const isOversized = (f) => f.sizeBytes !== undefined && f.sizeBytes > MAX_ATTACHMENT_BYTES;
|
|
57
|
-
const fitting = args.files.filter((f) => !isOversized(f));
|
|
58
|
-
const oversized = args.files.filter(isOversized);
|
|
59
|
-
const refusedLine = () => {
|
|
60
|
-
const named = oversized
|
|
61
|
-
.map((f) => `${f.filename} (${formatSize(f.sizeBytes ?? 0)})`)
|
|
62
|
-
.join(", ");
|
|
63
|
-
return (`Not uploadable (${oversized.length}): ${named} — over the ${MAX_MB} MB an attachment ` +
|
|
64
|
-
"can be. Send it smaller, split it, or link to it instead.");
|
|
65
|
-
};
|
|
66
|
-
if (fitting.length === 0) {
|
|
67
|
-
return errorResult(`${refusedLine()} No upload URL was issued.`);
|
|
68
|
-
}
|
|
69
|
-
const authorization = authorizationHeader(token);
|
|
70
|
-
const accountId = await deps.resolveAccountId(authorization);
|
|
71
|
-
const publicUrl = await deps.publicUrl();
|
|
72
|
-
const blocks = fitting.map((file) => {
|
|
73
|
-
const type = mimeTypeFor({
|
|
74
|
-
filename: file.filename,
|
|
75
|
-
...(file.mimeType ? { mimeType: file.mimeType } : {}),
|
|
76
|
-
});
|
|
77
|
-
const minted = deps.mintUploadTicket({
|
|
78
|
-
accountId,
|
|
79
|
-
authorization,
|
|
80
|
-
filename: file.filename,
|
|
81
|
-
type,
|
|
82
|
-
});
|
|
83
|
-
const url = `${publicUrl}/attachments/uploads/${minted.token}`;
|
|
84
|
-
return (`${file.filename} (${type}), expires ${new Date(minted.expiresAt).toISOString()}:\n` +
|
|
85
|
-
` curl -sS -T '<path to ${file.filename.replaceAll("'", "")}>' '${url}'\n` +
|
|
86
|
-
` then attach: ${attachEntry("<blobId>", file.filename, type)}`);
|
|
87
|
-
});
|
|
88
|
-
const refused = oversized.length > 0 ? `\n\n${refusedLine()}` : "";
|
|
89
|
-
return textResult(
|
|
90
|
-
// The count leads, so a batch with a refused file reads differently from
|
|
91
|
-
// a clean one before the reader reaches the blocks.
|
|
92
|
-
`Upload URLs for ${fitting.length} of ${args.files.length} file(s), each single use, up to ${MAX_MB} MB, ` +
|
|
93
|
-
`valid ${UPLOAD_TICKET_TTL_MINUTES} minutes:\n\n` +
|
|
94
|
-
`${blocks.join("\n\n")}${refused}\n\n` +
|
|
95
|
-
"PUT each file straight from disk with its command. Each response is JSON with that file’s `blobId`. " +
|
|
96
|
-
"Then pass each file’s `then attach` entry, with its `blobId` filled in, in the `attachments` of " +
|
|
97
|
-
`create_draft or update_draft within ${UNREFERENCED_BLOB_TTL_MINUTES} minutes of uploading.\n` +
|
|
98
|
-
"The URLs are credentials: do not show them to the user or paste them anywhere else.");
|
|
99
|
-
};
|
|
100
|
-
// --- live-deps wiring ----------------------------------------------------
|
|
101
|
-
export const makeLiveDeps = (live, uploadTickets, publicUrl) => ({
|
|
102
|
-
mintUploadTicket: uploadTickets.mint,
|
|
103
|
-
publicUrl,
|
|
104
|
-
resolveAccountId: live.resolveAccountId,
|
|
105
|
-
});
|
|
106
|
-
// --- MCP registration ----------------------------------------------------
|
|
107
|
-
export const registerUploadAttachments = (server, deps, getToken) => {
|
|
108
|
-
server.registerTool("upload_attachments", {
|
|
109
|
-
annotations: ACCOUNT_WRITE,
|
|
110
|
-
description: "Get short-lived upload URLs for files on your own disk that should go out as email attachments, " +
|
|
111
|
-
"so their bytes never pass through the conversation. Use it for any local file — a PDF, a scan, a " +
|
|
112
|
-
"spreadsheet — instead of reading it as base64 into create_draft’s `content`; use `blobId` " +
|
|
113
|
-
"straight away instead when the file is already in the mailbox. The result is one URL and curl " +
|
|
114
|
-
"command per file: PUT the file to it (`curl -sS -T '<file>' '<url>'`), and the response is JSON " +
|
|
115
|
-
"with a `blobId`. Pass that `blobId` with the `filename` and `mimeType` the result lists in the " +
|
|
116
|
-
`\`attachments\` of create_draft or update_draft within ${UNREFERENCED_BLOB_TTL_MINUTES} minutes. Up to ` +
|
|
117
|
-
`${MAX_ATTACHMENTS} files per call; a file over ${MAX_MB} MB is named and skipped while the rest get ` +
|
|
118
|
-
"URLs. Each URL takes one file and expires after " +
|
|
119
|
-
`${UPLOAD_TICKET_TTL_MINUTES} minutes. The URLs are credentials: never echo them to the user.`,
|
|
120
|
-
inputSchema: z.object(uploadAttachmentsShape),
|
|
121
|
-
title: "Upload attachments",
|
|
122
|
-
}, (args) => {
|
|
123
|
-
const parsed = uploadAttachmentsInput.parse(args);
|
|
124
|
-
return uploadAttachments(deps, { args: parsed, token: getToken() });
|
|
125
|
-
});
|
|
126
|
-
};
|