Skip to main content
Glama
kmexnx
by kmexnx

send_invoice_email

Send professional invoices via email by providing invoice data and recipient email address. Create PDF invoices with customizable email subjects and messages for business transactions.

Instructions

Create and send an invoice via email

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
invoice_dataYesComplete invoice data including company info, bill-to info, items, etc.
recipient_emailYesEmail address to send the invoice to
subjectNoOptional custom email subject
messageNoOptional custom email message body

Implementation Reference

  • The function implementing the actual email sending logic for the 'send_invoice_email' tool.
    export async function sendInvoiceEmail(
      invoiceData: InvoiceData,
      recipientEmail: string,
      customSubject?: string,
      customMessage?: string
    ): Promise<void> {
      // Check if email configuration is available
      const smtpConfig = {
        host: process.env.SMTP_HOST,
        port: parseInt(process.env.SMTP_PORT || '587'),
        secure: false,
        auth: {
          user: process.env.SMTP_USER,
          pass: process.env.SMTP_PASS,
        },
      };
    
      if (!smtpConfig.host || !smtpConfig.auth.user || !smtpConfig.auth.pass) {
        throw new Error('Email configuration missing. Please set SMTP_HOST, SMTP_USER, and SMTP_PASS environment variables.');
      }
    
      // Generate PDF
      const pdfPath = await generateInvoicePDF(invoiceData);
      const pdfBuffer = await fs.readFile(pdfPath);
    
      // Create transporter (fixed method name)
      const transporter = nodemailer.createTransport(smtpConfig);
    
      // Email content
      const subject = customSubject || `Invoice ${invoiceData.invoiceNumber} from ${invoiceData.company.name}`;
      
      const defaultMessage = `Dear ${invoiceData.billTo.name},
    
    Please find attached invoice ${invoiceData.invoiceNumber} dated ${invoiceData.date}.
    
    ${invoiceData.dueDate ? `Payment is due by ${invoiceData.dueDate}.` : ''}
    
    If you have any questions regarding this invoice, please don't hesitate to contact us.
    
    Thank you for your business!
    
    Best regards,
    ${invoiceData.company.name}
    ${invoiceData.company.phone ? `Phone: ${invoiceData.company.phone}` : ''}
    ${invoiceData.company.email ? `Email: ${invoiceData.company.email}` : ''}`;
    
      const message = customMessage || defaultMessage;
    
      // Send email
      const mailOptions = {
        from: {
          name: process.env.FROM_NAME || invoiceData.company.name,
          address: process.env.FROM_EMAIL || process.env.SMTP_USER!,
        },
        to: recipientEmail,
        subject,
        text: message,
        attachments: [
          {
            filename: `invoice-${invoiceData.invoiceNumber}.pdf`,
            content: pdfBuffer,
            contentType: 'application/pdf',
          },
        ],
      };
    
      await transporter.sendMail(mailOptions);
    
      // Clean up temporary PDF file
      try {
        await fs.unlink(pdfPath);
      } catch (error) {
        // Ignore cleanup errors
        console.warn('Failed to clean up temporary PDF file:', error);
      }
    }
  • src/index.ts:159-175 (registration)
    The handler in the MCP server setup that invokes the 'sendInvoiceEmail' service function.
    case 'send_invoice_email': {
      const invoiceData = InvoiceDataSchema.parse(args.invoice_data);
      const recipientEmail = args.recipient_email as string;
      const subject = args.subject as string | undefined;
      const message = args.message as string | undefined;
      
      await sendInvoiceEmail(invoiceData, recipientEmail, subject, message);
      
      return {
        content: [
          {
            type: 'text',
            text: `Invoice sent successfully to ${recipientEmail}`,
          },
        ],
      };
    }
  • The MCP tool definition and input schema for 'send_invoice_email'.
      name: 'send_invoice_email',
      description: 'Create and send an invoice via email',
      inputSchema: {
        type: 'object',
        properties: {
          invoice_data: {
            type: 'object',
            description: 'Complete invoice data including company info, bill-to info, items, etc.',
          },
          recipient_email: {
            type: 'string',
            description: 'Email address to send the invoice to',
          },
          subject: {
            type: 'string',
            description: 'Optional custom email subject',
          },
          message: {
            type: 'string',
            description: 'Optional custom email message body',
          },
        },
        required: ['invoice_data', 'recipient_email'],
      },
    },
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 fails to disclose critical behavioral traits: that sending email triggers external irreversible actions, potential for duplicate sends if retried, delivery status limitations, or authentication requirements.

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?

Extremely concise at seven words with no redundancy. However, the brevity constitutes under-specification rather than efficient information density given 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?

Inadequate for a 4-parameter mutation tool with nested objects and external side effects. No output schema, no annotations, and minimal description leaves significant gaps in understanding prerequisites, error cases, and return behavior.

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?

Schema coverage is 100% with clear descriptions for all four parameters. The tool description adds no parameter-specific guidance beyond the schema, which warrants the baseline score of 3 for high-coverage schemas.

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

Purpose3/5

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

The description states the core action (create and send) and medium (email), but lacks specificity about the invoice content/structure and does not explicitly differentiate from sibling 'create_invoice_pdf' which presumably also creates invoices but does not send them.

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?

No guidance provided on when to use this versus 'create_invoice_pdf' or prerequisites like invoice validation. No mention of idempotency concerns for email sending or retry behavior.

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/kmexnx/invoice-mcp-server'

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