@fullqueso/mcp-bc-gastos 1.10.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server.js +5 -0
- package/tools/get-exchange-rate.js +112 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fullqueso/mcp-bc-gastos",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "MCP server for Business Central operational expense analysis, bank reconciliation, POS reconciliation, accounts receivable/payable, and multi-payment draft visibility - Full Queso franchise stores",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"bin": {
|
package/server.js
CHANGED
|
@@ -32,6 +32,7 @@ import { expenseDetailsTool, handleExpenseDetails } from './tools/expense-detail
|
|
|
32
32
|
import { accountTransactionsTool, handleAccountTransactions } from './tools/account-transactions.js';
|
|
33
33
|
import { vendorTransactionsTool, handleVendorTransactions } from './tools/vendor-transactions.js';
|
|
34
34
|
import { listVendorsTool, handleListVendors } from './tools/list-vendors.js';
|
|
35
|
+
import { exchangeRateTool, handleGetExchangeRate } from './tools/get-exchange-rate.js';
|
|
35
36
|
|
|
36
37
|
// Auditoria tools (bank reconciliation)
|
|
37
38
|
import { listBankAccountsTool, handleListBankAccounts } from './tools/auditoria/list-bank-accounts.js';
|
|
@@ -86,6 +87,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
|
86
87
|
accountTransactionsTool,
|
|
87
88
|
vendorTransactionsTool,
|
|
88
89
|
listVendorsTool,
|
|
90
|
+
exchangeRateTool,
|
|
89
91
|
// Auditoria (bank reconciliation)
|
|
90
92
|
listBankAccountsTool,
|
|
91
93
|
reconciliationStatusTool,
|
|
@@ -145,6 +147,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
145
147
|
case 'list_vendors':
|
|
146
148
|
result = await handleListVendors(bcClient, args);
|
|
147
149
|
break;
|
|
150
|
+
case 'get_exchange_rate':
|
|
151
|
+
result = await handleGetExchangeRate(bcClient, args);
|
|
152
|
+
break;
|
|
148
153
|
// Auditoria (bank reconciliation)
|
|
149
154
|
case 'list_bank_accounts':
|
|
150
155
|
result = await handleListBankAccounts(bcClient, args);
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { resolveStores } from '../config/company-config.js';
|
|
2
|
+
import { round2 } from '../utils/currency-converter.js';
|
|
3
|
+
|
|
4
|
+
export const exchangeRateTool = {
|
|
5
|
+
name: 'get_exchange_rate',
|
|
6
|
+
description:
|
|
7
|
+
'Obtiene la tasa de cambio USD → VES desde Business Central. Modo fecha: retorna la tasa vigente para una fecha específica. Modo rango: retorna el historial de tasas en un período.',
|
|
8
|
+
inputSchema: {
|
|
9
|
+
type: 'object',
|
|
10
|
+
properties: {
|
|
11
|
+
store: {
|
|
12
|
+
type: 'string',
|
|
13
|
+
enum: ['FQ01', 'FQ28', 'FQ88'],
|
|
14
|
+
description: 'Tienda a consultar.',
|
|
15
|
+
},
|
|
16
|
+
date: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
description:
|
|
19
|
+
'Fecha específica (YYYY-MM-DD). Retorna la tasa vigente (más reciente en o antes de esa fecha). Si no se indica fecha ni rango, usa hoy.',
|
|
20
|
+
},
|
|
21
|
+
start_date: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
description:
|
|
24
|
+
'Inicio del rango (YYYY-MM-DD). Usar junto con end_date para obtener historial de tasas.',
|
|
25
|
+
},
|
|
26
|
+
end_date: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
description:
|
|
29
|
+
'Fin del rango (YYYY-MM-DD). Usar junto con start_date para obtener historial de tasas.',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
required: ['store'],
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export async function handleGetExchangeRate(bcClient, args) {
|
|
37
|
+
const store = args.store;
|
|
38
|
+
if (!store) throw new Error('Parámetro requerido: store');
|
|
39
|
+
|
|
40
|
+
const stores = resolveStores([store]);
|
|
41
|
+
const storeInfo = stores[0];
|
|
42
|
+
|
|
43
|
+
const rates = await bcClient.getExchangeRates(store);
|
|
44
|
+
|
|
45
|
+
if (!rates || rates.length === 0) {
|
|
46
|
+
return {
|
|
47
|
+
store,
|
|
48
|
+
store_name: storeInfo.name,
|
|
49
|
+
error: 'No se encontraron tasas de cambio VES en Business Central.',
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Range mode
|
|
54
|
+
if (args.start_date && args.end_date) {
|
|
55
|
+
const filtered = rates.filter(
|
|
56
|
+
(r) => r.startingDate >= args.start_date && r.startingDate <= args.end_date
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const rateList = filtered.map((r) => {
|
|
60
|
+
const rate = round2(r.exchangeRateAmount / r.relationalExchangeRateAmount);
|
|
61
|
+
return {
|
|
62
|
+
starting_date: r.startingDate,
|
|
63
|
+
rate,
|
|
64
|
+
label: `1 USD = ${rate} VES`,
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Also get the rate applicable at start_date (may be before the range)
|
|
69
|
+
const rateAtStart = bcClient.getExchangeRateForDate(rates, args.start_date);
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
store,
|
|
73
|
+
store_name: storeInfo.name,
|
|
74
|
+
start_date: args.start_date,
|
|
75
|
+
end_date: args.end_date,
|
|
76
|
+
rate_at_start: rateAtStart
|
|
77
|
+
? {
|
|
78
|
+
rate: round2(rateAtStart.rate),
|
|
79
|
+
starting_date: rateAtStart.startingDate,
|
|
80
|
+
label: `1 USD = ${round2(rateAtStart.rate)} VES`,
|
|
81
|
+
}
|
|
82
|
+
: null,
|
|
83
|
+
rates_in_range: rateList,
|
|
84
|
+
count: rateList.length,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Single date mode (default: today)
|
|
89
|
+
const targetDate = args.date || new Date().toISOString().slice(0, 10);
|
|
90
|
+
const found = bcClient.getExchangeRateForDate(rates, targetDate);
|
|
91
|
+
|
|
92
|
+
if (!found) {
|
|
93
|
+
return {
|
|
94
|
+
store,
|
|
95
|
+
store_name: storeInfo.name,
|
|
96
|
+
date: targetDate,
|
|
97
|
+
exchange_rate: null,
|
|
98
|
+
message: 'No se encontró tasa de cambio para la fecha indicada.',
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
store,
|
|
104
|
+
store_name: storeInfo.name,
|
|
105
|
+
date: targetDate,
|
|
106
|
+
exchange_rate: {
|
|
107
|
+
rate: round2(found.rate),
|
|
108
|
+
starting_date: found.startingDate,
|
|
109
|
+
label: `1 USD = ${round2(found.rate)} VES`,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|