Skip to content

Commit 45db2b0

Browse files
committed
chore: add type hints and suppress Pylance Blender import warnings
- Add # type: ignore to all bpy, bmesh, addon_utils, mathutils imports - Fix Optional type hints to use X | None syntax (Python 3.10+) - Add type guards for socket.socket | None in server.py - Add dict isinstance checks before attribute access - Fix mixed-in method calls with # type: ignore in modeling operators - Fix tuple attribute access (.z -> [2]) for Pylance compatibility - Update integration_tests.md with all four scenarios (grid, arch, print, filament_tag) - Update unit_tests.md to use [PASS] instead of emoji - Simplify mushroom keychain to red cap, update README - Delete outdated MULTICOLOR_3MF_GUIDE.md All type checking now passes with no false positives on Blender APIs.
1 parent dc1c65b commit 45db2b0

83 files changed

Lines changed: 3001 additions & 992 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ Set environment variables in `.env`:
356356

357357
```
358358
BLENDER_MCP_HOST=127.0.0.1
359-
BLENDER_MCP_PORT=8888
359+
BLENDER_MCP_PORT=8585
360360
BLENDER_ASSETS_DIR=C:/path/to/your/assets
361361
362362
```

blender_mcp_addon/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import bpy
1+
# blender_mcp_addon/__init__.py
2+
3+
import bpy # type: ignore
24

35
from .server import BlenderMCPServer
6+
from .utils import DEFAULT_PORT
47

58
bl_info = {
69
"name": "Blender MCP for n8n",
@@ -69,7 +72,7 @@ def draw(self, context):
6972
layout.operator("blendermcp.start_server")
7073
layout.operator("blendermcp.stop_server")
7174
layout.separator()
72-
layout.label(text="Port: 8888")
75+
layout.label(text=f"Port: {DEFAULT_PORT}")
7376
layout.label(text="45+ Structured Tools")
7477

7578

blender_mcp_addon/server.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
# blender_mcp_addon/server.py
2+
13
import json
24
import queue
35
import socket
46
import threading
57
import traceback
68

7-
import bpy
9+
import bpy # type: ignore
810

911
from .tools.animation import AnimationTools
1012
from .tools.camera import CameraTools
@@ -17,6 +19,7 @@
1719
from .tools.rendering import RenderingTools
1820
from .tools.scene import SceneTools
1921
from .tools.sculpting import SculptingTools
22+
from .utils import DEFAULT_HOST, DEFAULT_PORT
2023

2124

2225
class BlenderMCPServer(
@@ -35,7 +38,7 @@ class BlenderMCPServer(
3538
"""Blender MCP Server for n8n with componentized tools"""
3639

3740
def __init__(self):
38-
self.server_socket = None
41+
self.server_socket: socket.socket | None = None
3942
self.running = False
4043
self.server_thread = None
4144
self.command_queue = queue.Queue()
@@ -85,10 +88,11 @@ def import_and_analyze_reference(self, filepath=None):
8588
"bound_box": bound_box,
8689
}
8790

88-
def start_server(self, host="0.0.0.0", port=8888):
91+
def start_server(self, host=DEFAULT_HOST, port=DEFAULT_PORT):
8992
if self.running:
9093
return
9194
try:
95+
self.addon_log("Attempting to start MCP Server...")
9296
self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
9397
self.server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
9498
self.server_socket.bind((host, port))
@@ -97,10 +101,14 @@ def start_server(self, host="0.0.0.0", port=8888):
97101
self.server_thread = threading.Thread(target=self._server_loop, daemon=True)
98102
self.server_thread.start()
99103
self._register_timer()
104+
self.addon_log(f"MCP Server successfully started on {host}:{port}")
100105
print(f"MCP Server started on {host}:{port}")
101106
except Exception as e:
102-
print(f"Failed to start server: {e}")
103-
traceback.print_exc()
107+
import traceback
108+
109+
error_msg = f"Failed to start server: {e}\n{traceback.format_exc()}"
110+
print(error_msg)
111+
self.addon_log(error_msg)
104112

105113
def _register_timer(self):
106114
if self.timer_handle:
@@ -129,6 +137,8 @@ def stop_server(self):
129137
def _server_loop(self):
130138
while self.running:
131139
try:
140+
if not self.server_socket: # type: ignore
141+
break
132142
self.server_socket.settimeout(1.0)
133143
try:
134144
client, _ = self.server_socket.accept()
@@ -263,6 +273,7 @@ def execute_command(self, command):
263273
"create_text": self.create_text,
264274
"create_plane": self.create_plane,
265275
"create_empty": self.create_empty,
276+
"create_polygon": self.create_polygon,
266277
"duplicate_object": self.duplicate_object,
267278
"duplicate_selection": self.duplicate_selection,
268279
"create_and_array": self.create_and_array,
@@ -329,6 +340,7 @@ def execute_command(self, command):
329340
"repair_mesh": self.repair_mesh,
330341
"apply_voxel_remesh": self.apply_voxel_remesh,
331342
"export_model": self.export_model,
343+
"import_model": self.import_model,
332344
# Sculpting
333345
"enter_sculpt_mode": self.enter_sculpt_mode,
334346
"exit_sculpt_mode": self.exit_sculpt_mode,

blender_mcp_addon/tools/animation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# blender_mcp_addon/tools/animation.py
2+
13
import math
24

3-
import bpy
5+
import bpy # type: ignore
46

57
from ..utils import get_object
68

blender_mcp_addon/tools/camera.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# blender_mcp_addon/tools/camera.py
2+
13
import math
24

3-
import bpy
4-
from mathutils import Vector
5+
import bpy # type: ignore
6+
from mathutils import Vector # type: ignore
57

68
from ..utils import get_object
79

blender_mcp_addon/tools/collections.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import bpy
1+
# blender_mcp_addon/tools/collections.py
2+
3+
import bpy # type: ignore
24

35
from ..utils import get_collection, get_object
46

blender_mcp_addon/tools/history.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import bpy
1+
# blender_mcp_addon/tools/history.py
2+
3+
import bpy # type: ignore
24

35

46
class HistoryTools:

blender_mcp_addon/tools/lighting.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# blender_mcp_addon/tools/lighting.py
2+
13
import math
24

3-
import bpy
5+
import bpy # type: ignore
46

57
from ..utils import get_object, hex_to_rgb
68

blender_mcp_addon/tools/materials.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# blender_mcp_addon/tools/materials.py
2+
13
import fnmatch
24

3-
import bpy
5+
import bpy # type: ignore
46

57
from ..utils import get_object, hex_to_rgb
68

blender_mcp_addon/tools/modeling/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# blender_mcp_addon/tools/modeling/__init__.py
2+
13
from .architectural import ModelingArchitectural
24
from .modifiers import ModelingModifiers
35
from .operators import ModelingOperators

0 commit comments

Comments
 (0)