Skip to main content
Glama
jahfer

JMAP MCP Server

by jahfer

get_email_content

Retrieve the full content of a specific email by providing its ID to access message details through the JMAP protocol.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputSchemaYes

Implementation Reference

  • The handler function that implements the core logic for retrieving full email content by ID. It fetches email metadata and body (text/HTML) using JMAP API, downloads blobs if needed, and formats the output as structured text.
    async ({ emailId }) => {
      const session = await jam.session;
      const accountId = session.primaryAccounts["urn:ietf:params:jmap:mail"];
      const [emails] = await jam.api.Email.get({
        accountId,
        ids: [emailId],
        properties: ["id", "textBody", "htmlBody", "subject", "from", "to", "cc", "bcc", "sentAt", "receivedAt"]
      });
    
      if (!emails || emails.list.length === 0) {
        return {
          content: [{
            type: "text",
            text: `Error: Email with ID ${emailId} not found.`
          }],
          isError: true
        };
      }
    
      const email = emails.list[0];
    
      let bodyContent = 'No body content found.';
    
      const downloadBodyPartContent = async (bodyPart) => {
        if (!bodyPart || !bodyPart.blobId) {
          return null;
        }
        try {
          const response = await jam.downloadBlob({
            accountId,
            blobId: bodyPart.blobId,
            mimeType: bodyPart.type || 'application/octet-stream', // Use part type or a default
            fileName: bodyPart.name || 'body_part' // Use part name or a default
          });
          if (response.ok) {
            return response.text(); // Read the response body as text
          } else {
            console.error(`Failed to download blob ${bodyPart.blobId}: ${response.status} ${response.statusText}`);
            return null;
          }
        } catch (error) {
          console.error(`Error downloading blob ${bodyPart.blobId}:`, error);
          return null;
        }
      };
    
      // Prioritize text body, then HTML body
      if (email.textBody && email.textBody.length > 0) {
        // Assuming we only need the content of the first text part for simplicity
        const firstTextPart = email.textBody[0];
        const downloadedText = await downloadBodyPartContent(firstTextPart);
        if (downloadedText !== null) {
          bodyContent = downloadedText;
        }
      } else if (email.htmlBody && email.htmlBody.length > 0) {
         // Assuming we only need the content of the first html part for simplicity
        const firstHtmlPart = email.htmlBody[0];
        const downloadedHtml = await downloadBodyPartContent(firstHtmlPart);
         // Note: For HTML body, you might want to strip HTML tags for a text representation
        if (downloadedHtml !== null) {
          bodyContent = `[HTML Body - may contain tags]\n${downloadedHtml}`; // Indicate it's HTML
        }
      }
    
      return {
        content: [{
          type: "text",
          text: `Subject: ${email.subject || '(No Subject)'}\nFrom: ${email.from ? email.from.map(f => f.name ? `${f.name} <${f.email}>` : f.email).join(', ') : '(Unknown Sender)'}\nTo: ${email.to ? email.to.map(t => t.name ? `${t.name} <${t.email}>` : t.email).join(', ') : '(Unknown Recipient)'}\nDate: ${email.receivedAt || email.sentAt || '(Unknown Date)'}\n\n---\n\n${bodyContent}`
        }]
      };
    }
  • Input schema and description for the get_email_content tool, using Zod for validation of the emailId parameter.
    {
      description: "Retrieves the full content of an email by its ID, including subject, sender, recipients, date, and body (text or HTML).",
      inputSchema: z.object({
        emailId: z.string().describe("The ID of the email to fetch.")
      })
    },
  • index.js:229-230 (registration)
    Registration of the get_email_content tool on the MCP server via server.tool() call.
    server.tool(
      "get_email_content",
  • Nested helper function used by the handler to download email body part content from JMAP blobs.
    const downloadBodyPartContent = async (bodyPart) => {
      if (!bodyPart || !bodyPart.blobId) {
        return null;
      }
      try {
        const response = await jam.downloadBlob({
          accountId,
          blobId: bodyPart.blobId,
          mimeType: bodyPart.type || 'application/octet-stream', // Use part type or a default
          fileName: bodyPart.name || 'body_part' // Use part name or a default
        });
        if (response.ok) {
          return response.text(); // Read the response body as text
        } else {
          console.error(`Failed to download blob ${bodyPart.blobId}: ${response.status} ${response.statusText}`);
          return null;
        }
      } catch (error) {
        console.error(`Error downloading blob ${bodyPart.blobId}:`, error);
        return null;
      }
    };
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jahfer/jmap-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server