Execute JS Code (Sandbox)
mj_execute_codeExecute JavaScript in a secure sandbox to automate Memory Journal MCP tool calls, inspect schemas, and pass context data for journal, search, and update workflows.
Instructions
Run arbitrary JavaScript to automate tasks in a secure sandbox. IMPORTANT: You MUST use the mj object (NOT api, journal, or mcp) to access tools. DO NOT use import() or require(); the mj tools are globally available in the sandbox. Available tools are mapped directly from MCP tool names, converted to camelCase (e.g., create_entry -> mj.createEntry(), search_entries -> mj.searchEntries()). Anti-Hallucination Hint: DO NOT GUESS parameter keys (e.g., passing repo instead of repo_name will fail). ALWAYS inspect the schema first if unsure: return await mj.createEntry.schema(). Execution limit: 30s. Network access (fetch) disabled. Example: return await mj.searchEntries({ query: "PowerShell" })
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | No | REQUIRED string parameter containing JavaScript code to execute inside the sandbox. Uses the `mj` global object for API access (e.g. `return await mj.core.getRecentEntries({ limit: 10 })` or `return await mj.core.createEntry(context.entry)`). Anti-Hallucination Hint: Code Mode executes valid JavaScript (e.g., `return await mj.core.getRecentEntries({ limit: 10 })`), NOT raw SQL queries (e.g. `SELECT * FROM journal_entries`) or direct SQLite prepared statements (e.g. `const db = mj.getDatabase(); db.prepare(...)`). When querying or searching, use `mj.core.getRecentEntries({ limit: 10 })` or `mj.search.searchEntries({ query: "..." })`. To update entries, use `mj.admin.updateEntry({ entry_id: ..., content: ... })` instead of raw SQL UPDATE statements. DO NOT call with an empty payload `{}` or pass entry/query payloads directly without including the `code` parameter. When passing markdown or strings with nested backticks, single quotes, or double quotes, pass them safely via the `context` parameter (e.g., `mj.createEntry({ ...context.entry })` or `context.content`) to avoid double-escaping errors that prematurely terminate string literals, or ensure nested characters are escaped cleanly. Node.js native modules (`fs`, `path`, `child_process`, `require()`, `import`) are disabled in the sandbox; pass file content or external data using the `context` parameter instead. | |
| repo | No | Target repository name to set as default context for all github/kanban tools executed in this sandbox (e.g., "memory-journal-mcp"). | |
| entry | No | Optional entry object or dictionary to create/update. When passed without code, Code Mode automatically synthesizes an appropriate journal entry. | |
| query | No | Optional search query string or SQL-style query string. If provided, Code Mode will automatically resolve it to search or retrieve entries. | |
| context | No | A JSON object, string, or array to pass variables directly into the sandbox (accessible via `context` inside JS code). Use this to pass file contents, external text, or complex entry objects into Code Mode without requiring `fs` or dynamic `require()`. | |
| dry_run | No | If true, state-modifying API calls (create_entry, update_entry, etc.) will be skipped, returning simulated success. | |
| payload | No | Optional payload object, dictionary, or JSON string (e.g. { action: "create", task: "...", notes: "...", changes: [...] }). When passed without code, Code Mode automatically translates and synthesizes it into a type-safe journal entry or API execution. | |
| timeout | No | Maximum execution time in milliseconds before the sandbox forcibly terminates the script (max: 30000ms). | |
| readonly | No | If true, execution is restricted to read-only operations. Write tools will be filtered out of the API bridge. | |
| use_test_db | No | ||
| auto_version | No | Automatically inject expected_version for optimistic concurrency on updates/deletes | |
| workspace_id | No | Target workspace ID to isolate data. If omitted, uses defaultWorkspaceId if configured. | |
| maxResultSize | No | Alias for max_result_size. | |
| project_number | No | Numeric project ID to bind to all tool calls in this sandbox. Repo name strings (e.g., "mysql-mcp") are auto-resolved via the project registry. Falls back to DEFAULT_PROJECT_NUMBER if unspecified. Find it by querying memory://agent-id. | |
| max_result_size | No | Maximum allowed result size in bytes (default: 102400 / 100KB, max: 52428800 / 50MB). Pass a higher limit (e.g. 200000 or 524288) when returning large datasets or multi-entry contents to avoid result truncation. |