82c23d79c7
Adds an opt-in setting to automatically start the RPC server when FreeCAD opens, removing the need to manually click "Start RPC Server" each session. Changes: - New `auto_start_rpc` setting in freecad_mcp_settings.json (default: false) - New "Auto-Start Server" checkable menu item under FreeCAD MCP menu - InitGui.py uses QTimer.singleShot(0) to start the server after FreeCAD finishes initialization, only when the setting is enabled - Consolidated _sync_remote_toggle_state into _sync_toggle_states to handle both Remote Connections and Auto-Start checkboxes Tested on macOS with FreeCAD 1.0. Cross-platform: uses only PySide QtCore.QTimer and FreeCAD.getUserAppDataDir() (no OS-specific code). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
class FreeCADMCPAddonWorkbench(Workbench):
|
|
MenuText = "MCP Addon"
|
|
ToolTip = "Addon for MCP Communication"
|
|
|
|
def Initialize(self):
|
|
from rpc_server import rpc_server
|
|
|
|
commands = [
|
|
"Start_RPC_Server",
|
|
"Stop_RPC_Server",
|
|
"Toggle_Auto_Start",
|
|
"Toggle_Remote_Connections",
|
|
"Configure_Allowed_IPs",
|
|
]
|
|
self.appendToolbar("FreeCAD MCP", commands)
|
|
self.appendMenu("FreeCAD MCP", commands)
|
|
|
|
def Activated(self):
|
|
pass
|
|
|
|
def Deactivated(self):
|
|
pass
|
|
|
|
def ContextMenu(self, recipient):
|
|
pass
|
|
|
|
def GetClassName(self):
|
|
return "Gui::PythonWorkbench"
|
|
|
|
|
|
Gui.addWorkbench(FreeCADMCPAddonWorkbench())
|
|
|
|
|
|
def _auto_start_mcp():
|
|
try:
|
|
from rpc_server import rpc_server
|
|
|
|
settings = rpc_server.load_settings()
|
|
if not settings.get("auto_start_rpc", False):
|
|
return
|
|
|
|
msg = rpc_server.start_rpc_server()
|
|
FreeCAD.Console.PrintMessage(f"[MCP] Auto-start: {msg}\n")
|
|
except Exception as e:
|
|
FreeCAD.Console.PrintWarning(f"[MCP] Auto-start failed: {e}\n")
|
|
|
|
|
|
from PySide import QtCore
|
|
|
|
QtCore.QTimer.singleShot(0, _auto_start_mcp)
|