feat(mcp): implement all MCP tools (transactions, budgets, categories, receipts, merchants, accounts, dashboard)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ModelContextProtocol.Server;
|
||||
using MoneyMap.Data;
|
||||
|
||||
namespace MoneyMap.Mcp.Tools;
|
||||
|
||||
[McpServerToolType]
|
||||
public static class AccountTools
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonOptions = new() { WriteIndented = true };
|
||||
|
||||
[McpServerTool(Name = "list_accounts"), Description("List all accounts with transaction counts.")]
|
||||
public static async Task<string> ListAccounts(
|
||||
MoneyMapContext db = default!)
|
||||
{
|
||||
var accounts = await db.Accounts
|
||||
.Include(a => a.Cards)
|
||||
.Include(a => a.Transactions)
|
||||
.OrderBy(a => a.Institution).ThenBy(a => a.Last4)
|
||||
.Select(a => new
|
||||
{
|
||||
a.Id,
|
||||
a.Institution,
|
||||
a.Last4,
|
||||
a.Owner,
|
||||
Label = a.DisplayLabel,
|
||||
TransactionCount = a.Transactions.Count,
|
||||
CardCount = a.Cards.Count
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return JsonSerializer.Serialize(accounts, JsonOptions);
|
||||
}
|
||||
|
||||
[McpServerTool(Name = "list_cards"), Description("List all cards with account info and transaction counts.")]
|
||||
public static async Task<string> ListCards(
|
||||
[Description("Filter cards by account ID")] int? accountId = null,
|
||||
MoneyMapContext db = default!)
|
||||
{
|
||||
var q = db.Cards
|
||||
.Include(c => c.Account)
|
||||
.Include(c => c.Transactions)
|
||||
.AsQueryable();
|
||||
|
||||
if (accountId.HasValue)
|
||||
q = q.Where(c => c.AccountId == accountId.Value);
|
||||
|
||||
var cards = await q
|
||||
.OrderBy(c => c.Owner).ThenBy(c => c.Last4)
|
||||
.Select(c => new
|
||||
{
|
||||
c.Id,
|
||||
c.Issuer,
|
||||
c.Last4,
|
||||
c.Owner,
|
||||
Label = c.DisplayLabel,
|
||||
Account = c.Account != null ? c.Account.Institution + " " + c.Account.Last4 : null,
|
||||
AccountId = c.AccountId,
|
||||
TransactionCount = c.Transactions.Count
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return JsonSerializer.Serialize(cards, JsonOptions);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user