Skip to content

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

TypeScript

fix(mcp-host): give the percent cells of an XLSX column one format

marcotebd407c2655cdd
diff --git a/mcp-host/src/workflow/__tests__/internalTools.xlsx.values.test.ts b/mcp-host/src/workflow/__tests__/internalTools.xlsx.values.test.ts
index 3a1a8f8e6..a3095301a 100644
--- a/mcp-host/src/workflow/__tests__/internalTools.xlsx.values.test.ts
+++ b/mcp-host/src/workflow/__tests__/internalTools.xlsx.values.test.ts
@@ -404,6 +404,11 @@ describe('signs, identifiers and text left as sent', () => {
expect(ws.getCell('E4').value).toBe('+1-800-555-0100')
})
+ it('gives the percent cells of a column one format, with the places any needs', async () => {
+ const { ws } = await oneSheet([['Growth %'], ['12.5%'], ['10%'], ['8%']])
+ expect(['A2', 'A3', 'A4'].map(a => ws.getCell(a).numFmt)).toEqual(['0.0%', '0.0%', '0.0%'])
+ })
+
it('keeps showing the plus a number was written with', async () => {
const { ws } = await oneSheet([
['Dial prefix', 'Score change', 'Share'],
diff --git a/mcp-host/src/workflow/xlsxWorkbook.ts b/mcp-host/src/workflow/xlsxWorkbook.ts
index 1b97d54bf..3b668048c 100644
--- a/mcp-host/src/workflow/xlsxWorkbook.ts
+++ b/mcp-host/src/workflow/xlsxWorkbook.ts
@@ -239,6 +239,8 @@ interface ColumnPlan {
divisor: number
/** Some amount in the column has decimals, so currency shows cents. */
fraction: boolean
+ /** Format shared by the column's percent cells, with the places any of them needs. */
+ percentFmt?: string
}
function maxAbs(values: number[]): number {
@@ -265,7 +267,14 @@ function planColumn(
if (cell.currency) currencies.add(cell.currency)
}
const spec = requested ?? detectFormat(header, numbers)
- const plan: ColumnPlan = { spec, explicit: requested !== undefined, divisor: 1, fraction }
+ const written = cells.flatMap(cell => (cell.kind === 'percent' ? [cell.value as number] : []))
+ const plan: ColumnPlan = {
+ spec,
+ explicit: requested !== undefined,
+ divisor: 1,
+ fraction,
+ ...(written.length > 0 ? { percentFmt: percentFormat(undefined, written) } : {}),
+ }
if (!spec) return plan
if (spec.type === 'currency') {
const symbol =
@@ -420,7 +429,9 @@ function plainCellOutput(
return {
value,
numFmt:
- spec?.type === 'percent' ? plan.numFmt : percentFormat(undefined, [value as number]),
+ spec?.type === 'percent'
+ ? plan.numFmt
+ : (plan.percentFmt ?? percentFormat(undefined, [value as number])),
}
case 'currency':
return { value, numFmt: currencyFormat(cell.currency ?? '$', plan.fraction ? 2 : 0) }