Skip to content

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

TypeScript

fix(mcp-host): declare every field of a template chart, not only its type

marcoteb7a8125fe34f0
diff --git a/mcp-host/src/workflow/__tests__/internalTools.pptx.templates.test.ts b/mcp-host/src/workflow/__tests__/internalTools.pptx.templates.test.ts
index df89d3bff..98b1b4f0f 100644
--- a/mcp-host/src/workflow/__tests__/internalTools.pptx.templates.test.ts
+++ b/mcp-host/src/workflow/__tests__/internalTools.pptx.templates.test.ts
@@ -8,7 +8,16 @@ import * as os from 'os'
import * as path from 'path'
import { INTERNAL_TOOLS } from '../internalTools'
import { PPTX_TEMPLATE_FIELDS } from '../pptxTemplates'
-import { chartXmls, generatePptx, shapeWithText, slideCount, slideXml } from './support/pptxXml'
+import {
+ chartValues,
+ chartXmls,
+ generatePptx,
+ pictures,
+ shapeWithText,
+ slideCount,
+ slideXml,
+ writeImage,
+} from './support/pptxXml'
let outputDir: string
@@ -42,6 +51,129 @@ describe('clerum__generate_pptx — template data is declared', () => {
})
})
+type SchemaNode = Record<string, any>
+
+const pptxTool = INTERNAL_TOOLS.find(t => t.name === 'clerum__generate_pptx')!
+const pptxParameters = pptxTool.parameters as SchemaNode
+
+function isRecord(value: unknown): value is Record<string, unknown> {
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
+}
+
+/** A schema with its descriptions taken out: what a validator or a provider acts on. */
+function shapeOf(node: unknown): unknown {
+ if (Array.isArray(node)) return node.map(shapeOf)
+ if (!isRecord(node)) return node
+ return Object.fromEntries(
+ Object.entries(node)
+ .filter(([key, value]) => !(key === 'description' && typeof value === 'string'))
+ .map(([key, value]) => [key, shapeOf(value)])
+ )
+}
+
+/**
+ * `value` with only the properties `schema` declares, as a client or provider
+ * that builds the call from the declared fields sends it.
+ */
+function declaredOnly(schema: SchemaNode | undefined, value: unknown): unknown {
+ const kind = Array.isArray(value) ? 'array' : isRecord(value) ? 'object' : typeof value
+ const node = schema?.anyOf
+ ? (schema.anyOf as SchemaNode[]).find(branch => [branch.type].flat().includes(kind))
+ : schema
+ if (Array.isArray(value)) return value.map(item => declaredOnly(node?.items, item))
+ if (!isRecord(value) || !node?.properties) return value
+ return Object.fromEntries(
+ Object.entries(value)
+ .filter(([key]) => key in node.properties)
+ .map(([key, item]) => [key, declaredOnly(node.properties[key], item)])
+ )
+}
+
+describe('clerum__generate_pptx — template charts are declared', () => {
+ const data = pptxParameters.properties.data.properties as Record<string, SchemaNode>
+ const slideChart = pptxParameters.properties.slides.items.properties.chart as SchemaNode
+ const templateCharts = (): Array<[string, SchemaNode]> =>
+ Object.entries(data)
+ .map(([name, node]): [string, SchemaNode] =>
+ node.type === 'array' ? [`${name}[]`, node.items] : [name, node]
+ )
+ .filter(([, node]) => node.properties?.type?.enum?.includes('bar'))
+
+ it('finds every chart the templates read', () => {
+ expect(templateCharts().map(([name]) => name)).toEqual([
+ 'charts[]',
+ 'revenueChart',
+ 'breakdownChart',
+ 'tractionChart',
+ ])
+ })
+
+ it('declares at each the fields of slides[].chart, as slides[].chart types them', () => {
+ // The nested `data` form is left out of the template charts; the flat
+ // fields alone draw any chart.
+ const { data: nested, ...fields } = slideChart.properties as Record<string, SchemaNode>
+ expect(nested).toBeDefined()
+ for (const [name, node] of templateCharts()) {
+ expect(shapeOf(node.properties), name).toEqual(shapeOf(fields))
+ expect(node.description, name).toContain('slides[].chart')
+ }
+ })
+})
+
+describe('clerum__generate_pptx — template charts sent with declared fields only', () => {
+ const NATIVE = {
+ type: 'bar',
+ title: 'Revenue by month',
+ labels: ['Jul', 'Aug'],
+ datasets: [{ label: 'Revenue', data: [1200, 1500] }],
+ caption: 'Unaudited figures.',
+ }
+ const COVERS: Record<string, Record<string, unknown>> = {
+ 'executive-brief': { title: 'Brief' },
+ 'quarterly-review': { title: 'Q3 review', period: 'Q3 2026' },
+ 'pitch-deck': { company: 'Acme', tagline: 'T', problem: 'P', solution: 'S' },
+ }
+ const CHARTS: Array<[string, string, (chart: unknown) => Record<string, unknown>]> = [
+ ['executive-brief', 'charts', chart => ({ charts: [chart] })],
+ ['quarterly-review', 'revenueChart', chart => ({ revenueChart: chart })],
+ ['quarterly-review', 'breakdownChart', chart => ({ breakdownChart: chart })],
+ ['pitch-deck', 'tractionChart', chart => ({ tractionChart: chart })],
+ ]
+
+ async function sendDeclared(template: string, data: Record<string, unknown>) {
+ const args = { filename: 'd.pptx', template, data: { ...COVERS[template], ...data } }
+ const sent = declaredOnly(pptxParameters, args) as Record<string, unknown>
+ return { sent, result: await generatePptx(sent, outputDir) }
+ }
+
+ it.each(CHARTS)('%s draws data.%s as a native chart', async (template, _field, place) => {
+ const { sent, result } = await sendDeclared(template, place(NATIVE))
+ expect(sent.data).toEqual({ ...COVERS[template], ...place(NATIVE) })
+ expect(result.success, result.error).toBe(true)
+ const file = path.join(outputDir, 'd.pptx')
+ const charts = chartXmls(file)
+ expect(charts).toHaveLength(1)
+ expect(chartValues(charts[0])).toEqual([['1200', '1500']])
+ expect(allText(file)).toContain('Revenue by month')
+ expect(allText(file)).toContain('Unaudited figures.')
+ })
+
+ it.each(CHARTS)('%s draws data.%s from a chart image', async (template, _field, place) => {
+ await writeImage(outputDir, 'sales.png', 400, 300)
+ const chart = { path: 'sales.png', title: 'Sales', caption: 'From the chart tool.' }
+ const { sent, result } = await sendDeclared(template, place(chart))
+ expect(sent.data).toEqual({ ...COVERS[template], ...place(chart) })
+ expect(result.success, result.error).toBe(true)
+ const file = path.join(outputDir, 'd.pptx')
+ expect(chartXmls(file)).toHaveLength(0)
+ const withPicture = Array.from({ length: slideCount(file) }, (_, i) =>
+ slideXml(file, i + 1)
+ ).filter(xml => pictures(xml).length > 0)
+ expect(withPicture).toHaveLength(1)
+ expect(allText(file)).toContain('From the chart tool.')
+ })
+})
+
describe('clerum__generate_pptx — template data is checked', () => {
it('names a missing required field instead of drawing "undefined Highlights"', async () => {
const result = await generatePptx(
diff --git a/mcp-host/src/workflow/__tests__/internalTools.schemaBudget.test.ts b/mcp-host/src/workflow/__tests__/internalTools.schemaBudget.test.ts
index cad8eaf3a..6f57762b4 100644
--- a/mcp-host/src/workflow/__tests__/internalTools.schemaBudget.test.ts
+++ b/mcp-host/src/workflow/__tests__/internalTools.schemaBudget.test.ts
@@ -11,7 +11,9 @@ const BUDGET: Record<string, number> = {
clerum__generate_pdf: 3800,
clerum__generate_docx: 3200,
clerum__generate_xlsx: 5400,
- clerum__generate_pptx: 14000,
+ // Each template chart declares its own fields, as a client that sends only
+ // declared fields needs; internalTools.pptx.templates.test.ts holds them there.
+ clerum__generate_pptx: 16700,
clerum__generate_chart: 4300,
clerum__generate_dashboard: 14100,
clerum__list_workflows: 500,
@@ -21,7 +23,7 @@ const BUDGET: Record<string, number> = {
clerum__context_files_read: 550,
}
-const TOTAL_BUDGET = 47500
+const TOTAL_BUDGET = 50300
function size(tool: (typeof INTERNAL_TOOLS)[number]): number {
return JSON.stringify({
diff --git a/mcp-host/src/workflow/internalTools.ts b/mcp-host/src/workflow/internalTools.ts
index b634abebc..529115c29 100644
--- a/mcp-host/src/workflow/internalTools.ts
+++ b/mcp-host/src/workflow/internalTools.ts
@@ -1415,52 +1415,78 @@ const PPTX_SERIES_SHORT = {
data: 'Values.',
}
-const PPTX_CHART_SCHEMA = {
- type: 'object',
- description:
- 'A native, editable chart { type, labels, datasets }, or { path } for a chart image.',
- properties: {
- path: {
- type: 'string',
- description:
- "Chart image file name from clerum__generate_chart (e.g. 'sales.png'), for " +
- 'types the native list lacks. Native data given too is drawn if the file cannot be used.',
- },
- type: {
- type: 'string',
- enum: [...NATIVE_CHART_TYPES],
- description: 'Native chart type. Only for native charts: with path, leave it out.',
+/** What a chart's fields say: in full under slides[].chart, briefly in each template chart. */
+interface PptxChartAbout {
+ path: string
+ type: string
+ title: string
+ series: Parameters<typeof pptxChartSeries>[0]
+ /** The labels and datasets nested under `data`; declared only where this is set. */
+ nested?: string
+ caption: string
+}
+
+/**
+ * A chart, as slides[].chart and every template chart declare it. Both are
+ * built here, so each declares the same fields with the same types and only
+ * the descriptions differ: a provider or client that builds the call from the
+ * declared fields sends no other, so a field named only in prose never arrives.
+ */
+function pptxChart(description: string, about: PptxChartAbout): Record<string, unknown> {
+ return {
+ type: 'object',
+ description,
+ properties: {
+ path: { type: 'string', description: about.path },
+ type: { type: 'string', enum: [...NATIVE_CHART_TYPES], description: about.type },
+ title: { type: 'string', description: about.title },
+ ...pptxChartSeries(about.series),
+ ...(about.nested === undefined
+ ? {}
+ : {
+ data: {
+ type: 'object',
+ description: about.nested,
+ properties: pptxChartSeries(PPTX_SERIES_SHORT),
+ },
+ }),
+ caption: { type: 'string', description: about.caption },
},
- title: { type: 'string', description: 'Heading, unless it repeats the slide title.' },
- ...pptxChartSeries({
+ }
+}
+
+const PPTX_CHART_SCHEMA = pptxChart(
+ 'A native, editable chart { type, labels, datasets }, or { path } for a chart image.',
+ {
+ path:
+ "Chart image file name from clerum__generate_chart (e.g. 'sales.png'), for " +
+ 'types the native list lacks. Native data given too is drawn if the file cannot be used.',
+ type: 'Native chart type. Only for native charts: with path, leave it out.',
+ title: 'Heading, unless it repeats the slide title.',
+ series: {
labels: 'Category labels, one per value.',
datasets: 'Series; a pie or doughnut draws only the first.',
label: 'Legend name.',
data: 'One value per label; null leaves a gap.',
- }),
- data: {
- type: 'object',
- description: 'Or labels and datasets nested here, as clerum__generate_chart takes them.',
- properties: pptxChartSeries(PPTX_SERIES_SHORT),
},
- caption: { type: 'string', description: 'Note under the chart.' },
- },
-}
+ nested: 'Or labels and datasets nested here, as clerum__generate_chart takes them.',
+ caption: 'Note under the chart.',
+ }
+)
/**
- * A template chart. Its fields are those of slides[].chart, which the schema
- * spells out once: every model request carries the schema, and the deck
- * builder checks a template chart as it checks a slide's (readNativeChart, then
- * the chart normalizer), naming the field it cannot use.
+ * A template chart: slides[].chart with short descriptions and without its
+ * nested `data` form, which the flat fields make unnecessary. The deck builder
+ * reads both the same way (readChart).
*/
function pptxTemplateChart(description: string): Record<string, unknown> {
- return {
- type: 'object',
- description: `${description} Same fields as slides[].chart.`,
- properties: {
- type: { type: 'string', enum: [...NATIVE_CHART_TYPES], description: 'Chart type.' },
- },
- }
+ return pptxChart(`${description} As slides[].chart.`, {
+ path: PPTX_PATH_SHORT,
+ type: 'Chart type.',
+ title: 'Slide title.',
+ series: PPTX_SERIES_SHORT,
+ caption: 'Note.',
+ })
}
function pptxColumn(description: string): Record<string, unknown> {