@tiwater/office-mcp 0.11.0 → 0.11.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/office/index.mjs +1 -58
- package/package.json +1 -1
package/office/index.mjs
CHANGED
|
@@ -3,7 +3,6 @@ import { createHash } from 'node:crypto';
|
|
|
3
3
|
import { createReadStream } from 'node:fs';
|
|
4
4
|
import { mkdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
-
import { spawn } from 'node:child_process';
|
|
7
6
|
import { isDeepStrictEqual } from 'node:util';
|
|
8
7
|
import { McpServer } from '@modelcontextprotocol/server';
|
|
9
8
|
import { serveStdio } from '@modelcontextprotocol/server/stdio';
|
|
@@ -1058,7 +1057,7 @@ async function xlsxApply(args) {
|
|
|
1058
1057
|
|
|
1059
1058
|
async function xlsxValidate(args) {
|
|
1060
1059
|
const input = requireString(args.input, 'input');
|
|
1061
|
-
const result = await
|
|
1060
|
+
const result = await runJsonCandidateChain(xlsxCandidates, ['validate', input], { allowedExitCodes: [0, 1] });
|
|
1062
1061
|
return { tool: 'xlsx_validate', runtime: commandRuntime(result), result: result.json };
|
|
1063
1062
|
}
|
|
1064
1063
|
|
|
@@ -1125,59 +1124,3 @@ function commandRuntime(result) {
|
|
|
1125
1124
|
}
|
|
1126
1125
|
|
|
1127
1126
|
serveStdio(buildServer);
|
|
1128
|
-
|
|
1129
|
-
async function runXlsxValidateCandidateChain(args) {
|
|
1130
|
-
const errors = [];
|
|
1131
|
-
for (const candidate of xlsxCandidates) {
|
|
1132
|
-
try {
|
|
1133
|
-
const result = await runValidationCommand(candidate, args);
|
|
1134
|
-
const text = result.stdout.trim();
|
|
1135
|
-
if (!text) return { ...result, json: null };
|
|
1136
|
-
try {
|
|
1137
|
-
return { ...result, json: JSON.parse(text) };
|
|
1138
|
-
} catch {
|
|
1139
|
-
if (result.code !== 0) {
|
|
1140
|
-
errors.push(`${candidate.command}: validate did not return JSON`);
|
|
1141
|
-
continue;
|
|
1142
|
-
}
|
|
1143
|
-
throw new Error(`Expected JSON output but received: ${text.slice(0, 300)}${text.length > 300 ? '…' : ''}`);
|
|
1144
|
-
}
|
|
1145
|
-
} catch (error) {
|
|
1146
|
-
if (error?.code === 'ENOENT') {
|
|
1147
|
-
errors.push(`${candidate.command}: not found`);
|
|
1148
|
-
continue;
|
|
1149
|
-
}
|
|
1150
|
-
throw error;
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
throw new Error(`No runnable command candidate succeeded. ${errors.join('; ')}`);
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
async function runValidationCommand(candidate, args) {
|
|
1157
|
-
const env = { ...process.env, ...(candidate.env || {}) };
|
|
1158
|
-
const cwd = candidate.cwd || process.cwd();
|
|
1159
|
-
const commandArgs = [...(candidate.argsPrefix || []), ...args];
|
|
1160
|
-
|
|
1161
|
-
return await new Promise((resolve, reject) => {
|
|
1162
|
-
const child = spawn(candidate.command, commandArgs, { cwd, env, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
1163
|
-
let stdout = '';
|
|
1164
|
-
let stderr = '';
|
|
1165
|
-
|
|
1166
|
-
child.stdout.on('data', chunk => {
|
|
1167
|
-
stdout += chunk.toString();
|
|
1168
|
-
});
|
|
1169
|
-
|
|
1170
|
-
child.stderr.on('data', chunk => {
|
|
1171
|
-
stderr += chunk.toString();
|
|
1172
|
-
});
|
|
1173
|
-
|
|
1174
|
-
child.on('error', reject);
|
|
1175
|
-
child.on('close', code => {
|
|
1176
|
-
if (code === 0 || code === 1) {
|
|
1177
|
-
resolve({ code, stdout, stderr, command: candidate.command, args: commandArgs, cwd });
|
|
1178
|
-
return;
|
|
1179
|
-
}
|
|
1180
|
-
reject(new Error(`${candidate.command} ${commandArgs.join(' ')} failed with exit code ${code}\n${stderr || stdout}`));
|
|
1181
|
-
});
|
|
1182
|
-
});
|
|
1183
|
-
}
|