read_email
Retrieve and display the complete content of a Gmail message using its unique message ID for reading and analysis.
Instructions
Read the full content of an email
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| messageId | Yes | Email message ID |
Implementation Reference
- src/tools.ts:73-78 (handler)The handler function within handleToolCall that processes 'read_email' tool invocations: validates the input messageId, retrieves the email via GmailService, and formats a detailed response including subject, headers, URL, and body content.case "read_email": { const v = validated as z.infer<typeof schemas.read_email>; const email = await gmailService.readEmail(v.messageId); return { content: [{ type: "text", text: `Subject: ${email.subject}\nFrom: ${email.from}\nTo: ${email.to}\nDate: ${email.date}\nThread ID: ${email.threadId}\nGmail URL: ${gmailService.getEmailUrl(v.messageId)}\n\nContent:\n${email.body}` }] }; }
- src/tools.ts:10-10 (schema)Zod schema defining the input for the 'read_email' tool: requires a 'messageId' string parameter.read_email: z.object({ messageId: z.string().describe("Email message ID") }),
- src/tools.ts:50-55 (registration)Registration function that generates JSON schemas and descriptions for all MCP tools, including 'read_email', for protocol exposure.export const getToolDefinitions = () => Object.entries(schemas).map(([name, schema]) => ({ name, description: toolDescriptions[name], inputSchema: zodToJsonSchema(schema) }));
- src/gmail-service.ts:56-70 (helper)Helper method in GmailService that implements the core logic for fetching and parsing a full email message from Gmail API, extracting headers and body content.async readEmail(messageId: string): Promise<EmailDetails> { const { data } = await this.gmail.users.messages.get({ userId: 'me', id: messageId, format: 'full' }); const h = data.payload?.headers || []; const findHeader = (name: string) => h.find(x => x.name?.toLowerCase() === name.toLowerCase())?.value || ''; return { id: messageId, threadId: data.threadId || '', subject: findHeader('subject'), from: findHeader('from'), to: findHeader('to'), date: findHeader('date'), body: this.extractBody(data.payload) }; }
- src/gmail-service.ts:14-16 (schema)TypeScript interface defining the output structure for email details returned by readEmail, extending EmailInfo with body content.export interface EmailDetails extends EmailInfo { body: string; }