Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/applescript/execute.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { exec } from "child_process";
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) => {
const command = `osascript -l JavaScript -e '${script.replace(/'/g, "''")}'`;
exec(command, (error, stdout, stderr) => {
execFile("osascript", ["-l", "JavaScript", "-e", script], (error, stdout, stderr) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While execFile is a significant improvement over exec for security and escaping, it still uses a default maxBuffer of 1MB. For a tool interacting with a database like DEVONthink, which can return large amounts of metadata or document content (e.g., via get_record_content), this limit might be exceeded, causing the process to fail with ERR_CHILD_PROCESS_STDIO_MAXBUFFER. Consider increasing the buffer size.\n\nAdditionally, passing the script via the -e flag is subject to the system's command-line argument length limit (ARG_MAX). For very large scripts (e.g., when updating records with large text content), it would be more robust to pipe the script to osascript via stdin in the future.

Suggested change
execFile("osascript", ["-l", "JavaScript", "-e", script], (error, stdout, stderr) => {
\t\texecFile("osascript", ["-l", "JavaScript", "-e", script], { maxBuffer: 10 * 1024 * 1024 }, (error, stdout, stderr) => {

if (error) {
return reject(
new McpError(ErrorCode.InternalError, `JXA execution failed: ${error.message}`),
Expand Down
Loading