Skip to content

Enhance list-invoices with advanced filtering (Type, status, dates, amounts)#110

Open
cesarho wants to merge 1 commit into
XeroAPI:mainfrom
cesarho:update-list-invoices-tool
Open

Enhance list-invoices with advanced filtering (Type, status, dates, amounts)#110
cesarho wants to merge 1 commit into
XeroAPI:mainfrom
cesarho:update-list-invoices-tool

Conversation

@cesarho

@cesarho cesarho commented Jan 17, 2026

Copy link
Copy Markdown

Add advanced filtering capabilities to list-invoices tool

Summary

This PR enhances the list-invoices tool with comprehensive filtering options, enabling more precise invoice queries through the Xero API. The changes add support for filtering by invoice IDs, statuses, custom where clauses, and customizable ordering.

Changes

New Filtering Parameters

  • invoiceIds: Filter invoices by specific invoice IDs (array of strings)
  • statuses: Filter by invoice statuses - DRAFT, SUBMITTED, DELETED, AUTHORISED, PAID, VOIDED (array of strings)
  • where: Advanced filtering using Xero's where clause syntax for complex queries including:
    • Invoice Type (ACCREC for sales invoices, ACCPAY for bills)
    • Date ranges (Date, DueDate)
    • Amount filtering (AmountDue)
    • Contact name filtering
    • Complex logical combinations (AND, OR)
  • order: Customizable ordering (defaults to "UpdatedDateUTC DESC")

Implementation Details

  • Refactored listXeroInvoices handler to use a ListInvoicesParams interface for better type safety
  • Made page parameter optional with default value of 1
  • Enhanced tool description with comprehensive AI agent guidance, including:
    • Decision guide for choosing the right parameter
    • Common query examples
    • Critical notes about filtering by invoice Type (must use where parameter)
    • Performance recommendations (prefer dedicated array parameters for multiple IDs/statuses)

Updated Files

  • src/tools/list/list-invoices.tool.ts: Added new parameters and comprehensive documentation
  • src/handlers/list-xero-invoices.handler.ts: Refactored to support new filtering options
  • README.md: Updated tool description to reflect advanced filtering capabilities

Benefits

  • More flexible queries: Users can now filter invoices by Type, status, dates, amounts, and more
  • Better AI agent support: Comprehensive documentation helps AI agents make optimal parameter choices
  • Performance optimized: Dedicated array parameters for common use cases (IDs, statuses)
  • Type safety: New interface ensures proper parameter handling

Example Use Cases

  • Filter sales invoices: where=Type=="ACCREC"
  • Filter bills: where=Type=="ACCPAY"
  • Find overdue invoices: where=DueDate<DateTime(2024,12,01) AND Status=="AUTHORISED"
  • Filter by multiple statuses: statuses=["AUTHORISED","PAID"]
  • Complex queries: where=Type=="ACCREC" AND Status=="AUTHORISED" AND AmountDue>1000

… README.

- Updated the `list-invoices` tool to support advanced filtering capabilities, including a required 'where' parameter for invoice types and additional filtering options for statuses, dates, and amounts.
- Refactored the `getInvoices` function to accept a single parameter object for better clarity and usability.
- Revised the README to reflect the new advanced filtering features for the `list-invoices` command.
rathga added a commit to rathga/xero-mcp-server that referenced this pull request Jun 15, 2026
…ense prep)

create-linked-transaction needs a bill line's sourceLineItemId, and the only
way to read line-item IDs via MCP is list-invoices. Until now that tool only
printed line items when filtering by invoiceNumbers — but email-imported bills
frequently have no InvoiceNumber, so their line-item IDs were unreadable and
the billable-expense flow couldn't be driven for them.

Add an invoiceIds filter to list-invoices (threaded into the existing getInvoices
iDs slot) and return line items for invoiceIds fetches as well, so any bill —
numbered or not — can have its Line Item IDs read by ID. This completes the
"surface Line Item ID" half of this PR for the no-InvoiceNumber case.

Note: PR XeroAPI#110 also introduces an invoiceIds filter (among broader list-invoices
filters); this adds the minimal slice needed for the linked-transaction flow and
supersedes that part of XeroAPI#110 for this purpose.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rathga

rathga commented Jun 15, 2026

Copy link
Copy Markdown

Cross-reference for reconciliation: #191 (linked-transaction / billable-expense tools) now adds a minimal invoiceIds filter to list-invoices, plus line-item-by-ID display, which overlaps the invoiceIds part of this PR. This PR's filter set is broader (Type/status/dates/amounts/where); #191 only needs the invoiceIds slice so it can read a bill's Line Item IDs for create-linked-transaction (including bills with no InvoiceNumber). Flagging so that whichever lands first, the other can drop or rebase the duplicate invoiceIds bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants