Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: start Blender MCP on mcp 2 (#16895)

Daniel Hanb51cde829dda
diff --git a/studio/backend/integrations/blender/launcher.py b/studio/backend/integrations/blender/launcher.py
index de4a3d390a3..6bd6f8da301 100644
--- a/studio/backend/integrations/blender/launcher.py
+++ b/studio/backend/integrations/blender/launcher.py
@@ -4,10 +4,44 @@
"""Launch the cached Blender MCP runtime over stdio without downloading."""
+import functools
import sys
+import types
from pathlib import Path
+def _alias_fastmcp() -> None:
+ # mcp 2 renamed FastMCP to MCPServer; the pinned runtime still imports the v1 module.
+ try:
+ import mcp.server.fastmcp # noqa: F401
+ except ModuleNotFoundError:
+ from mcp.server import mcpserver
+ from mcp.server.mcpserver.exceptions import ToolError
+
+ class FastMCP(mcpserver.MCPServer):
+ # mcp 2 hides a tool's exception text from the model; v1 sent it (e.g. Blender tracebacks).
+ def tool(self, *args, **kwargs):
+ register = super().tool(*args, **kwargs)
+
+ def decorator(fn):
+ @functools.wraps(fn)
+ def call(*call_args, **call_kwargs):
+ try:
+ return fn(*call_args, **call_kwargs)
+ except Exception as exc:
+ raise ToolError(str(exc)) from exc
+
+ register(call)
+ return fn
+
+ return decorator
+
+ shim = types.ModuleType("mcp.server.fastmcp")
+ shim.FastMCP = FastMCP
+ shim.__getattr__ = lambda name: getattr(mcpserver, name)
+ sys.modules["mcp.server.fastmcp"] = shim
+
+
def main() -> int:
if sys.version_info < (3, 10):
print("Blender MCP requires Python 3.10 or newer.", file = sys.stderr)
@@ -20,6 +54,7 @@ def main() -> int:
print("Open Blender MCP in Unsloth and enable it to download the runtime.", file = sys.stderr)
return 1
sys.path.insert(0, str(runtime))
+ _alias_fastmcp()
from blmcp import main as upstream_main
sys.argv = [str(Path(__file__).resolve()), "--transport", "stdio"]
diff --git a/studio/backend/tests/test_blender_runtime.py b/studio/backend/tests/test_blender_runtime.py
index d586cda84a2..59eadc24138 100644
--- a/studio/backend/tests/test_blender_runtime.py
+++ b/studio/backend/tests/test_blender_runtime.py
@@ -3,8 +3,11 @@
import hashlib
import io
+import subprocess
+import sys
import tarfile
from concurrent.futures import ThreadPoolExecutor
+from pathlib import Path
from unittest.mock import Mock
import pytest
@@ -57,3 +60,33 @@ def test_verified_archive_still_rejects_traversal(tmp_path, monkeypatch):
with pytest.raises(ValueError, match = "Unsafe"):
runtime._extract(data, tmp_path / "runtime")
assert not (tmp_path / "escape.py").exists()
+
+
+def test_launcher_runs_v1_fastmcp_runtime_on_installed_mcp(tmp_path):
+ package = tmp_path / "blmcp"
+ package.mkdir()
+ (tmp_path / ".ready").write_text("x")
+ (package / "__init__.py").write_text(
+ "import asyncio\n"
+ "from mcp.server.fastmcp import FastMCP, Image\n"
+ "def main():\n"
+ " server = FastMCP('blender-mcp', instructions='x')\n"
+ " @server.tool()\n"
+ " def fail() -> int:\n"
+ " raise RuntimeError('Blender error: NameError')\n"
+ " try:\n"
+ " asyncio.run(server.call_tool('fail', {}))\n"
+ " except Exception as exc:\n"
+ " print(exc)\n"
+ " print(Image(data=b'x', format='png').data)\n"
+ " return 0\n"
+ )
+ launcher = Path(runtime.__file__).with_name("launcher.py")
+ result = subprocess.run(
+ [sys.executable, str(launcher), str(tmp_path)], capture_output = True, text = True
+ )
+ assert result.returncode == 0, result.stderr
+ assert result.stdout.splitlines() == [
+ "Error executing tool fail: Blender error: NameError",
+ "b'x'",
+ ]