xlsx-for-ai 3.0.8 → 3.0.9
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/mcp.js +194 -21
- package/package.json +1 -1
package/mcp.js
CHANGED
|
@@ -110,24 +110,95 @@ const TOOLS = [
|
|
|
110
110
|
{
|
|
111
111
|
name: 'xlsx_write',
|
|
112
112
|
description:
|
|
113
|
-
'create or update a LOCAL .xlsx file from a structured spec.\n' +
|
|
114
|
-
'
|
|
115
|
-
'
|
|
116
|
-
'
|
|
117
|
-
'
|
|
118
|
-
'USE WHEN:
|
|
119
|
-
'Supports multi-sheet workbooks, formulas, named ranges, and table definitions. ' +
|
|
120
|
-
'Server-validated before writing — safer than generating xlsx bytes directly.\n\n' +
|
|
121
|
-
'DO NOT USE WHEN: working in a sandbox without local filesystem write access. ' +
|
|
122
|
-
'Or when the user wants to edit an uploaded file in place (there is no local path to write to).',
|
|
113
|
+
'create or update a LOCAL .xlsx file from a structured spec.\n\n' +
|
|
114
|
+
'Spec shape: `{sheets: [{name, cells: [{address, value | formula}]}]}`. Each cell has an A1 address ("A1", "B2") and EITHER `value` (string|number|boolean|null) OR `formula` (string, no leading "="). Minimal example:\n' +
|
|
115
|
+
'`{"sheets":[{"name":"Sheet1","cells":[{"address":"A1","value":"id"},{"address":"A2","value":1},{"address":"B2","formula":"A2*2"}]}]}`\n\n' +
|
|
116
|
+
'ALWAYS pass out_path to save to disk. Without out_path the workbook bytes return in _meta.file_b64.\n\n' +
|
|
117
|
+
'USE WHEN: the user wants to write or edit a spreadsheet at a LOCAL file path. Server-validated before writing — safer than generating xlsx bytes directly.\n\n' +
|
|
118
|
+
'DO NOT USE WHEN: working in a sandbox without local filesystem write access. Or editing an uploaded file in place (there is no local path to write to).',
|
|
123
119
|
inputSchema: {
|
|
124
120
|
type: 'object',
|
|
125
121
|
properties: {
|
|
126
|
-
spec:
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
spec: {
|
|
123
|
+
type: 'object',
|
|
124
|
+
description:
|
|
125
|
+
'Workbook spec. Shape: {sheets: [{name: string, cells: [{address, value | formula}]}]}. ' +
|
|
126
|
+
'Each cell has an A1-style `address` (regex ^[A-Za-z]+\\d+$) and EXACTLY ONE of `value` ' +
|
|
127
|
+
'(string|number|boolean|null) or `formula` (string WITHOUT leading "=" — e.g. "SUM(A1:A10)" not "=SUM(A1:A10)"). ' +
|
|
128
|
+
'Example: {"sheets":[{"name":"Sheet1","cells":[{"address":"A1","value":"id"},{"address":"A2","value":1},{"address":"B2","formula":"A2*2"}]}]}',
|
|
129
|
+
properties: {
|
|
130
|
+
sheets: {
|
|
131
|
+
type: 'array',
|
|
132
|
+
minItems: 1,
|
|
133
|
+
description: 'One or more sheets. Each sheet is { name: string, cells: array }.',
|
|
134
|
+
items: {
|
|
135
|
+
type: 'object',
|
|
136
|
+
required: ['name', 'cells'],
|
|
137
|
+
properties: {
|
|
138
|
+
name: {
|
|
139
|
+
type: 'string',
|
|
140
|
+
minLength: 1,
|
|
141
|
+
description: 'Sheet name (non-empty).',
|
|
142
|
+
},
|
|
143
|
+
cells: {
|
|
144
|
+
type: 'array',
|
|
145
|
+
description: 'List of cells to write. Order does not matter; addresses are absolute.',
|
|
146
|
+
items: {
|
|
147
|
+
type: 'object',
|
|
148
|
+
required: ['address'],
|
|
149
|
+
description: 'Cell entry. Provide EXACTLY ONE of `value` or `formula`.',
|
|
150
|
+
properties: {
|
|
151
|
+
address: {
|
|
152
|
+
type: 'string',
|
|
153
|
+
pattern: '^[A-Za-z]+\\d+$',
|
|
154
|
+
description: 'A1-style cell address — e.g. "A1", "B2", "AA10".',
|
|
155
|
+
},
|
|
156
|
+
value: {
|
|
157
|
+
type: ['string', 'number', 'boolean', 'null'],
|
|
158
|
+
description: 'Cell value: string, number, boolean, or null. Mutually exclusive with `formula`.',
|
|
159
|
+
},
|
|
160
|
+
formula: {
|
|
161
|
+
type: 'string',
|
|
162
|
+
// No leading `=` — the server expects bare expressions.
|
|
163
|
+
// `^(?!=)` is a negative lookahead that rejects an `=`
|
|
164
|
+
// as the first character; ECMA-262 supported.
|
|
165
|
+
pattern: '^(?!=).+',
|
|
166
|
+
description: 'Excel formula, WITHOUT leading "=". E.g. "SUM(A1:A10)" not "=SUM(A1:A10)". Mutually exclusive with `value`.',
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
// Enforce the value-XOR-formula rule at the schema layer
|
|
170
|
+
// so a strict client (or future server) rejects malformed
|
|
171
|
+
// cells before the request fires. SPM 2026-06-06
|
|
172
|
+
// wild-adoption follow-up.
|
|
173
|
+
oneOf: [
|
|
174
|
+
{ required: ['value'], not: { required: ['formula'] } },
|
|
175
|
+
{ required: ['formula'], not: { required: ['value'] } },
|
|
176
|
+
],
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
required: ['sheets'],
|
|
184
|
+
},
|
|
185
|
+
spec_path: {
|
|
186
|
+
type: 'string',
|
|
187
|
+
description: 'Path to a .json file carrying the spec (alternative to inline spec for large workbooks).',
|
|
188
|
+
},
|
|
189
|
+
out_path: {
|
|
190
|
+
type: 'string',
|
|
191
|
+
description: 'Destination .xlsx path. Required when the caller wants the file saved to disk.',
|
|
192
|
+
},
|
|
193
|
+
base_file_b64: {
|
|
194
|
+
type: 'string',
|
|
195
|
+
description: 'Optional base64 of an existing .xlsx to edit-in-place. When omitted, a fresh workbook is created.',
|
|
196
|
+
},
|
|
129
197
|
},
|
|
130
|
-
|
|
198
|
+
// out_path is the typical caller's choice but not strictly required —
|
|
199
|
+
// when omitted, the workbook bytes return in _meta.file_b64 and the
|
|
200
|
+
// caller saves them (or feeds them to another tool). spec / spec_path
|
|
201
|
+
// is the only hard requirement.
|
|
131
202
|
},
|
|
132
203
|
},
|
|
133
204
|
{
|
|
@@ -1355,7 +1426,63 @@ async function applyFileB64(result, outPath) {
|
|
|
1355
1426
|
// reveal at the boundary.
|
|
1356
1427
|
// ---------------------------------------------------------------------------
|
|
1357
1428
|
|
|
1358
|
-
|
|
1429
|
+
// Defense in depth on the 4xx inline message. The SPEC's bet is that
|
|
1430
|
+
// 4xx server messages describe the CALLER'S OWN INPUT (which field,
|
|
1431
|
+
// what was expected) — but a wrapped 4xx path could still carry
|
|
1432
|
+
// absolute file paths, emails, JWTs / Bearer tokens, Slack tokens,
|
|
1433
|
+
// or other PII. Scrub those before surfacing, replace with `<…>`
|
|
1434
|
+
// placeholders so the caller still sees the SHAPE of the message
|
|
1435
|
+
// without the sensitive payload.
|
|
1436
|
+
//
|
|
1437
|
+
// `<…>` was picked over a more verbose `[redacted-x]` so it's
|
|
1438
|
+
// visually compact and unambiguously not real input.
|
|
1439
|
+
const PII_SCRUBBERS = [
|
|
1440
|
+
// Bearer / Authorization tokens — match before generic JWT pattern.
|
|
1441
|
+
[/\bBearer\s+[A-Za-z0-9._~+/-]{8,}=*/g, '<bearer>'],
|
|
1442
|
+
// JSON Web Tokens. Three dot-separated base64url segments, the first
|
|
1443
|
+
// starting with `eyJ` (the canonical JWT header prefix).
|
|
1444
|
+
[/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, '<jwt>'],
|
|
1445
|
+
// Slack bot / user / app tokens.
|
|
1446
|
+
[/\bxox[bpoars]-[A-Za-z0-9-]{10,}\b/g, '<slack-token>'],
|
|
1447
|
+
// Our own API keys.
|
|
1448
|
+
[/\bxfa_[a-z]+_[A-Za-z0-9]{16,}\b/g, '<xfa-key>'],
|
|
1449
|
+
// Generic 32+ char hex (api keys / hashes).
|
|
1450
|
+
[/\b[a-f0-9]{32,}\b/gi, '<hex>'],
|
|
1451
|
+
// Emails.
|
|
1452
|
+
[/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g, '<email>'],
|
|
1453
|
+
// POSIX absolute paths under /Users, /home, /var, /opt, /tmp, /etc, /private.
|
|
1454
|
+
[/\/(?:Users|home|var|opt|tmp|etc|private)\/[^\s'"`)\]]+/g, '<path>'],
|
|
1455
|
+
// Windows absolute paths.
|
|
1456
|
+
[/[A-Za-z]:\\[^\s'"`)\]]+/g, '<path>'],
|
|
1457
|
+
];
|
|
1458
|
+
|
|
1459
|
+
// Strip the well-known low-signal noise an inline 4xx surface message
|
|
1460
|
+
// could carry: leading "xlsx-for-ai API error 4xx: " prefix from
|
|
1461
|
+
// lib/client.js, scrub PII via PII_SCRUBBERS, bound the length so a
|
|
1462
|
+
// pathological payload can't blow up the conversation log.
|
|
1463
|
+
const INLINE_4XX_MAX_LEN = 280;
|
|
1464
|
+
function shapeInline4xxMessage(raw) {
|
|
1465
|
+
if (typeof raw !== 'string') return '';
|
|
1466
|
+
let s = raw.replace(/^xlsx-for-ai API error \d+:\s*/i, '').trim();
|
|
1467
|
+
for (const [pattern, replacement] of PII_SCRUBBERS) {
|
|
1468
|
+
s = s.replace(pattern, replacement);
|
|
1469
|
+
}
|
|
1470
|
+
if (s.length > INLINE_4XX_MAX_LEN) {
|
|
1471
|
+
s = s.slice(0, INLINE_4XX_MAX_LEN - 1) + '…';
|
|
1472
|
+
}
|
|
1473
|
+
return s;
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
function friendlyErrorMessage(toolName, err) {
|
|
1477
|
+
// err may be undefined (defensive) or any thrown value. Extract the
|
|
1478
|
+
// fields we care about safely.
|
|
1479
|
+
const code = err && err.code;
|
|
1480
|
+
const status = err && err.status;
|
|
1481
|
+
const payload = err && err.payload;
|
|
1482
|
+
|
|
1483
|
+
// Known client-side / mcp.js error codes — keep their pre-existing
|
|
1484
|
+
// short text. Ordered before the 4xx default so the specific message
|
|
1485
|
+
// wins.
|
|
1359
1486
|
switch (code) {
|
|
1360
1487
|
case 'DISALLOWED_EXTENSION':
|
|
1361
1488
|
return `${toolName}: file path must point at a workbook (allowed: .xlsx/.xls/.xlsm/.xlsb/.csv/.ods/.fods/.numbers/.tsv).`;
|
|
@@ -1371,8 +1498,6 @@ function friendlyErrorMessage(toolName, code) {
|
|
|
1371
1498
|
return `${toolName}: required token env var is not set (see tool docs for which one).`;
|
|
1372
1499
|
case 'API_UNREACHABLE':
|
|
1373
1500
|
return `${toolName}: API is unreachable — check network connectivity.`;
|
|
1374
|
-
case 'API_SERVER_ERROR':
|
|
1375
|
-
return `${toolName}: API returned a server error — retry shortly.`;
|
|
1376
1501
|
case 'TIER_UPGRADE_REQUIRED':
|
|
1377
1502
|
return `${toolName}: this capability requires a paid tier.`;
|
|
1378
1503
|
case 'RATE_LIMITED':
|
|
@@ -1380,8 +1505,57 @@ function friendlyErrorMessage(toolName, code) {
|
|
|
1380
1505
|
case 'FALLBACK_ENGINE_MISSING':
|
|
1381
1506
|
return `${toolName}: local fallback engine not installed (\`npm install @protobi/exceljs\`).`;
|
|
1382
1507
|
default:
|
|
1383
|
-
|
|
1508
|
+
break;
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
// 4xx client-error class: surface the server's validation message
|
|
1512
|
+
// inline. SPM 2026-06-06 wild-adoption SPEC. The 4xx surface
|
|
1513
|
+
// describes the CALLER'S OWN INPUT shape ("spec.sheets must be an
|
|
1514
|
+
// array", "cells[3].address is not a valid Excel address"); the
|
|
1515
|
+
// caller needs that message to fix their call. 5xx stays generic
|
|
1516
|
+
// (it can carry upstream internals).
|
|
1517
|
+
//
|
|
1518
|
+
// Known specific HTTP statuses are mapped first so they keep their
|
|
1519
|
+
// short curated text:
|
|
1520
|
+
if (code === 'API_CLIENT_ERROR') {
|
|
1521
|
+
if (status === 429) {
|
|
1522
|
+
return `${toolName}: free-tier monthly cap reached — see xlsx-for-ai.dev/pricing.`;
|
|
1523
|
+
}
|
|
1524
|
+
if (status === 402) {
|
|
1525
|
+
return `${toolName}: this capability requires a paid tier.`;
|
|
1526
|
+
}
|
|
1527
|
+
// Generic 4xx: surface the server message. Prefer the structured
|
|
1528
|
+
// shape, fall through to the flat message, fall through to the
|
|
1529
|
+
// wrapped err.message (stripped of the "API error 4xx:" prefix).
|
|
1530
|
+
let inline = '';
|
|
1531
|
+
if (payload && typeof payload === 'object') {
|
|
1532
|
+
const structured = payload.error;
|
|
1533
|
+
if (structured && typeof structured === 'object' && typeof structured.message === 'string') {
|
|
1534
|
+
inline = structured.message;
|
|
1535
|
+
} else if (typeof payload.message === 'string') {
|
|
1536
|
+
inline = payload.message;
|
|
1537
|
+
} else if (typeof payload.error === 'string') {
|
|
1538
|
+
inline = payload.error;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
if (!inline && err && typeof err.message === 'string') {
|
|
1542
|
+
inline = err.message;
|
|
1543
|
+
}
|
|
1544
|
+
const shaped = shapeInline4xxMessage(inline);
|
|
1545
|
+
if (shaped) {
|
|
1546
|
+
return `${toolName}: ${shaped}`;
|
|
1547
|
+
}
|
|
1548
|
+
// Graceful fallback when no message is available (empty/absent
|
|
1549
|
+
// payload, non-string fields): generic with tool name, no
|
|
1550
|
+
// `undefined`, no `[object Object]`.
|
|
1551
|
+
return `${toolName}: invalid request (no detail provided).`;
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
// 5xx and everything else — stay generic. Security boundary preserved.
|
|
1555
|
+
if (code === 'API_SERVER_ERROR') {
|
|
1556
|
+
return `${toolName}: API returned a server error — retry shortly.`;
|
|
1384
1557
|
}
|
|
1558
|
+
return `${toolName} failed — see server-side logs (request_id in response _meta) for details.`;
|
|
1385
1559
|
}
|
|
1386
1560
|
|
|
1387
1561
|
// ---------------------------------------------------------------------------
|
|
@@ -1873,8 +2047,7 @@ async function main() {
|
|
|
1873
2047
|
// generic "tool failed" with the tool name so callers can still
|
|
1874
2048
|
// route on it without leaking path/server detail. Pre-Friday-
|
|
1875
2049
|
// external CRITICAL per the Tier-1 audit.
|
|
1876
|
-
const
|
|
1877
|
-
const safeMessage = friendlyErrorMessage(name, code);
|
|
2050
|
+
const safeMessage = friendlyErrorMessage(name, err);
|
|
1878
2051
|
return {
|
|
1879
2052
|
content: [{ type: 'text', text: `xlsx-for-ai error: ${safeMessage}` }],
|
|
1880
2053
|
isError: true,
|
|
@@ -1981,4 +2154,4 @@ if (require.main === module) {
|
|
|
1981
2154
|
// script use TOOLS as the single source of truth for downstream artifacts
|
|
1982
2155
|
// (manifest.json, mcp-tools.json snapshot consumed by the MSFT plugin
|
|
1983
2156
|
// manifest), and to expose helpers under test.
|
|
1984
|
-
module.exports = { applyFileB64, dispatchTool, TOOLS };
|
|
2157
|
+
module.exports = { applyFileB64, dispatchTool, TOOLS, friendlyErrorMessage };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xlsx-for-ai",
|
|
3
3
|
"mcpName": "io.github.senoff/xlsx-for-ai",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.9",
|
|
5
5
|
"description": "The MCP server that makes LLMs reliable on real-world Excel spreadsheets. Thin npm client over a hosted API — read, write, diff, redact, and supervise .xlsx files from any MCP-aware agent.",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"bin": {
|