sendEvent
Track user actions by sending custom events to Mailmodo with email and event name, along with optional properties and timestamp for detailed analytics.
Instructions
Send custom events with email, event name and event properties
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| Yes | |||
| event_name | Yes | ||
| ts | No | ||
| event_properties | No |
Implementation Reference
- src/server.ts:118-151 (registration)Registers the 'sendEvent' tool on the MCP server with input schema (email, event_name, ts, event_properties) and handler that calls addMailmodoEvent.
server.tool( "sendEvent", "Send custom events with email, event name and event properties", { email: z.string(), event_name: z.string(), ts: z.number().optional(), event_properties: eventPropertiesSchema.optional(), }, async (params) => { try { const respone = await addMailmodoEvent(mmApiKey,params); // Here you would typically integrate with your event sending system // For example: eventBus.emit(eventName, eventData) // For demonstration, we'll just return a success message return { content: [{ type: "text", text: respone.success?`Successfully sent event '${params.event_name}' for email ${params.email} with payload: ${JSON.stringify(params.event_properties)} with reference id ${respone.ref}`: `Something went wrong. Please check if the email is correct`, }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : "Failed to send event", }], isError: true }; } } ); - src/apicalls/sendEvents.ts:13-45 (handler)Executes the actual event-sending logic by POSTing to Mailmodo's /addEvent API endpoint with axios.
export async function addMailmodoEvent( mmApiKey: string, payload: MailmodoEvent ): Promise<AddCustomeEventResponse> { if (!payload.email || !payload.event_name) { throw new Error('Email and event_name are required fields'); } try { const response = await axios.post<AddCustomeEventResponse>( 'https://api.mailmodo.com/api/v1/addEvent', { ...payload, ts: payload.ts || Math.floor(Date.now() / 1000) }, { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'mmApiKey': mmApiKey || '' } } ); return response.data; } catch (error) { if (error instanceof AxiosError) { return {success: false} } throw new Error('An unexpected error occurred'); } } - Type definition for the MailmodoEvent payload used by addMailmodoEvent.
export interface MailmodoEvent { email: string; event_name: string; ts?: number; event_properties?: EventProperties; } export const eventPropertiesSchema = z.record( z.union([ z.string(), z.number(), z.boolean(), z.undefined() ]) ); export interface AddCustomeEventResponse { // Define your expected response structure here success: boolean; ref?: string; } - Zod schema for event_properties used in the sendEvent tool's input validation.
export const eventPropertiesSchema = z.record( z.union([ z.string(), z.number(), z.boolean(), z.undefined() ]) ); - Response type returned by the Mailmodo API for event sending.
export interface AddCustomeEventResponse { // Define your expected response structure here success: boolean; ref?: string; }