Skip to main content
Glama

gmail-send-email

Send emails through Gmail by specifying recipients, subject, and body content. Use this tool to automate email dispatch from the MCP Server Boilerplate.

Instructions

Send an email using Gmail

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toYesRecipient email address
subjectYesEmail subject
bodyYesEmail body content
ccNoCC email addresses (comma-separated)
bccNoBCC email addresses (comma-separated)

Implementation Reference

  • The core handler function that implements the gmail-send-email tool logic using Google Gmail API to send an email.
    export async function sendEmail(params: z.infer<typeof sendEmailSchema>) {
      try {
        const auth = createGmailAuth();
        const gmail = google.gmail({ version: "v1", auth });
    
        // Create email content
        const email = [];
        email.push(`To: ${params.to}`);
        if (params.cc) email.push(`Cc: ${params.cc}`);
        if (params.bcc) email.push(`Bcc: ${params.bcc}`);
        email.push(`Subject: ${params.subject}`);
        email.push("");
        email.push(params.body);
    
        const rawEmail = Buffer.from(email.join("\n")).toString("base64url");
    
        const response = await gmail.users.messages.send({
          userId: "me",
          requestBody: {
            raw: rawEmail,
          },
        });
    
        return {
          content: [
            {
              type: "text" as const,
              text: `# Email Sent Successfully ✅\n\nMessage ID: \`${response.data.id}\`  \nThread ID: \`${response.data.threadId}\`  \nTo: ${params.to}  \nSubject: ${params.subject}`,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text" as const,
              text: `Error sending email: ${
                error instanceof Error ? error.message : String(error)
              }`,
            },
          ],
        };
      }
    }
  • Zod schema defining the input parameters for the sendEmail function.
    export const sendEmailSchema = z.object({
      to: z.string().describe("Recipient email address"),
      subject: z.string().describe("Email subject"),
      body: z.string().describe("Email body content"),
      cc: z.string().optional().describe("CC email addresses (comma-separated)"),
      bcc: z.string().optional().describe("BCC email addresses (comma-separated)"),
    });
  • src/index.ts:182-189 (registration)
    Tool registration in the MCP server, linking the name 'gmail-send-email' to the sendEmail handler and schema.
    server.tool(
      "gmail-send-email",
      "Send an email using Gmail",
      sendEmailSchema.shape,
      async (params) => {
        return await sendEmail(params);
      }
    );
  • Helper function to create and configure OAuth2 authentication client for accessing Gmail API.
    function createGmailAuth() {
      const clientId = process.env.GOOGLE_CLIENT_ID;
      const clientSecret = process.env.GOOGLE_CLIENT_SECRET;
      const redirectUri =
        process.env.GOOGLE_REDIRECT_URI || "http://localhost:3000/oauth2callback";
    
      if (!clientId || !clientSecret) {
        throw new Error(
          "GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET are required. Run oauth-setup.js to configure."
        );
      }
    
      const oauth2Client = new google.auth.OAuth2(
        clientId,
        clientSecret,
        redirectUri
      );
    
      const accessToken = process.env.GOOGLE_ACCESS_TOKEN;
      const refreshToken = process.env.GOOGLE_REFRESH_TOKEN;
    
      if (!accessToken || !refreshToken) {
        throw new Error("OAuth2 tokens missing. Run oauth-setup.js to get tokens.");
      }
    
      oauth2Client.setCredentials({
        access_token: accessToken,
        refresh_token: refreshToken,
      });
    
      return oauth2Client;
    }
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 states the action ('Send an email') but lacks critical details: it doesn't mention authentication requirements, potential rate limits, whether the email is sent immediately or queued, or what happens on failure. For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

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

Conciseness5/5

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

The description is a single, efficient sentence with zero wasted words. It's front-loaded with the core action and resource, making it immediately scannable and appropriately sized for the tool's complexity.

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

Completeness2/5

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

Given the tool's complexity (a mutation operation with 5 parameters) and the lack of annotations and output schema, the description is incomplete. It doesn't address authentication, error handling, return values, or behavioral constraints, leaving the agent with insufficient context for reliable use.

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

Parameters3/5

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

The input schema has 100% description coverage, with each parameter clearly documented (e.g., 'to' as 'Recipient email address'). The description adds no additional parameter semantics beyond what the schema provides, so it meets the baseline of 3 for adequate coverage without extra value.

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 'Send an email using Gmail' clearly states the verb ('Send') and resource ('email using Gmail'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'gmail-get-email' or 'gmail-read-emails' beyond the obvious action difference, which keeps it from a perfect score.

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. It doesn't mention prerequisites (e.g., authentication needs), when it's appropriate compared to other email-related tools, or any exclusions. This leaves the agent with minimal context for decision-making.

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/CaptainCrouton89/maps-mcp'

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