@dritan/mcp 0.10.0 → 0.10.1
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/index.js +43 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -329,7 +329,7 @@ function formatChartLabel(ts) {
|
|
|
329
329
|
return String(ts);
|
|
330
330
|
return date.toISOString().replace("T", " ").slice(0, 16);
|
|
331
331
|
}
|
|
332
|
-
function
|
|
332
|
+
function buildLineVolumeOhlcvChartConfig(mint, timeframe, bars) {
|
|
333
333
|
const labels = bars.map((bar) => formatChartLabel(bar.time));
|
|
334
334
|
const closeSeries = bars.map((bar) => Number(bar.close.toFixed(12)));
|
|
335
335
|
const volumeSeries = bars.map((bar) => Number(bar.volume.toFixed(12)));
|
|
@@ -373,12 +373,9 @@ function buildLineVolumeOhlcvChartUrl(mint, timeframe, bars, width, height) {
|
|
|
373
373
|
},
|
|
374
374
|
},
|
|
375
375
|
};
|
|
376
|
-
|
|
377
|
-
// QuickChart defaults to Chart.js v2. Our config uses v3+/v4 scale syntax (`options.scales.{id}`),
|
|
378
|
-
// so pinning `v=4` prevents runtime render errors like "Cannot read properties of undefined (reading 'options')".
|
|
379
|
-
return `https://quickchart.io/chart?w=${width}&h=${height}&f=png&v=4&c=${encoded}`;
|
|
376
|
+
return config;
|
|
380
377
|
}
|
|
381
|
-
function
|
|
378
|
+
function buildCandlestickOhlcvChartConfig(mint, timeframe, bars) {
|
|
382
379
|
const labels = bars.map((bar) => formatChartLabel(bar.time));
|
|
383
380
|
const candles = bars.map((bar, index) => ({
|
|
384
381
|
x: labels[index],
|
|
@@ -441,15 +438,47 @@ function buildCandlestickOhlcvChartUrl(mint, timeframe, bars, width, height) {
|
|
|
441
438
|
},
|
|
442
439
|
},
|
|
443
440
|
};
|
|
441
|
+
return config;
|
|
442
|
+
}
|
|
443
|
+
function buildQuickChartDirectUrl(config, width, height) {
|
|
444
444
|
const encoded = encodeURIComponent(JSON.stringify(config));
|
|
445
|
-
//
|
|
445
|
+
// QuickChart defaults to Chart.js v2. Our config uses v3+/v4 scale syntax (`options.scales.{id}`),
|
|
446
|
+
// so pinning `v=4` prevents runtime render errors like "Cannot read properties of undefined (reading 'options')".
|
|
446
447
|
return `https://quickchart.io/chart?w=${width}&h=${height}&f=png&v=4&c=${encoded}`;
|
|
447
448
|
}
|
|
448
|
-
function
|
|
449
|
+
async function buildQuickChartShortUrl(config, width, height) {
|
|
450
|
+
const controller = new AbortController();
|
|
451
|
+
const timeout = setTimeout(() => controller.abort(), 5_000);
|
|
452
|
+
try {
|
|
453
|
+
const response = await fetch("https://quickchart.io/chart/create", {
|
|
454
|
+
method: "POST",
|
|
455
|
+
headers: { "content-type": "application/json" },
|
|
456
|
+
body: JSON.stringify({
|
|
457
|
+
chart: config,
|
|
458
|
+
width,
|
|
459
|
+
height,
|
|
460
|
+
format: "png",
|
|
461
|
+
version: "4",
|
|
462
|
+
}),
|
|
463
|
+
signal: controller.signal,
|
|
464
|
+
});
|
|
465
|
+
if (!response.ok)
|
|
466
|
+
return null;
|
|
467
|
+
const payload = (await response.json());
|
|
468
|
+
return typeof payload.url === "string" && payload.url.length > 0 ? payload.url : null;
|
|
469
|
+
}
|
|
470
|
+
catch {
|
|
471
|
+
return null;
|
|
472
|
+
}
|
|
473
|
+
finally {
|
|
474
|
+
clearTimeout(timeout);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
function buildOhlcvChartConfig(chartType, mint, timeframe, bars) {
|
|
449
478
|
if (chartType === "candlestick") {
|
|
450
|
-
return
|
|
479
|
+
return buildCandlestickOhlcvChartConfig(mint, timeframe, bars);
|
|
451
480
|
}
|
|
452
|
-
return
|
|
481
|
+
return buildLineVolumeOhlcvChartConfig(mint, timeframe, bars);
|
|
453
482
|
}
|
|
454
483
|
function getPlatformInstallHint(binary) {
|
|
455
484
|
switch (process.platform) {
|
|
@@ -1440,12 +1469,15 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
1440
1469
|
if (trimmedBars.length === 0) {
|
|
1441
1470
|
throw new Error(`No OHLCV data available for ${input.mint} (${input.timeframe})`);
|
|
1442
1471
|
}
|
|
1443
|
-
const
|
|
1472
|
+
const chartConfig = buildOhlcvChartConfig(input.chartType, input.mint, input.timeframe, trimmedBars);
|
|
1473
|
+
const shortChartUrl = await buildQuickChartShortUrl(chartConfig, input.width, input.height);
|
|
1474
|
+
const chartUrl = shortChartUrl ?? buildQuickChartDirectUrl(chartConfig, input.width, input.height);
|
|
1444
1475
|
return ok({
|
|
1445
1476
|
mint: input.mint,
|
|
1446
1477
|
timeframe: input.timeframe,
|
|
1447
1478
|
chartType: input.chartType,
|
|
1448
1479
|
points: trimmedBars.length,
|
|
1480
|
+
chartUrlType: shortChartUrl ? "short" : "direct",
|
|
1449
1481
|
chartUrl,
|
|
1450
1482
|
markdown: ``,
|
|
1451
1483
|
lastBar: trimmedBars[trimmedBars.length - 1],
|