Skip to main content
Glama
klodr

mercury-invoicing-mcp

mercury_create_invoice

Create a new invoice for an existing Mercury customer. Optionally email it immediately with a payment link.

Instructions

Create a new invoice (one-shot or to be sent recurrently). Requires AR write scope.

USE WHEN: billing a customer that already exists in Mercury (customerId from mercury_create_customer or mercury_list_customers). Set sendEmailOption: "SendNow" to email the invoice immediately to the customer's contact email.

DO NOT USE: when the customer does not exist yet (call mercury_create_customer first). To attach a file to the invoice, use the Mercury web app at creation time — the API attachment-upload endpoint is not exposed by this MCP currently.

SIDE EFFECTS: writes a new invoice to Mercury. Persistent. With sendEmailOption: "SendNow" (the default), Mercury also sends a real email with a payment link to the customer — confirm the customer's email and the line items before calling. Mercury Plus tier required for the AR write scope.

RETURNS: { id, status, amount, paymentUrl, ... }paymentUrl is the Mercury-hosted page where the customer pays.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
customerIdYesCustomer ID (created via mercury_create_customer)
destinationAccountIdYesMercury account ID where invoice payments will be deposited
invoiceDateYesInvoice date (YYYY-MM-DD)
dueDateYesDue date (YYYY-MM-DD)
lineItemsYesInvoice line items
achDebitEnabledNoAllow ACH debit payments. Default: true
creditCardEnabledNoAllow credit card payments. Default: true
useRealAccountNumberNoShow real (vs virtual) account number on the invoice. Default: false
ccEmailsNoCC emails for notifications
sendEmailOptionNoWhether to email the invoice immediately. Default: SendNow
invoiceNumberNoCustomer-facing invoice number (≤255 chars; Mercury rejects 300+ characters on the edit endpoint)
poNumberNoPurchase order number
payerMemoNoMemo shown to payer
internalNoteNoNote visible only to your org
servicePeriodStartDateNoService period start (YYYY-MM-DD)
servicePeriodEndDateNoService period end (YYYY-MM-DD)

Implementation Reference

  • The handler function for mercury_create_invoice. Defined via defineTool on line 79-140. It accepts customerId, destinationAccountId, invoiceDate, dueDate, lineItems, and optional fields, then POSTs to /ar/invoices with the provided body.
    defineTool(
      server,
      "mercury_create_invoice",
      [
        "Create a new invoice (one-shot or to be sent recurrently). Requires AR write scope.",
        "",
        'USE WHEN: billing a customer that already exists in Mercury (`customerId` from `mercury_create_customer` or `mercury_list_customers`). Set `sendEmailOption: "SendNow"` to email the invoice immediately to the customer\'s contact email.',
        "",
        "DO NOT USE: when the customer does not exist yet (call `mercury_create_customer` first). To attach a file to the invoice, use the Mercury web app at creation time — the API attachment-upload endpoint is not exposed by this MCP currently.",
        "",
        'SIDE EFFECTS: writes a new invoice to Mercury. Persistent. With `sendEmailOption: "SendNow"` (the default), Mercury also sends a real email with a payment link to the customer — confirm the customer\'s email and the line items before calling. Mercury Plus tier required for the AR write scope.',
        "",
        "RETURNS: `{ id, status, amount, paymentUrl, ... }` — `paymentUrl` is the Mercury-hosted page where the customer pays.",
      ].join("\n"),
      {
        customerId: z.uuid().describe("Customer ID (created via mercury_create_customer)"),
        destinationAccountId: z
          .uuid()
          .describe("Mercury account ID where invoice payments will be deposited"),
        invoiceDate: z.iso.date().describe("Invoice date (YYYY-MM-DD)"),
        dueDate: z.iso.date().describe("Due date (YYYY-MM-DD)"),
        lineItems: z.array(lineItemSchema).min(1).describe("Invoice line items"),
        achDebitEnabled: z.boolean().optional().describe("Allow ACH debit payments. Default: true"),
        creditCardEnabled: z
          .boolean()
          .optional()
          .describe("Allow credit card payments. Default: true"),
        useRealAccountNumber: z
          .boolean()
          .optional()
          .describe("Show real (vs virtual) account number on the invoice. Default: false"),
        ccEmails: z.array(z.email()).optional().describe("CC emails for notifications"),
        sendEmailOption: z
          .enum(["DontSend", "SendNow"])
          .optional()
          .describe("Whether to email the invoice immediately. Default: SendNow"),
        invoiceNumber: z
          .string()
          .max(255)
          .optional()
          .describe(
            "Customer-facing invoice number (≤255 chars; Mercury rejects 300+ characters on the edit endpoint)",
          ),
        poNumber: z.string().optional().describe("Purchase order number"),
        payerMemo: z.string().optional().describe("Memo shown to payer"),
        internalNote: z.string().optional().describe("Note visible only to your org"),
        servicePeriodStartDate: z.iso.date().optional().describe("Service period start (YYYY-MM-DD)"),
        servicePeriodEndDate: z.iso.date().optional().describe("Service period end (YYYY-MM-DD)"),
      },
      async (args) => {
        const body = {
          ...args,
          achDebitEnabled: args.achDebitEnabled ?? true,
          creditCardEnabled: args.creditCardEnabled ?? true,
          useRealAccountNumber: args.useRealAccountNumber ?? false,
          ccEmails: args.ccEmails ?? [],
        };
        const data = await client.post("/ar/invoices", body);
        return textResult(data);
      },
      { title: "Create Invoice", destructiveHint: false, openWorldHint: true },
    );
  • Zod input schema for mercury_create_invoice. Defines all input parameters: customerId, destinationAccountId, invoiceDate, dueDate, lineItems (array of lineItemSchema), plus optional fields like sendEmailOption, ccEmails, etc.
    {
      customerId: z.uuid().describe("Customer ID (created via mercury_create_customer)"),
      destinationAccountId: z
        .uuid()
        .describe("Mercury account ID where invoice payments will be deposited"),
      invoiceDate: z.iso.date().describe("Invoice date (YYYY-MM-DD)"),
      dueDate: z.iso.date().describe("Due date (YYYY-MM-DD)"),
      lineItems: z.array(lineItemSchema).min(1).describe("Invoice line items"),
      achDebitEnabled: z.boolean().optional().describe("Allow ACH debit payments. Default: true"),
      creditCardEnabled: z
        .boolean()
        .optional()
        .describe("Allow credit card payments. Default: true"),
      useRealAccountNumber: z
        .boolean()
        .optional()
        .describe("Show real (vs virtual) account number on the invoice. Default: false"),
      ccEmails: z.array(z.email()).optional().describe("CC emails for notifications"),
      sendEmailOption: z
        .enum(["DontSend", "SendNow"])
        .optional()
        .describe("Whether to email the invoice immediately. Default: SendNow"),
      invoiceNumber: z
        .string()
        .max(255)
        .optional()
        .describe(
          "Customer-facing invoice number (≤255 chars; Mercury rejects 300+ characters on the edit endpoint)",
        ),
      poNumber: z.string().optional().describe("Purchase order number"),
      payerMemo: z.string().optional().describe("Memo shown to payer"),
      internalNote: z.string().optional().describe("Note visible only to your org"),
      servicePeriodStartDate: z.iso.date().optional().describe("Service period start (YYYY-MM-DD)"),
      servicePeriodEndDate: z.iso.date().optional().describe("Service period end (YYYY-MM-DD)"),
    },
  • Zod schema for invoice line items (lineItemSchema). Defines name (required, ≤200 chars), description (optional), quantity (positive number), and unitPrice (nonnegative number).
    const lineItemSchema = z.object({
      name: z
        .string()
        .min(1)
        .max(200)
        .describe(
          "Line item name (required, ≤200 characters — Mercury rejects longer values on the edit endpoint with 'Item name: Must be 200 characters or fewer', leaving the invoice unmodifiable). Put long descriptions in the optional `description` field or in the attached invoice PDF.",
        ),
      description: z.string().optional().describe("Optional longer description"),
      quantity: z.number().positive().describe("Quantity"),
      unitPrice: z.number().nonnegative().describe("Price per unit in USD"),
    });
  • The defineTool helper that registers the tool on the McpServer via server.registerTool. Called by the invoices.ts handler definition.
    export function defineTool<S extends ZodRawShape>(
      server: McpServer,
      name: string,
      description: string,
      inputSchema: S,
      handler: (args: z.infer<z.ZodObject<S>>) => Promise<ToolResult>,
      annotations: ToolAnnotations,
    ): void {
      const wrapped = wrapToolHandler(name, handler);
      const strictSchema = z.object(inputSchema).strict();
      // MCP behavioral annotations (readOnlyHint / destructiveHint /
      // idempotentHint / openWorldHint) — declared machine-readable so
      // hosts and rubrics (TDQS / Glama Behavior dimension) can detect
      // tool semantics without scraping the prose description. Required
      // (not optional) so every new tool ships with explicit semantics —
      // forgetting the annotation now fails typecheck instead of
      // silently shipping a tool with no hint set.
      // The MCP SDK overloads `registerTool` with shape narrowing the runtime
      // strict-schema and the wrapped callback can't satisfy through generics.
      // Both casts are runtime-safe — the signatures only diverge at the type
      // level. Asserted by the existing tool-registration tests.
      (server.registerTool as unknown as (...a: unknown[]) => unknown)(
        name,
        { description, inputSchema: strictSchema, annotations },
        wrapped,
      );
    }
  • Middleware registration mapping mercury_create_invoice to the 'invoices_write' bucket for rate limiting (daily: 10, monthly: 200).
    mercury_create_invoice: "invoices_write",
  • Top-level registration: calls registerInvoiceTools(server, client) to register all invoice tools including mercury_create_invoice.
    registerInvoiceTools(server, client);
Behavior5/5

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

The description discloses side effects: writes a persistent invoice, sends a real email with payment link when sendEmailOption is default, and requires Mercury Plus tier. Annotations only have openWorldHint and destructiveHint; the description adds much-needed behavioral context (persistence, email sending, tier requirement) without contradicting annotations.

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 well-organized into purpose, USE WHEN, DO NOT USE, SIDE EFFECTS, and RETURNS sections. It is front-loaded with the core purpose, each sentence earns its place, and the length is appropriate given the tool's 16 parameters.

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

Completeness5/5

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

Given the complexity (16 params, no output schema), the description covers prerequisites, side effects, return structure, and edge cases (attachment limitation). It also warns about email sending and tier requirement, making it complete for an AI agent to invoke correctly.

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?

Input schema has 100% description coverage, so baseline is 3. The description adds extra meaning for key parameters: explains customerId source, highlights lineItems.name 200-char limit and workaround, and clarifies sendEmailOption default. This goes beyond schema descriptions for critical parameters, justifying a 4.

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

Purpose5/5

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

The description clearly states 'Create a new invoice (one-shot or to be sent recurrently)' with a specific verb and resource. It distinguishes from sibling tools like mercury_cancel_invoice and mercury_create_customer by providing explicit 'USE WHEN' and 'DO NOT USE' conditions.

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

Usage Guidelines5/5

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

The description provides explicit 'USE WHEN' and 'DO NOT USE' sections, including when to call mercury_create_customer first. It also advises on setting sendEmailOption to 'SendNow' for immediate email, giving clear context for when to use the tool versus alternatives.

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/klodr/mercury-invoicing-mcp'

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