Skip to main content
Glama
mundume
by mundume

sendEmail

Send emails directly from Gmail by specifying recipient, subject, and body content for communication and note management.

Instructions

Send an email from Gmail.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toYesRecipient email address.
subjectYesEmail subject.
bodyYesEmail body.

Implementation Reference

  • The main handler function for sendEmail that validates input, constructs a raw email message, encodes it in base64 URL-safe format, and sends it via Gmail API
    case "sendEmail": {
      if (!GMAIL_API_KEY) {
        return { content: [{ type: "text", text: "API Key not set." }] };
      }
    
      try {
        const { to, subject, body } = SendEmailSchema.parse(
          request.params.arguments
        );
    
        let emailHeaders = `To: ${to}\r\nSubject: ${subject}\r\nContent-Type: text/plain; charset=utf-8\r\n\r\n`;
    
        const raw = Buffer.from(emailHeaders + body)
          .toString("base64")
          .replace(/\+/g, "-")
          .replace(/\//g, "_")
          .replace(/=+$/, "");
    
        console.log("Raw message:", raw);
    
        const response = await fetch(
          `https://gmail.googleapis.com/gmail/v1/users/${GMAIL_USER_ID}/messages/send`,
          {
            method: "POST",
            headers: {
              "Content-Type": "application/json",
              Authorization: `Bearer ${GMAIL_API_KEY}`,
            },
            body: JSON.stringify({ raw: raw }),
          }
        );
    
        if (!response.ok) {
          const errorData = await response.json();
          console.error("Gmail API Error:", errorData); // Debugging: Log the full error
          const errorMessage = errorData.error?.message || response.statusText;
          return {
            content: [{ type: "text", text: `Error: ${errorMessage}` }],
          };
        }
    
        return {
          content: [{ type: "text", text: "Email sent successfully." }],
        };
      } catch (error: any) {
        return { content: [{ type: "text", text: `Error: ${error.message}` }] };
      }
    }
  • Zod schema definition for sendEmail tool input validation, defining required fields: to (email), subject (string), and body (string)
    const SendEmailSchema = z.object({
      to: z.string().email().describe("Recipient email address."),
      subject: z.string().describe("Email subject."),
      body: z.string().describe("Email body."),
    });
  • src/index.ts:70-74 (registration)
    Tool registration in the MCP server's ListToolsRequestSchema handler, exposing sendEmail with its description and input schema
    {
      name: "sendEmail",
      description: "Send an email from Gmail.",
      inputSchema: zodToJsonSchema(SendEmailSchema),
    },
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic action. It doesn't disclose behavioral traits such as authentication requirements, rate limits, whether emails are sent immediately or queued, or potential side effects like saving drafts.

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 extremely concise with a single sentence that directly states the tool's function. It's front-loaded with no wasted words, making it easy to parse quickly.

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?

For a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't address important context like authentication needs, error handling, or what happens after sending. Given the complexity of email sending, more behavioral disclosure is needed.

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, so parameters are fully documented there. The description adds no additional meaning beyond the schema, which already explains 'to', 'subject', and 'body'. Baseline 3 is appropriate when schema does the heavy lifting.

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 action ('Send') and resource ('email from Gmail'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'getEmailContent' or 'listEmails', which are read operations versus this write operation.

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 like authentication, compare to siblings, or specify scenarios where sending is appropriate versus reading emails.

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

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