Skip to main content
Glama

send_message

Send email messages to recipients with options for subject, body, CC, BCC, and thread association using Gmail integration.

Instructions

Send an email message to specified recipients. Note the mechanics of the raw parameter.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
rawNoThe entire email message in base64url encoded RFC 2822 format, ignores params.to, cc, bcc, subject, body, includeBodyHtml if provided
threadIdNoThe thread ID to associate this message with
toNoList of recipient email addresses
ccNoList of CC recipient email addresses
bccNoList of BCC recipient email addresses
subjectNoThe subject of the email
bodyNoThe body of the email
includeBodyHtmlNoWhether to include the parsed HTML in the return for each body, excluded by default because they can be excessively large

Implementation Reference

  • The handler function for the 'send_message' tool. It constructs a raw email message if not provided using constructRawMessage, sends it via the Gmail API's users.messages.send method, processes the returned message payload to decode bodies and filter headers, and formats the response as JSON text content.
    async (params) => {
      return handleTool(config, async (gmail: gmail_v1.Gmail) => {
        let raw = params.raw
        if (!raw) raw = await constructRawMessage(gmail, params)
    
        const messageSendParams: MessageSendParams = { userId: 'me', requestBody: { raw } }
        if (params.threadId && messageSendParams.requestBody) {
          messageSendParams.requestBody.threadId = params.threadId
        }
    
        const { data } = await gmail.users.messages.send(messageSendParams)
    
        if (data.payload) {
          data.payload = processMessagePart(
            data.payload,
            params.includeBodyHtml
          )
        }
    
        return formatResponse(data)
      })
    }
  • Zod schema defining the input parameters for the 'send_message' tool, including optional raw message, threadId, recipients (to, cc, bcc), subject, body, and flag for including HTML body.
      raw: z.string().optional().describe("The entire email message in base64url encoded RFC 2822 format, ignores params.to, cc, bcc, subject, body, includeBodyHtml if provided"),
      threadId: z.string().optional().describe("The thread ID to associate this message with"),
      to: z.array(z.string()).optional().describe("List of recipient email addresses"),
      cc: z.array(z.string()).optional().describe("List of CC recipient email addresses"),
      bcc: z.array(z.string()).optional().describe("List of BCC recipient email addresses"),
      subject: z.string().optional().describe("The subject of the email"),
      body: z.string().optional().describe("The body of the email"),
      includeBodyHtml: z.boolean().optional().describe("Whether to include the parsed HTML in the return for each body, excluded by default because they can be excessively large")
    },
  • src/index.ts:626-660 (registration)
    Registration of the 'send_message' tool on the McpServer instance, including name, description, input schema, and handler function.
    server.tool("send_message",
      "Send an email message to specified recipients. Note the mechanics of the raw parameter.",
      {
        raw: z.string().optional().describe("The entire email message in base64url encoded RFC 2822 format, ignores params.to, cc, bcc, subject, body, includeBodyHtml if provided"),
        threadId: z.string().optional().describe("The thread ID to associate this message with"),
        to: z.array(z.string()).optional().describe("List of recipient email addresses"),
        cc: z.array(z.string()).optional().describe("List of CC recipient email addresses"),
        bcc: z.array(z.string()).optional().describe("List of BCC recipient email addresses"),
        subject: z.string().optional().describe("The subject of the email"),
        body: z.string().optional().describe("The body of the email"),
        includeBodyHtml: z.boolean().optional().describe("Whether to include the parsed HTML in the return for each body, excluded by default because they can be excessively large")
      },
      async (params) => {
        return handleTool(config, async (gmail: gmail_v1.Gmail) => {
          let raw = params.raw
          if (!raw) raw = await constructRawMessage(gmail, params)
    
          const messageSendParams: MessageSendParams = { userId: 'me', requestBody: { raw } }
          if (params.threadId && messageSendParams.requestBody) {
            messageSendParams.requestBody.threadId = params.threadId
          }
    
          const { data } = await gmail.users.messages.send(messageSendParams)
    
          if (data.payload) {
            data.payload = processMessagePart(
              data.payload,
              params.includeBodyHtml
            )
          }
    
          return formatResponse(data)
        })
      }
    )
  • Helper function to construct the raw base64url-encoded RFC 2822 email message from parameters, handling thread quoting, headers, and body wrapping.
    const constructRawMessage = async (gmail: gmail_v1.Gmail, params: NewMessage) => {
      let thread: Thread | null = null
      if (params.threadId) {
        const threadParams = { userId: 'me', id: params.threadId, format: 'full' }
        const { data } = await gmail.users.threads.get(threadParams)
        thread = data
      }
    
      const message = []
      if (params.to?.length) message.push(`To: ${wrapTextBody(params.to.join(', '))}`)
      if (params.cc?.length) message.push(`Cc: ${wrapTextBody(params.cc.join(', '))}`)
      if (params.bcc?.length) message.push(`Bcc: ${wrapTextBody(params.bcc.join(', '))}`)
      if (thread) {
        message.push(...getThreadHeaders(thread).map(header => wrapTextBody(header)))
      } else if (params.subject) {
        message.push(`Subject: ${wrapTextBody(params.subject)}`)
      } else {
        message.push('Subject: (No Subject)')
      }
      message.push('Content-Type: text/plain; charset="UTF-8"')
      message.push('Content-Transfer-Encoding: quoted-printable')
      message.push('MIME-Version: 1.0')
      message.push('')
    
      if (params.body) message.push(wrapTextBody(params.body))
    
      if (thread) {
        const quotedContent = getQuotedContent(thread)
        if (quotedContent) {
          message.push('')
          message.push(wrapTextBody(quotedContent))
        }
      }
    
      return Buffer.from(message.join('\r\n')).toString('base64url').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
    }
  • Shared helper function that handles OAuth2 authentication, client creation, and execution of Gmail API calls for all tools, with error handling.
    const handleTool = async (queryConfig: Record<string, any> | undefined, apiCall: (gmail: gmail_v1.Gmail) => Promise<any>) => {
      try {
        const oauth2Client = queryConfig ? createOAuth2Client(queryConfig) : defaultOAuth2Client
        if (!oauth2Client) throw new Error('OAuth2 client could not be created, please check your credentials')
    
        const credentialsAreValid = await validateCredentials(oauth2Client)
        if (!credentialsAreValid) throw new Error('OAuth2 credentials are invalid, please re-authenticate')
    
        const gmailClient = queryConfig ? google.gmail({ version: 'v1', auth: oauth2Client }) : defaultGmailClient
        if (!gmailClient) throw new Error('Gmail client could not be created, please check your credentials')
    
        const result = await apiCall(gmailClient)
        return result
      } catch (error: any) {
        return `Tool execution failed: ${error.message}`
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'the mechanics of the raw parameter' which hints at some complexity, but doesn't explain what those mechanics are, whether this is a synchronous or asynchronous operation, what permissions are required, whether it's rate-limited, or what happens on failure. For a mutation tool with significant parameters, this leaves critical behavioral aspects unspecified.

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

Conciseness4/5

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

The description is appropriately concise with two sentences. The first sentence clearly states the purpose, and the second sentence provides important technical context about parameter interaction. There's no wasted verbiage, though it could be slightly more structured by explicitly mentioning the parameter override behavior upfront.

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

Completeness3/5

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

Given the tool's complexity (8 parameters, mutation operation, no annotations, no output schema), the description is minimally adequate but incomplete. It covers the core purpose and a critical parameter interaction, but lacks information about behavioral aspects, error handling, return values, and usage context relative to siblings. For a send operation in a rich email API, more context would be helpful.

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

Parameters4/5

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

The description adds meaningful context about the raw parameter that goes beyond the schema's technical description. While the schema has 100% description coverage for all 8 parameters, the tool description highlights that 'raw' overrides other parameters (to, cc, bcc, subject, body, includeBodyHtml), which is crucial semantic information not evident from the schema alone. This compensates well for the high schema coverage.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Send an email message to specified recipients.' This is a specific verb+resource combination that distinguishes it from siblings like create_draft or send_draft. However, it doesn't explicitly differentiate from batch operations or other message-related tools beyond the basic function.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With siblings like send_draft, create_draft, batch_modify_messages, and modify_message, there's no indication of when this direct send operation is preferred over creating/sending drafts or using batch operations. The note about the raw parameter is technical, not usage guidance.

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/nk900600/gmail-mcp'

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