Skip to main content
Glama
MadLlama25

Fastmail MCP Server

by MadLlama25

get_contact

Retrieve a specific contact from Fastmail using its unique ID to access contact details stored in your account.

Instructions

Get a specific contact by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contactIdYesID of the contact to retrieve

Implementation Reference

  • MCP tool handler for 'get_contact' that validates input, initializes ContactsCalendarClient, calls getContactById, and returns the contact as JSON.
    case 'get_contact': {
      const { contactId } = args as any;
      if (!contactId) {
        throw new McpError(ErrorCode.InvalidParams, 'contactId is required');
      }
      const contactsClient = initializeContactsCalendarClient();
      const contact = await contactsClient.getContactById(contactId);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(contact, null, 2),
          },
        ],
      };
    }
  • Input schema definition for the 'get_contact' tool, specifying required 'contactId' parameter.
    {
      name: 'get_contact',
      description: 'Get a specific contact by ID',
      inputSchema: {
        type: 'object',
        properties: {
          contactId: {
            type: 'string',
            description: 'ID of the contact to retrieve',
          },
        },
        required: ['contactId'],
      },
    },
  • Core implementation of contact retrieval via JMAP Contact/get method in ContactsCalendarClient, including permission check.
    async getContactById(id: string): Promise<any> {
      // Check permissions first
      const hasPermission = await this.checkContactsPermission();
      if (!hasPermission) {
        throw new Error('Contacts access not available. This account may not have JMAP contacts permissions enabled. Please check your Fastmail account settings or contact support to enable contacts API access.');
      }
    
      const session = await this.getSession();
      
      const request: JmapRequest = {
        using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:contacts'],
        methodCalls: [
          ['Contact/get', {
            accountId: session.accountId,
            ids: [id]
          }, 'contact']
        ]
      };
    
      try {
        const response = await this.makeRequest(request);
        return response.methodResponses[0][1].list[0];
      } catch (error) {
        throw new Error(`Contact access not supported: ${error instanceof Error ? error.message : String(error)}. Try checking account permissions or enabling contacts API access in Fastmail settings.`);
      }
    }
  • Factory function to initialize singleton ContactsCalendarClient instance used by contact-related tools.
    function initializeContactsCalendarClient(): ContactsCalendarClient {
      if (contactsCalendarClient) {
        return contactsCalendarClient;
      }
    
      const tokenInfo = findEnvValue([
        'FASTMAIL_API_TOKEN',
        'USER_CONFIG_FASTMAIL_API_TOKEN',
        'USER_CONFIG_fastmail_api_token',
        'fastmail_api_token',
      ]);
      // production: do not log token-related env details (contacts/calendar)
      const apiToken = tokenInfo.value;
      if (!apiToken) {
        throw new McpError(
          ErrorCode.InvalidRequest,
          'FASTMAIL_API_TOKEN environment variable is required'
        );
      }
    
      const baseInfo = findEnvValue([
        'FASTMAIL_BASE_URL',
        'USER_CONFIG_FASTMAIL_BASE_URL',
        'USER_CONFIG_fastmail_base_url',
        'fastmail_base_url',
      ]);
      // production: do not log base URL env details (contacts/calendar)
    
      const config: FastmailConfig = {
        apiToken,
        baseUrl: baseInfo.value
      };
    
      const auth = new FastmailAuth(config);
      contactsCalendarClient = new ContactsCalendarClient(auth);
      return contactsCalendarClient;
    }
  • src/index.ts:135-652 (registration)
    Registration of all tools including 'get_contact' via ListToolsRequestSchema handler returning the tools list.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: 'list_mailboxes',
            description: 'List all mailboxes in the Fastmail account',
            inputSchema: {
              type: 'object',
              properties: {},
            },
          },
          {
            name: 'list_emails',
            description: 'List emails from a mailbox',
            inputSchema: {
              type: 'object',
              properties: {
                mailboxId: {
                  type: 'string',
                  description: 'ID of the mailbox to list emails from (optional, defaults to all)',
                },
                limit: {
                  type: 'number',
                  description: 'Maximum number of emails to return (default: 20)',
                  default: 20,
                },
              },
            },
          },
          {
            name: 'get_email',
            description: 'Get a specific email by ID',
            inputSchema: {
              type: 'object',
              properties: {
                emailId: {
                  type: 'string',
                  description: 'ID of the email to retrieve',
                },
              },
              required: ['emailId'],
            },
          },
          {
            name: 'send_email',
            description: 'Send an email',
            inputSchema: {
              type: 'object',
              properties: {
                to: {
                  type: 'array',
                  items: { type: 'string' },
                  description: 'Recipient email addresses',
                },
                cc: {
                  type: 'array',
                  items: { type: 'string' },
                  description: 'CC email addresses (optional)',
                },
                bcc: {
                  type: 'array',
                  items: { type: 'string' },
                  description: 'BCC email addresses (optional)',
                },
                from: {
                  type: 'string',
                  description: 'Sender email address (optional, defaults to account primary email)',
                },
                mailboxId: {
                  type: 'string',
                  description: 'Mailbox ID to save the email to (optional, defaults to Drafts folder)',
                },
                subject: {
                  type: 'string',
                  description: 'Email subject',
                },
                textBody: {
                  type: 'string',
                  description: 'Plain text body (optional)',
                },
                htmlBody: {
                  type: 'string',
                  description: 'HTML body (optional)',
                },
              },
              required: ['to', 'subject'],
            },
          },
          {
            name: 'search_emails',
            description: 'Search emails by subject or content',
            inputSchema: {
              type: 'object',
              properties: {
                query: {
                  type: 'string',
                  description: 'Search query string',
                },
                limit: {
                  type: 'number',
                  description: 'Maximum number of results (default: 20)',
                  default: 20,
                },
              },
              required: ['query'],
            },
          },
          {
            name: 'list_contacts',
            description: 'List contacts from the address book',
            inputSchema: {
              type: 'object',
              properties: {
                limit: {
                  type: 'number',
                  description: 'Maximum number of contacts to return (default: 50)',
                  default: 50,
                },
              },
            },
          },
          {
            name: 'get_contact',
            description: 'Get a specific contact by ID',
            inputSchema: {
              type: 'object',
              properties: {
                contactId: {
                  type: 'string',
                  description: 'ID of the contact to retrieve',
                },
              },
              required: ['contactId'],
            },
          },
          {
            name: 'search_contacts',
            description: 'Search contacts by name or email',
            inputSchema: {
              type: 'object',
              properties: {
                query: {
                  type: 'string',
                  description: 'Search query string',
                },
                limit: {
                  type: 'number',
                  description: 'Maximum number of results (default: 20)',
                  default: 20,
                },
              },
              required: ['query'],
            },
          },
          {
            name: 'list_calendars',
            description: 'List all calendars',
            inputSchema: {
              type: 'object',
              properties: {},
            },
          },
          {
            name: 'list_calendar_events',
            description: 'List events from a calendar',
            inputSchema: {
              type: 'object',
              properties: {
                calendarId: {
                  type: 'string',
                  description: 'ID of the calendar (optional, defaults to all calendars)',
                },
                limit: {
                  type: 'number',
                  description: 'Maximum number of events to return (default: 50)',
                  default: 50,
                },
              },
            },
          },
          {
            name: 'get_calendar_event',
            description: 'Get a specific calendar event by ID',
            inputSchema: {
              type: 'object',
              properties: {
                eventId: {
                  type: 'string',
                  description: 'ID of the event to retrieve',
                },
              },
              required: ['eventId'],
            },
          },
          {
            name: 'create_calendar_event',
            description: 'Create a new calendar event',
            inputSchema: {
              type: 'object',
              properties: {
                calendarId: {
                  type: 'string',
                  description: 'ID of the calendar to create the event in',
                },
                title: {
                  type: 'string',
                  description: 'Event title',
                },
                description: {
                  type: 'string',
                  description: 'Event description (optional)',
                },
                start: {
                  type: 'string',
                  description: 'Start time in ISO 8601 format',
                },
                end: {
                  type: 'string',
                  description: 'End time in ISO 8601 format',
                },
                location: {
                  type: 'string',
                  description: 'Event location (optional)',
                },
                participants: {
                  type: 'array',
                  items: {
                    type: 'object',
                    properties: {
                      email: { type: 'string' },
                      name: { type: 'string' }
                    }
                  },
                  description: 'Event participants (optional)',
                },
              },
              required: ['calendarId', 'title', 'start', 'end'],
            },
          },
          {
            name: 'list_identities',
            description: 'List sending identities (email addresses that can be used for sending)',
            inputSchema: {
              type: 'object',
              properties: {},
            },
          },
          {
            name: 'get_recent_emails',
            description: 'Get the most recent emails from inbox (like top-ten)',
            inputSchema: {
              type: 'object',
              properties: {
                limit: {
                  type: 'number',
                  description: 'Number of recent emails to retrieve (default: 10, max: 50)',
                  default: 10,
                },
                mailboxName: {
                  type: 'string',
                  description: 'Mailbox to search (default: inbox)',
                  default: 'inbox',
                },
              },
            },
          },
          {
            name: 'mark_email_read',
            description: 'Mark an email as read or unread',
            inputSchema: {
              type: 'object',
              properties: {
                emailId: {
                  type: 'string',
                  description: 'ID of the email to mark',
                },
                read: {
                  type: 'boolean',
                  description: 'true to mark as read, false to mark as unread',
                  default: true,
                },
              },
              required: ['emailId'],
            },
          },
          {
            name: 'delete_email',
            description: 'Delete an email (move to trash)',
            inputSchema: {
              type: 'object',
              properties: {
                emailId: {
                  type: 'string',
                  description: 'ID of the email to delete',
                },
              },
              required: ['emailId'],
            },
          },
          {
            name: 'move_email',
            description: 'Move an email to a different mailbox',
            inputSchema: {
              type: 'object',
              properties: {
                emailId: {
                  type: 'string',
                  description: 'ID of the email to move',
                },
                targetMailboxId: {
                  type: 'string',
                  description: 'ID of the target mailbox',
                },
              },
              required: ['emailId', 'targetMailboxId'],
            },
          },
          {
            name: 'get_email_attachments',
            description: 'Get list of attachments for an email',
            inputSchema: {
              type: 'object',
              properties: {
                emailId: {
                  type: 'string',
                  description: 'ID of the email',
                },
              },
              required: ['emailId'],
            },
          },
          {
            name: 'download_attachment',
            description: 'Download an email attachment',
            inputSchema: {
              type: 'object',
              properties: {
                emailId: {
                  type: 'string',
                  description: 'ID of the email',
                },
                attachmentId: {
                  type: 'string',
                  description: 'ID of the attachment',
                },
              },
              required: ['emailId', 'attachmentId'],
            },
          },
          {
            name: 'advanced_search',
            description: 'Advanced email search with multiple criteria',
            inputSchema: {
              type: 'object',
              properties: {
                query: {
                  type: 'string',
                  description: 'Text to search for in subject/body',
                },
                from: {
                  type: 'string',
                  description: 'Filter by sender email',
                },
                to: {
                  type: 'string',
                  description: 'Filter by recipient email',
                },
                subject: {
                  type: 'string',
                  description: 'Filter by subject',
                },
                hasAttachment: {
                  type: 'boolean',
                  description: 'Filter emails with attachments',
                },
                isUnread: {
                  type: 'boolean',
                  description: 'Filter unread emails',
                },
                mailboxId: {
                  type: 'string',
                  description: 'Search within specific mailbox',
                },
                after: {
                  type: 'string',
                  description: 'Emails after this date (ISO 8601)',
                },
                before: {
                  type: 'string',
                  description: 'Emails before this date (ISO 8601)',
                },
                limit: {
                  type: 'number',
                  description: 'Maximum results (default: 50)',
                  default: 50,
                },
              },
            },
          },
          {
            name: 'get_thread',
            description: 'Get all emails in a conversation thread',
            inputSchema: {
              type: 'object',
              properties: {
                threadId: {
                  type: 'string',
                  description: 'ID of the thread/conversation',
                },
              },
              required: ['threadId'],
            },
          },
          {
            name: 'get_mailbox_stats',
            description: 'Get statistics for a mailbox (unread count, total emails, etc.)',
            inputSchema: {
              type: 'object',
              properties: {
                mailboxId: {
                  type: 'string',
                  description: 'ID of the mailbox (optional, defaults to all mailboxes)',
                },
              },
            },
          },
          {
            name: 'get_account_summary',
            description: 'Get overall account summary with statistics',
            inputSchema: {
              type: 'object',
              properties: {},
            },
          },
          {
            name: 'bulk_mark_read',
            description: 'Mark multiple emails as read/unread',
            inputSchema: {
              type: 'object',
              properties: {
                emailIds: {
                  type: 'array',
                  items: { type: 'string' },
                  description: 'Array of email IDs to mark',
                },
                read: {
                  type: 'boolean',
                  description: 'true to mark as read, false as unread',
                  default: true,
                },
              },
              required: ['emailIds'],
            },
          },
          {
            name: 'bulk_move',
            description: 'Move multiple emails to a mailbox',
            inputSchema: {
              type: 'object',
              properties: {
                emailIds: {
                  type: 'array',
                  items: { type: 'string' },
                  description: 'Array of email IDs to move',
                },
                targetMailboxId: {
                  type: 'string',
                  description: 'ID of target mailbox',
                },
              },
              required: ['emailIds', 'targetMailboxId'],
            },
          },
          {
            name: 'bulk_delete',
            description: 'Delete multiple emails (move to trash)',
            inputSchema: {
              type: 'object',
              properties: {
                emailIds: {
                  type: 'array',
                  items: { type: 'string' },
                  description: 'Array of email IDs to delete',
                },
              },
              required: ['emailIds'],
            },
          },
          {
            name: 'check_function_availability',
            description: 'Check which MCP functions are available based on account permissions',
            inputSchema: {
              type: 'object',
              properties: {},
            },
          },
          {
            name: 'test_bulk_operations',
            description: 'Test bulk operations by finding recent emails and performing safe operations (mark read/unread)',
            inputSchema: {
              type: 'object',
              properties: {
                dryRun: {
                  type: 'boolean',
                  description: 'If true, only shows what would be done without making changes (default: true)',
                  default: true,
                },
                limit: {
                  type: 'number',
                  description: 'Number of emails to test with (default: 3, max: 10)',
                  default: 3,
                },
              },
            },
          },
        ],
      };
    });

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/MadLlama25/fastmail-mcp'

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