feat: add invoice attachment list and download tools#126
Open
harryblam wants to merge 4 commits intoXeroAPI:mainfrom
Open
feat: add invoice attachment list and download tools#126harryblam wants to merge 4 commits intoXeroAPI:mainfrom
harryblam wants to merge 4 commits intoXeroAPI:mainfrom
Conversation
Add two new read-only tools for accessing files attached to Xero invoices: - list-invoice-attachments: list attachment metadata (filename, MIME type, size) for a given invoice - get-invoice-attachment-content: download an attachment's content as base64 Also adds accounting.attachments.read to the requested scopes and improves error handling for invalid_scope responses with a clear message directing users to update their Custom Connection scopes.
Currently, authenticate() fetches a new token from Xero's identity server on every single tool call. This is wasteful and can trigger rate limiting on long-running sessions, causing 'Failed to get Xero token' errors. This change caches the token and tracks its expiry using the expires_in value from Xero's response. The token is only refreshed when it's within 5 minutes of expiring, reducing unnecessary calls to the identity endpoint from dozens per session to ~1 per 25 minutes.
- Add orderBy, orderDirection, status, type, dateFrom, dateTo, pageSize params - Build where clause from structured params (type + date range) - Change default pageSize from 10 to 100 - Add comprehensive negative guidance to list-invoices description - Add COMMON MISTAKES sections to 7 other paginated list tools - Fix copy-paste typo in list-bank-transactions description - Bump version to 0.0.14-fix.4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add two new read-only tools for accessing files attached to Xero invoices:
list-invoice-attachmentsget-invoice-attachment-contentChanges
New files
src/handlers/list-xero-invoice-attachments.handler.ts— callsaccountingApi.getInvoiceAttachments()src/handlers/download-xero-invoice-attachment.handler.ts— callsaccountingApi.getInvoiceAttachmentByFileName(), returns Buffer as base64src/tools/list/list-invoice-attachments.tool.ts— tool definition withinvoiceIdparametersrc/tools/get/get-invoice-attachment.tool.ts— tool definition withinvoiceId,fileName,contentTypeparametersModified files
src/clients/xero-client.ts— addsaccounting.attachments.readto requested scopes; addsinvalid_scopeerror detection with a clear message directing users to update their Custom Connectionsrc/tools/list/index.ts— registersListInvoiceAttachmentsToolsrc/tools/get/index.ts— registersGetInvoiceAttachmentToolScope requirement
The
accounting.attachments.readscope is required for the Xero Attachments API. This scope is added to theclient_credentialstoken request. If a user's Custom Connection doesn't include this scope, the error handler now returns a clear message listing all required scopes instead of a generic auth failure.Testing
list-invoice-attachmentssuccessfully returns attachment metadata for invoicesget-invoice-attachment-contentsuccessfully downloads attachments as base64