hypermail-mcp 0.2.0 → 0.4.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/README.md +5 -1
- package/dist/cli.js +362 -29
- package/dist/cli.js.map +1 -1
- package/package.json +11 -10
package/README.md
CHANGED
|
@@ -88,8 +88,12 @@ account store.
|
|
|
88
88
|
| `search_emails` | `account`, `query`, `limit?` | KQL on Outlook. |
|
|
89
89
|
| `read_email` | `account`, `id`, `format?` | Returns full body + recipients + attachment metadata. `format`: `markdown` (default), `html`, or `text`. |
|
|
90
90
|
| `read_attachment` | `account`, `messageId`, `attachmentId` | Download an attachment to a temporary file and return its path. |
|
|
91
|
+
| `archive_email` | `account`, `id` | Move a message to the Archive folder. Disabled under `--read-only`. |
|
|
92
|
+
| `trash_email` | `account`, `id` | Move a message to Deleted Items (trash). Disabled under `--read-only`. |
|
|
93
|
+
| `move_email` | `account`, `id`, `destination` | Move to any folder by well-known name (`inbox`, `drafts`, etc.) or custom folder ID. Disabled under `--read-only`. |
|
|
91
94
|
| `send_email` | `account`, `to[]`, `cc?`, `bcc?`, `subject`, `body`, `isHtml?`, `include_signature?`, `inReplyTo?`, `replyAll?`, `forwardMessageId?` | Send an email. Appends signature when `include_signature` is true. `inReplyTo` sends as threaded reply; `forwardMessageId` sends as forward. Disabled under `--read-only`. |
|
|
92
|
-
| `draft_email` | `account`, `to[]`, `cc?`, `bcc?`, `subject`, `body`, `isHtml?`, `include_signature?`, `inReplyTo?`, `replyAll?`, `forwardMessageId?` | Save as draft instead of sending. Returns the draft message ID. Disabled under `--read-only`. |
|
|
95
|
+
| `draft_email` | `account`, `to[]`, `cc?`, `bcc?`, `subject`, `body`, `isHtml?`, `include_signature?`, `inReplyTo?`, `replyAll?`, `forwardMessageId?` | Save as draft instead of sending. Returns the draft message ID and HTML body (`draftHtml`). Disabled under `--read-only`. |
|
|
96
|
+
| `edit_draft` | `account`, `id`, `to?`, `cc?`, `bcc?`, `subject?`, `body?`, `isHtml?`, `include_signature?` | Edit an existing draft by ID. Only provided fields are updated. Returns the updated draft ID and HTML body (`draftHtml`). Disabled under `--read-only`. |
|
|
93
97
|
|
|
94
98
|
### Add-account flow (Outlook)
|
|
95
99
|
|
package/dist/cli.js
CHANGED
|
@@ -648,6 +648,38 @@ var OutlookProvider = class {
|
|
|
648
648
|
const draft = await client.api("/me/messages").post(draftPayload);
|
|
649
649
|
return { id: draft.id };
|
|
650
650
|
}
|
|
651
|
+
async updateDraft(account, id, update) {
|
|
652
|
+
const client = this.clients.get(account);
|
|
653
|
+
const payload = {};
|
|
654
|
+
if (update.subject !== void 0) {
|
|
655
|
+
payload.subject = update.subject;
|
|
656
|
+
}
|
|
657
|
+
if (update.to !== void 0) {
|
|
658
|
+
payload.toRecipients = update.to.map(toRecipient);
|
|
659
|
+
}
|
|
660
|
+
if (update.cc !== void 0) {
|
|
661
|
+
payload.ccRecipients = update.cc.map(toRecipient);
|
|
662
|
+
}
|
|
663
|
+
if (update.bcc !== void 0) {
|
|
664
|
+
payload.bccRecipients = update.bcc.map(toRecipient);
|
|
665
|
+
}
|
|
666
|
+
if (update.body !== void 0) {
|
|
667
|
+
const converted = convertInlineImages(update.body);
|
|
668
|
+
payload.body = {
|
|
669
|
+
contentType: update.isHtml ? "HTML" : "Text",
|
|
670
|
+
content: converted.body
|
|
671
|
+
};
|
|
672
|
+
if (converted.attachments.length > 0) {
|
|
673
|
+
payload.attachments = converted.attachments;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
await client.api(`/me/messages/${encodeURIComponent(id)}`).patch(payload);
|
|
677
|
+
return { id };
|
|
678
|
+
}
|
|
679
|
+
async moveEmail(account, id, destinationId) {
|
|
680
|
+
const client = this.clients.get(account);
|
|
681
|
+
await client.api(`/me/messages/${encodeURIComponent(id)}/move`).post({ destinationId });
|
|
682
|
+
}
|
|
651
683
|
};
|
|
652
684
|
function mapRecipient(r) {
|
|
653
685
|
return {
|
|
@@ -706,6 +738,12 @@ var ImapProvider = class {
|
|
|
706
738
|
async saveDraft(_account, _msg) {
|
|
707
739
|
throw new Error(NOT_IMPLEMENTED);
|
|
708
740
|
}
|
|
741
|
+
async updateDraft(_account, _id, _update) {
|
|
742
|
+
throw new Error(NOT_IMPLEMENTED);
|
|
743
|
+
}
|
|
744
|
+
async moveEmail(_account, _id, _destinationId) {
|
|
745
|
+
throw new Error(NOT_IMPLEMENTED);
|
|
746
|
+
}
|
|
709
747
|
};
|
|
710
748
|
|
|
711
749
|
// src/providers/registry.ts
|
|
@@ -764,12 +802,16 @@ function selectBody(msg, format) {
|
|
|
764
802
|
}
|
|
765
803
|
|
|
766
804
|
// src/tools/index.ts
|
|
767
|
-
function ok(data) {
|
|
768
|
-
|
|
805
|
+
function ok(data, structuredContent) {
|
|
806
|
+
const result = {
|
|
769
807
|
content: [
|
|
770
808
|
{ type: "text", text: JSON.stringify(data, null, 2) }
|
|
771
809
|
]
|
|
772
810
|
};
|
|
811
|
+
if (structuredContent !== void 0) {
|
|
812
|
+
result.structuredContent = structuredContent;
|
|
813
|
+
}
|
|
814
|
+
return result;
|
|
773
815
|
}
|
|
774
816
|
function fail(message) {
|
|
775
817
|
return {
|
|
@@ -781,13 +823,51 @@ var emailAddrSchema = z.object({
|
|
|
781
823
|
address: z.string().email(),
|
|
782
824
|
name: z.string().optional()
|
|
783
825
|
});
|
|
826
|
+
var emailAddrOutputSchema = z.object({
|
|
827
|
+
name: z.string().optional(),
|
|
828
|
+
address: z.string()
|
|
829
|
+
});
|
|
830
|
+
var accountSummaryOutputSchema = z.object({
|
|
831
|
+
email: z.string(),
|
|
832
|
+
provider: z.enum(["outlook", "imap", "gmail"]),
|
|
833
|
+
displayName: z.string().optional(),
|
|
834
|
+
addedAt: z.string(),
|
|
835
|
+
hasSignature: z.boolean(),
|
|
836
|
+
hasStyle: z.boolean()
|
|
837
|
+
});
|
|
838
|
+
var emailSummaryOutputSchema = z.object({
|
|
839
|
+
id: z.string(),
|
|
840
|
+
subject: z.string(),
|
|
841
|
+
from: emailAddrOutputSchema.optional(),
|
|
842
|
+
to: z.array(emailAddrOutputSchema).optional(),
|
|
843
|
+
receivedAt: z.string().optional(),
|
|
844
|
+
preview: z.string().optional(),
|
|
845
|
+
isRead: z.boolean().optional(),
|
|
846
|
+
hasAttachments: z.boolean().optional(),
|
|
847
|
+
folder: z.string().optional()
|
|
848
|
+
});
|
|
849
|
+
var attachmentMetaOutputSchema = z.object({
|
|
850
|
+
id: z.string(),
|
|
851
|
+
name: z.string(),
|
|
852
|
+
contentType: z.string().optional(),
|
|
853
|
+
size: z.number().optional()
|
|
854
|
+
});
|
|
855
|
+
var styleOutputSchema = z.object({
|
|
856
|
+
fontFamily: z.string().optional(),
|
|
857
|
+
fontSize: z.string().optional(),
|
|
858
|
+
fontColor: z.string().optional()
|
|
859
|
+
});
|
|
784
860
|
function registerTools(server, opts) {
|
|
785
861
|
const { store, registry, readOnly = false, draftOnly = false } = opts;
|
|
862
|
+
const listAccountsOutputSchema = {
|
|
863
|
+
accounts: z.array(accountSummaryOutputSchema)
|
|
864
|
+
};
|
|
786
865
|
server.registerTool(
|
|
787
866
|
"list_accounts",
|
|
788
867
|
{
|
|
789
868
|
description: "List all email accounts known to this server (no secrets). Use the returned `email` value as the `account` argument to other tools.",
|
|
790
|
-
inputSchema: {}
|
|
869
|
+
inputSchema: {},
|
|
870
|
+
outputSchema: listAccountsOutputSchema
|
|
791
871
|
},
|
|
792
872
|
async () => {
|
|
793
873
|
const rows = store.listAccounts().map((a) => ({
|
|
@@ -798,9 +878,34 @@ function registerTools(server, opts) {
|
|
|
798
878
|
hasSignature: !!a.signature,
|
|
799
879
|
hasStyle: !!(a.style && (a.style.fontFamily || a.style.fontSize || a.style.fontColor))
|
|
800
880
|
}));
|
|
801
|
-
|
|
881
|
+
const data = { accounts: rows };
|
|
882
|
+
return ok(data, data);
|
|
802
883
|
}
|
|
803
884
|
);
|
|
885
|
+
const addAccountOutputSchema = z.discriminatedUnion("status", [
|
|
886
|
+
z.object({
|
|
887
|
+
status: z.literal("pending"),
|
|
888
|
+
handle: z.string(),
|
|
889
|
+
verification: z.object({
|
|
890
|
+
userCode: z.string(),
|
|
891
|
+
verificationUri: z.string(),
|
|
892
|
+
expiresAt: z.string(),
|
|
893
|
+
message: z.string()
|
|
894
|
+
})
|
|
895
|
+
}),
|
|
896
|
+
z.object({
|
|
897
|
+
status: z.literal("ready"),
|
|
898
|
+
account: z.object({
|
|
899
|
+
email: z.string(),
|
|
900
|
+
provider: z.enum(["outlook", "imap", "gmail"]),
|
|
901
|
+
displayName: z.string().optional(),
|
|
902
|
+
tokens: z.record(z.unknown()),
|
|
903
|
+
addedAt: z.string(),
|
|
904
|
+
signature: z.string().optional(),
|
|
905
|
+
style: styleOutputSchema.optional()
|
|
906
|
+
})
|
|
907
|
+
})
|
|
908
|
+
]);
|
|
804
909
|
server.registerTool(
|
|
805
910
|
"add_account",
|
|
806
911
|
{
|
|
@@ -809,19 +914,33 @@ function registerTools(server, opts) {
|
|
|
809
914
|
provider: z.enum(["outlook", "imap", "gmail"]).describe("Email backend. v1 only fully implements 'outlook'."),
|
|
810
915
|
email: z.string().email().optional().describe("Optional hint \u2014 the provider will verify it against the auth result."),
|
|
811
916
|
config: z.record(z.unknown()).optional().describe("Provider-specific config (e.g. IMAP host/port). Unused for Outlook.")
|
|
812
|
-
}
|
|
917
|
+
},
|
|
918
|
+
outputSchema: addAccountOutputSchema
|
|
813
919
|
},
|
|
814
920
|
async (args) => {
|
|
815
921
|
if (readOnly) return fail("server is in --read-only mode; add_account is disabled");
|
|
816
922
|
const provider = registry.get(args.provider);
|
|
817
923
|
try {
|
|
818
924
|
const res = await provider.addAccount({ email: args.email, config: args.config });
|
|
819
|
-
return ok(res);
|
|
925
|
+
return ok(res, res);
|
|
820
926
|
} catch (err) {
|
|
821
927
|
return fail(errMsg(err));
|
|
822
928
|
}
|
|
823
929
|
}
|
|
824
930
|
);
|
|
931
|
+
const completeAddAccountOutputSchema = z.object({
|
|
932
|
+
status: z.enum(["pending", "ready", "expired", "error"]),
|
|
933
|
+
account: z.object({
|
|
934
|
+
email: z.string(),
|
|
935
|
+
provider: z.enum(["outlook", "imap", "gmail"]),
|
|
936
|
+
displayName: z.string().optional(),
|
|
937
|
+
tokens: z.record(z.unknown()),
|
|
938
|
+
addedAt: z.string(),
|
|
939
|
+
signature: z.string().optional(),
|
|
940
|
+
style: styleOutputSchema.optional()
|
|
941
|
+
}).optional(),
|
|
942
|
+
error: z.string().optional()
|
|
943
|
+
});
|
|
825
944
|
server.registerTool(
|
|
826
945
|
"complete_add_account",
|
|
827
946
|
{
|
|
@@ -829,7 +948,8 @@ function registerTools(server, opts) {
|
|
|
829
948
|
inputSchema: {
|
|
830
949
|
provider: z.enum(["outlook", "imap", "gmail"]),
|
|
831
950
|
handle: z.string().min(1)
|
|
832
|
-
}
|
|
951
|
+
},
|
|
952
|
+
outputSchema: completeAddAccountOutputSchema
|
|
833
953
|
},
|
|
834
954
|
async (args) => {
|
|
835
955
|
const provider = registry.get(args.provider);
|
|
@@ -838,23 +958,29 @@ function registerTools(server, opts) {
|
|
|
838
958
|
}
|
|
839
959
|
try {
|
|
840
960
|
const res = await provider.completeAddAccount(args.handle);
|
|
841
|
-
return ok(res);
|
|
961
|
+
return ok(res, res);
|
|
842
962
|
} catch (err) {
|
|
843
963
|
return fail(errMsg(err));
|
|
844
964
|
}
|
|
845
965
|
}
|
|
846
966
|
);
|
|
967
|
+
const accountSettingsOutputSchema = {
|
|
968
|
+
signature: z.string().nullable(),
|
|
969
|
+
style: styleOutputSchema.nullable()
|
|
970
|
+
};
|
|
847
971
|
server.registerTool(
|
|
848
972
|
"get_account_settings",
|
|
849
973
|
{
|
|
850
974
|
description: "Get signature (HTML) and style preferences for an account.",
|
|
851
|
-
inputSchema: { account: z.string().email() }
|
|
975
|
+
inputSchema: { account: z.string().email() },
|
|
976
|
+
outputSchema: accountSettingsOutputSchema
|
|
852
977
|
},
|
|
853
978
|
async (args) => {
|
|
854
979
|
try {
|
|
855
980
|
const acct = store.getAccount(args.account);
|
|
856
981
|
if (!acct) return fail(`no account registered for "${args.account}"`);
|
|
857
|
-
|
|
982
|
+
const data = { signature: acct.signature ?? null, style: acct.style ?? null };
|
|
983
|
+
return ok(data, data);
|
|
858
984
|
} catch (err) {
|
|
859
985
|
return fail(errMsg(err));
|
|
860
986
|
}
|
|
@@ -872,7 +998,8 @@ function registerTools(server, opts) {
|
|
|
872
998
|
fontSize: z.string().optional(),
|
|
873
999
|
fontColor: z.string().optional()
|
|
874
1000
|
}).optional().describe("Font preferences applied to outgoing HTML emails. Pass null to clear.")
|
|
875
|
-
}
|
|
1001
|
+
},
|
|
1002
|
+
outputSchema: accountSettingsOutputSchema
|
|
876
1003
|
},
|
|
877
1004
|
async (args) => {
|
|
878
1005
|
if (readOnly) return fail("server is in --read-only mode; set_account_settings is disabled");
|
|
@@ -884,24 +1011,36 @@ function registerTools(server, opts) {
|
|
|
884
1011
|
signature: args.signature ?? acct.signature,
|
|
885
1012
|
style: args.style ?? acct.style
|
|
886
1013
|
});
|
|
887
|
-
|
|
1014
|
+
const data = { signature: updated.signature ?? null, style: updated.style ?? null };
|
|
1015
|
+
return ok(data, data);
|
|
888
1016
|
} catch (err) {
|
|
889
1017
|
return fail(errMsg(err));
|
|
890
1018
|
}
|
|
891
1019
|
}
|
|
892
1020
|
);
|
|
1021
|
+
const removeAccountOutputSchema = {
|
|
1022
|
+
removed: z.boolean(),
|
|
1023
|
+
email: z.string()
|
|
1024
|
+
};
|
|
893
1025
|
server.registerTool(
|
|
894
1026
|
"remove_account",
|
|
895
1027
|
{
|
|
896
1028
|
description: "Forget an account and delete its stored tokens. Disabled in --read-only mode.",
|
|
897
|
-
inputSchema: { email: z.string().email() }
|
|
1029
|
+
inputSchema: { email: z.string().email() },
|
|
1030
|
+
outputSchema: removeAccountOutputSchema
|
|
898
1031
|
},
|
|
899
1032
|
async (args) => {
|
|
900
1033
|
if (readOnly) return fail("server is in --read-only mode; remove_account is disabled");
|
|
901
1034
|
const removed = await store.removeAccount(args.email);
|
|
902
|
-
|
|
1035
|
+
const data = { removed, email: args.email };
|
|
1036
|
+
return ok(data, data);
|
|
903
1037
|
}
|
|
904
1038
|
);
|
|
1039
|
+
const emailListOutputSchema = {
|
|
1040
|
+
account: z.string(),
|
|
1041
|
+
count: z.number(),
|
|
1042
|
+
items: z.array(emailSummaryOutputSchema)
|
|
1043
|
+
};
|
|
905
1044
|
server.registerTool(
|
|
906
1045
|
"list_emails",
|
|
907
1046
|
{
|
|
@@ -911,7 +1050,8 @@ function registerTools(server, opts) {
|
|
|
911
1050
|
folder: z.string().default("inbox").optional(),
|
|
912
1051
|
limit: z.number().int().positive().max(100).optional(),
|
|
913
1052
|
unreadOnly: z.boolean().optional()
|
|
914
|
-
}
|
|
1053
|
+
},
|
|
1054
|
+
outputSchema: emailListOutputSchema
|
|
915
1055
|
},
|
|
916
1056
|
async (args) => {
|
|
917
1057
|
try {
|
|
@@ -921,7 +1061,8 @@ function registerTools(server, opts) {
|
|
|
921
1061
|
limit: args.limit,
|
|
922
1062
|
unreadOnly: args.unreadOnly
|
|
923
1063
|
});
|
|
924
|
-
|
|
1064
|
+
const data = { account: account.email, count: items.length, items };
|
|
1065
|
+
return ok(data, data);
|
|
925
1066
|
} catch (err) {
|
|
926
1067
|
return fail(errMsg(err));
|
|
927
1068
|
}
|
|
@@ -935,7 +1076,8 @@ function registerTools(server, opts) {
|
|
|
935
1076
|
account: z.string().email(),
|
|
936
1077
|
query: z.string().min(1),
|
|
937
1078
|
limit: z.number().int().positive().max(100).optional()
|
|
938
|
-
}
|
|
1079
|
+
},
|
|
1080
|
+
outputSchema: emailListOutputSchema
|
|
939
1081
|
},
|
|
940
1082
|
async (args) => {
|
|
941
1083
|
try {
|
|
@@ -943,12 +1085,29 @@ function registerTools(server, opts) {
|
|
|
943
1085
|
const items = await provider.searchEmails(account, args.query, {
|
|
944
1086
|
limit: args.limit
|
|
945
1087
|
});
|
|
946
|
-
|
|
1088
|
+
const data = { account: account.email, count: items.length, items };
|
|
1089
|
+
return ok(data, data);
|
|
947
1090
|
} catch (err) {
|
|
948
1091
|
return fail(errMsg(err));
|
|
949
1092
|
}
|
|
950
1093
|
}
|
|
951
1094
|
);
|
|
1095
|
+
const readEmailOutputSchema = {
|
|
1096
|
+
id: z.string(),
|
|
1097
|
+
subject: z.string(),
|
|
1098
|
+
from: emailAddrOutputSchema.optional(),
|
|
1099
|
+
to: z.array(emailAddrOutputSchema).optional(),
|
|
1100
|
+
cc: z.array(emailAddrOutputSchema).optional(),
|
|
1101
|
+
bcc: z.array(emailAddrOutputSchema).optional(),
|
|
1102
|
+
receivedAt: z.string().optional(),
|
|
1103
|
+
preview: z.string().optional(),
|
|
1104
|
+
isRead: z.boolean().optional(),
|
|
1105
|
+
hasAttachments: z.boolean().optional(),
|
|
1106
|
+
folder: z.string().optional(),
|
|
1107
|
+
attachments: z.array(attachmentMetaOutputSchema).optional(),
|
|
1108
|
+
body: z.string(),
|
|
1109
|
+
bodyFormat: z.enum(["markdown", "html", "text"])
|
|
1110
|
+
};
|
|
952
1111
|
server.registerTool(
|
|
953
1112
|
"read_email",
|
|
954
1113
|
{
|
|
@@ -959,7 +1118,8 @@ function registerTools(server, opts) {
|
|
|
959
1118
|
format: z.enum(["markdown", "html", "text"]).default("markdown").optional().describe(
|
|
960
1119
|
"Output body format. 'markdown' converts HTML to Markdown (default), 'html' returns the raw HTML, 'text' returns plain text."
|
|
961
1120
|
)
|
|
962
|
-
}
|
|
1121
|
+
},
|
|
1122
|
+
outputSchema: readEmailOutputSchema
|
|
963
1123
|
},
|
|
964
1124
|
async (args) => {
|
|
965
1125
|
try {
|
|
@@ -967,7 +1127,7 @@ function registerTools(server, opts) {
|
|
|
967
1127
|
const msg = await provider.readEmail(account, args.id);
|
|
968
1128
|
const format = args.format ?? "markdown";
|
|
969
1129
|
const body = selectBody(msg, format);
|
|
970
|
-
|
|
1130
|
+
const data = {
|
|
971
1131
|
id: msg.id,
|
|
972
1132
|
subject: msg.subject,
|
|
973
1133
|
from: msg.from,
|
|
@@ -982,12 +1142,18 @@ function registerTools(server, opts) {
|
|
|
982
1142
|
attachments: msg.attachments,
|
|
983
1143
|
body,
|
|
984
1144
|
bodyFormat: format
|
|
985
|
-
}
|
|
1145
|
+
};
|
|
1146
|
+
return ok(data, data);
|
|
986
1147
|
} catch (err) {
|
|
987
1148
|
return fail(errMsg(err));
|
|
988
1149
|
}
|
|
989
1150
|
}
|
|
990
1151
|
);
|
|
1152
|
+
const readAttachmentOutputSchema = {
|
|
1153
|
+
name: z.string(),
|
|
1154
|
+
contentType: z.string().optional(),
|
|
1155
|
+
path: z.string()
|
|
1156
|
+
};
|
|
991
1157
|
server.registerTool(
|
|
992
1158
|
"read_attachment",
|
|
993
1159
|
{
|
|
@@ -996,13 +1162,96 @@ function registerTools(server, opts) {
|
|
|
996
1162
|
account: z.string().email(),
|
|
997
1163
|
messageId: z.string().min(1),
|
|
998
1164
|
attachmentId: z.string().min(1)
|
|
999
|
-
}
|
|
1165
|
+
},
|
|
1166
|
+
outputSchema: readAttachmentOutputSchema
|
|
1000
1167
|
},
|
|
1001
1168
|
async (args) => {
|
|
1002
1169
|
try {
|
|
1003
1170
|
const { provider, account } = registry.resolveByEmail(args.account);
|
|
1004
1171
|
const res = await provider.readAttachment(account, args.messageId, args.attachmentId);
|
|
1005
|
-
return ok(res);
|
|
1172
|
+
return ok(res, res);
|
|
1173
|
+
} catch (err) {
|
|
1174
|
+
return fail(errMsg(err));
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
);
|
|
1178
|
+
{
|
|
1179
|
+
const schema = {
|
|
1180
|
+
account: z.string().email(),
|
|
1181
|
+
id: z.string().min(1).describe("Message ID to move")
|
|
1182
|
+
};
|
|
1183
|
+
const archiveOutputSchema = {
|
|
1184
|
+
archived: z.literal(true),
|
|
1185
|
+
id: z.string()
|
|
1186
|
+
};
|
|
1187
|
+
server.registerTool(
|
|
1188
|
+
"archive_email",
|
|
1189
|
+
{
|
|
1190
|
+
description: "Move a message to the Archive folder. Disabled in --read-only mode.",
|
|
1191
|
+
inputSchema: schema,
|
|
1192
|
+
outputSchema: archiveOutputSchema
|
|
1193
|
+
},
|
|
1194
|
+
async (args) => {
|
|
1195
|
+
if (readOnly) return fail("server is in --read-only mode; archive_email is disabled");
|
|
1196
|
+
try {
|
|
1197
|
+
const { provider, account } = registry.resolveByEmail(args.account);
|
|
1198
|
+
await provider.moveEmail(account, args.id, "archive");
|
|
1199
|
+
const data = { archived: true, id: args.id };
|
|
1200
|
+
return ok(data, data);
|
|
1201
|
+
} catch (err) {
|
|
1202
|
+
return fail(errMsg(err));
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
);
|
|
1206
|
+
const trashOutputSchema = {
|
|
1207
|
+
trashed: z.literal(true),
|
|
1208
|
+
id: z.string()
|
|
1209
|
+
};
|
|
1210
|
+
server.registerTool(
|
|
1211
|
+
"trash_email",
|
|
1212
|
+
{
|
|
1213
|
+
description: "Move a message to the Deleted Items (trash) folder. Disabled in --read-only mode.",
|
|
1214
|
+
inputSchema: schema,
|
|
1215
|
+
outputSchema: trashOutputSchema
|
|
1216
|
+
},
|
|
1217
|
+
async (args) => {
|
|
1218
|
+
if (readOnly) return fail("server is in --read-only mode; trash_email is disabled");
|
|
1219
|
+
try {
|
|
1220
|
+
const { provider, account } = registry.resolveByEmail(args.account);
|
|
1221
|
+
await provider.moveEmail(account, args.id, "deleteditems");
|
|
1222
|
+
const data = { trashed: true, id: args.id };
|
|
1223
|
+
return ok(data, data);
|
|
1224
|
+
} catch (err) {
|
|
1225
|
+
return fail(errMsg(err));
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
const moveEmailOutputSchema = {
|
|
1231
|
+
moved: z.literal(true),
|
|
1232
|
+
id: z.string(),
|
|
1233
|
+
destination: z.string()
|
|
1234
|
+
};
|
|
1235
|
+
server.registerTool(
|
|
1236
|
+
"move_email",
|
|
1237
|
+
{
|
|
1238
|
+
description: "Move a message to any folder by well-known name (e.g. 'inbox', 'drafts', 'junkemail', 'sentitems', 'outbox') or custom folder ID. Disabled in --read-only mode.",
|
|
1239
|
+
inputSchema: {
|
|
1240
|
+
account: z.string().email(),
|
|
1241
|
+
id: z.string().min(1).describe("Message ID to move"),
|
|
1242
|
+
destination: z.string().min(1).describe(
|
|
1243
|
+
"Destination folder \u2014 a well-known folder name ('archive', 'deleteditems', 'inbox', 'drafts', 'junkemail', 'sentitems', 'outbox') or a raw folder ID."
|
|
1244
|
+
)
|
|
1245
|
+
},
|
|
1246
|
+
outputSchema: moveEmailOutputSchema
|
|
1247
|
+
},
|
|
1248
|
+
async (args) => {
|
|
1249
|
+
if (readOnly) return fail("server is in --read-only mode; move_email is disabled");
|
|
1250
|
+
try {
|
|
1251
|
+
const { provider, account } = registry.resolveByEmail(args.account);
|
|
1252
|
+
await provider.moveEmail(account, args.id, args.destination);
|
|
1253
|
+
const data = { moved: true, id: args.id, destination: args.destination };
|
|
1254
|
+
return ok(data, data);
|
|
1006
1255
|
} catch (err) {
|
|
1007
1256
|
return fail(errMsg(err));
|
|
1008
1257
|
}
|
|
@@ -1017,7 +1266,7 @@ function registerTools(server, opts) {
|
|
|
1017
1266
|
body: z.string(),
|
|
1018
1267
|
isHtml: z.boolean().optional(),
|
|
1019
1268
|
include_signature: z.boolean().describe(
|
|
1020
|
-
"Whether to append the account's HTML signature to the email. Returns an error if true but no signature is configured for this account."
|
|
1269
|
+
"Whether to append the account's saved HTML signature to the email. If true, don't include a signature in the body param to avoid double signature. Returns an error if true but no signature is configured for this account."
|
|
1021
1270
|
),
|
|
1022
1271
|
inReplyTo: z.string().optional().describe(
|
|
1023
1272
|
"Message ID to reply to. When set, sends as a threaded reply which includes the quoted thread history automatically."
|
|
@@ -1061,17 +1310,27 @@ function registerTools(server, opts) {
|
|
|
1061
1310
|
replyAll: args.replyAll,
|
|
1062
1311
|
forwardMessageId: args.forwardMessageId
|
|
1063
1312
|
});
|
|
1064
|
-
|
|
1313
|
+
const result = { [resultKey]: true, ...res };
|
|
1314
|
+
if (toolName === "draft_email" && res.id) {
|
|
1315
|
+
const draft = await provider.readEmail(account, res.id);
|
|
1316
|
+
result.draftHtml = draft.bodyHtml;
|
|
1317
|
+
}
|
|
1318
|
+
return ok(result, result);
|
|
1065
1319
|
} catch (err) {
|
|
1066
1320
|
return fail(errMsg(err));
|
|
1067
1321
|
}
|
|
1068
1322
|
}
|
|
1323
|
+
const sendEmailOutputSchema = {
|
|
1324
|
+
sent: z.literal(true),
|
|
1325
|
+
id: z.string()
|
|
1326
|
+
};
|
|
1069
1327
|
if (!draftOnly) {
|
|
1070
1328
|
server.registerTool(
|
|
1071
1329
|
"send_email",
|
|
1072
1330
|
{
|
|
1073
1331
|
description: "Send an email from the given account. Appends the account's signature (HTML) and applies style preferences when `include_signature` is true. Returns an error if `include_signature` is true but no signature is configured. When `inReplyTo` is set, sends as a reply (or reply-all) which preserves thread history and conversation threading. When `forwardMessageId` is set, sends as a forward of the specified message, preserving the original content. `inReplyTo` and `forwardMessageId` are mutually exclusive. Disabled in --read-only mode.",
|
|
1074
|
-
inputSchema: sendEmailSchema
|
|
1332
|
+
inputSchema: sendEmailSchema,
|
|
1333
|
+
outputSchema: sendEmailOutputSchema
|
|
1075
1334
|
},
|
|
1076
1335
|
async (args) => handleSendOrDraft(
|
|
1077
1336
|
args,
|
|
@@ -1081,11 +1340,17 @@ function registerTools(server, opts) {
|
|
|
1081
1340
|
)
|
|
1082
1341
|
);
|
|
1083
1342
|
}
|
|
1343
|
+
const draftEmailOutputSchema = {
|
|
1344
|
+
draft: z.literal(true),
|
|
1345
|
+
id: z.string(),
|
|
1346
|
+
draftHtml: z.string().optional()
|
|
1347
|
+
};
|
|
1084
1348
|
server.registerTool(
|
|
1085
1349
|
"draft_email",
|
|
1086
1350
|
{
|
|
1087
|
-
description: "Create a draft email from the given account without sending it. Works identically to send_email \u2014 appends signature when `include_signature` is true, applies style, and supports replies and forwards \u2014 but saves the message to the Drafts folder instead of sending. Returns the draft message ID
|
|
1088
|
-
inputSchema: sendEmailSchema
|
|
1351
|
+
description: "Create a draft email from the given account without sending it. Works identically to send_email \u2014 appends signature when `include_signature` is true, applies style, and supports replies and forwards \u2014 but saves the message to the Drafts folder instead of sending. Returns the draft message ID and the draft's HTML body content (`draftHtml`). Before sending the draft, inspect `draftHtml` to verify the draft looks correct: no duplicate signature blocks, no broken or missing inline images, no malformed HTML, and no other formatting issues. Disabled in --read-only mode.",
|
|
1352
|
+
inputSchema: sendEmailSchema,
|
|
1353
|
+
outputSchema: draftEmailOutputSchema
|
|
1089
1354
|
},
|
|
1090
1355
|
async (args) => handleSendOrDraft(
|
|
1091
1356
|
args,
|
|
@@ -1094,6 +1359,74 @@ function registerTools(server, opts) {
|
|
|
1094
1359
|
"draft_email"
|
|
1095
1360
|
)
|
|
1096
1361
|
);
|
|
1362
|
+
const editDraftSchema = z.object({
|
|
1363
|
+
account: z.string().email(),
|
|
1364
|
+
id: z.string().min(1).describe("Draft message ID to edit"),
|
|
1365
|
+
to: z.array(emailAddrSchema).optional(),
|
|
1366
|
+
cc: z.array(emailAddrSchema).optional(),
|
|
1367
|
+
bcc: z.array(emailAddrSchema).optional(),
|
|
1368
|
+
subject: z.string().optional(),
|
|
1369
|
+
body: z.string().optional(),
|
|
1370
|
+
isHtml: z.boolean().optional(),
|
|
1371
|
+
include_signature: z.boolean().optional().describe(
|
|
1372
|
+
"Whether to re-apply the account's saved HTML signature to the body. If true, don't include a signature in the body param. Only meaningful when `body` is also provided. Returns an error if true but no signature is configured for this account."
|
|
1373
|
+
)
|
|
1374
|
+
});
|
|
1375
|
+
const editDraftOutputSchema = {
|
|
1376
|
+
edited: z.literal(true),
|
|
1377
|
+
id: z.string(),
|
|
1378
|
+
draftHtml: z.string().optional()
|
|
1379
|
+
};
|
|
1380
|
+
server.registerTool(
|
|
1381
|
+
"edit_draft",
|
|
1382
|
+
{
|
|
1383
|
+
description: "Edit an existing draft email by ID. Only the fields you provide are updated \u2014 unmentioned fields stay unchanged. When `body` is provided and `include_signature` is true, the account's signature is re-applied. Returns the draft ID and the draft's updated HTML body content (`draftHtml`). Before sending, inspect `draftHtml` to verify the draft looks correct. Does not support changing `inReplyTo` or `forwardMessageId` \u2014 those are set at creation time via `draft_email`. Disabled in --read-only mode.",
|
|
1384
|
+
inputSchema: editDraftSchema,
|
|
1385
|
+
outputSchema: editDraftOutputSchema
|
|
1386
|
+
},
|
|
1387
|
+
async (args) => {
|
|
1388
|
+
const a = args;
|
|
1389
|
+
if (readOnly) return fail("server is in --read-only mode; edit_draft is disabled");
|
|
1390
|
+
try {
|
|
1391
|
+
const { provider, account } = registry.resolveByEmail(a.account);
|
|
1392
|
+
if (a.include_signature && !account.signature) {
|
|
1393
|
+
return fail(
|
|
1394
|
+
"include_signature is true but no signature is configured for this account. Set up a signature first with set_account_settings."
|
|
1395
|
+
);
|
|
1396
|
+
}
|
|
1397
|
+
let bodyPayload;
|
|
1398
|
+
let isHtmlPayload;
|
|
1399
|
+
if (a.body !== void 0) {
|
|
1400
|
+
const composed = composeBody({
|
|
1401
|
+
body: a.body,
|
|
1402
|
+
isHtml: a.isHtml,
|
|
1403
|
+
signature: account.signature,
|
|
1404
|
+
style: account.style,
|
|
1405
|
+
includeSignature: !!a.include_signature
|
|
1406
|
+
});
|
|
1407
|
+
bodyPayload = composed.body;
|
|
1408
|
+
isHtmlPayload = composed.isHtml;
|
|
1409
|
+
}
|
|
1410
|
+
const res = await provider.updateDraft(account, a.id, {
|
|
1411
|
+
to: a.to,
|
|
1412
|
+
cc: a.cc,
|
|
1413
|
+
bcc: a.bcc,
|
|
1414
|
+
subject: a.subject,
|
|
1415
|
+
body: bodyPayload,
|
|
1416
|
+
isHtml: isHtmlPayload
|
|
1417
|
+
});
|
|
1418
|
+
const draft = await provider.readEmail(account, res.id);
|
|
1419
|
+
const result = {
|
|
1420
|
+
edited: true,
|
|
1421
|
+
id: res.id,
|
|
1422
|
+
draftHtml: draft.bodyHtml
|
|
1423
|
+
};
|
|
1424
|
+
return ok(result, result);
|
|
1425
|
+
} catch (err) {
|
|
1426
|
+
return fail(errMsg(err));
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
);
|
|
1097
1430
|
}
|
|
1098
1431
|
function composeBody(input) {
|
|
1099
1432
|
const { body, isHtml = false, signature, style, includeSignature } = input;
|
|
@@ -1131,7 +1464,7 @@ function errMsg(err) {
|
|
|
1131
1464
|
}
|
|
1132
1465
|
|
|
1133
1466
|
// src/version.ts
|
|
1134
|
-
var VERSION = "0.
|
|
1467
|
+
var VERSION = "0.3.0";
|
|
1135
1468
|
|
|
1136
1469
|
// src/server.ts
|
|
1137
1470
|
async function startServer(opts = {}) {
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts","../src/store/account-store.ts","../src/providers/outlook/index.ts","../src/providers/outlook/client.ts","../src/providers/outlook/auth.ts","../src/providers/imap/index.ts","../src/providers/registry.ts","../src/tools/index.ts","../src/html-to-markdown.ts","../src/version.ts","../src/cli.ts"],"sourcesContent":["import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { StreamableHTTPServerTransport } from \"@modelcontextprotocol/sdk/server/streamableHttp.js\";\nimport { randomUUID } from \"node:crypto\";\nimport { createServer as createHttpServer, type IncomingMessage, type ServerResponse } from \"node:http\";\n\nimport { AccountStore } from \"./store/account-store.js\";\nimport { buildRegistry } from \"./providers/registry.js\";\nimport { registerTools } from \"./tools/index.js\";\nimport { VERSION } from \"./version.js\";\n\nexport interface ServerOptions {\n http?: boolean;\n port?: number;\n host?: string;\n dataDir?: string;\n readOnly?: boolean;\n /** When true, hide send_email and only expose draft_email. */\n draftOnly?: boolean;\n}\n\nexport async function startServer(opts: ServerOptions = {}): Promise<void> {\n const store = await AccountStore.open({ dataDir: opts.dataDir });\n const registry = buildRegistry({ store });\n\n const server = new McpServer(\n { name: \"hypermail-mcp\", version: VERSION },\n { capabilities: { tools: {}, logging: {} } },\n );\n\n registerTools(server, { store, registry, readOnly: !!opts.readOnly, draftOnly: !!opts.draftOnly });\n\n if (opts.http) {\n await startHttp(server, opts.host ?? \"127.0.0.1\", opts.port ?? 3000);\n } else {\n const transport = new StdioServerTransport();\n await server.connect(transport);\n }\n}\n\nasync function startHttp(server: McpServer, host: string, port: number): Promise<void> {\n // One transport per session, keyed by Mcp-Session-Id header.\n const sessions = new Map<string, StreamableHTTPServerTransport>();\n\n const http = createHttpServer(async (req: IncomingMessage, res: ServerResponse) => {\n try {\n if (!req.url || !req.url.startsWith(\"/mcp\")) {\n res.statusCode = 404;\n res.end(\"not found\");\n return;\n }\n const sessionId = (req.headers[\"mcp-session-id\"] as string | undefined) ?? undefined;\n let transport = sessionId ? sessions.get(sessionId) : undefined;\n\n if (!transport) {\n transport = new StreamableHTTPServerTransport({\n sessionIdGenerator: () => randomUUID(),\n onsessioninitialized: (sid: string) => {\n sessions.set(sid, transport!);\n },\n });\n transport.onclose = () => {\n if (transport!.sessionId) sessions.delete(transport!.sessionId);\n };\n await server.connect(transport);\n }\n\n // Buffer body for POST / DELETE\n let body: unknown = undefined;\n if (req.method === \"POST\" || req.method === \"DELETE\") {\n const chunks: Buffer[] = [];\n for await (const chunk of req) chunks.push(chunk as Buffer);\n const raw = Buffer.concat(chunks).toString(\"utf8\");\n body = raw ? JSON.parse(raw) : undefined;\n }\n await transport.handleRequest(req, res, body);\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error(\"[hypermail-mcp] http error:\", err);\n if (!res.headersSent) {\n res.statusCode = 500;\n res.end(\"internal error\");\n }\n }\n });\n\n await new Promise<void>((resolve) => http.listen(port, host, resolve));\n // eslint-disable-next-line no-console\n console.error(`[hypermail-mcp] listening on http://${host}:${port}/mcp`);\n}\n","import {\n createCipheriv,\n createDecipheriv,\n randomBytes,\n createHash,\n} from \"node:crypto\";\nimport { promises as fs } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport path from \"node:path\";\n\n/**\n * One stored account. `tokens` is provider-specific (e.g. serialized MSAL cache\n * for Outlook, host/port/password blob for IMAP) — the store is opaque to it.\n */\nexport interface AccountRecord {\n email: string;\n provider: \"outlook\" | \"imap\" | \"gmail\";\n displayName?: string;\n tokens: Record<string, unknown>;\n addedAt: string;\n /** HTML snippet — may contain formatting, images, links. Injected at end of outgoing emails. */\n signature?: string;\n /** Font/style preferences applied to outgoing HTML emails. */\n style?: { fontFamily?: string; fontSize?: string; fontColor?: string };\n}\n\ninterface StoreFile {\n version: 1;\n accounts: AccountRecord[];\n}\n\nexport interface OpenOptions {\n dataDir?: string;\n /** Inject the encryption key directly (mostly for tests). Otherwise resolved\n * from `HYPERMAIL_MCP_KEY` env, then OS keychain, then auto-generated. */\n key?: Buffer;\n}\n\nconst FILE_NAME = \"accounts.json.enc\";\nconst ALGO = \"aes-256-gcm\";\nconst KEY_LEN = 32;\n\nexport class AccountStore {\n private constructor(\n private readonly filePath: string,\n private readonly key: Buffer,\n private data: StoreFile,\n ) {}\n\n static async open(opts: OpenOptions = {}): Promise<AccountStore> {\n const dataDir = resolveDataDir(opts.dataDir);\n await fs.mkdir(dataDir, { recursive: true, mode: 0o700 });\n const filePath = path.join(dataDir, FILE_NAME);\n const key = opts.key ?? (await resolveKey(dataDir));\n\n let data: StoreFile;\n try {\n const buf = await fs.readFile(filePath);\n data = decrypt(buf, key);\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n data = { version: 1, accounts: [] };\n } else {\n throw err;\n }\n }\n return new AccountStore(filePath, key, data);\n }\n\n listAccounts(): AccountRecord[] {\n // Return shallow clones without tokens leaking out unintentionally is the\n // caller's job; here we expose the full record for provider use.\n return this.data.accounts.map((a) => ({ ...a }));\n }\n\n getAccount(email: string): AccountRecord | undefined {\n const norm = email.trim().toLowerCase();\n const rec = this.data.accounts.find((a) => a.email.toLowerCase() === norm);\n return rec ? { ...rec } : undefined;\n }\n\n async upsertAccount(rec: AccountRecord): Promise<AccountRecord> {\n const norm = rec.email.trim().toLowerCase();\n const next: AccountRecord = { ...rec, email: norm };\n const idx = this.data.accounts.findIndex((a) => a.email.toLowerCase() === norm);\n if (idx >= 0) this.data.accounts[idx] = next;\n else this.data.accounts.push(next);\n await this.flush();\n return { ...next };\n }\n\n async removeAccount(email: string): Promise<boolean> {\n const norm = email.trim().toLowerCase();\n const before = this.data.accounts.length;\n this.data.accounts = this.data.accounts.filter((a) => a.email.toLowerCase() !== norm);\n if (this.data.accounts.length === before) return false;\n await this.flush();\n return true;\n }\n\n private async flush(): Promise<void> {\n const buf = encrypt(this.data, this.key);\n const tmp = `${this.filePath}.${process.pid}.${Date.now()}.tmp`;\n await fs.writeFile(tmp, buf, { mode: 0o600 });\n await fs.rename(tmp, this.filePath);\n }\n}\n\n// ---------- encryption helpers ----------\n\nfunction encrypt(data: StoreFile, key: Buffer): Buffer {\n const iv = randomBytes(12);\n const cipher = createCipheriv(ALGO, key, iv);\n const plaintext = Buffer.from(JSON.stringify(data), \"utf8\");\n const ct = Buffer.concat([cipher.update(plaintext), cipher.final()]);\n const tag = cipher.getAuthTag();\n // layout: [1-byte version=1][12 iv][16 tag][ct...]\n return Buffer.concat([Buffer.from([1]), iv, tag, ct]);\n}\n\nfunction decrypt(buf: Buffer, key: Buffer): StoreFile {\n if (buf.length < 1 + 12 + 16 + 1) throw new Error(\"accounts file truncated\");\n const v = buf[0];\n if (v !== 1) throw new Error(`unsupported accounts file version: ${v}`);\n const iv = buf.subarray(1, 13);\n const tag = buf.subarray(13, 29);\n const ct = buf.subarray(29);\n const decipher = createDecipheriv(ALGO, key, iv);\n decipher.setAuthTag(tag);\n const pt = Buffer.concat([decipher.update(ct), decipher.final()]);\n const parsed = JSON.parse(pt.toString(\"utf8\")) as StoreFile;\n if (parsed.version !== 1 || !Array.isArray(parsed.accounts)) {\n throw new Error(\"accounts file is malformed\");\n }\n return parsed;\n}\n\n// ---------- key + path resolution ----------\n\nfunction resolveDataDir(explicit?: string): string {\n if (explicit && explicit.length > 0) return path.resolve(explicit);\n const env = process.env.HYPERMAIL_MCP_DATA_DIR;\n if (env && env.length > 0) return path.resolve(env);\n return path.join(homedir(), \".hypermail-mcp\");\n}\n\nfunction parseEnvKey(raw: string): Buffer | undefined {\n const s = raw.trim();\n // hex (64 chars)\n if (/^[0-9a-fA-F]{64}$/.test(s)) return Buffer.from(s, \"hex\");\n // base64 — accept any length, then check\n try {\n const buf = Buffer.from(s, \"base64\");\n if (buf.length === KEY_LEN) return buf;\n } catch {\n /* ignore */\n }\n // last-resort: derive 32 bytes via SHA-256 over the raw string. This lets\n // users pass any passphrase; not ideal but predictable.\n return createHash(\"sha256\").update(s, \"utf8\").digest();\n}\n\nasync function resolveKey(dataDir: string): Promise<Buffer> {\n const env = process.env.HYPERMAIL_MCP_KEY;\n if (env && env.length > 0) {\n const k = parseEnvKey(env);\n if (k) return k;\n }\n\n // Try OS keychain via keytar (optional dep).\n const fromKeytar = await tryKeytarGet();\n if (fromKeytar) return fromKeytar;\n\n // Local-dev fallback: persist a generated key to a 0600 file next to the\n // accounts blob so subsequent runs can decrypt. Hosted deployments should\n // always set HYPERMAIL_MCP_KEY explicitly.\n const keyFile = path.join(dataDir, \"master.key\");\n try {\n const existing = await fs.readFile(keyFile);\n if (existing.length === KEY_LEN) return existing;\n } catch {\n /* fall through to generate */\n }\n const gen = randomBytes(KEY_LEN);\n await fs.writeFile(keyFile, gen, { mode: 0o600 });\n await tryKeytarSet(gen);\n return gen;\n}\n\nasync function tryKeytarGet(): Promise<Buffer | undefined> {\n try {\n const mod = (await import(\"keytar\")) as typeof import(\"keytar\");\n const val = await mod.getPassword(\"hypermail-mcp\", \"master\");\n if (val) {\n const buf = Buffer.from(val, \"base64\");\n if (buf.length === KEY_LEN) return buf;\n }\n } catch {\n /* keytar not installed or unsupported platform */\n }\n return undefined;\n}\n\nasync function tryKeytarSet(key: Buffer): Promise<void> {\n try {\n const mod = (await import(\"keytar\")) as typeof import(\"keytar\");\n await mod.setPassword(\"hypermail-mcp\", \"master\", key.toString(\"base64\"));\n } catch {\n /* ignore */\n }\n}\n","import { randomUUID } from \"node:crypto\";\nimport { writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join as pathJoin } from \"node:path\";\n\nimport { ResponseType, type Client } from \"@microsoft/microsoft-graph-client\";\n\nimport type { AccountRecord, AccountStore } from \"../../store/account-store.js\";\nimport type {\n AddAccountInput,\n AddAccountResult,\n AttachmentContent,\n CompleteAddAccountResult,\n EmailFull,\n EmailProvider,\n EmailSummary,\n ListEmailsOptions,\n SearchEmailsOptions,\n SendInput,\n EmailAddress,\n} from \"../types.js\";\nimport { OutlookClientFactory } from \"./client.js\";\nimport {\n awaitDeviceCodeReady,\n beginDeviceCode,\n type DeviceCodeBegin,\n type SerializedTokens,\n} from \"./auth.js\";\n\n// ---------- inline image conversion ----------\n\ninterface InlineAttachment {\n \"@odata.type\": string;\n name: string;\n contentType: string;\n contentId: string;\n contentBytes: string;\n isInline: boolean;\n}\n\n/**\n * Scans HTML for data:image/...;base64,... URIs, extracts the raw base64\n * data, assigns unique contentIds, and returns the transformed body\n * (with src=\"cid:...\" references) plus an array of inline fileAttachment\n * objects ready for the Graph API.\n *\n * Pass-through when there are no matches — returns the original body with\n * an empty attachments array.\n */\nexport function convertInlineImages(body: string): {\n body: string;\n attachments: InlineAttachment[];\n} {\n const attachments: InlineAttachment[] = [];\n // Match src=\"data:image/<subtype>;base64,<payload>\"\n // Supports png, jpg, jpeg, gif, svg+xml, webp, bmp, etc.\n const re = /src=\"data:image\\/([\\w+]+);base64,([^\"]+)\"/gi;\n\n const transformed = body.replace(re, (_fullMatch, mimeSubtype, b64) => {\n const contentId = `sig-img-${randomUUID()}`;\n const ext = mimeSubtype.toLowerCase().replace(/\\+/g, \"-\") === \"svg-xml\"\n ? \"svg\"\n : mimeSubtype.toLowerCase().replace(/\\+/g, \"-\");\n attachments.push({\n \"@odata.type\": \"#microsoft.graph.fileAttachment\",\n name: `signature-image.${ext}`,\n contentType: `image/${mimeSubtype}`,\n contentId,\n contentBytes: b64,\n isInline: true,\n });\n return `src=\"cid:${contentId}\"`;\n });\n\n return { body: transformed, attachments };\n}\n\ninterface PendingFlow {\n begin: DeviceCodeBegin;\n emailHint?: string;\n startedAt: number;\n settled: \"pending\" | \"ready\" | \"error\" | \"expired\";\n account?: AccountRecord;\n error?: string;\n}\n\nexport interface OutlookProviderOptions {\n store: AccountStore;\n}\n\nexport class OutlookProvider implements EmailProvider {\n readonly id = \"outlook\" as const;\n private readonly clients: OutlookClientFactory;\n private readonly pending = new Map<string, PendingFlow>();\n\n constructor(private readonly opts: OutlookProviderOptions) {\n this.clients = new OutlookClientFactory(opts.store);\n }\n\n // ---------- account lifecycle ----------\n\n async addAccount(input: AddAccountInput): Promise<AddAccountResult> {\n const begin = beginDeviceCode();\n await awaitDeviceCodeReady(begin);\n\n const handle = randomUUID();\n const flow: PendingFlow = {\n begin,\n emailHint: input.email,\n startedAt: Date.now(),\n settled: \"pending\",\n };\n this.pending.set(handle, flow);\n\n // Fire-and-forget: when the user finishes, persist and update flow.\n begin.result\n .then(async ({ tokens, account }) => {\n const email = (account.username || input.email || \"\").toLowerCase();\n if (!email) {\n flow.settled = \"error\";\n flow.error = \"no email returned from Microsoft account\";\n return;\n }\n const rec: AccountRecord = {\n email,\n provider: \"outlook\",\n displayName: account.name ?? undefined,\n tokens: tokens as unknown as Record<string, unknown>,\n addedAt: new Date().toISOString(),\n };\n const saved = await this.opts.store.upsertAccount(rec);\n flow.account = saved;\n flow.settled = \"ready\";\n })\n .catch((err: unknown) => {\n flow.settled = \"error\";\n flow.error = err instanceof Error ? err.message : String(err);\n });\n\n return {\n status: \"pending\",\n handle,\n verification: {\n userCode: begin.userCode,\n verificationUri: begin.verificationUri,\n expiresAt: begin.expiresAt,\n message: begin.message,\n },\n };\n }\n\n async completeAddAccount(handle: string): Promise<CompleteAddAccountResult> {\n const flow = this.pending.get(handle);\n if (!flow) return { status: \"error\", error: \"unknown handle\" };\n // expire after 20 minutes regardless\n if (Date.now() - flow.startedAt > 20 * 60_000 && flow.settled === \"pending\") {\n flow.settled = \"expired\";\n flow.begin.cancel();\n }\n if (flow.settled === \"ready\" && flow.account) {\n this.pending.delete(handle);\n return { status: \"ready\", account: flow.account };\n }\n if (flow.settled === \"error\") {\n this.pending.delete(handle);\n return { status: \"error\", error: flow.error ?? \"unknown error\" };\n }\n if (flow.settled === \"expired\") {\n this.pending.delete(handle);\n return { status: \"expired\" };\n }\n return { status: \"pending\" };\n }\n\n // ---------- email ops ----------\n\n async listEmails(\n account: AccountRecord,\n opts: ListEmailsOptions,\n ): Promise<EmailSummary[]> {\n const client = this.clients.get(account);\n const limit = clampLimit(opts.limit, 25, 100);\n const folder = opts.folder ?? \"inbox\";\n const filterParts: string[] = [];\n if (opts.unreadOnly) filterParts.push(\"isRead eq false\");\n\n let req = client\n .api(`/me/mailFolders/${encodeURIComponent(folder)}/messages`)\n .top(limit)\n .select([\n \"id\",\n \"subject\",\n \"from\",\n \"toRecipients\",\n \"receivedDateTime\",\n \"bodyPreview\",\n \"isRead\",\n \"hasAttachments\",\n ].join(\",\"))\n .orderby(\"receivedDateTime DESC\");\n\n if (filterParts.length > 0) req = req.filter(filterParts.join(\" and \"));\n\n const res = (await req.get()) as { value: GraphMessage[] };\n return res.value.map((m) => mapSummary(m, folder));\n }\n\n async searchEmails(\n account: AccountRecord,\n query: string,\n opts: SearchEmailsOptions,\n ): Promise<EmailSummary[]> {\n const client = this.clients.get(account);\n const limit = clampLimit(opts.limit, 25, 100);\n // $search requires the ConsistencyLevel: eventual header\n const res = (await client\n .api(\"/me/messages\")\n .header(\"ConsistencyLevel\", \"eventual\")\n .top(limit)\n .search(`\"${query.replace(/\"/g, '\\\\\"')}\"`)\n .select(\n [\n \"id\",\n \"subject\",\n \"from\",\n \"toRecipients\",\n \"receivedDateTime\",\n \"bodyPreview\",\n \"isRead\",\n \"hasAttachments\",\n ].join(\",\"),\n )\n .get()) as { value: GraphMessage[] };\n return res.value.map((m) => mapSummary(m));\n }\n\n async readEmail(account: AccountRecord, id: string): Promise<EmailFull> {\n const client = this.clients.get(account);\n const m = (await client\n .api(`/me/messages/${encodeURIComponent(id)}`)\n .select(\n [\n \"id\",\n \"subject\",\n \"from\",\n \"toRecipients\",\n \"ccRecipients\",\n \"bccRecipients\",\n \"receivedDateTime\",\n \"bodyPreview\",\n \"isRead\",\n \"hasAttachments\",\n \"body\",\n ].join(\",\"),\n )\n .get()) as GraphMessage;\n\n let attachments: EmailFull[\"attachments\"] = undefined;\n if (m.hasAttachments) {\n try {\n const attRes = (await client\n .api(`/me/messages/${encodeURIComponent(id)}/attachments`)\n .select(\"id,name,contentType,size\")\n .get()) as { value: GraphAttachment[] };\n attachments = attRes.value.map((a) => ({\n id: a.id,\n name: a.name,\n contentType: a.contentType,\n size: a.size,\n }));\n } catch {\n /* ignore attachment listing failure */\n }\n }\n\n const summary = mapSummary(m);\n const body = m.body;\n return {\n ...summary,\n cc: (m.ccRecipients ?? []).map(mapRecipient),\n bcc: (m.bccRecipients ?? []).map(mapRecipient),\n bodyText: body?.contentType === \"text\" ? body.content : undefined,\n bodyHtml: body?.contentType === \"html\" ? body.content : undefined,\n attachments,\n };\n }\n\n async readAttachment(\n account: AccountRecord,\n messageId: string,\n attachmentId: string,\n ): Promise<AttachmentContent> {\n const client = this.clients.get(account);\n // First, get the attachment metadata to know the filename\n const att = (await client\n .api(`/me/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(attachmentId)}`)\n .select(\"name,contentType\")\n .get()) as { name: string; contentType?: string };\n\n // Download the raw content as ArrayBuffer\n const data = (await client\n .api(`/me/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(attachmentId)}/$value`)\n .responseType(ResponseType.ARRAYBUFFER)\n .get()) as ArrayBuffer;\n\n // Write to temp file with original name\n const outPath = pathJoin(tmpdir(), att.name);\n writeFileSync(outPath, Buffer.from(data));\n\n return {\n name: att.name,\n contentType: att.contentType,\n path: outPath,\n };\n }\n\n // Shared helper — creates a draft from a reference message (forward or\n // reply), prepends our composed body before the existing content, and\n // attaches inline images. Returns the draft message ID.\n private async buildDraftFromReference(\n client: Client,\n createEndpoint: string,\n createPayload: Record<string, unknown>,\n converted: { body: string; attachments: InlineAttachment[] },\n ): Promise<string> {\n const draft: { id: string } = await client\n .api(createEndpoint)\n .post(createPayload);\n\n const draftMsg: { body?: { content?: string; contentType?: string } } =\n await client.api(`/me/messages/${draft.id}`).select(\"body\").get();\n\n const draftBody = draftMsg.body?.content ?? \"\";\n const draftContentType = draftMsg.body?.contentType ?? \"HTML\";\n const spacer = '<div style=\"line-height:12px\"><br></div>';\n const prepend = converted.body + spacer;\n const finalBody = draftBody.includes(\"<body\")\n ? draftBody.replace(/(<body[^>]*>)/i, `$1${prepend}`)\n : prepend + draftBody;\n\n await client.api(`/me/messages/${draft.id}`).patch({\n body: { contentType: draftContentType, content: finalBody },\n });\n\n for (const att of converted.attachments) {\n await client.api(`/me/messages/${draft.id}/attachments`).post(att);\n }\n\n return draft.id;\n }\n\n async sendEmail(\n account: AccountRecord,\n msg: SendInput,\n ): Promise<{ id: string }> {\n const client = this.clients.get(account);\n\n if (msg.inReplyTo && msg.forwardMessageId) {\n throw new Error(\n \"inReplyTo and forwardMessageId are mutually exclusive — use one or the other\",\n );\n }\n\n // Convert data:image URIs to cid: references + inline attachments.\n const converted = convertInlineImages(msg.body);\n\n if (msg.forwardMessageId) {\n const draftId = await this.buildDraftFromReference(\n client,\n `/me/messages/${encodeURIComponent(msg.forwardMessageId)}/createForward`,\n {\n message: {\n toRecipients: msg.to.map(toRecipient),\n ccRecipients: (msg.cc ?? []).map(toRecipient),\n bccRecipients: (msg.bcc ?? []).map(toRecipient),\n },\n comment: \"\",\n },\n converted,\n );\n await client.api(`/me/messages/${draftId}/send`).post({});\n return { id: draftId };\n }\n\n if (msg.inReplyTo) {\n const createEndpoint = msg.replyAll\n ? `/me/messages/${encodeURIComponent(msg.inReplyTo)}/createReplyAll`\n : `/me/messages/${encodeURIComponent(msg.inReplyTo)}/createReply`;\n const draftId = await this.buildDraftFromReference(\n client,\n createEndpoint,\n {},\n converted,\n );\n await client.api(`/me/messages/${draftId}/send`).post({});\n return { id: draftId };\n }\n\n // New email — use sendMail with inline attachments\n const payload: Record<string, unknown> = {\n message: {\n subject: msg.subject,\n body: {\n contentType: msg.isHtml ? \"HTML\" : \"Text\",\n content: converted.body,\n },\n toRecipients: msg.to.map(toRecipient),\n ccRecipients: (msg.cc ?? []).map(toRecipient),\n bccRecipients: (msg.bcc ?? []).map(toRecipient),\n },\n saveToSentItems: true,\n };\n if (converted.attachments.length > 0) {\n (payload.message as Record<string, unknown>).attachments =\n converted.attachments;\n }\n await client.api(\"/me/sendMail\").post(payload);\n // Graph's sendMail returns 202 with no body; we don't have an id back.\n return { id: \"\" };\n }\n\n async saveDraft(\n account: AccountRecord,\n msg: SendInput,\n ): Promise<{ id: string }> {\n const client = this.clients.get(account);\n\n if (msg.inReplyTo && msg.forwardMessageId) {\n throw new Error(\n \"inReplyTo and forwardMessageId are mutually exclusive — use one or the other\",\n );\n }\n\n const converted = convertInlineImages(msg.body);\n\n // Forward/reply drafts: same flow as sendEmail, but skip the final send.\n if (msg.forwardMessageId) {\n const draftId = await this.buildDraftFromReference(\n client,\n `/me/messages/${encodeURIComponent(msg.forwardMessageId)}/createForward`,\n {\n message: {\n toRecipients: msg.to.map(toRecipient),\n ccRecipients: (msg.cc ?? []).map(toRecipient),\n bccRecipients: (msg.bcc ?? []).map(toRecipient),\n },\n comment: \"\",\n },\n converted,\n );\n return { id: draftId };\n }\n\n if (msg.inReplyTo) {\n const createEndpoint = msg.replyAll\n ? `/me/messages/${encodeURIComponent(msg.inReplyTo)}/createReplyAll`\n : `/me/messages/${encodeURIComponent(msg.inReplyTo)}/createReply`;\n const draftId = await this.buildDraftFromReference(\n client,\n createEndpoint,\n {},\n converted,\n );\n return { id: draftId };\n }\n\n // New email — create a draft message directly (POST /me/messages).\n // Graph creates drafts by default when posting to /me/messages.\n const draftPayload: Record<string, unknown> = {\n subject: msg.subject,\n body: {\n contentType: msg.isHtml ? \"HTML\" : \"Text\",\n content: converted.body,\n },\n toRecipients: msg.to.map(toRecipient),\n ccRecipients: (msg.cc ?? []).map(toRecipient),\n bccRecipients: (msg.bcc ?? []).map(toRecipient),\n };\n if (converted.attachments.length > 0) {\n draftPayload.attachments = converted.attachments;\n }\n const draft: { id: string } = await client\n .api(\"/me/messages\")\n .post(draftPayload);\n return { id: draft.id };\n }\n}\n\n// ---------- mapping helpers ----------\n\ninterface GraphRecipient {\n emailAddress?: { name?: string; address?: string };\n}\ninterface GraphMessage {\n id: string;\n subject?: string;\n from?: GraphRecipient;\n toRecipients?: GraphRecipient[];\n ccRecipients?: GraphRecipient[];\n bccRecipients?: GraphRecipient[];\n receivedDateTime?: string;\n bodyPreview?: string;\n isRead?: boolean;\n hasAttachments?: boolean;\n body?: { contentType?: \"text\" | \"html\"; content?: string };\n}\ninterface GraphAttachment {\n id: string;\n name: string;\n contentType?: string;\n size?: number;\n}\n\nfunction mapRecipient(r: GraphRecipient): EmailAddress {\n return {\n name: r.emailAddress?.name,\n address: r.emailAddress?.address ?? \"\",\n };\n}\n\nfunction mapSummary(m: GraphMessage, folder?: string): EmailSummary {\n return {\n id: m.id,\n subject: m.subject ?? \"\",\n from: m.from ? mapRecipient(m.from) : undefined,\n to: (m.toRecipients ?? []).map(mapRecipient),\n receivedAt: m.receivedDateTime,\n preview: m.bodyPreview,\n isRead: m.isRead,\n hasAttachments: m.hasAttachments,\n folder,\n };\n}\n\nfunction toRecipient(a: EmailAddress): GraphRecipient {\n return { emailAddress: { name: a.name, address: a.address } };\n}\n\nfunction clampLimit(v: number | undefined, dflt: number, max: number): number {\n if (!v || v <= 0) return dflt;\n return Math.min(v, max);\n}\n","import \"isomorphic-fetch\";\nimport {\n Client,\n type AuthenticationProvider,\n} from \"@microsoft/microsoft-graph-client\";\n\nimport type { AccountStore, AccountRecord } from \"../../store/account-store.js\";\nimport { acquireAccessToken, type SerializedTokens } from \"./auth.js\";\n\n/**\n * Builds a Graph `Client` bound to a stored account. The client uses an\n * `AuthenticationProvider` that calls msal silently on every request, and\n * writes the (possibly-refreshed) cache back into the AccountStore.\n *\n * Clients are cached per email since the underlying SDK reuses connections.\n */\nexport class OutlookClientFactory {\n private readonly cache = new Map<string, Client>();\n\n constructor(private readonly store: AccountStore) {}\n\n get(account: AccountRecord): Client {\n const key = account.email.toLowerCase();\n const existing = this.cache.get(key);\n if (existing) return existing;\n\n const store = this.store;\n const provider: AuthenticationProvider = {\n getAccessToken: async () => {\n const fresh = store.getAccount(account.email) ?? account;\n const tokens = fresh.tokens as unknown as SerializedTokens;\n const { accessToken, tokens: nextTokens } = await acquireAccessToken(tokens);\n // Persist refreshed cache opportunistically; failures here shouldn't\n // break the in-flight Graph call.\n if (nextTokens.msalCache !== tokens.msalCache) {\n store\n .upsertAccount({\n ...fresh,\n tokens: nextTokens as unknown as Record<string, unknown>,\n })\n .catch(() => {\n /* swallow — next call will refresh again */\n });\n }\n return accessToken;\n },\n };\n\n const client = Client.initWithMiddleware({ authProvider: provider });\n this.cache.set(key, client);\n return client;\n }\n\n /** Drop a cached client (e.g. after removeAccount). */\n invalidate(email: string): void {\n this.cache.delete(email.toLowerCase());\n }\n}\n","import {\n PublicClientApplication,\n type Configuration,\n type AuthenticationResult,\n type AccountInfo,\n} from \"@azure/msal-node\";\n\n/**\n * Public client app id. Default is the well-known `ms-365` client id used by\n * the softeria/ms-365-mcp-server project — it's a public client registered\n * for personal MSA + multi-tenant work/school. Users can override via\n * MS_CLIENT_ID for their own Entra app registrations.\n */\nconst DEFAULT_CLIENT_ID = \"084a3e9f-a9f4-43f7-89f9-d229cf97853e\";\n// ^ Pre-registered public client app (same one used by softeria/ms-365-mcp-server).\n// Supports personal MSA + multi-tenant work/school via device-code flow.\n// Operators should set MS_CLIENT_ID to a client they control for production.\n\nconst DEFAULT_SCOPES = [\n \"offline_access\",\n \"User.Read\",\n \"Mail.ReadWrite\",\n \"Mail.Send\",\n];\n\nexport interface DeviceCodeBegin {\n userCode: string;\n verificationUri: string;\n message: string;\n expiresAt: string; // ISO\n /** Resolves with the auth result once the user completes the flow. */\n result: Promise<{ tokens: SerializedTokens; account: AccountInfo }>;\n /** Aborts the in-flight polling promise. */\n cancel(): void;\n}\n\nexport interface SerializedTokens {\n /** MSAL cache JSON, encrypted at rest by the account store. */\n msalCache: string;\n /** Home account id used to look up the account in the rehydrated cache. */\n homeAccountId: string;\n /** Tenant id captured at sign-in. */\n tenantId: string;\n /** Username captured at sign-in (typically the primary email). */\n username: string;\n scopes: string[];\n}\n\nfunction makeConfig(prevCacheJson?: string): Configuration {\n const clientId = process.env.MS_CLIENT_ID || DEFAULT_CLIENT_ID;\n const tenant = process.env.MS_TENANT_ID || \"common\";\n return {\n auth: {\n clientId,\n authority: `https://login.microsoftonline.com/${tenant}`,\n },\n cache: prevCacheJson\n ? {\n // msal-node supports an in-memory cache plugin; we hydrate manually\n // below via deserialize after construction.\n }\n : undefined,\n };\n}\n\nexport function buildPca(prevCacheJson?: string): PublicClientApplication {\n const pca = new PublicClientApplication(makeConfig(prevCacheJson));\n if (prevCacheJson) {\n pca.getTokenCache().deserialize(prevCacheJson);\n }\n return pca;\n}\n\n/**\n * Start a device-code flow. The returned `result` promise resolves once the\n * user has entered the code and consented; callers should poll it (or await it)\n * via `complete_add_account`.\n */\nexport function beginDeviceCode(scopes: string[] = DEFAULT_SCOPES): DeviceCodeBegin {\n const pca = buildPca();\n let resolve!: (v: { tokens: SerializedTokens; account: AccountInfo }) => void;\n let reject!: (err: unknown) => void;\n const result = new Promise<{ tokens: SerializedTokens; account: AccountInfo }>(\n (res, rej) => {\n resolve = res;\n reject = rej;\n },\n );\n\n // We capture the deviceCodeCallback synchronously to surface the user-facing\n // info back out via this object before awaiting the long-running poll.\n let userCode = \"\";\n let verificationUri = \"\";\n let message = \"\";\n let expiresAt = new Date(Date.now() + 15 * 60_000).toISOString();\n let aborted = false;\n\n const ready = new Promise<void>((r) => {\n pca\n .acquireTokenByDeviceCode({\n scopes,\n deviceCodeCallback: (info) => {\n if (!info.userCode || !info.verificationUri) {\n // MSAL may fire the callback with an empty object if the\n // downstream HTTP request fails — reject so the caller\n // gets a clear error instead of silent empty strings.\n reject(\n new Error(\n \"Microsoft device-code endpoint returned no code. \" +\n \"Check MS_CLIENT_ID is a valid Azure Entra public-client application.\",\n ),\n );\n return;\n }\n userCode = info.userCode;\n verificationUri = info.verificationUri;\n message = info.message;\n if (info.expiresIn) {\n expiresAt = new Date(Date.now() + info.expiresIn * 1000).toISOString();\n }\n r();\n },\n })\n .then((authResult: AuthenticationResult | null) => {\n if (aborted) return;\n if (!authResult || !authResult.account) {\n reject(new Error(\"device-code flow returned no account\"));\n return;\n }\n const cache = pca.getTokenCache().serialize();\n const tokens: SerializedTokens = {\n msalCache: cache,\n homeAccountId: authResult.account.homeAccountId,\n tenantId: authResult.account.tenantId,\n username: authResult.account.username,\n scopes,\n };\n resolve({ tokens, account: authResult.account });\n })\n .catch((err) => {\n if (!aborted) reject(err);\n });\n });\n\n // Surface device-code info synchronously via a wrapper Promise:\n // we return the object but its strings are populated once `ready` settles.\n // To keep the API simple, we attach a getter that callers must `await` on.\n // Instead of getters, we wait for `ready` inside the begin helper:\n return {\n // these are placeholders until ready resolves\n get userCode() {\n return userCode;\n },\n get verificationUri() {\n return verificationUri;\n },\n get message() {\n return message;\n },\n get expiresAt() {\n return expiresAt;\n },\n result,\n cancel() {\n aborted = true;\n },\n // hidden helper for the caller to await initial code\n // (typed via a cast below where used)\n ...({ _ready: ready } as Record<string, unknown>),\n } as DeviceCodeBegin;\n}\n\n/** Await `_ready` so the user-code fields are populated. */\nexport async function awaitDeviceCodeReady(b: DeviceCodeBegin): Promise<void> {\n const r = (b as unknown as { _ready: Promise<void> })._ready;\n await r;\n}\n\n/**\n * Acquire a fresh access token for a stored account, refreshing silently from\n * the persisted MSAL cache. Returns the (possibly-updated) cache so the caller\n * can write it back to the store.\n */\nexport async function acquireAccessToken(\n tokens: SerializedTokens,\n scopes: string[] = DEFAULT_SCOPES,\n): Promise<{ accessToken: string; tokens: SerializedTokens }> {\n const pca = buildPca(tokens.msalCache);\n const cache = pca.getTokenCache();\n const account =\n (await cache.getAccountByHomeId(tokens.homeAccountId)) ??\n (await cache.getAllAccounts()).find((a) => a.username === tokens.username);\n if (!account) {\n throw new Error(\"no MSAL account in cache — re-run add_account\");\n }\n const res = await pca.acquireTokenSilent({ account, scopes });\n if (!res?.accessToken) {\n throw new Error(\"acquireTokenSilent returned no access token\");\n }\n const next: SerializedTokens = {\n ...tokens,\n msalCache: cache.serialize(),\n scopes,\n };\n return { accessToken: res.accessToken, tokens: next };\n}\n","import type { AccountRecord } from \"../../store/account-store.js\";\nimport type {\n AddAccountInput,\n AddAccountResult,\n AttachmentContent,\n CompleteAddAccountResult,\n EmailFull,\n EmailProvider,\n EmailSummary,\n ListEmailsOptions,\n SearchEmailsOptions,\n SendInput,\n} from \"../types.js\";\n\nconst NOT_IMPLEMENTED =\n \"IMAP provider is not yet implemented in v1. Tracked at \" +\n \"src/providers/imap/index.ts — see src/providers/types.ts for the contract.\";\n\n/**\n * Placeholder IMAP provider — registered so the contract is locked in and\n * `add_account` returns a clear \"coming soon\" error instead of \"unknown provider\".\n *\n * v2 plan: use `imapflow` + `nodemailer` (for send). Tokens shape will be\n * `{ host, port, secure, user, password|appPassword }` encrypted at rest by\n * the AccountStore, identical to how Outlook's MSAL cache is stored.\n */\nexport class ImapProvider implements EmailProvider {\n readonly id = \"imap\" as const;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async addAccount(_input: AddAccountInput): Promise<AddAccountResult> {\n throw new Error(NOT_IMPLEMENTED);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async completeAddAccount(_handle: string): Promise<CompleteAddAccountResult> {\n return { status: \"error\", error: NOT_IMPLEMENTED };\n }\n\n async listEmails(\n _account: AccountRecord,\n _opts: ListEmailsOptions,\n ): Promise<EmailSummary[]> {\n throw new Error(NOT_IMPLEMENTED);\n }\n\n async searchEmails(\n _account: AccountRecord,\n _query: string,\n _opts: SearchEmailsOptions,\n ): Promise<EmailSummary[]> {\n throw new Error(NOT_IMPLEMENTED);\n }\n\n async readEmail(_account: AccountRecord, _id: string): Promise<EmailFull> {\n throw new Error(NOT_IMPLEMENTED);\n }\n\n async readAttachment(\n _account: AccountRecord,\n _messageId: string,\n _attachmentId: string,\n ): Promise<AttachmentContent> {\n throw new Error(NOT_IMPLEMENTED);\n }\n\n async sendEmail(\n _account: AccountRecord,\n _msg: SendInput,\n ): Promise<{ id: string }> {\n throw new Error(NOT_IMPLEMENTED);\n }\n\n async saveDraft(\n _account: AccountRecord,\n _msg: SendInput,\n ): Promise<{ id: string }> {\n throw new Error(NOT_IMPLEMENTED);\n }\n}\n","import type { AccountStore, AccountRecord } from \"../store/account-store.js\";\nimport type { EmailProvider, ProviderId } from \"./types.js\";\nimport { OutlookProvider } from \"./outlook/index.js\";\nimport { ImapProvider } from \"./imap/index.js\";\n\nexport interface Registry {\n get(id: ProviderId): EmailProvider;\n resolveByEmail(email: string): { provider: EmailProvider; account: AccountRecord };\n list(): EmailProvider[];\n}\n\nexport interface BuildRegistryOptions {\n store: AccountStore;\n}\n\nexport function buildRegistry(opts: BuildRegistryOptions): Registry {\n const providers = new Map<ProviderId, EmailProvider>();\n providers.set(\"outlook\", new OutlookProvider({ store: opts.store }));\n providers.set(\"imap\", new ImapProvider());\n // gmail can be added later — registry will return a clear error if asked.\n\n function get(id: ProviderId): EmailProvider {\n const p = providers.get(id);\n if (!p) throw new Error(`unknown provider: ${id}`);\n return p;\n }\n\n function resolveByEmail(email: string): {\n provider: EmailProvider;\n account: AccountRecord;\n } {\n const account = opts.store.getAccount(email);\n if (!account) {\n throw new Error(\n `no account registered for \"${email}\". Call add_account first.`,\n );\n }\n return { provider: get(account.provider), account };\n }\n\n return {\n get,\n resolveByEmail,\n list: () => Array.from(providers.values()),\n };\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\n\nimport type { AccountRecord, AccountStore } from \"../store/account-store.js\";\nimport type { Registry } from \"../providers/registry.js\";\nimport type { EmailProvider, ProviderId, SendInput } from \"../providers/types.js\";\nimport { selectBody } from \"../html-to-markdown.js\";\n\nexport interface RegisterToolsOptions {\n store: AccountStore;\n registry: Registry;\n readOnly?: boolean;\n /** When true, send_email is not registered — only send_draft is available. */\n draftOnly?: boolean;\n}\n\n/** JSON-stringify a value into a single MCP text content block. */\nfunction ok(data: unknown) {\n return {\n content: [\n { type: \"text\" as const, text: JSON.stringify(data, null, 2) },\n ],\n };\n}\nfunction fail(message: string) {\n return {\n isError: true,\n content: [{ type: \"text\" as const, text: message }],\n };\n}\n\nconst emailAddrSchema = z.object({\n address: z.string().email(),\n name: z.string().optional(),\n});\n\nexport function registerTools(server: McpServer, opts: RegisterToolsOptions): void {\n const { store, registry, readOnly = false, draftOnly = false } = opts;\n\n // ---------- account management ----------\n\n server.registerTool(\n \"list_accounts\",\n {\n description:\n \"List all email accounts known to this server (no secrets). \" +\n \"Use the returned `email` value as the `account` argument to other tools.\",\n inputSchema: {},\n },\n async () => {\n const rows = store.listAccounts().map((a) => ({\n email: a.email,\n provider: a.provider,\n displayName: a.displayName,\n addedAt: a.addedAt,\n hasSignature: !!a.signature,\n hasStyle: !!(a.style && (a.style.fontFamily || a.style.fontSize || a.style.fontColor)),\n }));\n return ok({ accounts: rows });\n },\n );\n\n server.registerTool(\n \"add_account\",\n {\n description:\n \"Start adding an email account. For Outlook this returns a device code \" +\n \"the user must enter at the verification URL; then call `complete_add_account` \" +\n \"with the returned `handle` to finalize. Disabled in --read-only mode.\",\n inputSchema: {\n provider: z\n .enum([\"outlook\", \"imap\", \"gmail\"])\n .describe(\"Email backend. v1 only fully implements 'outlook'.\"),\n email: z\n .string()\n .email()\n .optional()\n .describe(\"Optional hint — the provider will verify it against the auth result.\"),\n config: z\n .record(z.unknown())\n .optional()\n .describe(\"Provider-specific config (e.g. IMAP host/port). Unused for Outlook.\"),\n },\n },\n async (args) => {\n if (readOnly) return fail(\"server is in --read-only mode; add_account is disabled\");\n const provider = registry.get(args.provider as ProviderId);\n try {\n const res = await provider.addAccount({ email: args.email, config: args.config });\n return ok(res);\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n server.registerTool(\n \"complete_add_account\",\n {\n description:\n \"Poll/finalize a pending add_account flow. Returns `pending` until the user \" +\n \"completes the device-code step, then `ready` with the persisted account.\",\n inputSchema: {\n provider: z.enum([\"outlook\", \"imap\", \"gmail\"]),\n handle: z.string().min(1),\n },\n },\n async (args) => {\n const provider = registry.get(args.provider as ProviderId);\n if (!provider.completeAddAccount) {\n return fail(`provider ${args.provider} has no async add-account flow`);\n }\n try {\n const res = await provider.completeAddAccount(args.handle);\n return ok(res);\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n // ---------- account settings ----------\n\n server.registerTool(\n \"get_account_settings\",\n {\n description:\n \"Get signature (HTML) and style preferences for an account.\",\n inputSchema: { account: z.string().email() },\n },\n async (args) => {\n try {\n const acct = store.getAccount(args.account);\n if (!acct) return fail(`no account registered for \"${args.account}\"`);\n return ok({ signature: acct.signature ?? null, style: acct.style ?? null });\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n server.registerTool(\n \"set_account_settings\",\n {\n description:\n \"Set signature (HTML snippet) and/or style preferences for an account. \" +\n \"Disabled in --read-only mode.\",\n inputSchema: {\n account: z.string().email(),\n signature: z\n .string()\n .optional()\n .describe(\"HTML snippet — may contain formatting, images, links. Pass null to clear.\"),\n style: z\n .object({\n fontFamily: z.string().optional(),\n fontSize: z.string().optional(),\n fontColor: z.string().optional(),\n })\n .optional()\n .describe(\"Font preferences applied to outgoing HTML emails. Pass null to clear.\"),\n },\n },\n async (args) => {\n if (readOnly) return fail(\"server is in --read-only mode; set_account_settings is disabled\");\n try {\n const acct = store.getAccount(args.account);\n if (!acct) return fail(`no account registered for \"${args.account}\"`);\n const updated = await store.upsertAccount({\n ...acct,\n signature: args.signature ?? acct.signature,\n style: args.style ?? acct.style,\n });\n return ok({ signature: updated.signature ?? null, style: updated.style ?? null });\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n server.registerTool(\n \"remove_account\",\n {\n description: \"Forget an account and delete its stored tokens. Disabled in --read-only mode.\",\n inputSchema: { email: z.string().email() },\n },\n async (args) => {\n if (readOnly) return fail(\"server is in --read-only mode; remove_account is disabled\");\n const removed = await store.removeAccount(args.email);\n return ok({ removed, email: args.email });\n },\n );\n\n // ---------- email ops ----------\n\n server.registerTool(\n \"list_emails\",\n {\n description:\n \"List recent emails in a folder of the given account. Pass the user's email \" +\n \"address as `account`; the server routes to the correct backend automatically.\",\n inputSchema: {\n account: z.string().email(),\n folder: z.string().default(\"inbox\").optional(),\n limit: z.number().int().positive().max(100).optional(),\n unreadOnly: z.boolean().optional(),\n },\n },\n async (args) => {\n try {\n const { provider, account } = registry.resolveByEmail(args.account);\n const items = await provider.listEmails(account, {\n folder: args.folder,\n limit: args.limit,\n unreadOnly: args.unreadOnly,\n });\n return ok({ account: account.email, count: items.length, items });\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n server.registerTool(\n \"search_emails\",\n {\n description:\n \"Search emails by free-text query (KQL on Outlook). Returns lightweight summaries.\",\n inputSchema: {\n account: z.string().email(),\n query: z.string().min(1),\n limit: z.number().int().positive().max(100).optional(),\n },\n },\n async (args) => {\n try {\n const { provider, account } = registry.resolveByEmail(args.account);\n const items = await provider.searchEmails(account, args.query, {\n limit: args.limit,\n });\n return ok({ account: account.email, count: items.length, items });\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n server.registerTool(\n \"read_email\",\n {\n description:\n \"Fetch a single email with full body and recipients by id. \" +\n \"Body is returned as `body` with `bodyFormat` indicating the format. \" +\n \"Default format is 'markdown' — HTML is automatically converted to save context tokens.\",\n inputSchema: {\n account: z.string().email(),\n id: z.string().min(1),\n format: z\n .enum([\"markdown\", \"html\", \"text\"])\n .default(\"markdown\")\n .optional()\n .describe(\n \"Output body format. 'markdown' converts HTML to Markdown (default), \" +\n \"'html' returns the raw HTML, 'text' returns plain text.\",\n ),\n },\n },\n async (args) => {\n try {\n const { provider, account } = registry.resolveByEmail(args.account);\n const msg = await provider.readEmail(account, args.id);\n const format = args.format ?? \"markdown\";\n const body = selectBody(msg, format);\n return ok({\n id: msg.id,\n subject: msg.subject,\n from: msg.from,\n to: msg.to,\n cc: msg.cc,\n bcc: msg.bcc,\n receivedAt: msg.receivedAt,\n preview: msg.preview,\n isRead: msg.isRead,\n hasAttachments: msg.hasAttachments,\n folder: msg.folder,\n attachments: msg.attachments,\n body,\n bodyFormat: format,\n });\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n server.registerTool(\n \"read_attachment\",\n {\n description:\n \"Download an email attachment to a temporary file and return its path. \" +\n \"Use messageId and attachmentId from a prior read_email call.\",\n inputSchema: {\n account: z.string().email(),\n messageId: z.string().min(1),\n attachmentId: z.string().min(1),\n },\n },\n async (args) => {\n try {\n const { provider, account } = registry.resolveByEmail(args.account);\n const res = await provider.readAttachment(account, args.messageId, args.attachmentId);\n return ok(res);\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n // ---------- shared send/draft helpers ----------\n\n const sendEmailSchema = z.object({\n account: z.string().email(),\n to: z.array(emailAddrSchema).min(1),\n cc: z.array(emailAddrSchema).optional(),\n bcc: z.array(emailAddrSchema).optional(),\n subject: z.string(),\n body: z.string(),\n isHtml: z.boolean().optional(),\n include_signature: z\n .boolean()\n .describe(\n \"Whether to append the account's HTML signature to the email. \" +\n \"Returns an error if true but no signature is configured for this account.\",\n ),\n inReplyTo: z\n .string()\n .optional()\n .describe(\n \"Message ID to reply to. When set, sends as a threaded reply \" +\n \"which includes the quoted thread history automatically.\",\n ),\n replyAll: z\n .boolean()\n .default(false)\n .optional()\n .describe(\n \"When true and `inReplyTo` is set, reply to all recipients \" +\n \"instead of just the sender.\",\n ),\n forwardMessageId: z\n .string()\n .optional()\n .describe(\n \"Message ID to forward. When set, sends as a forward of the \" +\n \"specified message, preserving the original content. \" +\n \"Mutually exclusive with `inReplyTo`.\",\n ),\n });\n\n type SendEmailArgs = z.infer<typeof sendEmailSchema>;\n\n async function handleSendOrDraft(\n args: SendEmailArgs,\n action: (\n provider: EmailProvider,\n account: AccountRecord,\n msg: SendInput,\n ) => Promise<{ id: string }>,\n resultKey: string,\n toolName: string,\n ) {\n if (readOnly) return fail(`server is in --read-only mode; ${toolName} is disabled`);\n try {\n const { provider, account } = registry.resolveByEmail(args.account);\n if (args.include_signature && !account.signature) {\n return fail(\n \"include_signature is true but no signature is configured for this account. \" +\n \"Set up a signature first with set_account_settings.\",\n );\n }\n const composed = composeBody({\n body: args.body,\n isHtml: args.isHtml,\n signature: account.signature,\n style: account.style,\n includeSignature: args.include_signature,\n });\n if (args.inReplyTo && args.forwardMessageId) {\n return fail(\n \"inReplyTo and forwardMessageId are mutually exclusive — use one or the other\",\n );\n }\n const res = await action(provider, account, {\n to: args.to,\n cc: args.cc,\n bcc: args.bcc,\n subject: args.subject,\n body: composed.body,\n isHtml: composed.isHtml,\n inReplyTo: args.inReplyTo,\n replyAll: args.replyAll,\n forwardMessageId: args.forwardMessageId,\n });\n return ok({ [resultKey]: true, ...res });\n } catch (err) {\n return fail(errMsg(err));\n }\n }\n\n // ---------- send / draft ----------\n\n if (!draftOnly) {\n server.registerTool(\n \"send_email\",\n {\n description:\n \"Send an email from the given account. Appends the \" +\n \"account's signature (HTML) and applies style preferences when \" +\n \"`include_signature` is true. Returns an error if \" +\n \"`include_signature` is true but no signature is configured. \" +\n \"When `inReplyTo` is set, sends as a reply (or reply-all) which \" +\n \"preserves thread history and conversation threading. \" +\n \"When `forwardMessageId` is set, sends as a forward of the \" +\n \"specified message, preserving the original content. \" +\n \"`inReplyTo` and `forwardMessageId` are mutually exclusive. \" +\n \"Disabled in --read-only mode.\",\n inputSchema: sendEmailSchema,\n },\n async (args) =>\n handleSendOrDraft(\n args as SendEmailArgs,\n (p, a, m) => p.sendEmail(a, m),\n \"sent\",\n \"send_email\",\n ),\n );\n }\n\n server.registerTool(\n \"draft_email\",\n {\n description:\n \"Create a draft email from the given account without sending it. \" +\n \"Works identically to send_email — appends signature when \" +\n \"`include_signature` is true, applies style, and supports replies \" +\n \"and forwards — but saves the message to the Drafts folder \" +\n \"instead of sending. Returns the draft message ID so you can \" +\n \"later find it, edit it, or send it manually. \" +\n \"Disabled in --read-only mode.\",\n inputSchema: sendEmailSchema,\n },\n async (args) =>\n handleSendOrDraft(\n args as SendEmailArgs,\n (p, a, m) => p.saveDraft(a, m),\n \"draft\",\n \"draft_email\",\n ),\n );\n}\n\n// ---------- body composition helpers ----------\n\ninterface ComposeBodyInput {\n body: string;\n isHtml?: boolean;\n signature?: string;\n style?: { fontFamily?: string; fontSize?: string; fontColor?: string };\n includeSignature: boolean;\n}\n\nexport function composeBody(input: ComposeBodyInput): { body: string; isHtml: boolean } {\n const { body, isHtml = false, signature, style, includeSignature } = input;\n const hasSignature = includeSignature && !!signature;\n const hasStyle = !!(style && (style.fontFamily || style.fontSize || style.fontColor));\n\n // Nothing to inject — pass through unchanged\n if (!hasSignature && !hasStyle) {\n return { body, isHtml };\n }\n\n // Need HTML for signature or style injection\n const styleAttr = hasStyle ? buildStyleAttr(style!) : \"\";\n\n if (isHtml) {\n let result = hasStyle ? `<div style=\"${styleAttr}\">${body}</div>` : body;\n if (hasSignature) result += `\\n<div class=\"signature\">${signature}</div>`;\n return { body: result, isHtml: true };\n }\n\n // Auto-upgrade plain text to HTML\n const escaped = escapeHtml(body);\n let result = `<div style=\"${styleAttr}\">${escaped}</div>`;\n if (hasSignature) result += `\\n<div class=\"signature\">${signature}</div>`;\n return { body: result, isHtml: true };\n}\n\nexport function buildStyleAttr(style: { fontFamily?: string; fontSize?: string; fontColor?: string }): string {\n const parts: string[] = [];\n if (style.fontFamily) parts.push(`font-family: ${style.fontFamily}`);\n if (style.fontSize) parts.push(`font-size: ${style.fontSize}`);\n if (style.fontColor) parts.push(`color: ${style.fontColor}`);\n return parts.join(\"; \");\n}\n\nexport function escapeHtml(text: string): string {\n return text\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/\\n/g, \"<br>\");\n}\n\nfunction errMsg(err: unknown): string {\n if (err instanceof Error) return err.message;\n return String(err);\n}\n","import TurndownService from \"turndown\";\n\nconst turndown = new TurndownService();\n\n/** Light wrapper — callers just pass HTML, get markdown back. */\nexport function htmlToMarkdown(html: string): string {\n return turndown.turndown(html);\n}\n\n/** Pick the right body for the requested format. */\nexport function selectBody(\n msg: { bodyHtml?: string; bodyText?: string },\n format: \"markdown\" | \"html\" | \"text\",\n): string {\n switch (format) {\n case \"markdown\": {\n if (msg.bodyHtml) return htmlToMarkdown(msg.bodyHtml);\n if (msg.bodyText) return msg.bodyText;\n return \"\";\n }\n case \"html\": {\n if (msg.bodyHtml) return msg.bodyHtml;\n if (msg.bodyText) return msg.bodyText;\n return \"\";\n }\n case \"text\": {\n if (msg.bodyText) return msg.bodyText;\n if (msg.bodyHtml) return msg.bodyHtml.replace(/<[^>]*>/g, \"\");\n return \"\";\n }\n }\n}\n","export const VERSION = \"0.2.0\";\n","import { startServer } from \"./server.js\";\n\ntype ParsedArgs = {\n http: boolean;\n port: number;\n host: string;\n dataDir?: string;\n readOnly: boolean;\n help: boolean;\n};\n\nfunction parseArgs(argv: string[]): ParsedArgs {\n const out: ParsedArgs = {\n http: false,\n port: 3000,\n host: \"127.0.0.1\",\n readOnly: false,\n help: false,\n };\n for (let i = 0; i < argv.length; i++) {\n const a = argv[i];\n switch (a) {\n case \"--http\":\n out.http = true;\n break;\n case \"--port\":\n out.port = Number(argv[++i] ?? \"3000\");\n break;\n case \"--host\":\n out.host = String(argv[++i] ?? \"127.0.0.1\");\n break;\n case \"--data-dir\":\n out.dataDir = String(argv[++i] ?? \"\");\n break;\n case \"--read-only\":\n out.readOnly = true;\n break;\n case \"-h\":\n case \"--help\":\n out.help = true;\n break;\n default:\n if (a && a.startsWith(\"--\")) {\n // ignore unknown flags rather than crashing — keeps the CLI forgiving\n // when embedded in MCP host configs.\n }\n }\n }\n return out;\n}\n\nfunction printHelp(): void {\n const msg = `hypermail-mcp — unified email MCP server\n\nUsage:\n hypermail-mcp [options]\n\nOptions:\n --http Run as Streamable HTTP server (default: stdio)\n --port <n> HTTP port (default: 3000)\n --host <addr> HTTP bind address (default: 127.0.0.1)\n --data-dir <path> Where to store the encrypted accounts file\n (default: $HYPERMAIL_MCP_DATA_DIR or ~/.hypermail-mcp)\n --read-only Disable tools that modify state (send_email, remove_account, add_account)\n -h, --help Show this help\n\nEnvironment:\n HYPERMAIL_MCP_DATA_DIR Same as --data-dir\n HYPERMAIL_MCP_KEY 32-byte key (base64 or hex) for at-rest encryption\n MS_CLIENT_ID Azure AD public client (application) ID\n MS_TENANT_ID Tenant (default: \"common\")\n`;\n process.stdout.write(msg);\n}\n\nasync function main(): Promise<void> {\n const opts = parseArgs(process.argv.slice(2));\n if (opts.help) {\n printHelp();\n return;\n }\n const draftOnly = process.env.HYPERMAIL_DRAFT_ONLY === \"true\";\n\n await startServer({\n http: opts.http,\n port: opts.port,\n host: opts.host,\n dataDir: opts.dataDir,\n readOnly: opts.readOnly,\n draftOnly,\n });\n}\n\nmain().catch((err) => {\n // eslint-disable-next-line no-console\n console.error(\"[hypermail-mcp] fatal:\", err);\n process.exit(1);\n});\n"],"mappings":";;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,4BAA4B;AACrC,SAAS,qCAAqC;AAC9C,SAAS,cAAAA,mBAAkB;AAC3B,SAAS,gBAAgB,wBAAmE;;;ACJ5F;AAAA,EACE;AAAA,EAC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YAAI,UAAU,OAAO,KAAK,EAAE,CAAC,KAAK,EAAE;AACpC;AAAA,MACF,KAAK;AACH,YAAI,WAAW;AACf;AAAA,MACF,KAAK;AAAA,MACL,KAAK;AACH,YAAI,OAAO;AACX;AAAA,MACF;AACE,YAAI,KAAK,EAAE,WAAW,IAAI,GAAG;AAAA,QAG7B;AAAA,IACJ;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,YAAkB;AACzB,QAAM,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBZ,UAAQ,OAAO,MAAM,GAAG;AAC1B;AAEA,eAAe,OAAsB;AACnC,QAAM,OAAO,UAAU,QAAQ,KAAK,MAAM,CAAC,CAAC;AAC5C,MAAI,KAAK,MAAM;AACb,cAAU;AACV;AAAA,EACF;AACA,QAAM,YAAY,QAAQ,IAAI,yBAAyB;AAEvD,QAAM,YAAY;AAAA,IAChB,MAAM,KAAK;AAAA,IACX,MAAM,KAAK;AAAA,IACX,MAAM,KAAK;AAAA,IACX,SAAS,KAAK;AAAA,IACd,UAAU,KAAK;AAAA,IACf;AAAA,EACF,CAAC;AACH;AAEA,KAAK,EAAE,MAAM,CAAC,QAAQ;AAEpB,UAAQ,MAAM,0BAA0B,GAAG;AAC3C,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["randomUUID","result","randomUUID"]}
|
|
1
|
+
{"version":3,"sources":["../src/server.ts","../src/store/account-store.ts","../src/providers/outlook/index.ts","../src/providers/outlook/client.ts","../src/providers/outlook/auth.ts","../src/providers/imap/index.ts","../src/providers/registry.ts","../src/tools/index.ts","../src/html-to-markdown.ts","../src/version.ts","../src/cli.ts"],"sourcesContent":["import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { StreamableHTTPServerTransport } from \"@modelcontextprotocol/sdk/server/streamableHttp.js\";\nimport { randomUUID } from \"node:crypto\";\nimport { createServer as createHttpServer, type IncomingMessage, type ServerResponse } from \"node:http\";\n\nimport { AccountStore } from \"./store/account-store.js\";\nimport { buildRegistry } from \"./providers/registry.js\";\nimport { registerTools } from \"./tools/index.js\";\nimport { VERSION } from \"./version.js\";\n\nexport interface ServerOptions {\n http?: boolean;\n port?: number;\n host?: string;\n dataDir?: string;\n readOnly?: boolean;\n /** When true, hide send_email and only expose draft_email. */\n draftOnly?: boolean;\n}\n\nexport async function startServer(opts: ServerOptions = {}): Promise<void> {\n const store = await AccountStore.open({ dataDir: opts.dataDir });\n const registry = buildRegistry({ store });\n\n const server = new McpServer(\n { name: \"hypermail-mcp\", version: VERSION },\n { capabilities: { tools: {}, logging: {} } },\n );\n\n registerTools(server, { store, registry, readOnly: !!opts.readOnly, draftOnly: !!opts.draftOnly });\n\n if (opts.http) {\n await startHttp(server, opts.host ?? \"127.0.0.1\", opts.port ?? 3000);\n } else {\n const transport = new StdioServerTransport();\n await server.connect(transport);\n }\n}\n\nasync function startHttp(server: McpServer, host: string, port: number): Promise<void> {\n // One transport per session, keyed by Mcp-Session-Id header.\n const sessions = new Map<string, StreamableHTTPServerTransport>();\n\n const http = createHttpServer(async (req: IncomingMessage, res: ServerResponse) => {\n try {\n if (!req.url || !req.url.startsWith(\"/mcp\")) {\n res.statusCode = 404;\n res.end(\"not found\");\n return;\n }\n const sessionId = (req.headers[\"mcp-session-id\"] as string | undefined) ?? undefined;\n let transport = sessionId ? sessions.get(sessionId) : undefined;\n\n if (!transport) {\n transport = new StreamableHTTPServerTransport({\n sessionIdGenerator: () => randomUUID(),\n onsessioninitialized: (sid: string) => {\n sessions.set(sid, transport!);\n },\n });\n transport.onclose = () => {\n if (transport!.sessionId) sessions.delete(transport!.sessionId);\n };\n await server.connect(transport);\n }\n\n // Buffer body for POST / DELETE\n let body: unknown = undefined;\n if (req.method === \"POST\" || req.method === \"DELETE\") {\n const chunks: Buffer[] = [];\n for await (const chunk of req) chunks.push(chunk as Buffer);\n const raw = Buffer.concat(chunks).toString(\"utf8\");\n body = raw ? JSON.parse(raw) : undefined;\n }\n await transport.handleRequest(req, res, body);\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error(\"[hypermail-mcp] http error:\", err);\n if (!res.headersSent) {\n res.statusCode = 500;\n res.end(\"internal error\");\n }\n }\n });\n\n await new Promise<void>((resolve) => http.listen(port, host, resolve));\n // eslint-disable-next-line no-console\n console.error(`[hypermail-mcp] listening on http://${host}:${port}/mcp`);\n}\n","import {\n createCipheriv,\n createDecipheriv,\n randomBytes,\n createHash,\n} from \"node:crypto\";\nimport { promises as fs } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport path from \"node:path\";\n\n/**\n * One stored account. `tokens` is provider-specific (e.g. serialized MSAL cache\n * for Outlook, host/port/password blob for IMAP) — the store is opaque to it.\n */\nexport interface AccountRecord {\n email: string;\n provider: \"outlook\" | \"imap\" | \"gmail\";\n displayName?: string;\n tokens: Record<string, unknown>;\n addedAt: string;\n /** HTML snippet — may contain formatting, images, links. Injected at end of outgoing emails. */\n signature?: string;\n /** Font/style preferences applied to outgoing HTML emails. */\n style?: { fontFamily?: string; fontSize?: string; fontColor?: string };\n}\n\ninterface StoreFile {\n version: 1;\n accounts: AccountRecord[];\n}\n\nexport interface OpenOptions {\n dataDir?: string;\n /** Inject the encryption key directly (mostly for tests). Otherwise resolved\n * from `HYPERMAIL_MCP_KEY` env, then OS keychain, then auto-generated. */\n key?: Buffer;\n}\n\nconst FILE_NAME = \"accounts.json.enc\";\nconst ALGO = \"aes-256-gcm\";\nconst KEY_LEN = 32;\n\nexport class AccountStore {\n private constructor(\n private readonly filePath: string,\n private readonly key: Buffer,\n private data: StoreFile,\n ) {}\n\n static async open(opts: OpenOptions = {}): Promise<AccountStore> {\n const dataDir = resolveDataDir(opts.dataDir);\n await fs.mkdir(dataDir, { recursive: true, mode: 0o700 });\n const filePath = path.join(dataDir, FILE_NAME);\n const key = opts.key ?? (await resolveKey(dataDir));\n\n let data: StoreFile;\n try {\n const buf = await fs.readFile(filePath);\n data = decrypt(buf, key);\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n data = { version: 1, accounts: [] };\n } else {\n throw err;\n }\n }\n return new AccountStore(filePath, key, data);\n }\n\n listAccounts(): AccountRecord[] {\n // Return shallow clones without tokens leaking out unintentionally is the\n // caller's job; here we expose the full record for provider use.\n return this.data.accounts.map((a) => ({ ...a }));\n }\n\n getAccount(email: string): AccountRecord | undefined {\n const norm = email.trim().toLowerCase();\n const rec = this.data.accounts.find((a) => a.email.toLowerCase() === norm);\n return rec ? { ...rec } : undefined;\n }\n\n async upsertAccount(rec: AccountRecord): Promise<AccountRecord> {\n const norm = rec.email.trim().toLowerCase();\n const next: AccountRecord = { ...rec, email: norm };\n const idx = this.data.accounts.findIndex((a) => a.email.toLowerCase() === norm);\n if (idx >= 0) this.data.accounts[idx] = next;\n else this.data.accounts.push(next);\n await this.flush();\n return { ...next };\n }\n\n async removeAccount(email: string): Promise<boolean> {\n const norm = email.trim().toLowerCase();\n const before = this.data.accounts.length;\n this.data.accounts = this.data.accounts.filter((a) => a.email.toLowerCase() !== norm);\n if (this.data.accounts.length === before) return false;\n await this.flush();\n return true;\n }\n\n private async flush(): Promise<void> {\n const buf = encrypt(this.data, this.key);\n const tmp = `${this.filePath}.${process.pid}.${Date.now()}.tmp`;\n await fs.writeFile(tmp, buf, { mode: 0o600 });\n await fs.rename(tmp, this.filePath);\n }\n}\n\n// ---------- encryption helpers ----------\n\nfunction encrypt(data: StoreFile, key: Buffer): Buffer {\n const iv = randomBytes(12);\n const cipher = createCipheriv(ALGO, key, iv);\n const plaintext = Buffer.from(JSON.stringify(data), \"utf8\");\n const ct = Buffer.concat([cipher.update(plaintext), cipher.final()]);\n const tag = cipher.getAuthTag();\n // layout: [1-byte version=1][12 iv][16 tag][ct...]\n return Buffer.concat([Buffer.from([1]), iv, tag, ct]);\n}\n\nfunction decrypt(buf: Buffer, key: Buffer): StoreFile {\n if (buf.length < 1 + 12 + 16 + 1) throw new Error(\"accounts file truncated\");\n const v = buf[0];\n if (v !== 1) throw new Error(`unsupported accounts file version: ${v}`);\n const iv = buf.subarray(1, 13);\n const tag = buf.subarray(13, 29);\n const ct = buf.subarray(29);\n const decipher = createDecipheriv(ALGO, key, iv);\n decipher.setAuthTag(tag);\n const pt = Buffer.concat([decipher.update(ct), decipher.final()]);\n const parsed = JSON.parse(pt.toString(\"utf8\")) as StoreFile;\n if (parsed.version !== 1 || !Array.isArray(parsed.accounts)) {\n throw new Error(\"accounts file is malformed\");\n }\n return parsed;\n}\n\n// ---------- key + path resolution ----------\n\nfunction resolveDataDir(explicit?: string): string {\n if (explicit && explicit.length > 0) return path.resolve(explicit);\n const env = process.env.HYPERMAIL_MCP_DATA_DIR;\n if (env && env.length > 0) return path.resolve(env);\n return path.join(homedir(), \".hypermail-mcp\");\n}\n\nfunction parseEnvKey(raw: string): Buffer | undefined {\n const s = raw.trim();\n // hex (64 chars)\n if (/^[0-9a-fA-F]{64}$/.test(s)) return Buffer.from(s, \"hex\");\n // base64 — accept any length, then check\n try {\n const buf = Buffer.from(s, \"base64\");\n if (buf.length === KEY_LEN) return buf;\n } catch {\n /* ignore */\n }\n // last-resort: derive 32 bytes via SHA-256 over the raw string. This lets\n // users pass any passphrase; not ideal but predictable.\n return createHash(\"sha256\").update(s, \"utf8\").digest();\n}\n\nasync function resolveKey(dataDir: string): Promise<Buffer> {\n const env = process.env.HYPERMAIL_MCP_KEY;\n if (env && env.length > 0) {\n const k = parseEnvKey(env);\n if (k) return k;\n }\n\n // Try OS keychain via keytar (optional dep).\n const fromKeytar = await tryKeytarGet();\n if (fromKeytar) return fromKeytar;\n\n // Local-dev fallback: persist a generated key to a 0600 file next to the\n // accounts blob so subsequent runs can decrypt. Hosted deployments should\n // always set HYPERMAIL_MCP_KEY explicitly.\n const keyFile = path.join(dataDir, \"master.key\");\n try {\n const existing = await fs.readFile(keyFile);\n if (existing.length === KEY_LEN) return existing;\n } catch {\n /* fall through to generate */\n }\n const gen = randomBytes(KEY_LEN);\n await fs.writeFile(keyFile, gen, { mode: 0o600 });\n await tryKeytarSet(gen);\n return gen;\n}\n\nasync function tryKeytarGet(): Promise<Buffer | undefined> {\n try {\n const mod = (await import(\"keytar\")) as typeof import(\"keytar\");\n const val = await mod.getPassword(\"hypermail-mcp\", \"master\");\n if (val) {\n const buf = Buffer.from(val, \"base64\");\n if (buf.length === KEY_LEN) return buf;\n }\n } catch {\n /* keytar not installed or unsupported platform */\n }\n return undefined;\n}\n\nasync function tryKeytarSet(key: Buffer): Promise<void> {\n try {\n const mod = (await import(\"keytar\")) as typeof import(\"keytar\");\n await mod.setPassword(\"hypermail-mcp\", \"master\", key.toString(\"base64\"));\n } catch {\n /* ignore */\n }\n}\n","import { randomUUID } from \"node:crypto\";\nimport { writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join as pathJoin } from \"node:path\";\n\nimport { ResponseType, type Client } from \"@microsoft/microsoft-graph-client\";\n\nimport type { AccountRecord, AccountStore } from \"../../store/account-store.js\";\nimport type {\n AddAccountInput,\n AddAccountResult,\n AttachmentContent,\n CompleteAddAccountResult,\n DraftUpdateInput,\n EmailFull,\n EmailProvider,\n EmailSummary,\n ListEmailsOptions,\n SearchEmailsOptions,\n SendInput,\n EmailAddress,\n} from \"../types.js\";\nimport { OutlookClientFactory } from \"./client.js\";\nimport {\n awaitDeviceCodeReady,\n beginDeviceCode,\n type DeviceCodeBegin,\n type SerializedTokens,\n} from \"./auth.js\";\n\n// ---------- inline image conversion ----------\n\ninterface InlineAttachment {\n \"@odata.type\": string;\n name: string;\n contentType: string;\n contentId: string;\n contentBytes: string;\n isInline: boolean;\n}\n\n/**\n * Scans HTML for data:image/...;base64,... URIs, extracts the raw base64\n * data, assigns unique contentIds, and returns the transformed body\n * (with src=\"cid:...\" references) plus an array of inline fileAttachment\n * objects ready for the Graph API.\n *\n * Pass-through when there are no matches — returns the original body with\n * an empty attachments array.\n */\nexport function convertInlineImages(body: string): {\n body: string;\n attachments: InlineAttachment[];\n} {\n const attachments: InlineAttachment[] = [];\n // Match src=\"data:image/<subtype>;base64,<payload>\"\n // Supports png, jpg, jpeg, gif, svg+xml, webp, bmp, etc.\n const re = /src=\"data:image\\/([\\w+]+);base64,([^\"]+)\"/gi;\n\n const transformed = body.replace(re, (_fullMatch, mimeSubtype, b64) => {\n const contentId = `sig-img-${randomUUID()}`;\n const ext = mimeSubtype.toLowerCase().replace(/\\+/g, \"-\") === \"svg-xml\"\n ? \"svg\"\n : mimeSubtype.toLowerCase().replace(/\\+/g, \"-\");\n attachments.push({\n \"@odata.type\": \"#microsoft.graph.fileAttachment\",\n name: `signature-image.${ext}`,\n contentType: `image/${mimeSubtype}`,\n contentId,\n contentBytes: b64,\n isInline: true,\n });\n return `src=\"cid:${contentId}\"`;\n });\n\n return { body: transformed, attachments };\n}\n\ninterface PendingFlow {\n begin: DeviceCodeBegin;\n emailHint?: string;\n startedAt: number;\n settled: \"pending\" | \"ready\" | \"error\" | \"expired\";\n account?: AccountRecord;\n error?: string;\n}\n\nexport interface OutlookProviderOptions {\n store: AccountStore;\n}\n\nexport class OutlookProvider implements EmailProvider {\n readonly id = \"outlook\" as const;\n private readonly clients: OutlookClientFactory;\n private readonly pending = new Map<string, PendingFlow>();\n\n constructor(private readonly opts: OutlookProviderOptions) {\n this.clients = new OutlookClientFactory(opts.store);\n }\n\n // ---------- account lifecycle ----------\n\n async addAccount(input: AddAccountInput): Promise<AddAccountResult> {\n const begin = beginDeviceCode();\n await awaitDeviceCodeReady(begin);\n\n const handle = randomUUID();\n const flow: PendingFlow = {\n begin,\n emailHint: input.email,\n startedAt: Date.now(),\n settled: \"pending\",\n };\n this.pending.set(handle, flow);\n\n // Fire-and-forget: when the user finishes, persist and update flow.\n begin.result\n .then(async ({ tokens, account }) => {\n const email = (account.username || input.email || \"\").toLowerCase();\n if (!email) {\n flow.settled = \"error\";\n flow.error = \"no email returned from Microsoft account\";\n return;\n }\n const rec: AccountRecord = {\n email,\n provider: \"outlook\",\n displayName: account.name ?? undefined,\n tokens: tokens as unknown as Record<string, unknown>,\n addedAt: new Date().toISOString(),\n };\n const saved = await this.opts.store.upsertAccount(rec);\n flow.account = saved;\n flow.settled = \"ready\";\n })\n .catch((err: unknown) => {\n flow.settled = \"error\";\n flow.error = err instanceof Error ? err.message : String(err);\n });\n\n return {\n status: \"pending\",\n handle,\n verification: {\n userCode: begin.userCode,\n verificationUri: begin.verificationUri,\n expiresAt: begin.expiresAt,\n message: begin.message,\n },\n };\n }\n\n async completeAddAccount(handle: string): Promise<CompleteAddAccountResult> {\n const flow = this.pending.get(handle);\n if (!flow) return { status: \"error\", error: \"unknown handle\" };\n // expire after 20 minutes regardless\n if (Date.now() - flow.startedAt > 20 * 60_000 && flow.settled === \"pending\") {\n flow.settled = \"expired\";\n flow.begin.cancel();\n }\n if (flow.settled === \"ready\" && flow.account) {\n this.pending.delete(handle);\n return { status: \"ready\", account: flow.account };\n }\n if (flow.settled === \"error\") {\n this.pending.delete(handle);\n return { status: \"error\", error: flow.error ?? \"unknown error\" };\n }\n if (flow.settled === \"expired\") {\n this.pending.delete(handle);\n return { status: \"expired\" };\n }\n return { status: \"pending\" };\n }\n\n // ---------- email ops ----------\n\n async listEmails(\n account: AccountRecord,\n opts: ListEmailsOptions,\n ): Promise<EmailSummary[]> {\n const client = this.clients.get(account);\n const limit = clampLimit(opts.limit, 25, 100);\n const folder = opts.folder ?? \"inbox\";\n const filterParts: string[] = [];\n if (opts.unreadOnly) filterParts.push(\"isRead eq false\");\n\n let req = client\n .api(`/me/mailFolders/${encodeURIComponent(folder)}/messages`)\n .top(limit)\n .select([\n \"id\",\n \"subject\",\n \"from\",\n \"toRecipients\",\n \"receivedDateTime\",\n \"bodyPreview\",\n \"isRead\",\n \"hasAttachments\",\n ].join(\",\"))\n .orderby(\"receivedDateTime DESC\");\n\n if (filterParts.length > 0) req = req.filter(filterParts.join(\" and \"));\n\n const res = (await req.get()) as { value: GraphMessage[] };\n return res.value.map((m) => mapSummary(m, folder));\n }\n\n async searchEmails(\n account: AccountRecord,\n query: string,\n opts: SearchEmailsOptions,\n ): Promise<EmailSummary[]> {\n const client = this.clients.get(account);\n const limit = clampLimit(opts.limit, 25, 100);\n // $search requires the ConsistencyLevel: eventual header\n const res = (await client\n .api(\"/me/messages\")\n .header(\"ConsistencyLevel\", \"eventual\")\n .top(limit)\n .search(`\"${query.replace(/\"/g, '\\\\\"')}\"`)\n .select(\n [\n \"id\",\n \"subject\",\n \"from\",\n \"toRecipients\",\n \"receivedDateTime\",\n \"bodyPreview\",\n \"isRead\",\n \"hasAttachments\",\n ].join(\",\"),\n )\n .get()) as { value: GraphMessage[] };\n return res.value.map((m) => mapSummary(m));\n }\n\n async readEmail(account: AccountRecord, id: string): Promise<EmailFull> {\n const client = this.clients.get(account);\n const m = (await client\n .api(`/me/messages/${encodeURIComponent(id)}`)\n .select(\n [\n \"id\",\n \"subject\",\n \"from\",\n \"toRecipients\",\n \"ccRecipients\",\n \"bccRecipients\",\n \"receivedDateTime\",\n \"bodyPreview\",\n \"isRead\",\n \"hasAttachments\",\n \"body\",\n ].join(\",\"),\n )\n .get()) as GraphMessage;\n\n let attachments: EmailFull[\"attachments\"] = undefined;\n if (m.hasAttachments) {\n try {\n const attRes = (await client\n .api(`/me/messages/${encodeURIComponent(id)}/attachments`)\n .select(\"id,name,contentType,size\")\n .get()) as { value: GraphAttachment[] };\n attachments = attRes.value.map((a) => ({\n id: a.id,\n name: a.name,\n contentType: a.contentType,\n size: a.size,\n }));\n } catch {\n /* ignore attachment listing failure */\n }\n }\n\n const summary = mapSummary(m);\n const body = m.body;\n return {\n ...summary,\n cc: (m.ccRecipients ?? []).map(mapRecipient),\n bcc: (m.bccRecipients ?? []).map(mapRecipient),\n bodyText: body?.contentType === \"text\" ? body.content : undefined,\n bodyHtml: body?.contentType === \"html\" ? body.content : undefined,\n attachments,\n };\n }\n\n async readAttachment(\n account: AccountRecord,\n messageId: string,\n attachmentId: string,\n ): Promise<AttachmentContent> {\n const client = this.clients.get(account);\n // First, get the attachment metadata to know the filename\n const att = (await client\n .api(`/me/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(attachmentId)}`)\n .select(\"name,contentType\")\n .get()) as { name: string; contentType?: string };\n\n // Download the raw content as ArrayBuffer\n const data = (await client\n .api(`/me/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(attachmentId)}/$value`)\n .responseType(ResponseType.ARRAYBUFFER)\n .get()) as ArrayBuffer;\n\n // Write to temp file with original name\n const outPath = pathJoin(tmpdir(), att.name);\n writeFileSync(outPath, Buffer.from(data));\n\n return {\n name: att.name,\n contentType: att.contentType,\n path: outPath,\n };\n }\n\n // Shared helper — creates a draft from a reference message (forward or\n // reply), prepends our composed body before the existing content, and\n // attaches inline images. Returns the draft message ID.\n private async buildDraftFromReference(\n client: Client,\n createEndpoint: string,\n createPayload: Record<string, unknown>,\n converted: { body: string; attachments: InlineAttachment[] },\n ): Promise<string> {\n const draft: { id: string } = await client\n .api(createEndpoint)\n .post(createPayload);\n\n const draftMsg: { body?: { content?: string; contentType?: string } } =\n await client.api(`/me/messages/${draft.id}`).select(\"body\").get();\n\n const draftBody = draftMsg.body?.content ?? \"\";\n const draftContentType = draftMsg.body?.contentType ?? \"HTML\";\n const spacer = '<div style=\"line-height:12px\"><br></div>';\n const prepend = converted.body + spacer;\n const finalBody = draftBody.includes(\"<body\")\n ? draftBody.replace(/(<body[^>]*>)/i, `$1${prepend}`)\n : prepend + draftBody;\n\n await client.api(`/me/messages/${draft.id}`).patch({\n body: { contentType: draftContentType, content: finalBody },\n });\n\n for (const att of converted.attachments) {\n await client.api(`/me/messages/${draft.id}/attachments`).post(att);\n }\n\n return draft.id;\n }\n\n async sendEmail(\n account: AccountRecord,\n msg: SendInput,\n ): Promise<{ id: string }> {\n const client = this.clients.get(account);\n\n if (msg.inReplyTo && msg.forwardMessageId) {\n throw new Error(\n \"inReplyTo and forwardMessageId are mutually exclusive — use one or the other\",\n );\n }\n\n // Convert data:image URIs to cid: references + inline attachments.\n const converted = convertInlineImages(msg.body);\n\n if (msg.forwardMessageId) {\n const draftId = await this.buildDraftFromReference(\n client,\n `/me/messages/${encodeURIComponent(msg.forwardMessageId)}/createForward`,\n {\n message: {\n toRecipients: msg.to.map(toRecipient),\n ccRecipients: (msg.cc ?? []).map(toRecipient),\n bccRecipients: (msg.bcc ?? []).map(toRecipient),\n },\n comment: \"\",\n },\n converted,\n );\n await client.api(`/me/messages/${draftId}/send`).post({});\n return { id: draftId };\n }\n\n if (msg.inReplyTo) {\n const createEndpoint = msg.replyAll\n ? `/me/messages/${encodeURIComponent(msg.inReplyTo)}/createReplyAll`\n : `/me/messages/${encodeURIComponent(msg.inReplyTo)}/createReply`;\n const draftId = await this.buildDraftFromReference(\n client,\n createEndpoint,\n {},\n converted,\n );\n await client.api(`/me/messages/${draftId}/send`).post({});\n return { id: draftId };\n }\n\n // New email — use sendMail with inline attachments\n const payload: Record<string, unknown> = {\n message: {\n subject: msg.subject,\n body: {\n contentType: msg.isHtml ? \"HTML\" : \"Text\",\n content: converted.body,\n },\n toRecipients: msg.to.map(toRecipient),\n ccRecipients: (msg.cc ?? []).map(toRecipient),\n bccRecipients: (msg.bcc ?? []).map(toRecipient),\n },\n saveToSentItems: true,\n };\n if (converted.attachments.length > 0) {\n (payload.message as Record<string, unknown>).attachments =\n converted.attachments;\n }\n await client.api(\"/me/sendMail\").post(payload);\n // Graph's sendMail returns 202 with no body; we don't have an id back.\n return { id: \"\" };\n }\n\n async saveDraft(\n account: AccountRecord,\n msg: SendInput,\n ): Promise<{ id: string }> {\n const client = this.clients.get(account);\n\n if (msg.inReplyTo && msg.forwardMessageId) {\n throw new Error(\n \"inReplyTo and forwardMessageId are mutually exclusive — use one or the other\",\n );\n }\n\n const converted = convertInlineImages(msg.body);\n\n // Forward/reply drafts: same flow as sendEmail, but skip the final send.\n if (msg.forwardMessageId) {\n const draftId = await this.buildDraftFromReference(\n client,\n `/me/messages/${encodeURIComponent(msg.forwardMessageId)}/createForward`,\n {\n message: {\n toRecipients: msg.to.map(toRecipient),\n ccRecipients: (msg.cc ?? []).map(toRecipient),\n bccRecipients: (msg.bcc ?? []).map(toRecipient),\n },\n comment: \"\",\n },\n converted,\n );\n return { id: draftId };\n }\n\n if (msg.inReplyTo) {\n const createEndpoint = msg.replyAll\n ? `/me/messages/${encodeURIComponent(msg.inReplyTo)}/createReplyAll`\n : `/me/messages/${encodeURIComponent(msg.inReplyTo)}/createReply`;\n const draftId = await this.buildDraftFromReference(\n client,\n createEndpoint,\n {},\n converted,\n );\n return { id: draftId };\n }\n\n // New email — create a draft message directly (POST /me/messages).\n // Graph creates drafts by default when posting to /me/messages.\n const draftPayload: Record<string, unknown> = {\n subject: msg.subject,\n body: {\n contentType: msg.isHtml ? \"HTML\" : \"Text\",\n content: converted.body,\n },\n toRecipients: msg.to.map(toRecipient),\n ccRecipients: (msg.cc ?? []).map(toRecipient),\n bccRecipients: (msg.bcc ?? []).map(toRecipient),\n };\n if (converted.attachments.length > 0) {\n draftPayload.attachments = converted.attachments;\n }\n const draft: { id: string } = await client\n .api(\"/me/messages\")\n .post(draftPayload);\n return { id: draft.id };\n }\n\n async updateDraft(\n account: AccountRecord,\n id: string,\n update: DraftUpdateInput,\n ): Promise<{ id: string }> {\n const client = this.clients.get(account);\n const payload: Record<string, unknown> = {};\n\n if (update.subject !== undefined) {\n payload.subject = update.subject;\n }\n if (update.to !== undefined) {\n payload.toRecipients = update.to.map(toRecipient);\n }\n if (update.cc !== undefined) {\n payload.ccRecipients = update.cc.map(toRecipient);\n }\n if (update.bcc !== undefined) {\n payload.bccRecipients = update.bcc.map(toRecipient);\n }\n if (update.body !== undefined) {\n const converted = convertInlineImages(update.body);\n payload.body = {\n contentType: update.isHtml ? \"HTML\" : \"Text\",\n content: converted.body,\n };\n if (converted.attachments.length > 0) {\n // Patch existing inline attachments: Graph will replace all\n // attachments on the message. We send only the new ones.\n payload.attachments = converted.attachments;\n }\n }\n\n await client\n .api(`/me/messages/${encodeURIComponent(id)}`)\n .patch(payload);\n\n return { id };\n }\n\n async moveEmail(\n account: AccountRecord,\n id: string,\n destinationId: string,\n ): Promise<void> {\n const client = this.clients.get(account);\n await client\n .api(`/me/messages/${encodeURIComponent(id)}/move`)\n .post({ destinationId });\n }\n}\n\n// ---------- mapping helpers ----------\n\ninterface GraphRecipient {\n emailAddress?: { name?: string; address?: string };\n}\ninterface GraphMessage {\n id: string;\n subject?: string;\n from?: GraphRecipient;\n toRecipients?: GraphRecipient[];\n ccRecipients?: GraphRecipient[];\n bccRecipients?: GraphRecipient[];\n receivedDateTime?: string;\n bodyPreview?: string;\n isRead?: boolean;\n hasAttachments?: boolean;\n body?: { contentType?: \"text\" | \"html\"; content?: string };\n}\ninterface GraphAttachment {\n id: string;\n name: string;\n contentType?: string;\n size?: number;\n}\n\nfunction mapRecipient(r: GraphRecipient): EmailAddress {\n return {\n name: r.emailAddress?.name,\n address: r.emailAddress?.address ?? \"\",\n };\n}\n\nfunction mapSummary(m: GraphMessage, folder?: string): EmailSummary {\n return {\n id: m.id,\n subject: m.subject ?? \"\",\n from: m.from ? mapRecipient(m.from) : undefined,\n to: (m.toRecipients ?? []).map(mapRecipient),\n receivedAt: m.receivedDateTime,\n preview: m.bodyPreview,\n isRead: m.isRead,\n hasAttachments: m.hasAttachments,\n folder,\n };\n}\n\nfunction toRecipient(a: EmailAddress): GraphRecipient {\n return { emailAddress: { name: a.name, address: a.address } };\n}\n\nfunction clampLimit(v: number | undefined, dflt: number, max: number): number {\n if (!v || v <= 0) return dflt;\n return Math.min(v, max);\n}\n","import \"isomorphic-fetch\";\nimport {\n Client,\n type AuthenticationProvider,\n} from \"@microsoft/microsoft-graph-client\";\n\nimport type { AccountStore, AccountRecord } from \"../../store/account-store.js\";\nimport { acquireAccessToken, type SerializedTokens } from \"./auth.js\";\n\n/**\n * Builds a Graph `Client` bound to a stored account. The client uses an\n * `AuthenticationProvider` that calls msal silently on every request, and\n * writes the (possibly-refreshed) cache back into the AccountStore.\n *\n * Clients are cached per email since the underlying SDK reuses connections.\n */\nexport class OutlookClientFactory {\n private readonly cache = new Map<string, Client>();\n\n constructor(private readonly store: AccountStore) {}\n\n get(account: AccountRecord): Client {\n const key = account.email.toLowerCase();\n const existing = this.cache.get(key);\n if (existing) return existing;\n\n const store = this.store;\n const provider: AuthenticationProvider = {\n getAccessToken: async () => {\n const fresh = store.getAccount(account.email) ?? account;\n const tokens = fresh.tokens as unknown as SerializedTokens;\n const { accessToken, tokens: nextTokens } = await acquireAccessToken(tokens);\n // Persist refreshed cache opportunistically; failures here shouldn't\n // break the in-flight Graph call.\n if (nextTokens.msalCache !== tokens.msalCache) {\n store\n .upsertAccount({\n ...fresh,\n tokens: nextTokens as unknown as Record<string, unknown>,\n })\n .catch(() => {\n /* swallow — next call will refresh again */\n });\n }\n return accessToken;\n },\n };\n\n const client = Client.initWithMiddleware({ authProvider: provider });\n this.cache.set(key, client);\n return client;\n }\n\n /** Drop a cached client (e.g. after removeAccount). */\n invalidate(email: string): void {\n this.cache.delete(email.toLowerCase());\n }\n}\n","import {\n PublicClientApplication,\n type Configuration,\n type AuthenticationResult,\n type AccountInfo,\n} from \"@azure/msal-node\";\n\n/**\n * Public client app id. Default is the well-known `ms-365` client id used by\n * the softeria/ms-365-mcp-server project — it's a public client registered\n * for personal MSA + multi-tenant work/school. Users can override via\n * MS_CLIENT_ID for their own Entra app registrations.\n */\nconst DEFAULT_CLIENT_ID = \"084a3e9f-a9f4-43f7-89f9-d229cf97853e\";\n// ^ Pre-registered public client app (same one used by softeria/ms-365-mcp-server).\n// Supports personal MSA + multi-tenant work/school via device-code flow.\n// Operators should set MS_CLIENT_ID to a client they control for production.\n\nconst DEFAULT_SCOPES = [\n \"offline_access\",\n \"User.Read\",\n \"Mail.ReadWrite\",\n \"Mail.Send\",\n];\n\nexport interface DeviceCodeBegin {\n userCode: string;\n verificationUri: string;\n message: string;\n expiresAt: string; // ISO\n /** Resolves with the auth result once the user completes the flow. */\n result: Promise<{ tokens: SerializedTokens; account: AccountInfo }>;\n /** Aborts the in-flight polling promise. */\n cancel(): void;\n}\n\nexport interface SerializedTokens {\n /** MSAL cache JSON, encrypted at rest by the account store. */\n msalCache: string;\n /** Home account id used to look up the account in the rehydrated cache. */\n homeAccountId: string;\n /** Tenant id captured at sign-in. */\n tenantId: string;\n /** Username captured at sign-in (typically the primary email). */\n username: string;\n scopes: string[];\n}\n\nfunction makeConfig(prevCacheJson?: string): Configuration {\n const clientId = process.env.MS_CLIENT_ID || DEFAULT_CLIENT_ID;\n const tenant = process.env.MS_TENANT_ID || \"common\";\n return {\n auth: {\n clientId,\n authority: `https://login.microsoftonline.com/${tenant}`,\n },\n cache: prevCacheJson\n ? {\n // msal-node supports an in-memory cache plugin; we hydrate manually\n // below via deserialize after construction.\n }\n : undefined,\n };\n}\n\nexport function buildPca(prevCacheJson?: string): PublicClientApplication {\n const pca = new PublicClientApplication(makeConfig(prevCacheJson));\n if (prevCacheJson) {\n pca.getTokenCache().deserialize(prevCacheJson);\n }\n return pca;\n}\n\n/**\n * Start a device-code flow. The returned `result` promise resolves once the\n * user has entered the code and consented; callers should poll it (or await it)\n * via `complete_add_account`.\n */\nexport function beginDeviceCode(scopes: string[] = DEFAULT_SCOPES): DeviceCodeBegin {\n const pca = buildPca();\n let resolve!: (v: { tokens: SerializedTokens; account: AccountInfo }) => void;\n let reject!: (err: unknown) => void;\n const result = new Promise<{ tokens: SerializedTokens; account: AccountInfo }>(\n (res, rej) => {\n resolve = res;\n reject = rej;\n },\n );\n\n // We capture the deviceCodeCallback synchronously to surface the user-facing\n // info back out via this object before awaiting the long-running poll.\n let userCode = \"\";\n let verificationUri = \"\";\n let message = \"\";\n let expiresAt = new Date(Date.now() + 15 * 60_000).toISOString();\n let aborted = false;\n\n const ready = new Promise<void>((r) => {\n pca\n .acquireTokenByDeviceCode({\n scopes,\n deviceCodeCallback: (info) => {\n if (!info.userCode || !info.verificationUri) {\n // MSAL may fire the callback with an empty object if the\n // downstream HTTP request fails — reject so the caller\n // gets a clear error instead of silent empty strings.\n reject(\n new Error(\n \"Microsoft device-code endpoint returned no code. \" +\n \"Check MS_CLIENT_ID is a valid Azure Entra public-client application.\",\n ),\n );\n return;\n }\n userCode = info.userCode;\n verificationUri = info.verificationUri;\n message = info.message;\n if (info.expiresIn) {\n expiresAt = new Date(Date.now() + info.expiresIn * 1000).toISOString();\n }\n r();\n },\n })\n .then((authResult: AuthenticationResult | null) => {\n if (aborted) return;\n if (!authResult || !authResult.account) {\n reject(new Error(\"device-code flow returned no account\"));\n return;\n }\n const cache = pca.getTokenCache().serialize();\n const tokens: SerializedTokens = {\n msalCache: cache,\n homeAccountId: authResult.account.homeAccountId,\n tenantId: authResult.account.tenantId,\n username: authResult.account.username,\n scopes,\n };\n resolve({ tokens, account: authResult.account });\n })\n .catch((err) => {\n if (!aborted) reject(err);\n });\n });\n\n // Surface device-code info synchronously via a wrapper Promise:\n // we return the object but its strings are populated once `ready` settles.\n // To keep the API simple, we attach a getter that callers must `await` on.\n // Instead of getters, we wait for `ready` inside the begin helper:\n return {\n // these are placeholders until ready resolves\n get userCode() {\n return userCode;\n },\n get verificationUri() {\n return verificationUri;\n },\n get message() {\n return message;\n },\n get expiresAt() {\n return expiresAt;\n },\n result,\n cancel() {\n aborted = true;\n },\n // hidden helper for the caller to await initial code\n // (typed via a cast below where used)\n ...({ _ready: ready } as Record<string, unknown>),\n } as DeviceCodeBegin;\n}\n\n/** Await `_ready` so the user-code fields are populated. */\nexport async function awaitDeviceCodeReady(b: DeviceCodeBegin): Promise<void> {\n const r = (b as unknown as { _ready: Promise<void> })._ready;\n await r;\n}\n\n/**\n * Acquire a fresh access token for a stored account, refreshing silently from\n * the persisted MSAL cache. Returns the (possibly-updated) cache so the caller\n * can write it back to the store.\n */\nexport async function acquireAccessToken(\n tokens: SerializedTokens,\n scopes: string[] = DEFAULT_SCOPES,\n): Promise<{ accessToken: string; tokens: SerializedTokens }> {\n const pca = buildPca(tokens.msalCache);\n const cache = pca.getTokenCache();\n const account =\n (await cache.getAccountByHomeId(tokens.homeAccountId)) ??\n (await cache.getAllAccounts()).find((a) => a.username === tokens.username);\n if (!account) {\n throw new Error(\"no MSAL account in cache — re-run add_account\");\n }\n const res = await pca.acquireTokenSilent({ account, scopes });\n if (!res?.accessToken) {\n throw new Error(\"acquireTokenSilent returned no access token\");\n }\n const next: SerializedTokens = {\n ...tokens,\n msalCache: cache.serialize(),\n scopes,\n };\n return { accessToken: res.accessToken, tokens: next };\n}\n","import type { AccountRecord } from \"../../store/account-store.js\";\nimport type {\n AddAccountInput,\n AddAccountResult,\n AttachmentContent,\n CompleteAddAccountResult,\n DraftUpdateInput,\n EmailFull,\n EmailProvider,\n EmailSummary,\n ListEmailsOptions,\n SearchEmailsOptions,\n SendInput,\n} from \"../types.js\";\n\nconst NOT_IMPLEMENTED =\n \"IMAP provider is not yet implemented in v1. Tracked at \" +\n \"src/providers/imap/index.ts — see src/providers/types.ts for the contract.\";\n\n/**\n * Placeholder IMAP provider — registered so the contract is locked in and\n * `add_account` returns a clear \"coming soon\" error instead of \"unknown provider\".\n *\n * v2 plan: use `imapflow` + `nodemailer` (for send). Tokens shape will be\n * `{ host, port, secure, user, password|appPassword }` encrypted at rest by\n * the AccountStore, identical to how Outlook's MSAL cache is stored.\n */\nexport class ImapProvider implements EmailProvider {\n readonly id = \"imap\" as const;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async addAccount(_input: AddAccountInput): Promise<AddAccountResult> {\n throw new Error(NOT_IMPLEMENTED);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async completeAddAccount(_handle: string): Promise<CompleteAddAccountResult> {\n return { status: \"error\", error: NOT_IMPLEMENTED };\n }\n\n async listEmails(\n _account: AccountRecord,\n _opts: ListEmailsOptions,\n ): Promise<EmailSummary[]> {\n throw new Error(NOT_IMPLEMENTED);\n }\n\n async searchEmails(\n _account: AccountRecord,\n _query: string,\n _opts: SearchEmailsOptions,\n ): Promise<EmailSummary[]> {\n throw new Error(NOT_IMPLEMENTED);\n }\n\n async readEmail(_account: AccountRecord, _id: string): Promise<EmailFull> {\n throw new Error(NOT_IMPLEMENTED);\n }\n\n async readAttachment(\n _account: AccountRecord,\n _messageId: string,\n _attachmentId: string,\n ): Promise<AttachmentContent> {\n throw new Error(NOT_IMPLEMENTED);\n }\n\n async sendEmail(\n _account: AccountRecord,\n _msg: SendInput,\n ): Promise<{ id: string }> {\n throw new Error(NOT_IMPLEMENTED);\n }\n\n async saveDraft(\n _account: AccountRecord,\n _msg: SendInput,\n ): Promise<{ id: string }> {\n throw new Error(NOT_IMPLEMENTED);\n }\n\n async updateDraft(\n _account: AccountRecord,\n _id: string,\n _update: DraftUpdateInput,\n ): Promise<{ id: string }> {\n throw new Error(NOT_IMPLEMENTED);\n }\n\n async moveEmail(\n _account: AccountRecord,\n _id: string,\n _destinationId: string,\n ): Promise<void> {\n throw new Error(NOT_IMPLEMENTED);\n }\n}\n","import type { AccountStore, AccountRecord } from \"../store/account-store.js\";\nimport type { EmailProvider, ProviderId } from \"./types.js\";\nimport { OutlookProvider } from \"./outlook/index.js\";\nimport { ImapProvider } from \"./imap/index.js\";\n\nexport interface Registry {\n get(id: ProviderId): EmailProvider;\n resolveByEmail(email: string): { provider: EmailProvider; account: AccountRecord };\n list(): EmailProvider[];\n}\n\nexport interface BuildRegistryOptions {\n store: AccountStore;\n}\n\nexport function buildRegistry(opts: BuildRegistryOptions): Registry {\n const providers = new Map<ProviderId, EmailProvider>();\n providers.set(\"outlook\", new OutlookProvider({ store: opts.store }));\n providers.set(\"imap\", new ImapProvider());\n // gmail can be added later — registry will return a clear error if asked.\n\n function get(id: ProviderId): EmailProvider {\n const p = providers.get(id);\n if (!p) throw new Error(`unknown provider: ${id}`);\n return p;\n }\n\n function resolveByEmail(email: string): {\n provider: EmailProvider;\n account: AccountRecord;\n } {\n const account = opts.store.getAccount(email);\n if (!account) {\n throw new Error(\n `no account registered for \"${email}\". Call add_account first.`,\n );\n }\n return { provider: get(account.provider), account };\n }\n\n return {\n get,\n resolveByEmail,\n list: () => Array.from(providers.values()),\n };\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\n\nimport type { AccountRecord, AccountStore } from \"../store/account-store.js\";\nimport type { Registry } from \"../providers/registry.js\";\nimport type { EmailProvider, ProviderId, SendInput } from \"../providers/types.js\";\nimport { selectBody } from \"../html-to-markdown.js\";\n\nexport interface RegisterToolsOptions {\n store: AccountStore;\n registry: Registry;\n readOnly?: boolean;\n /** When true, send_email is not registered — only send_draft is available. */\n draftOnly?: boolean;\n}\n\n/** JSON-stringify a value into a single MCP text content block. */\nfunction ok(data: unknown, structuredContent?: Record<string, unknown>) {\n const result: { content: Array<{ type: \"text\"; text: string }>; structuredContent?: Record<string, unknown> } = {\n content: [\n { type: \"text\" as const, text: JSON.stringify(data, null, 2) },\n ],\n };\n if (structuredContent !== undefined) {\n result.structuredContent = structuredContent;\n }\n return result;\n}\nfunction fail(message: string) {\n return {\n isError: true,\n content: [{ type: \"text\" as const, text: message }],\n };\n}\n\nconst emailAddrSchema = z.object({\n address: z.string().email(),\n name: z.string().optional(),\n});\n\n// ---------- shared output schemas ----------\n\nconst emailAddrOutputSchema = z.object({\n name: z.string().optional(),\n address: z.string(),\n});\n\nconst accountSummaryOutputSchema = z.object({\n email: z.string(),\n provider: z.enum([\"outlook\", \"imap\", \"gmail\"]),\n displayName: z.string().optional(),\n addedAt: z.string(),\n hasSignature: z.boolean(),\n hasStyle: z.boolean(),\n});\n\nconst emailSummaryOutputSchema = z.object({\n id: z.string(),\n subject: z.string(),\n from: emailAddrOutputSchema.optional(),\n to: z.array(emailAddrOutputSchema).optional(),\n receivedAt: z.string().optional(),\n preview: z.string().optional(),\n isRead: z.boolean().optional(),\n hasAttachments: z.boolean().optional(),\n folder: z.string().optional(),\n});\n\nconst attachmentMetaOutputSchema = z.object({\n id: z.string(),\n name: z.string(),\n contentType: z.string().optional(),\n size: z.number().optional(),\n});\n\nconst styleOutputSchema = z.object({\n fontFamily: z.string().optional(),\n fontSize: z.string().optional(),\n fontColor: z.string().optional(),\n});\n\nexport function registerTools(server: McpServer, opts: RegisterToolsOptions): void {\n const { store, registry, readOnly = false, draftOnly = false } = opts;\n\n // ---------- account management ----------\n\n const listAccountsOutputSchema = {\n accounts: z.array(accountSummaryOutputSchema),\n };\n\n server.registerTool(\n \"list_accounts\",\n {\n description:\n \"List all email accounts known to this server (no secrets). \" +\n \"Use the returned `email` value as the `account` argument to other tools.\",\n inputSchema: {},\n outputSchema: listAccountsOutputSchema,\n },\n async () => {\n const rows = store.listAccounts().map((a) => ({\n email: a.email,\n provider: a.provider,\n displayName: a.displayName,\n addedAt: a.addedAt,\n hasSignature: !!a.signature,\n hasStyle: !!(a.style && (a.style.fontFamily || a.style.fontSize || a.style.fontColor)),\n }));\n const data = { accounts: rows };\n return ok(data, data);\n },\n );\n\n const addAccountOutputSchema = z.discriminatedUnion(\"status\", [\n z.object({\n status: z.literal(\"pending\"),\n handle: z.string(),\n verification: z.object({\n userCode: z.string(),\n verificationUri: z.string(),\n expiresAt: z.string(),\n message: z.string(),\n }),\n }),\n z.object({\n status: z.literal(\"ready\"),\n account: z.object({\n email: z.string(),\n provider: z.enum([\"outlook\", \"imap\", \"gmail\"]),\n displayName: z.string().optional(),\n tokens: z.record(z.unknown()),\n addedAt: z.string(),\n signature: z.string().optional(),\n style: styleOutputSchema.optional(),\n }),\n }),\n ]);\n\n server.registerTool(\n \"add_account\",\n {\n description:\n \"Start adding an email account. For Outlook this returns a device code \" +\n \"the user must enter at the verification URL; then call `complete_add_account` \" +\n \"with the returned `handle` to finalize. Disabled in --read-only mode.\",\n inputSchema: {\n provider: z\n .enum([\"outlook\", \"imap\", \"gmail\"])\n .describe(\"Email backend. v1 only fully implements 'outlook'.\"),\n email: z\n .string()\n .email()\n .optional()\n .describe(\"Optional hint — the provider will verify it against the auth result.\"),\n config: z\n .record(z.unknown())\n .optional()\n .describe(\"Provider-specific config (e.g. IMAP host/port). Unused for Outlook.\"),\n },\n outputSchema: addAccountOutputSchema,\n },\n async (args) => {\n if (readOnly) return fail(\"server is in --read-only mode; add_account is disabled\");\n const provider = registry.get(args.provider as ProviderId);\n try {\n const res = await provider.addAccount({ email: args.email, config: args.config });\n return ok(res, res as unknown as Record<string, unknown>);\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n const completeAddAccountOutputSchema = z.object({\n status: z.enum([\"pending\", \"ready\", \"expired\", \"error\"]),\n account: z\n .object({\n email: z.string(),\n provider: z.enum([\"outlook\", \"imap\", \"gmail\"]),\n displayName: z.string().optional(),\n tokens: z.record(z.unknown()),\n addedAt: z.string(),\n signature: z.string().optional(),\n style: styleOutputSchema.optional(),\n })\n .optional(),\n error: z.string().optional(),\n });\n\n server.registerTool(\n \"complete_add_account\",\n {\n description:\n \"Poll/finalize a pending add_account flow. Returns `pending` until the user \" +\n \"completes the device-code step, then `ready` with the persisted account.\",\n inputSchema: {\n provider: z.enum([\"outlook\", \"imap\", \"gmail\"]),\n handle: z.string().min(1),\n },\n outputSchema: completeAddAccountOutputSchema,\n },\n async (args) => {\n const provider = registry.get(args.provider as ProviderId);\n if (!provider.completeAddAccount) {\n return fail(`provider ${args.provider} has no async add-account flow`);\n }\n try {\n const res = await provider.completeAddAccount(args.handle);\n return ok(res, res as unknown as Record<string, unknown>);\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n // ---------- account settings ----------\n\n const accountSettingsOutputSchema = {\n signature: z.string().nullable(),\n style: styleOutputSchema.nullable(),\n };\n\n server.registerTool(\n \"get_account_settings\",\n {\n description:\n \"Get signature (HTML) and style preferences for an account.\",\n inputSchema: { account: z.string().email() },\n outputSchema: accountSettingsOutputSchema,\n },\n async (args) => {\n try {\n const acct = store.getAccount(args.account);\n if (!acct) return fail(`no account registered for \"${args.account}\"`);\n const data = { signature: acct.signature ?? null, style: acct.style ?? null };\n return ok(data, data as Record<string, unknown>);\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n server.registerTool(\n \"set_account_settings\",\n {\n description:\n \"Set signature (HTML snippet) and/or style preferences for an account. \" +\n \"Disabled in --read-only mode.\",\n inputSchema: {\n account: z.string().email(),\n signature: z\n .string()\n .optional()\n .describe(\"HTML snippet — may contain formatting, images, links. Pass null to clear.\"),\n style: z\n .object({\n fontFamily: z.string().optional(),\n fontSize: z.string().optional(),\n fontColor: z.string().optional(),\n })\n .optional()\n .describe(\"Font preferences applied to outgoing HTML emails. Pass null to clear.\"),\n },\n outputSchema: accountSettingsOutputSchema,\n },\n async (args) => {\n if (readOnly) return fail(\"server is in --read-only mode; set_account_settings is disabled\");\n try {\n const acct = store.getAccount(args.account);\n if (!acct) return fail(`no account registered for \"${args.account}\"`);\n const updated = await store.upsertAccount({\n ...acct,\n signature: args.signature ?? acct.signature,\n style: args.style ?? acct.style,\n });\n const data = { signature: updated.signature ?? null, style: updated.style ?? null };\n return ok(data, data as Record<string, unknown>);\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n const removeAccountOutputSchema = {\n removed: z.boolean(),\n email: z.string(),\n };\n\n server.registerTool(\n \"remove_account\",\n {\n description: \"Forget an account and delete its stored tokens. Disabled in --read-only mode.\",\n inputSchema: { email: z.string().email() },\n outputSchema: removeAccountOutputSchema,\n },\n async (args) => {\n if (readOnly) return fail(\"server is in --read-only mode; remove_account is disabled\");\n const removed = await store.removeAccount(args.email);\n const data = { removed, email: args.email };\n return ok(data, data);\n },\n );\n\n // ---------- email ops ----------\n\n const emailListOutputSchema = {\n account: z.string(),\n count: z.number(),\n items: z.array(emailSummaryOutputSchema),\n };\n\n server.registerTool(\n \"list_emails\",\n {\n description:\n \"List recent emails in a folder of the given account. Pass the user's email \" +\n \"address as `account`; the server routes to the correct backend automatically.\",\n inputSchema: {\n account: z.string().email(),\n folder: z.string().default(\"inbox\").optional(),\n limit: z.number().int().positive().max(100).optional(),\n unreadOnly: z.boolean().optional(),\n },\n outputSchema: emailListOutputSchema,\n },\n async (args) => {\n try {\n const { provider, account } = registry.resolveByEmail(args.account);\n const items = await provider.listEmails(account, {\n folder: args.folder,\n limit: args.limit,\n unreadOnly: args.unreadOnly,\n });\n const data = { account: account.email, count: items.length, items };\n return ok(data, data);\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n server.registerTool(\n \"search_emails\",\n {\n description:\n \"Search emails by free-text query (KQL on Outlook). Returns lightweight summaries.\",\n inputSchema: {\n account: z.string().email(),\n query: z.string().min(1),\n limit: z.number().int().positive().max(100).optional(),\n },\n outputSchema: emailListOutputSchema,\n },\n async (args) => {\n try {\n const { provider, account } = registry.resolveByEmail(args.account);\n const items = await provider.searchEmails(account, args.query, {\n limit: args.limit,\n });\n const data = { account: account.email, count: items.length, items };\n return ok(data, data);\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n const readEmailOutputSchema = {\n id: z.string(),\n subject: z.string(),\n from: emailAddrOutputSchema.optional(),\n to: z.array(emailAddrOutputSchema).optional(),\n cc: z.array(emailAddrOutputSchema).optional(),\n bcc: z.array(emailAddrOutputSchema).optional(),\n receivedAt: z.string().optional(),\n preview: z.string().optional(),\n isRead: z.boolean().optional(),\n hasAttachments: z.boolean().optional(),\n folder: z.string().optional(),\n attachments: z.array(attachmentMetaOutputSchema).optional(),\n body: z.string(),\n bodyFormat: z.enum([\"markdown\", \"html\", \"text\"]),\n };\n\n server.registerTool(\n \"read_email\",\n {\n description:\n \"Fetch a single email with full body and recipients by id. \" +\n \"Body is returned as `body` with `bodyFormat` indicating the format. \" +\n \"Default format is 'markdown' — HTML is automatically converted to save context tokens.\",\n inputSchema: {\n account: z.string().email(),\n id: z.string().min(1),\n format: z\n .enum([\"markdown\", \"html\", \"text\"])\n .default(\"markdown\")\n .optional()\n .describe(\n \"Output body format. 'markdown' converts HTML to Markdown (default), \" +\n \"'html' returns the raw HTML, 'text' returns plain text.\",\n ),\n },\n outputSchema: readEmailOutputSchema,\n },\n async (args) => {\n try {\n const { provider, account } = registry.resolveByEmail(args.account);\n const msg = await provider.readEmail(account, args.id);\n const format = args.format ?? \"markdown\";\n const body = selectBody(msg, format);\n const data = {\n id: msg.id,\n subject: msg.subject,\n from: msg.from,\n to: msg.to,\n cc: msg.cc,\n bcc: msg.bcc,\n receivedAt: msg.receivedAt,\n preview: msg.preview,\n isRead: msg.isRead,\n hasAttachments: msg.hasAttachments,\n folder: msg.folder,\n attachments: msg.attachments,\n body,\n bodyFormat: format,\n };\n return ok(data, data as Record<string, unknown>);\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n const readAttachmentOutputSchema = {\n name: z.string(),\n contentType: z.string().optional(),\n path: z.string(),\n };\n\n server.registerTool(\n \"read_attachment\",\n {\n description:\n \"Download an email attachment to a temporary file and return its path. \" +\n \"Use messageId and attachmentId from a prior read_email call.\",\n inputSchema: {\n account: z.string().email(),\n messageId: z.string().min(1),\n attachmentId: z.string().min(1),\n },\n outputSchema: readAttachmentOutputSchema,\n },\n async (args) => {\n try {\n const { provider, account } = registry.resolveByEmail(args.account);\n const res = await provider.readAttachment(account, args.messageId, args.attachmentId);\n return ok(res, res as unknown as Record<string, unknown>);\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n // ---------- move / archive ----------\n\n {\n const schema = {\n account: z.string().email(),\n id: z.string().min(1).describe(\"Message ID to move\"),\n };\n\n const archiveOutputSchema = {\n archived: z.literal(true),\n id: z.string(),\n };\n\n server.registerTool(\n \"archive_email\",\n {\n description:\n \"Move a message to the Archive folder. Disabled in --read-only mode.\",\n inputSchema: schema,\n outputSchema: archiveOutputSchema,\n },\n async (args) => {\n if (readOnly) return fail(\"server is in --read-only mode; archive_email is disabled\");\n try {\n const { provider, account } = registry.resolveByEmail(args.account);\n await provider.moveEmail(account, args.id, \"archive\");\n const data = { archived: true as const, id: args.id };\n return ok(data, data);\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n const trashOutputSchema = {\n trashed: z.literal(true),\n id: z.string(),\n };\n\n server.registerTool(\n \"trash_email\",\n {\n description:\n \"Move a message to the Deleted Items (trash) folder. Disabled in --read-only mode.\",\n inputSchema: schema,\n outputSchema: trashOutputSchema,\n },\n async (args) => {\n if (readOnly) return fail(\"server is in --read-only mode; trash_email is disabled\");\n try {\n const { provider, account } = registry.resolveByEmail(args.account);\n await provider.moveEmail(account, args.id, \"deleteditems\");\n const data = { trashed: true as const, id: args.id };\n return ok(data, data);\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n }\n\n const moveEmailOutputSchema = {\n moved: z.literal(true),\n id: z.string(),\n destination: z.string(),\n };\n\n server.registerTool(\n \"move_email\",\n {\n description:\n \"Move a message to any folder by well-known name (e.g. 'inbox', 'drafts', \" +\n \"'junkemail', 'sentitems', 'outbox') or custom folder ID. \" +\n \"Disabled in --read-only mode.\",\n inputSchema: {\n account: z.string().email(),\n id: z.string().min(1).describe(\"Message ID to move\"),\n destination: z\n .string()\n .min(1)\n .describe(\n \"Destination folder — a well-known folder name \" +\n \"('archive', 'deleteditems', 'inbox', 'drafts', 'junkemail', \" +\n \"'sentitems', 'outbox') or a raw folder ID.\",\n ),\n },\n outputSchema: moveEmailOutputSchema,\n },\n async (args) => {\n if (readOnly) return fail(\"server is in --read-only mode; move_email is disabled\");\n try {\n const { provider, account } = registry.resolveByEmail(args.account);\n await provider.moveEmail(account, args.id, args.destination);\n const data = { moved: true as const, id: args.id, destination: args.destination };\n return ok(data, data);\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n\n const sendEmailSchema = z.object({\n account: z.string().email(),\n to: z.array(emailAddrSchema).min(1),\n cc: z.array(emailAddrSchema).optional(),\n bcc: z.array(emailAddrSchema).optional(),\n subject: z.string(),\n body: z.string(),\n isHtml: z.boolean().optional(),\n include_signature: z\n .boolean()\n .describe(\n \"Whether to append the account's saved HTML signature to the email. \" +\n \"If true, don't include a signature in the body param to avoid double signature. \" +\n \"Returns an error if true but no signature is configured for this account.\",\n ),\n inReplyTo: z\n .string()\n .optional()\n .describe(\n \"Message ID to reply to. When set, sends as a threaded reply \" +\n \"which includes the quoted thread history automatically.\",\n ),\n replyAll: z\n .boolean()\n .default(false)\n .optional()\n .describe(\n \"When true and `inReplyTo` is set, reply to all recipients \" +\n \"instead of just the sender.\",\n ),\n forwardMessageId: z\n .string()\n .optional()\n .describe(\n \"Message ID to forward. When set, sends as a forward of the \" +\n \"specified message, preserving the original content. \" +\n \"Mutually exclusive with `inReplyTo`.\",\n ),\n });\n\n type SendEmailArgs = z.infer<typeof sendEmailSchema>;\n\n async function handleSendOrDraft(\n args: SendEmailArgs,\n action: (\n provider: EmailProvider,\n account: AccountRecord,\n msg: SendInput,\n ) => Promise<{ id: string }>,\n resultKey: string,\n toolName: string,\n ) {\n if (readOnly) return fail(`server is in --read-only mode; ${toolName} is disabled`);\n try {\n const { provider, account } = registry.resolveByEmail(args.account);\n if (args.include_signature && !account.signature) {\n return fail(\n \"include_signature is true but no signature is configured for this account. \" +\n \"Set up a signature first with set_account_settings.\",\n );\n }\n const composed = composeBody({\n body: args.body,\n isHtml: args.isHtml,\n signature: account.signature,\n style: account.style,\n includeSignature: args.include_signature,\n });\n if (args.inReplyTo && args.forwardMessageId) {\n return fail(\n \"inReplyTo and forwardMessageId are mutually exclusive — use one or the other\",\n );\n }\n const res = await action(provider, account, {\n to: args.to,\n cc: args.cc,\n bcc: args.bcc,\n subject: args.subject,\n body: composed.body,\n isHtml: composed.isHtml,\n inReplyTo: args.inReplyTo,\n replyAll: args.replyAll,\n forwardMessageId: args.forwardMessageId,\n });\n const result: Record<string, unknown> = { [resultKey]: true, ...res };\n // For draft_email, fetch the created draft back so the agent can\n // inspect the actual HTML content before deciding to send it.\n if (toolName === \"draft_email\" && res.id) {\n const draft = await provider.readEmail(account, res.id);\n result.draftHtml = draft.bodyHtml;\n }\n return ok(result, result);\n } catch (err) {\n return fail(errMsg(err));\n }\n }\n\n // ---------- send / draft ----------\n\n const sendEmailOutputSchema = {\n sent: z.literal(true),\n id: z.string(),\n };\n\n if (!draftOnly) {\n server.registerTool(\n \"send_email\",\n {\n description:\n \"Send an email from the given account. Appends the \" +\n \"account's signature (HTML) and applies style preferences when \" +\n \"`include_signature` is true. Returns an error if \" +\n \"`include_signature` is true but no signature is configured. \" +\n \"When `inReplyTo` is set, sends as a reply (or reply-all) which \" +\n \"preserves thread history and conversation threading. \" +\n \"When `forwardMessageId` is set, sends as a forward of the \" +\n \"specified message, preserving the original content. \" +\n \"`inReplyTo` and `forwardMessageId` are mutually exclusive. \" +\n \"Disabled in --read-only mode.\",\n inputSchema: sendEmailSchema,\n outputSchema: sendEmailOutputSchema,\n },\n async (args) =>\n handleSendOrDraft(\n args as SendEmailArgs,\n (p, a, m) => p.sendEmail(a, m),\n \"sent\",\n \"send_email\",\n ),\n );\n }\n\n const draftEmailOutputSchema = {\n draft: z.literal(true),\n id: z.string(),\n draftHtml: z.string().optional(),\n };\n\n server.registerTool(\n \"draft_email\",\n {\n description:\n \"Create a draft email from the given account without sending it. \" +\n \"Works identically to send_email — appends signature when \" +\n \"`include_signature` is true, applies style, and supports replies \" +\n \"and forwards — but saves the message to the Drafts folder \" +\n \"instead of sending. Returns the draft message ID and the draft's \" +\n \"HTML body content (`draftHtml`). Before sending the draft, \" +\n \"inspect `draftHtml` to verify the draft looks correct: no \" +\n \"duplicate signature blocks, no broken or missing inline images, \" +\n \"no malformed HTML, and no other formatting issues. \" +\n \"Disabled in --read-only mode.\",\n inputSchema: sendEmailSchema,\n outputSchema: draftEmailOutputSchema,\n },\n async (args) =>\n handleSendOrDraft(\n args as SendEmailArgs,\n (p, a, m) => p.saveDraft(a, m),\n \"draft\",\n \"draft_email\",\n ),\n );\n\n // ---------- edit draft ----------\n\n const editDraftSchema = z.object({\n account: z.string().email(),\n id: z.string().min(1).describe(\"Draft message ID to edit\"),\n to: z.array(emailAddrSchema).optional(),\n cc: z.array(emailAddrSchema).optional(),\n bcc: z.array(emailAddrSchema).optional(),\n subject: z.string().optional(),\n body: z.string().optional(),\n isHtml: z.boolean().optional(),\n include_signature: z\n .boolean()\n .optional()\n .describe(\n \"Whether to re-apply the account's saved HTML signature to the body. \" +\n \"If true, don't include a signature in the body param. \" +\n \"Only meaningful when `body` is also provided. \" +\n \"Returns an error if true but no signature is configured for this account.\",\n ),\n });\n\n type EditDraftArgs = z.infer<typeof editDraftSchema>;\n\n const editDraftOutputSchema = {\n edited: z.literal(true),\n id: z.string(),\n draftHtml: z.string().optional(),\n };\n\n server.registerTool(\n \"edit_draft\",\n {\n description:\n \"Edit an existing draft email by ID. Only the fields you provide \" +\n \"are updated — unmentioned fields stay unchanged. When `body` is \" +\n \"provided and `include_signature` is true, the account's signature \" +\n \"is re-applied. Returns the draft ID and the draft's updated HTML \" +\n \"body content (`draftHtml`). Before sending, inspect `draftHtml` \" +\n \"to verify the draft looks correct. \" +\n \"Does not support changing `inReplyTo` or `forwardMessageId` — \" +\n \"those are set at creation time via `draft_email`. \" +\n \"Disabled in --read-only mode.\",\n inputSchema: editDraftSchema,\n outputSchema: editDraftOutputSchema,\n },\n async (args) => {\n const a = args as EditDraftArgs;\n if (readOnly) return fail(\"server is in --read-only mode; edit_draft is disabled\");\n try {\n const { provider, account } = registry.resolveByEmail(a.account);\n if (a.include_signature && !account.signature) {\n return fail(\n \"include_signature is true but no signature is configured for this account. \" +\n \"Set up a signature first with set_account_settings.\",\n );\n }\n let bodyPayload: string | undefined;\n let isHtmlPayload: boolean | undefined;\n if (a.body !== undefined) {\n const composed = composeBody({\n body: a.body,\n isHtml: a.isHtml,\n signature: account.signature,\n style: account.style,\n includeSignature: !!a.include_signature,\n });\n bodyPayload = composed.body;\n isHtmlPayload = composed.isHtml;\n }\n const res = await provider.updateDraft(account, a.id, {\n to: a.to,\n cc: a.cc,\n bcc: a.bcc,\n subject: a.subject,\n body: bodyPayload,\n isHtml: isHtmlPayload,\n });\n // Fetch the updated draft so the agent can inspect the HTML before sending.\n const draft = await provider.readEmail(account, res.id);\n const result: Record<string, unknown> = {\n edited: true as const,\n id: res.id,\n draftHtml: draft.bodyHtml,\n };\n return ok(result, result);\n } catch (err) {\n return fail(errMsg(err));\n }\n },\n );\n}\n\n// ---------- body composition helpers ----------\n\ninterface ComposeBodyInput {\n body: string;\n isHtml?: boolean;\n signature?: string;\n style?: { fontFamily?: string; fontSize?: string; fontColor?: string };\n includeSignature: boolean;\n}\n\nexport function composeBody(input: ComposeBodyInput): { body: string; isHtml: boolean } {\n const { body, isHtml = false, signature, style, includeSignature } = input;\n const hasSignature = includeSignature && !!signature;\n const hasStyle = !!(style && (style.fontFamily || style.fontSize || style.fontColor));\n\n // Nothing to inject — pass through unchanged\n if (!hasSignature && !hasStyle) {\n return { body, isHtml };\n }\n\n // Need HTML for signature or style injection\n const styleAttr = hasStyle ? buildStyleAttr(style!) : \"\";\n\n if (isHtml) {\n let result = hasStyle ? `<div style=\"${styleAttr}\">${body}</div>` : body;\n if (hasSignature) result += `\\n<div class=\"signature\">${signature}</div>`;\n return { body: result, isHtml: true };\n }\n\n // Auto-upgrade plain text to HTML\n const escaped = escapeHtml(body);\n let result = `<div style=\"${styleAttr}\">${escaped}</div>`;\n if (hasSignature) result += `\\n<div class=\"signature\">${signature}</div>`;\n return { body: result, isHtml: true };\n}\n\nexport function buildStyleAttr(style: { fontFamily?: string; fontSize?: string; fontColor?: string }): string {\n const parts: string[] = [];\n if (style.fontFamily) parts.push(`font-family: ${style.fontFamily}`);\n if (style.fontSize) parts.push(`font-size: ${style.fontSize}`);\n if (style.fontColor) parts.push(`color: ${style.fontColor}`);\n return parts.join(\"; \");\n}\n\nexport function escapeHtml(text: string): string {\n return text\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/\\n/g, \"<br>\");\n}\n\nfunction errMsg(err: unknown): string {\n if (err instanceof Error) return err.message;\n return String(err);\n}\n","import TurndownService from \"turndown\";\n\nconst turndown = new TurndownService();\n\n/** Light wrapper — callers just pass HTML, get markdown back. */\nexport function htmlToMarkdown(html: string): string {\n return turndown.turndown(html);\n}\n\n/** Pick the right body for the requested format. */\nexport function selectBody(\n msg: { bodyHtml?: string; bodyText?: string },\n format: \"markdown\" | \"html\" | \"text\",\n): string {\n switch (format) {\n case \"markdown\": {\n if (msg.bodyHtml) return htmlToMarkdown(msg.bodyHtml);\n if (msg.bodyText) return msg.bodyText;\n return \"\";\n }\n case \"html\": {\n if (msg.bodyHtml) return msg.bodyHtml;\n if (msg.bodyText) return msg.bodyText;\n return \"\";\n }\n case \"text\": {\n if (msg.bodyText) return msg.bodyText;\n if (msg.bodyHtml) return msg.bodyHtml.replace(/<[^>]*>/g, \"\");\n return \"\";\n }\n }\n}\n","export const VERSION = \"0.3.0\";\n","import { startServer } from \"./server.js\";\n\ntype ParsedArgs = {\n http: boolean;\n port: number;\n host: string;\n dataDir?: string;\n readOnly: boolean;\n help: boolean;\n};\n\nfunction parseArgs(argv: string[]): ParsedArgs {\n const out: ParsedArgs = {\n http: false,\n port: 3000,\n host: \"127.0.0.1\",\n readOnly: false,\n help: false,\n };\n for (let i = 0; i < argv.length; i++) {\n const a = argv[i];\n switch (a) {\n case \"--http\":\n out.http = true;\n break;\n case \"--port\":\n out.port = Number(argv[++i] ?? \"3000\");\n break;\n case \"--host\":\n out.host = String(argv[++i] ?? \"127.0.0.1\");\n break;\n case \"--data-dir\":\n out.dataDir = String(argv[++i] ?? \"\");\n break;\n case \"--read-only\":\n out.readOnly = true;\n break;\n case \"-h\":\n case \"--help\":\n out.help = true;\n break;\n default:\n if (a && a.startsWith(\"--\")) {\n // ignore unknown flags rather than crashing — keeps the CLI forgiving\n // when embedded in MCP host configs.\n }\n }\n }\n return out;\n}\n\nfunction printHelp(): void {\n const msg = `hypermail-mcp — unified email MCP server\n\nUsage:\n hypermail-mcp [options]\n\nOptions:\n --http Run as Streamable HTTP server (default: stdio)\n --port <n> HTTP port (default: 3000)\n --host <addr> HTTP bind address (default: 127.0.0.1)\n --data-dir <path> Where to store the encrypted accounts file\n (default: $HYPERMAIL_MCP_DATA_DIR or ~/.hypermail-mcp)\n --read-only Disable tools that modify state (send_email, remove_account, add_account)\n -h, --help Show this help\n\nEnvironment:\n HYPERMAIL_MCP_DATA_DIR Same as --data-dir\n HYPERMAIL_MCP_KEY 32-byte key (base64 or hex) for at-rest encryption\n MS_CLIENT_ID Azure AD public client (application) ID\n MS_TENANT_ID Tenant (default: \"common\")\n`;\n process.stdout.write(msg);\n}\n\nasync function main(): Promise<void> {\n const opts = parseArgs(process.argv.slice(2));\n if (opts.help) {\n printHelp();\n return;\n }\n const draftOnly = process.env.HYPERMAIL_DRAFT_ONLY === \"true\";\n\n await startServer({\n http: opts.http,\n port: opts.port,\n host: opts.host,\n dataDir: opts.dataDir,\n readOnly: opts.readOnly,\n draftOnly,\n });\n}\n\nmain().catch((err) => {\n // eslint-disable-next-line no-console\n console.error(\"[hypermail-mcp] fatal:\", err);\n process.exit(1);\n});\n"],"mappings":";;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,4BAA4B;AACrC,SAAS,qCAAqC;AAC9C,SAAS,cAAAA,mBAAkB;AAC3B,SAAS,gBAAgB,wBAAmE;;;ACJ5F;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,YAAY,UAAU;AAC/B,SAAS,eAAe;AACxB,OAAO,UAAU;AA8BjB,IAAM,YAAY;AAClB,IAAM,OAAO;AACb,IAAM,UAAU;AAET,IAAM,eAAN,MAAM,cAAa;AAAA,EAChB,YACW,UACA,KACT,MACR;AAHiB;AACA;AACT;AAAA,EACP;AAAA,EAHgB;AAAA,EACA;AAAA,EACT;AAAA,EAGV,aAAa,KAAK,OAAoB,CAAC,GAA0B;AAC/D,UAAM,UAAU,eAAe,KAAK,OAAO;AAC3C,UAAM,GAAG,MAAM,SAAS,EAAE,WA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AC;AACH;AAEA,KAAK,EAAE,MAAM,CAAC,QAAQ;AAEpB,UAAQ,MAAM,0BAA0B,GAAG;AAC3C,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["randomUUID","result","randomUUID"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hypermail-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Unified email MCP server — operate any inbox (Outlook now, IMAP/Gmail later) by passing an email address.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -12,6 +12,15 @@
|
|
|
12
12
|
"README.md",
|
|
13
13
|
"LICENSE"
|
|
14
14
|
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsup",
|
|
17
|
+
"dev": "tsup --watch",
|
|
18
|
+
"start": "node dist/cli.js",
|
|
19
|
+
"typecheck": "tsc --noEmit",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"test:watch": "vitest",
|
|
22
|
+
"prepublishOnly": "pnpm build && pnpm test"
|
|
23
|
+
},
|
|
15
24
|
"engines": {
|
|
16
25
|
"node": ">=20"
|
|
17
26
|
},
|
|
@@ -48,13 +57,5 @@
|
|
|
48
57
|
"tsup": "^8.3.5",
|
|
49
58
|
"typescript": "^5.7.2",
|
|
50
59
|
"vitest": "^2.1.8"
|
|
51
|
-
},
|
|
52
|
-
"scripts": {
|
|
53
|
-
"build": "tsup",
|
|
54
|
-
"dev": "tsup --watch",
|
|
55
|
-
"start": "node dist/cli.js",
|
|
56
|
-
"typecheck": "tsc --noEmit",
|
|
57
|
-
"test": "vitest run",
|
|
58
|
-
"test:watch": "vitest"
|
|
59
60
|
}
|
|
60
|
-
}
|
|
61
|
+
}
|