Skip to main content
Glama

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
NameRequiredDescriptionDefault
messageIdYesEmail message ID

Implementation Reference

  • 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}` }] }; }
  • 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) }));
  • 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) }; }
  • TypeScript interface defining the output structure for email details returned by readEmail, extending EmailInfo with body content.
    export interface EmailDetails extends EmailInfo { body: string; }

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/muammar-yacoob/GMail-Manager-MCP'

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