Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
required: ['emailId'],
},
},
{
name: 'get_email_metadata',
description: 'Get headers/metadata for an email — sender, recipients, subject, date, threading, mailbox membership, keywords (read/flagged/etc.), size, and whether an attachment is present — but NOT the body, preview, or any rendered text. Useful when a workflow needs to classify or route an email without ingesting its content (e.g. customer-mail least-privilege flows where reading bodies is forbidden, or skills that only need to verify post-archive folder placement). The return shape is the standard JMAP Email object restricted to a strict header-only allowlist.',
inputSchema: {
type: 'object',
properties: {
emailId: {
type: 'string',
description: 'ID of the email to retrieve metadata for',
},
},
required: ['emailId'],
},
},
{
name: 'send_email',
description: 'Send an email',
Expand Down Expand Up @@ -1036,6 +1050,22 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
};
}

case 'get_email_metadata': {
const { emailId } = (args ?? {}) as any;
if (!emailId) {
throw new McpError(ErrorCode.InvalidParams, 'emailId is required');
}
const email = await client.getEmailMetadata(emailId);
return {
content: [
{
type: 'text',
text: JSON.stringify(email, null, 2),
},
],
};
}

case 'send_email': {
const { to, cc, bcc, from, mailboxId, subject, textBody, htmlBody, inReplyTo, references, replyTo } = args as any;
const toArray = coerceStringArray(to);
Expand Down Expand Up @@ -1752,7 +1782,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
email: {
available: true,
functions: [
'list_mailboxes', 'list_emails', 'get_email', 'send_email', 'create_draft', 'edit_draft', 'send_draft', 'search_emails',
'list_mailboxes', 'list_emails', 'get_email', 'get_email_metadata', 'send_email', 'create_draft', 'edit_draft', 'send_draft', 'search_emails',
'get_recent_emails', 'mark_email_read', 'pin_email', 'delete_email', 'move_email',
'get_email_attachments', 'download_attachment', 'advanced_search', 'get_thread',
'get_mailbox_stats', 'get_account_summary', 'bulk_mark_read', 'bulk_pin', 'bulk_move', 'bulk_delete',
Expand Down
49 changes: 48 additions & 1 deletion src/jmap-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,54 @@ export class JmapClient {
if (!email) {
throw new Error(`Email with ID '${id}' not found or not accessible`);
}


return email;
}

async getEmailMetadata(id: string): Promise<any> {
const session = await this.getSession();

const request: JmapRequest = {
using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'],
methodCalls: [
['Email/get', {
accountId: session.accountId,
ids: [id],
properties: [
'id',
'threadId',
'mailboxIds',
'keywords',
'receivedAt',
'sentAt',
'subject',
'from',
'to',
'cc',
'bcc',
'replyTo',
'messageId',
'inReplyTo',
'references',
'size',
'hasAttachment',
],
}, 'emailMetadata']
]
};

const response = await this.makeRequest(request);
const result = this.getMethodResult(response, 0);

if (result.notFound && result.notFound.includes(id)) {
throw new Error(`Email with ID '${id}' not found`);
}

const email = result.list?.[0];
if (!email) {
throw new Error(`Email with ID '${id}' not found or not accessible`);
}

return email;
}

Expand Down