|
1 | 1 | import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
2 | 2 | import { z } from "zod";
|
3 | 3 | import type JamClient from "jmap-jam";
|
4 |
| -import type { EmailFilterCondition } from "jmap-jam"; |
| 4 | +import type { |
| 5 | + Email, |
| 6 | + EmailCreate, |
| 7 | + EmailFilterCondition, |
| 8 | + FilterCondition, |
| 9 | + GetEmailArguments, |
| 10 | + MailboxFilterCondition, |
| 11 | +} from "jmap-jam"; |
5 | 12 | import { formatError } from "../utils.ts";
|
6 | 13 |
|
7 | 14 | export const SearchEmailsSchema = z.object({
|
@@ -57,8 +64,37 @@ export const GetEmailsSchema = z.object({
|
57 | 64 | ids: z.array(z.string()).min(1).max(50).describe(
|
58 | 65 | "Array of email IDs to retrieve",
|
59 | 66 | ),
|
60 |
| - properties: z.array(z.string()).optional().describe( |
61 |
| - "Specific properties to return (default: all)", |
| 67 | + properties: z.array(z.enum( |
| 68 | + [ |
| 69 | + "id", |
| 70 | + "blobId", |
| 71 | + "threadId", |
| 72 | + "mailboxIds", |
| 73 | + "keywords", |
| 74 | + "size", |
| 75 | + "receivedAt", |
| 76 | + "headers", |
| 77 | + "messageId", |
| 78 | + "inReplyTo", |
| 79 | + "references", |
| 80 | + "sender", |
| 81 | + "from", |
| 82 | + "to", |
| 83 | + "cc", |
| 84 | + "bcc", |
| 85 | + "replyTo", |
| 86 | + "subject", |
| 87 | + "sentAt", |
| 88 | + "bodyStructure", |
| 89 | + "bodyValues", |
| 90 | + "textBody", |
| 91 | + "htmlBody", |
| 92 | + "attachments", |
| 93 | + "hasAttachment", |
| 94 | + "preview", |
| 95 | + ] as const satisfies Array<keyof Email>, |
| 96 | + )).optional().describe( |
| 97 | + "Specific Email properties to return (default: all).", |
62 | 98 | ),
|
63 | 99 | });
|
64 | 100 |
|
@@ -141,14 +177,6 @@ export function registerEmailTools(
|
141 | 177 | jam: JamClient,
|
142 | 178 | accountId: string,
|
143 | 179 | isReadOnly: boolean,
|
144 |
| - getConfig: () => { |
145 |
| - sessionUrl: string; |
146 |
| - bearerToken: string; |
147 |
| - accountId?: string; |
148 |
| - }, |
149 |
| - createClient: ( |
150 |
| - config: { sessionUrl: string; bearerToken: string; accountId?: string }, |
151 |
| - ) => JamClient, |
152 | 180 | ) {
|
153 | 181 | server.tool(
|
154 | 182 | "search_emails",
|
@@ -205,7 +233,7 @@ export function registerEmailTools(
|
205 | 233 | GetMailboxesSchema.shape,
|
206 | 234 | async (args) => {
|
207 | 235 | try {
|
208 |
| - let filter: Record<string, unknown> | undefined; |
| 236 | + let filter: FilterCondition<MailboxFilterCondition> | undefined; |
209 | 237 | if (args.parentId) {
|
210 | 238 | filter = { parentId: args.parentId };
|
211 | 239 | }
|
@@ -260,21 +288,13 @@ export function registerEmailTools(
|
260 | 288 | GetEmailsSchema.shape,
|
261 | 289 | async (args) => {
|
262 | 290 | try {
|
263 |
| - const config = getConfig(); |
264 |
| - const jam = createClient(config); |
265 |
| - const accountId = config.accountId || await jam.getPrimaryAccount(); |
266 |
| - |
267 |
| - const [result] = await jam.api.Email.get({ |
268 |
| - accountId, |
269 |
| - ids: args.ids, |
270 |
| - properties: args.properties as |
271 |
| - | readonly ( |
272 |
| - | keyof import("jmap-jam").Email |
273 |
| - | import("jmap-jam").HeaderFieldKey |
274 |
| - )[] |
275 |
| - | null |
276 |
| - | undefined, |
277 |
| - }); |
| 291 | + const [result] = await jam.api.Email.get( |
| 292 | + { |
| 293 | + accountId, |
| 294 | + ids: args.ids, |
| 295 | + properties: args.properties, |
| 296 | + } satisfies GetEmailArguments, |
| 297 | + ); |
278 | 298 |
|
279 | 299 | return {
|
280 | 300 | content: [
|
@@ -350,11 +370,7 @@ export function registerEmailTools(
|
350 | 370 | MarkEmailsSchema.shape,
|
351 | 371 | async (args) => {
|
352 | 372 | try {
|
353 |
| - const config = getConfig(); |
354 |
| - const jam = createClient(config); |
355 |
| - const accountId = config.accountId || await jam.getPrimaryAccount(); |
356 |
| - |
357 |
| - const updates: Record<string, Record<string, unknown>> = {}; |
| 373 | + const updates: Record<string, EmailCreate> = {}; |
358 | 374 |
|
359 | 375 | for (const id of args.ids) {
|
360 | 376 | const keywords: Record<string, boolean> = {};
|
@@ -408,7 +424,7 @@ export function registerEmailTools(
|
408 | 424 | MoveEmailsSchema.shape,
|
409 | 425 | async (args) => {
|
410 | 426 | try {
|
411 |
| - const updates: Record<string, Record<string, unknown>> = {}; |
| 427 | + const updates: Record<string, EmailCreate> = {}; |
412 | 428 |
|
413 | 429 | for (const id of args.ids) {
|
414 | 430 | updates[id] = {
|
|
0 commit comments