70 lines
2.1 KiB
Plaintext
70 lines
2.1 KiB
Plaintext
"""FreeCAD Macro: Start MCP Bridge Server.
|
|
|
|
Start the MCP bridge server for AI assistant integration with FreeCAD.
|
|
|
|
Version: 1.0.0
|
|
Author: FreeCAD MCP Project
|
|
|
|
Requirements:
|
|
- FreeCAD 0.21 or later
|
|
- freecad-mcp project installed and accessible
|
|
|
|
Usage:
|
|
1. Install via: just install-bridge-macro
|
|
2. Run the macro from: Macro -> Macros -> StartMCPBridge -> Execute
|
|
3. Connect your MCP client (Claude Code, etc.) to the running bridge
|
|
"""
|
|
|
|
import sys
|
|
|
|
import FreeCAD
|
|
|
|
|
|
def start_mcp_bridge():
|
|
"""Start the MCP bridge server for AI assistant integration."""
|
|
# The project path is injected during macro installation
|
|
# This placeholder will be replaced with the actual path
|
|
project_path = "__PROJECT_PATH__"
|
|
|
|
if project_path == "__PROJECT_PATH__":
|
|
FreeCAD.Console.PrintError(
|
|
"MCP Bridge macro not properly installed.\n"
|
|
"Please run: just install-bridge-macro\n"
|
|
)
|
|
return
|
|
|
|
if project_path not in sys.path:
|
|
sys.path.insert(0, project_path)
|
|
|
|
try:
|
|
# Import and start the plugin
|
|
from freecad_mcp.freecad_plugin.server import FreecadMCPPlugin
|
|
|
|
# Create and start the plugin
|
|
plugin = FreecadMCPPlugin(
|
|
host="localhost",
|
|
port=9876, # JSON-RPC socket port
|
|
xmlrpc_port=9875, # XML-RPC port (neka-nat compatible)
|
|
enable_xmlrpc=True,
|
|
)
|
|
plugin.start()
|
|
|
|
FreeCAD.Console.PrintMessage("MCP Bridge started!\n")
|
|
FreeCAD.Console.PrintMessage(" - XML-RPC: localhost:9875\n")
|
|
FreeCAD.Console.PrintMessage(" - Socket: localhost:9876\n")
|
|
FreeCAD.Console.PrintMessage(
|
|
"\nYou can now connect your MCP client (Claude Code, etc.) to FreeCAD.\n"
|
|
)
|
|
|
|
except ImportError as e:
|
|
FreeCAD.Console.PrintError(
|
|
f"Failed to import MCP Bridge module: {e}\n"
|
|
f"Ensure the freecad-mcp project is accessible at: {project_path}\n"
|
|
)
|
|
except Exception as e:
|
|
FreeCAD.Console.PrintError(f"Failed to start MCP Bridge: {e}\n")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
start_mcp_bridge()
|