MCPcopy Create free account
hub / github.com/capoomgit/houdini-mcp / execute_code

Method execute_code

server.py:460–483  ·  view source on GitHub ↗

Executes arbitrary Python code within Houdini.

(self, code)

Source from the content-addressed store, hash-verified

458 return node_info
459
460 def execute_code(self, code):
461 """Executes arbitrary Python code within Houdini."""
462 stdout_capture = io.StringIO()
463 stderr_capture = io.StringIO()
464 try:
465 namespace = {"hou": hou}
466 # Capture stdout/stderr during exec
467 with redirect_stdout(stdout_capture), redirect_stderr(stderr_capture):
468 exec(code, namespace)
469
470 # Success case: return execution status and captured output
471 return {
472 "executed": True,
473 "stdout": stdout_capture.getvalue(),
474 "stderr": stderr_capture.getvalue()
475 }
476 except Exception as e:
477 # Failure case: print traceback to actual stderr for debugging in Houdini
478 print("--- Houdini MCP: execute_code Error ---", file=sys.stderr)
479 traceback.print_exc(file=sys.stderr)
480 print("--- End Error ---", file=sys.stderr)
481 # Re-raise the exception so it's caught by execute_command
482 # and reported back as a standard error message.
483 raise Exception(f"Code execution error: {str(e)}")
484
485 # -------------------------------------------------------------------------
486 # Graph Editing & Introspection

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected