editor_run_python
Execute Python code directly within Unreal Editor to automate tasks, manipulate assets, or extend functionality using the Unreal Python API.
Instructions
Execute any python within the Unreal Editor. All python must have import unreal at the top. CHECK THE UNREAL PYTHON DOCUMENTATION BEFORE USING THIS TOOL. NEVER EVER ADD COMMENTS
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes |
Implementation Reference
- server/index.ts:146-156 (registration)Registration of the 'editor_run_python' tool using McpServer.tool, including inline handler and schema."editor_run_python", "Execute any python within the Unreal Editor. All python must have `import unreal` at the top. CHECK THE UNREAL PYTHON DOCUMENTATION BEFORE USING THIS TOOL. NEVER EVER ADD COMMENTS", { code: z.string() }, async ({ code }) => { const result = await tryRunCommand(code) return { content: [{ type: "text", text: result }], } }, )
- server/index.ts:149-155 (handler)Handler function that takes Python code input and executes it via tryRunCommand, returning the output as text.async ({ code }) => { const result = await tryRunCommand(code) return { content: [{ type: "text", text: result }], } },
- server/index.ts:148-148 (schema)Input schema defining 'code' as a string (the Python code to execute).{ code: z.string() },
- server/index.ts:61-72 (helper)Helper function used by the tool (and others) to execute commands on the remote Unreal Engine node via RemoteExecution.const tryRunCommand = async (command: string): Promise<string> => { if (!remoteNode) { throw new Error("Remote node is not available") } const result = await remoteNode.runCommand(command) if (!result.success) { throw new Error(`Command failed with: ${result.result}`) } return result.output.map((line) => line.output).join("\n") }