@warmio/mcp 3.0.1 → 3.0.2
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/dist/server.js +19 -7
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -17,11 +17,14 @@ const API_URL = process.env.WARM_API_URL || 'https://warm.io';
|
|
|
17
17
|
const MAX_TRANSACTION_PAGES = 10;
|
|
18
18
|
const MAX_TRANSACTION_SCAN = 5_000;
|
|
19
19
|
const TRANSACTION_PAGE_SIZE = 200;
|
|
20
|
+
const TRANSACTION_CACHE_TTL_MS = 600_000; // 10min cache for paginated reads
|
|
20
21
|
const REQUEST_TIMEOUT_MS = (() => {
|
|
21
22
|
const raw = Number(process.env.WARM_API_TIMEOUT_MS || 10_000);
|
|
22
23
|
return Number.isFinite(raw) && raw > 0 ? raw : 10_000;
|
|
23
24
|
})();
|
|
24
25
|
let cachedApiKey;
|
|
26
|
+
// In-memory transaction cache to avoid re-fetching on paginated reads
|
|
27
|
+
let txnCache = null;
|
|
25
28
|
function compactTransaction(t) {
|
|
26
29
|
return {
|
|
27
30
|
d: t.date || '',
|
|
@@ -134,11 +137,11 @@ async function handleGetAccounts() {
|
|
|
134
137
|
accounts: response.accounts || [],
|
|
135
138
|
};
|
|
136
139
|
}
|
|
137
|
-
async function
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
async function fetchAllTransactions(since, until) {
|
|
141
|
+
const cacheKey = `${since || ''}|${until || ''}`;
|
|
142
|
+
if (txnCache && txnCache.key === cacheKey && Date.now() - txnCache.fetchedAt < TRANSACTION_CACHE_TTL_MS) {
|
|
143
|
+
return { transactions: txnCache.transactions, summary: txnCache.summary };
|
|
144
|
+
}
|
|
142
145
|
let transactions = [];
|
|
143
146
|
let cursor;
|
|
144
147
|
let pagesFetched = 0;
|
|
@@ -163,6 +166,15 @@ async function handleGetTransactions(args) {
|
|
|
163
166
|
}
|
|
164
167
|
const compactTxns = transactions.map(compactTransaction);
|
|
165
168
|
const summary = calculateSummary(compactTxns);
|
|
169
|
+
txnCache = { key: cacheKey, transactions: compactTxns, summary, fetchedAt: Date.now() };
|
|
170
|
+
return { transactions: compactTxns, summary };
|
|
171
|
+
}
|
|
172
|
+
async function handleGetTransactions(args) {
|
|
173
|
+
const since = args?.since ? String(args.since) : undefined;
|
|
174
|
+
const until = args?.until ? String(args.until) : undefined;
|
|
175
|
+
const limit = Math.min(Math.max(args?.limit ? Number(args.limit) : 500, 1), 1000);
|
|
176
|
+
const offset = Math.max(args?.offset ? Number(args.offset) : 0, 0);
|
|
177
|
+
const { transactions: compactTxns, summary } = await fetchAllTransactions(since, until);
|
|
166
178
|
const total = compactTxns.length;
|
|
167
179
|
const page = compactTxns.slice(offset, offset + limit);
|
|
168
180
|
return {
|
|
@@ -215,7 +227,7 @@ const toolHandlers = {
|
|
|
215
227
|
// ============================================
|
|
216
228
|
// SERVER SETUP
|
|
217
229
|
// ============================================
|
|
218
|
-
const server = new Server({ name: 'warm', version: '3.0.
|
|
230
|
+
const server = new Server({ name: 'warm', version: '3.0.2' }, { capabilities: { tools: {} } });
|
|
219
231
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
220
232
|
tools: [
|
|
221
233
|
{
|
|
@@ -243,7 +255,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
243
255
|
},
|
|
244
256
|
limit: {
|
|
245
257
|
type: 'number',
|
|
246
|
-
description: 'Max transactions per page (default
|
|
258
|
+
description: 'Max transactions per page (default 500, max 1000).',
|
|
247
259
|
},
|
|
248
260
|
offset: {
|
|
249
261
|
type: 'number',
|