forked from dvcrn/mcp-server-devonthink
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute.ts
More file actions
27 lines (27 loc) · 802 Bytes
/
execute.ts
File metadata and controls
27 lines (27 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { execFile } from "child_process";
import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
export const executeJxa = <T>(script: string): Promise<T> => {
return new Promise((resolve, reject) => {
execFile("osascript", ["-l", "JavaScript", "-e", script], (error, stdout, stderr) => {
if (error) {
return reject(
new McpError(ErrorCode.InternalError, `JXA execution failed: ${error.message}`),
);
}
if (stderr) {
return reject(new McpError(ErrorCode.InternalError, `JXA error: ${stderr}`));
}
try {
const result = JSON.parse(stdout.trim());
resolve(result as T);
} catch (parseError) {
reject(
new McpError(
ErrorCode.InternalError,
`Failed to parse JXA output: ${parseError}`,
),
);
}
});
});
};