Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/lampyrid/clients/firefly.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,29 @@ async def get_transactions(self, req: GetTransactionsRequest) -> TransactionArra
r.raise_for_status()
return TransactionArray.model_validate(r.json())

async def get_account_transactions(self, req: GetTransactionsRequest) -> TransactionArray:
"""Get transactions for a specific account with optional time range filtering."""
params: Dict[str, Any] = {
'page': req.page,
'limit': req.limit,
}

if req.start_date:
params['start'] = req.start_date.strftime('%Y-%m-%d')

if req.end_date:
params['end'] = req.end_date.strftime('%Y-%m-%d')

if req.transaction_type:
params['type'] = req.transaction_type.value

if req.account_id is None:
raise ValueError('account_id must be provided for account transactions retrieval.')

Comment thread
RadCod3 marked this conversation as resolved.
r = await self._client.get(f'/api/v1/accounts/{req.account_id}/transactions', params=params)
r.raise_for_status()
return TransactionArray.model_validate(r.json())

async def get_transaction(self, req: GetTransactionRequest) -> Transaction:
"""Get a single transaction by ID."""
r = await self._client.get(f'/api/v1/transactions/{req.id}')
Expand Down
6 changes: 6 additions & 0 deletions src/lampyrid/models/lampyrid_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ class CreateTransferRequest(BaseModel):


class GetTransactionsRequest(BaseModel):
account_id: Optional[str] = Field(
None,
description='Optional account ID to filter results. When provided, only transactions involving this '
'specific account (as source or destination) are returned. When omitted or None, '
'transactions for all accounts are returned (subject to other filters).',
)
start_date: Optional[date] = Field(
None,
description='Start date for filtering transactions (YYYY-MM-DD format). If not specified, returns recent transactions.',
Expand Down
5 changes: 4 additions & 1 deletion src/lampyrid/tools/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ async def get_transaction(req: GetTransactionRequest) -> Transaction:
@mcp.tool(tags={'transactions', 'query'})
async def get_transactions(req: GetTransactionsRequest) -> TransactionListResponse:
"""Retrieve transaction history with flexible filtering and pagination. Essential for financial analysis, spending pattern review, and account activity monitoring."""
transaction_array = await client.get_transactions(req)
if req.account_id is not None:
transaction_array = await client.get_account_transactions(req)
else:
transaction_array = await client.get_transactions(req)

return TransactionListResponse.from_transaction_array(
transaction_array, current_page=req.page or 1, per_page=req.limit or 50
Expand Down