Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(mcp-host): read only the series and fields a native deck chart draws

marcotebb0e4e7e26641
diff --git a/mcp-host/src/workflow/__tests__/ignoredArguments.contract.test.ts b/mcp-host/src/workflow/__tests__/ignoredArguments.contract.test.ts
index 69b5982b4..dd38bf895 100644
--- a/mcp-host/src/workflow/__tests__/ignoredArguments.contract.test.ts
+++ b/mcp-host/src/workflow/__tests__/ignoredArguments.contract.test.ts
@@ -173,6 +173,32 @@ describe('every argument a generator does not read is named', () => {
expect(result.content).toContain(note(expected))
})
+ it('names the colors of a native deck chart, which takes its colors from the palette', async () => {
+ const tool = INTERNAL_TOOLS.find(t => t.name === 'clerum__generate_pptx')!
+ const sent = {
+ filename: 'c.pptx',
+ slides: [
+ {
+ layout: 'title-chart',
+ title: 'C',
+ chart: {
+ type: 'bar',
+ labels: ['a'],
+ datasets: [{ label: 'S', data: [1], backgroundColor: '#ff0000', fill: true }],
+ },
+ },
+ ],
+ }
+ const expected = unknownArguments(tool.parameters, sent)
+ expect(expected).toEqual([
+ 'slides[0].chart.datasets[0].backgroundColor',
+ 'slides[0].chart.datasets[0].fill',
+ ])
+ const result = await tool.execute(sent, dir)
+ expect(result.success, result.error).toBe(true)
+ expect(result.content).toContain(note(expected))
+ })
+
it('names the fields of the first sheet when top-level images are moved onto it', async () => {
// A 1x1 PNG in the output folder, named as the generators take images.
fs.writeFileSync(
diff --git a/mcp-host/src/workflow/__tests__/pptxCharts.test.ts b/mcp-host/src/workflow/__tests__/pptxCharts.test.ts
index 082fc0ea2..1e1aabe93 100644
--- a/mcp-host/src/workflow/__tests__/pptxCharts.test.ts
+++ b/mcp-host/src/workflow/__tests__/pptxCharts.test.ts
@@ -51,6 +51,51 @@ describe('readNativeChart', () => {
})
})
+describe('a pie or doughnut reads only the series it draws', () => {
+ it('is not rejected for a value in a series it leaves out', () => {
+ const warnings: string[] = []
+ const chart = readNativeChart(
+ {
+ type: 'pie',
+ labels: ['A', 'B'],
+ datasets: [{ data: [60, 40] }, { data: ['n/a'] }],
+ },
+ 'c',
+ warnings
+ )
+ expect(chart?.series).toEqual([{ name: '#1', values: [60, 40] }])
+ expect(warnings.join(' ')).toContain('1 more were left out')
+ })
+
+ it('takes no decimal convention and no category from it', () => {
+ // Alone, '1.250' reads two ways and is refused; a dropped '1,100.5' must not settle it.
+ expect(() =>
+ readNativeChart(
+ { type: 'doughnut', labels: ['A'], datasets: [{ data: ['1.250'] }, { data: ['1,100.5'] }] },
+ 'c',
+ []
+ )
+ ).toThrow(ChartSpecError)
+ const labelled = readNativeChart(
+ {
+ type: 'pie',
+ datasets: [
+ {
+ data: [
+ { label: 'A', value: 1 },
+ { label: 'B', value: 2 },
+ ],
+ },
+ { data: [{ label: 'C', value: 3 }] },
+ ],
+ },
+ 'c',
+ []
+ )
+ expect(labelled?.labels).toEqual(['A', 'B'])
+ })
+})
+
describe('nativeChartArgs', () => {
const chart = (over: Partial<NativeChart>): NativeChart => ({
type: 'bar',
diff --git a/mcp-host/src/workflow/pptxCharts.ts b/mcp-host/src/workflow/pptxCharts.ts
index 3e6b4cb90..5ca4cabb8 100644
--- a/mcp-host/src/workflow/pptxCharts.ts
+++ b/mcp-host/src/workflow/pptxCharts.ts
@@ -68,12 +68,18 @@ export function readNativeChart(
.replace(/\bdata\.labels\b/g, `${baseOf(labelsFrom)}.labels`)
.replace(/\bdata\.datasets\b/g, `${base}.datasets`)
.replace(/`data`/g, `\`${base}\``)
+ // Only what is drawn is read: a pie or doughnut draws its first series, and
+ // a native chart takes its colors from the palette. A series left out then
+ // neither sets the decimal convention, adds a category nor rejects the
+ // chart, and the colors sent stay in the "Ignored arguments" note.
+ const sent = datasetsFrom.datasets
+ const drawn = Array.isArray(sent) && SLICE_TYPES.has(type) ? sent.slice(0, 1) : sent
+ const datasets = Array.isArray(drawn)
+ ? drawn.map(d => (isRecord(d) ? { label: d.label, data: d.data } : d))
+ : drawn
let normalized
try {
- normalized = normalizeChartData(
- { labels: labelsFrom.labels, datasets: datasetsFrom.datasets },
- { chartType: type }
- )
+ normalized = normalizeChartData({ labels: labelsFrom.labels, datasets }, { chartType: type })
} catch (err) {
if (err instanceof ChartDataError) throw new ChartSpecError(rewrite(err.message))
throw err
@@ -89,16 +95,15 @@ export function readNativeChart(
`${base}.datasets: ${unnamed} series had no label, so the legend numbers them; give each a label.`
)
}
- let series = normalized.datasets.map((d, i) => ({
+ const series = normalized.datasets.map((d, i) => ({
name: boundLabel(d.label || `#${i + 1}`, MAX_SERIES_NAME),
values: d.data as Array<number | null>,
}))
- if (SLICE_TYPES.has(type) && series.length > 1) {
+ if (Array.isArray(sent) && sent.length > series.length) {
warnings.push(
`${where}: a ${type} chart draws one series, so only "${series[0].name}" was drawn and ` +
- `${series.length - 1} more were left out. Use a bar or line chart to compare series.`
+ `${sent.length - series.length} more were left out. Use a bar or line chart to compare series.`
)
- series = series.slice(0, 1)
}
const labels = (normalized.labels ?? []).map(l => boundLabel(l, MAX_CATEGORY_LABEL))
return { type, labels, series }