Skip to main content
Glama
klodr

mercury-invoicing-mcp

mercury_update_invoice

Update an existing invoice by passing only the fields you want to change. Merge your changes with the current invoice to amend line items, due date, memo, or PO number before payment.

Instructions

Update an existing invoice. Pass only the fields you want to change.

USE WHEN: amending an outstanding invoice (line items, due date, memo, PO number) before the customer pays. The MCP fetches the current invoice and merges your changes before submitting — Mercury's update endpoint requires the full payload despite the API docs implying PATCH.

DO NOT USE: to cancel an invoice (use mercury_cancel_invoice). To change the customer or the destination account, cancel + recreate. Once an invoice is paid, updates are likely rejected by Mercury — fetch first to confirm status.

SIDE EFFECTS: overwrites the invoice on Mercury's side. The customer-facing payment URL stays the same. If the invoice was already emailed, the customer is NOT re-notified of the change — communicate the change out-of-band if needed.

RETURNS: { id, status, amount, ... } — the updated invoice.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
invoiceIdYesInvoice ID
invoiceDateNoInvoice date (YYYY-MM-DD)
dueDateNoDue date (YYYY-MM-DD)
lineItemsNo
ccEmailsNo
payerMemoNo
internalNoteNo
poNumberNo
invoiceNumberNo

Implementation Reference

  • The handler function for mercury_update_invoice. It fetches the current invoice, strips read-only fields (id, slug, status, amount, createdAt, updatedAt), merges user changes on top, and POSTs the merged payload to Mercury's update endpoint.
    async ({ invoiceId, ...changes }) => {
      const current = await client.get<Record<string, unknown>>(`/ar/invoices/${invoiceId}`);
      // Strip read-only fields Mercury rejects in the update payload
      const {
        id: _index,
        slug: _s,
        status: _st,
        amount: _a,
        createdAt: _c,
        updatedAt: _u,
        ...editable
      } = current;
      const merged: Record<string, unknown> = { ...editable };
      for (const [k, v] of Object.entries(changes)) {
        // Zod-validated args never carry undefined values (optional keys
        // are elided), so the false branch is a defensive guard rather
        // than a runtime path we can hit.
        /* v8 ignore next */
        // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
        if (v !== undefined) merged[k] = v;
      }
      const data = await client.post(`/ar/invoices/${invoiceId}`, merged);
      return textResult(data);
    },
  • Input schema for mercury_update_invoice. Required: invoiceId (UUID). Optional: invoiceDate, dueDate, lineItems, ccEmails, payerMemo, internalNote, poNumber, invoiceNumber.
    {
      invoiceId: z.uuid().describe("Invoice ID"),
      invoiceDate: z.iso.date().optional().describe("Invoice date (YYYY-MM-DD)"),
      dueDate: z.iso.date().optional().describe("Due date (YYYY-MM-DD)"),
      lineItems: z.array(lineItemSchema).optional(),
      ccEmails: z.array(z.email()).optional(),
      payerMemo: z.string().optional(),
      internalNote: z.string().optional(),
      poNumber: z.string().optional(),
      invoiceNumber: z.string().optional(),
    },
  • Registration of the mercury_update_invoice tool via defineTool (which calls server.registerTool) with name, description, schema, handler, and annotations including title='Update Invoice', destructiveHint=false, openWorldHint=true.
    defineTool(
      server,
      "mercury_update_invoice",
      [
        "Update an existing invoice. Pass only the fields you want to change.",
        "",
        "USE WHEN: amending an outstanding invoice (line items, due date, memo, PO number) before the customer pays. The MCP fetches the current invoice and merges your changes before submitting — Mercury's update endpoint requires the full payload despite the API docs implying PATCH.",
        "",
        "DO NOT USE: to cancel an invoice (use `mercury_cancel_invoice`). To change the customer or the destination account, cancel + recreate. Once an invoice is paid, updates are likely rejected by Mercury — fetch first to confirm status.",
        "",
        "SIDE EFFECTS: overwrites the invoice on Mercury's side. The customer-facing payment URL stays the same. If the invoice was already emailed, the customer is NOT re-notified of the change — communicate the change out-of-band if needed.",
        "",
        "RETURNS: `{ id, status, amount, ... }` — the updated invoice.",
      ].join("\n"),
      {
        invoiceId: z.uuid().describe("Invoice ID"),
        invoiceDate: z.iso.date().optional().describe("Invoice date (YYYY-MM-DD)"),
        dueDate: z.iso.date().optional().describe("Due date (YYYY-MM-DD)"),
        lineItems: z.array(lineItemSchema).optional(),
        ccEmails: z.array(z.email()).optional(),
        payerMemo: z.string().optional(),
        internalNote: z.string().optional(),
        poNumber: z.string().optional(),
        invoiceNumber: z.string().optional(),
      },
      async ({ invoiceId, ...changes }) => {
        const current = await client.get<Record<string, unknown>>(`/ar/invoices/${invoiceId}`);
        // Strip read-only fields Mercury rejects in the update payload
        const {
          id: _index,
          slug: _s,
          status: _st,
          amount: _a,
          createdAt: _c,
          updatedAt: _u,
          ...editable
        } = current;
        const merged: Record<string, unknown> = { ...editable };
        for (const [k, v] of Object.entries(changes)) {
          // Zod-validated args never carry undefined values (optional keys
          // are elided), so the false branch is a defensive guard rather
          // than a runtime path we can hit.
          /* v8 ignore next */
          // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
          if (v !== undefined) merged[k] = v;
        }
        const data = await client.post(`/ar/invoices/${invoiceId}`, merged);
        return textResult(data);
      },
      { title: "Update Invoice", destructiveHint: false, openWorldHint: true },
    );
  • Rate-limit bucket assignment: mercury_update_invoice is mapped to the 'invoices_write' bucket, which has daily=10 and monthly=200 limits as defined in DEFAULT_BUCKET_LIMITS (line 81). Shared with mercury_create_invoice.
    const TOOL_BUCKET: Record<string, string> = {
      // Money out
      mercury_send_money: "payments",
      mercury_request_send_money: "payments",
      mercury_create_internal_transfer: "internal_transfer",
    
      // Invoicing
      mercury_create_invoice: "invoices_write",
      mercury_update_invoice: "invoices_write",
      mercury_cancel_invoice: "invoices_cancel",
  • The defineTool helper that wraps the handler with middleware (rate limiting, dry-run, audit) via wrapToolHandler, then registers it on the MCP server.
    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,
      );
    }
    
    export { type ToolResult } from "../middleware.js";
    export { type ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
Behavior5/5

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

Beyond annotations (destructiveHint=false, openWorldHint=true), description explains that MCP fetches current invoice and merges changes, that the payment URL stays the same, and that emailed customers are not re-notified. Also notes potential rejection for paid invoices.

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?

Well-structured with clear sections (basic action, USE WHEN, DO NOT USE, SIDE EFFECTS, RETURNS) and concise language. Length is slightly long but justified by complexity; front-loaded with main action.

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?

Covers purpose, usage guidelines, side effects, return value shape, and important behavioral details (e.g., MCP merge behavior). Missing some parameter specifics but schema provides descriptions; no output schema, so return structure is described adequately.

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?

With only 33% schema coverage, description adds significant value: explains partial update nature, details lineItems.name length limit (200 chars) and workaround, and notes that only fields to change are passed. However, not all optional parameters receive additional explanation.

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?

Clearly states 'Update an existing invoice' and distinguishes from related tools by specifying that it is for amending outstanding invoices before payment, not for canceling or changing customer/account.

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?

Explicit 'USE WHEN' and 'DO NOT USE' sections provide clear context: use for amending unpaid invoices, avoid for cancelling (use mercury_cancel_invoice) or changing customer/account (cancel+recreate). Also advises fetching invoice first to check status if paid.

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