Bridge API Reference¶
The bridge module provides the communication layer between the Robust MCP Server and FreeCAD.
Base Classes¶
freecad_mcp.bridge.base ¶
Abstract bridge interface for FreeCAD communication.
This module defines the abstract base class and data types for all FreeCAD bridge implementations. Bridges provide the communication layer between the Robust MCP Server and FreeCAD instances.
Based on learnings from existing implementations: - neka-nat: Queue-based thread safety for GUI operations - jango: Multiple connection modes with recovery - contextform: Comprehensive CAD operations
Classes¶
ConnectionStatus dataclass ¶
Status of the FreeCAD connection.
Attributes:
| Name | Type | Description |
|---|---|---|
connected | bool | Whether connection is established. |
mode | str | Connection mode (embedded, xmlrpc, socket). |
freecad_version | str | FreeCAD version string. |
gui_available | bool | Whether GUI is available. |
last_ping_ms | float | Last ping latency in milliseconds. |
error | str | None | Connection error message if any. |
Source code in src/freecad_mcp/bridge/base.py
DocumentInfo dataclass ¶
Information about a FreeCAD document.
Attributes:
| Name | Type | Description |
|---|---|---|
name | str | Internal document name (identifier). |
label | str | Display label (may differ from name). |
path | str | None | File path if saved, None otherwise. |
objects | list[str] | List of object names in the document. |
is_modified | bool | Whether document has unsaved changes. |
active_object | str | None | Name of the currently active object. |
Source code in src/freecad_mcp/bridge/base.py
ExecutionResult dataclass ¶
Result of Python code execution in FreeCAD.
Attributes:
| Name | Type | Description |
|---|---|---|
success | bool | Whether execution completed without errors. |
result | Any | The value assigned to |
stdout | str | Captured standard output. |
stderr | str | Captured standard error. |
execution_time_ms | float | Time taken in milliseconds. |
error_type | str | None | Type of exception if failed, None otherwise. |
error_traceback | str | None | Full traceback if failed, None otherwise. |
Source code in src/freecad_mcp/bridge/base.py
FreecadBridge ¶
Bases: ABC
Abstract base class for FreeCAD bridges.
A bridge provides communication between the Robust MCP Server and a FreeCAD instance. Implementations may run FreeCAD in-process (embedded), communicate via XML-RPC, or use JSON-RPC over sockets.
Thread Safety
GUI operations must be executed on the main thread. Implementations should use queue-based communication for thread safety (learned from neka-nat implementation).
Source code in src/freecad_mcp/bridge/base.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
Functions¶
activate_workbench(workbench_name) abstractmethod async ¶
Activate a workbench.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workbench_name | str | Workbench internal name. | required |
Raises:
| Type | Description |
|---|---|
ValueError | If workbench not found. |
close_document(doc_name=None) abstractmethod async ¶
Close a document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc_name | str | None | Document name (uses active if None). | None |
connect() abstractmethod async ¶
Establish connection to FreeCAD.
Raises:
| Type | Description |
|---|---|
ConnectionError | If connection cannot be established. |
create_document(name, label=None) abstractmethod async ¶
Create a new document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | Internal document name (no spaces). | required |
label | str | None | Display label (optional, defaults to name). | None |
Returns:
| Type | Description |
|---|---|
DocumentInfo | DocumentInfo for the created document. |
Source code in src/freecad_mcp/bridge/base.py
create_macro(name, code, description='') abstractmethod async ¶
Create a new macro.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | Macro name (without extension). | required |
code | str | Python code for the macro. | required |
description | str | Macro description. | '' |
Returns:
| Type | Description |
|---|---|
MacroInfo | MacroInfo for the created macro. |
Source code in src/freecad_mcp/bridge/base.py
create_object(type_id, name=None, properties=None, doc_name=None) abstractmethod async ¶
Create a new object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_id | str | FreeCAD type ID (e.g., "Part::Box", "Part::Cylinder"). | required |
name | str | None | Object name (auto-generated if None). | None |
properties | dict[str, Any] | None | Initial property values. | None |
doc_name | str | None | Target document (uses active if None). | None |
Returns:
| Type | Description |
|---|---|
ObjectInfo | ObjectInfo for the created object. |
Source code in src/freecad_mcp/bridge/base.py
delete_object(obj_name, doc_name=None) abstractmethod async ¶
Delete an object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj_name | str | Name of the object to delete. | required |
doc_name | str | None | Document name (uses active if None). | None |
Raises:
| Type | Description |
|---|---|
ValueError | If object not found. |
Source code in src/freecad_mcp/bridge/base.py
disconnect() abstractmethod async ¶
edit_object(obj_name, properties, doc_name=None) abstractmethod async ¶
Edit object properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj_name | str | Name of the object to edit. | required |
properties | dict[str, Any] | Property values to set. | required |
doc_name | str | None | Document name (uses active if None). | None |
Returns:
| Type | Description |
|---|---|
ObjectInfo | Updated ObjectInfo. |
Raises:
| Type | Description |
|---|---|
ValueError | If object not found. |
Source code in src/freecad_mcp/bridge/base.py
execute_python(code, timeout_ms=30000) abstractmethod async ¶
Execute Python code in FreeCAD context.
The code runs with access to FreeCAD modules (FreeCAD, App, Gui). To return a value, assign it to the _result_ variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code | str | Python code to execute. | required |
timeout_ms | int | Maximum execution time in milliseconds. | 30000 |
Returns:
| Type | Description |
|---|---|
ExecutionResult | ExecutionResult with success status, output, and any errors. |
Source code in src/freecad_mcp/bridge/base.py
get_active_document() abstractmethod async ¶
Get the active document.
Returns:
| Type | Description |
|---|---|
DocumentInfo | None | DocumentInfo for active document, or None if no document is active. |
get_console_output(lines=100) abstractmethod async ¶
Get recent console output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lines | int | Maximum number of lines to return. | 100 |
Returns:
| Type | Description |
|---|---|
list[str] | List of console output lines, most recent last. |
Source code in src/freecad_mcp/bridge/base.py
get_documents() abstractmethod async ¶
Get list of open documents.
Returns:
| Type | Description |
|---|---|
list[DocumentInfo] | List of DocumentInfo for each open document. |
get_freecad_version() abstractmethod async ¶
Get FreeCAD version information.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary with version, build_date, python_version, gui_available. |
get_macros() abstractmethod async ¶
Get list of available macros.
Returns:
| Type | Description |
|---|---|
list[MacroInfo] | List of MacroInfo for each macro. |
get_object(obj_name, doc_name=None) abstractmethod async ¶
Get detailed object information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj_name | str | Name of the object. | required |
doc_name | str | None | Document name (uses active if None). | None |
Returns:
| Type | Description |
|---|---|
ObjectInfo | ObjectInfo with full object details. |
Raises:
| Type | Description |
|---|---|
ValueError | If object not found. |
Source code in src/freecad_mcp/bridge/base.py
get_objects(doc_name=None) abstractmethod async ¶
Get all objects in a document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc_name | str | None | Document name (uses active if None). | None |
Returns:
| Type | Description |
|---|---|
list[ObjectInfo] | List of ObjectInfo for each object. |
Source code in src/freecad_mcp/bridge/base.py
get_screenshot(view_angle=None, width=800, height=600, doc_name=None) abstractmethod async ¶
Capture a screenshot of the 3D view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_angle | ViewAngle | None | View angle to set before capture. | None |
width | int | Image width in pixels. | 800 |
height | int | Image height in pixels. | 600 |
doc_name | str | None | Document name (uses active if None). | None |
Returns:
| Type | Description |
|---|---|
ScreenshotResult | ScreenshotResult with image data or error. |
Source code in src/freecad_mcp/bridge/base.py
get_status() abstractmethod async ¶
Get detailed connection status.
Returns:
| Type | Description |
|---|---|
ConnectionStatus | ConnectionStatus with full status information. |
get_workbenches() abstractmethod async ¶
Get list of available workbenches.
Returns:
| Type | Description |
|---|---|
list[WorkbenchInfo] | List of WorkbenchInfo for each workbench. |
is_connected() abstractmethod async ¶
Check if bridge is connected to FreeCAD.
Returns:
| Type | Description |
|---|---|
bool | True if connected, False otherwise. |
is_gui_available() abstractmethod async ¶
Check if FreeCAD GUI is available.
Returns:
| Type | Description |
|---|---|
bool | True if GUI is available, False for headless mode. |
open_document(path) abstractmethod async ¶
Open an existing document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | Path to the .FCStd file. | required |
Returns:
| Type | Description |
|---|---|
DocumentInfo | DocumentInfo for the opened document. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError | If file doesn't exist. |
ValueError | If file is not a valid FreeCAD document. |
Source code in src/freecad_mcp/bridge/base.py
ping() abstractmethod async ¶
Ping FreeCAD to check connection and measure latency.
Returns:
| Type | Description |
|---|---|
float | Round-trip time in milliseconds. |
Raises:
| Type | Description |
|---|---|
ConnectionError | If not connected. |
run_macro(macro_name, args=None) abstractmethod async ¶
Run a macro by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
macro_name | str | Macro name (without .FCMacro extension). | required |
args | dict[str, Any] | None | Arguments to pass to the macro. | None |
Returns:
| Type | Description |
|---|---|
ExecutionResult | ExecutionResult from macro execution. |
Source code in src/freecad_mcp/bridge/base.py
save_document(doc_name=None, path=None) abstractmethod async ¶
Save a document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc_name | str | None | Document name (uses active if None). | None |
path | str | None | Save path (uses existing path if None). | None |
Returns:
| Type | Description |
|---|---|
str | Path where document was saved. |
Raises:
| Type | Description |
|---|---|
ValueError | If document not found or no path specified for new doc. |
Source code in src/freecad_mcp/bridge/base.py
MacroInfo dataclass ¶
Information about a FreeCAD macro.
Attributes:
| Name | Type | Description |
|---|---|---|
name | str | Macro name (without extension). |
path | str | Full path to macro file. |
description | str | Macro description from comments. |
is_system | bool | Whether it's a system macro. |
Source code in src/freecad_mcp/bridge/base.py
ObjectInfo dataclass ¶
Information about a FreeCAD object.
Attributes:
| Name | Type | Description |
|---|---|---|
name | str | Object name (identifier). |
label | str | Display label. |
type_id | str | FreeCAD TypeId string (e.g., "Part::Box"). |
properties | dict[str, Any] | Dictionary of property names to values. |
shape_info | dict[str, Any] | None | Shape geometry details if applicable. |
children | list[str] | List of child object names (OutList). |
parents | list[str] | List of parent object names (InList). |
visibility | bool | Whether object is visible in the view. |
Source code in src/freecad_mcp/bridge/base.py
ObjectType ¶
Bases: str, Enum
FreeCAD object type categories.
Source code in src/freecad_mcp/bridge/base.py
ScreenshotResult dataclass ¶
Result of a screenshot capture.
Attributes:
| Name | Type | Description |
|---|---|---|
success | bool | Whether screenshot was captured successfully. |
data | str | None | Base64-encoded image data. |
format | str | Image format (png, jpg). |
width | int | Image width in pixels. |
height | int | Image height in pixels. |
view_angle | ViewAngle | None | The view angle used. |
error | str | None | Error message if failed. |
Source code in src/freecad_mcp/bridge/base.py
ShapeInfo dataclass ¶
Detailed shape geometry information.
Attributes:
| Name | Type | Description |
|---|---|---|
shape_type | str | Type of shape (Solid, Shell, Face, etc.). |
volume | float | None | Volume of the shape (for solids). |
area | float | None | Surface area of the shape. |
center_of_mass | tuple[float, float, float] | None | Center of mass coordinates. |
bounding_box | tuple[tuple[float, float, float], tuple[float, float, float]] | None | Bounding box as (min, max) tuples. |
is_valid | bool | Whether the shape is geometrically valid. |
is_closed | bool | Whether the shape is closed. |
vertex_count | int | Number of vertices. |
edge_count | int | Number of edges. |
face_count | int | Number of faces. |
Source code in src/freecad_mcp/bridge/base.py
ViewAngle ¶
Bases: str, Enum
Standard view angles for screenshots.
Source code in src/freecad_mcp/bridge/base.py
WorkbenchInfo dataclass ¶
Information about a FreeCAD workbench.
Attributes:
| Name | Type | Description |
|---|---|---|
name | str | Workbench internal name. |
label | str | Display label. |
icon | str | Icon resource path. |
is_active | bool | Whether workbench is currently active. |
Source code in src/freecad_mcp/bridge/base.py
options: show_root_heading: true show_source: true
XML-RPC Bridge¶
freecad_mcp.bridge.xmlrpc ¶
XML-RPC bridge for FreeCAD GUI mode communication.
This bridge connects to a FreeCAD instance running an XML-RPC server, allowing remote control while FreeCAD has its GUI open.
Compatible with neka-nat/freecad-mcp XML-RPC protocol, providing interoperability with existing FreeCAD Robust MCP addons.
Design inspired by neka-nat/freecad-mcp (MIT License): - Uses neka-nat's proven XML-RPC protocol (port 9875) - Connection health monitoring and auto-reconnect - Timeout handling for long operations
Attribution
The XML-RPC protocol design and port selection (9875) were inspired by neka-nat/freecad-mcp (https://github.com/neka-nat/freecad-mcp), which is licensed under the MIT License. This implementation is a complete rewrite that maintains protocol compatibility.
Classes¶
XmlRpcBridge ¶
Bases: FreecadBridge
Bridge that communicates with FreeCAD via XML-RPC.
This bridge connects to a FreeCAD instance that is running the XML-RPC server addon. It provides full access to FreeCAD functionality including GUI operations like screenshots.
Attributes:
| Name | Type | Description |
|---|---|---|
host | XML-RPC server hostname. | |
port | XML-RPC server port. | |
timeout | Connection and request timeout in seconds. |
Source code in src/freecad_mcp/bridge/xmlrpc.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 | |
Functions¶
__init__(host=DEFAULT_XMLRPC_HOST, port=DEFAULT_XMLRPC_PORT, timeout=DEFAULT_TIMEOUT) ¶
Initialize the XML-RPC bridge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host | str | XML-RPC server hostname. | DEFAULT_XMLRPC_HOST |
port | int | XML-RPC server port. | DEFAULT_XMLRPC_PORT |
timeout | float | Connection and request timeout in seconds. | DEFAULT_TIMEOUT |
Source code in src/freecad_mcp/bridge/xmlrpc.py
activate_workbench(workbench_name) async ¶
Activate a workbench.
Source code in src/freecad_mcp/bridge/xmlrpc.py
close_document(doc_name=None) async ¶
Close a document.
Source code in src/freecad_mcp/bridge/xmlrpc.py
connect() async ¶
Establish connection to FreeCAD XML-RPC server.
Raises:
| Type | Description |
|---|---|
ConnectionError | If connection cannot be established. |
Source code in src/freecad_mcp/bridge/xmlrpc.py
create_document(name, label=None) async ¶
Create a new document.
Source code in src/freecad_mcp/bridge/xmlrpc.py
create_macro(name, code, description='') async ¶
Create a new macro.
Source code in src/freecad_mcp/bridge/xmlrpc.py
create_object(type_id, name=None, properties=None, doc_name=None) async ¶
Create a new object.
Source code in src/freecad_mcp/bridge/xmlrpc.py
delete_object(obj_name, doc_name=None) async ¶
Delete an object.
Source code in src/freecad_mcp/bridge/xmlrpc.py
disconnect() async ¶
edit_object(obj_name, properties, doc_name=None) async ¶
Edit object properties.
Source code in src/freecad_mcp/bridge/xmlrpc.py
execute_python(code, timeout_ms=30000) async ¶
Execute Python code in FreeCAD context via XML-RPC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code | str | Python code to execute. | required |
timeout_ms | int | Maximum execution time in milliseconds. | 30000 |
Returns:
| Type | Description |
|---|---|
ExecutionResult | ExecutionResult with execution outcome. |
Source code in src/freecad_mcp/bridge/xmlrpc.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
get_active_document() async ¶
Get the active document.
Source code in src/freecad_mcp/bridge/xmlrpc.py
get_console_output(lines=100) async ¶
Get recent console output.
Source code in src/freecad_mcp/bridge/xmlrpc.py
get_documents() async ¶
Get list of open documents.
Source code in src/freecad_mcp/bridge/xmlrpc.py
get_freecad_version() async ¶
Get FreeCAD version information.
Source code in src/freecad_mcp/bridge/xmlrpc.py
get_macros() async ¶
Get list of available macros.
Source code in src/freecad_mcp/bridge/xmlrpc.py
get_object(obj_name, doc_name=None) async ¶
Get detailed object information.
Source code in src/freecad_mcp/bridge/xmlrpc.py
get_objects(doc_name=None) async ¶
Get all objects in a document.
Source code in src/freecad_mcp/bridge/xmlrpc.py
get_screenshot(view_angle=None, width=800, height=600, doc_name=None) async ¶
Capture a screenshot of the 3D view via XML-RPC.
Source code in src/freecad_mcp/bridge/xmlrpc.py
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 | |
get_status() async ¶
Get detailed connection status.
Returns:
| Type | Description |
|---|---|
ConnectionStatus | ConnectionStatus with full status information. |
Source code in src/freecad_mcp/bridge/xmlrpc.py
get_workbenches() async ¶
Get list of available workbenches.
Source code in src/freecad_mcp/bridge/xmlrpc.py
is_connected() async ¶
Check if bridge is connected to FreeCAD.
Source code in src/freecad_mcp/bridge/xmlrpc.py
is_gui_available() async ¶
open_document(path) async ¶
Open an existing document.
Source code in src/freecad_mcp/bridge/xmlrpc.py
ping() async ¶
Ping FreeCAD to check connection and measure latency.
Returns:
| Type | Description |
|---|---|
float | Round-trip time in milliseconds. |
Raises:
| Type | Description |
|---|---|
ConnectionError | If not connected. |
Source code in src/freecad_mcp/bridge/xmlrpc.py
run_macro(macro_name, args=None) async ¶
Run a macro by name.
Source code in src/freecad_mcp/bridge/xmlrpc.py
save_document(doc_name=None, path=None) async ¶
Save a document.
Source code in src/freecad_mcp/bridge/xmlrpc.py
set_view(view_angle, doc_name=None) async ¶
Set the 3D view angle.
Source code in src/freecad_mcp/bridge/xmlrpc.py
options: show_root_heading: true show_source: true
Socket Bridge¶
freecad_mcp.bridge.socket ¶
Socket bridge for FreeCAD communication via JSON-RPC.
This bridge communicates with FreeCAD using JSON-RPC over TCP sockets, providing a modern, lightweight alternative to XML-RPC.
Based on learnings from competitive analysis: - Simple socket-based approach (inspired by bonninr/freecad_mcp) - Connection recovery mechanisms (from jango-blockchained) - Automatic reconnection on connection loss
Classes¶
JsonRpcError ¶
Bases: Exception
JSON-RPC error response.
Source code in src/freecad_mcp/bridge/socket.py
SocketBridge ¶
Bases: FreecadBridge
Bridge that communicates with FreeCAD via JSON-RPC over sockets.
This bridge provides a lightweight, modern protocol for FreeCAD communication. It supports automatic reconnection and connection health monitoring.
Attributes:
| Name | Type | Description |
|---|---|---|
host | Socket server hostname. | |
port | Socket server port. | |
timeout | Connection and request timeout in seconds. |
Source code in src/freecad_mcp/bridge/socket.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 | |
Functions¶
__init__(host=DEFAULT_SOCKET_HOST, port=DEFAULT_SOCKET_PORT, timeout=DEFAULT_TIMEOUT, auto_reconnect=True) ¶
Initialize the socket bridge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host | str | Socket server hostname. | DEFAULT_SOCKET_HOST |
port | int | Socket server port. | DEFAULT_SOCKET_PORT |
timeout | float | Connection and request timeout in seconds. | DEFAULT_TIMEOUT |
auto_reconnect | bool | Whether to automatically reconnect on connection loss. | True |
Source code in src/freecad_mcp/bridge/socket.py
activate_workbench(workbench_name) async ¶
Activate a workbench.
Source code in src/freecad_mcp/bridge/socket.py
close_document(doc_name=None) async ¶
Close a document.
Source code in src/freecad_mcp/bridge/socket.py
connect() async ¶
Establish connection to FreeCAD socket server.
Raises:
| Type | Description |
|---|---|
ConnectionError | If connection cannot be established. |
Source code in src/freecad_mcp/bridge/socket.py
create_document(name, label=None) async ¶
Create a new document.
Source code in src/freecad_mcp/bridge/socket.py
create_macro(name, code, description='') async ¶
Create a new macro.
Source code in src/freecad_mcp/bridge/socket.py
create_object(type_id, name=None, properties=None, doc_name=None) async ¶
Create a new object.
Source code in src/freecad_mcp/bridge/socket.py
delete_object(obj_name, doc_name=None) async ¶
Delete an object.
Source code in src/freecad_mcp/bridge/socket.py
disconnect() async ¶
Close connection to FreeCAD socket server.
Source code in src/freecad_mcp/bridge/socket.py
edit_object(obj_name, properties, doc_name=None) async ¶
Edit object properties.
Source code in src/freecad_mcp/bridge/socket.py
execute_python(code, timeout_ms=30000) async ¶
Execute Python code in FreeCAD context via socket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code | str | Python code to execute. | required |
timeout_ms | int | Maximum execution time in milliseconds. | 30000 |
Returns:
| Type | Description |
|---|---|
ExecutionResult | ExecutionResult with execution outcome. |
Source code in src/freecad_mcp/bridge/socket.py
get_active_document() async ¶
Get the active document.
Source code in src/freecad_mcp/bridge/socket.py
get_console_output(lines=100) async ¶
Get recent console output.
Source code in src/freecad_mcp/bridge/socket.py
get_documents() async ¶
Get list of open documents.
Source code in src/freecad_mcp/bridge/socket.py
get_freecad_version() async ¶
Get FreeCAD version information.
Source code in src/freecad_mcp/bridge/socket.py
get_macros() async ¶
Get list of available macros.
Source code in src/freecad_mcp/bridge/socket.py
get_object(obj_name, doc_name=None) async ¶
Get detailed object information.
Source code in src/freecad_mcp/bridge/socket.py
get_objects(doc_name=None) async ¶
Get all objects in a document.
Source code in src/freecad_mcp/bridge/socket.py
get_screenshot(view_angle=None, width=800, height=600, doc_name=None) async ¶
Capture a screenshot of the 3D view via socket.
Source code in src/freecad_mcp/bridge/socket.py
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
get_status() async ¶
Get detailed connection status.
Returns:
| Type | Description |
|---|---|
ConnectionStatus | ConnectionStatus with full status information. |
Source code in src/freecad_mcp/bridge/socket.py
get_workbenches() async ¶
Get list of available workbenches.
Source code in src/freecad_mcp/bridge/socket.py
is_connected() async ¶
Check if bridge is connected to FreeCAD.
Source code in src/freecad_mcp/bridge/socket.py
is_gui_available() async ¶
open_document(path) async ¶
Open an existing document.
Source code in src/freecad_mcp/bridge/socket.py
ping() async ¶
Ping FreeCAD to check connection and measure latency.
Returns:
| Type | Description |
|---|---|
float | Round-trip time in milliseconds. |
Raises:
| Type | Description |
|---|---|
ConnectionError | If not connected. |
Source code in src/freecad_mcp/bridge/socket.py
run_macro(macro_name, args=None) async ¶
Run a macro by name.
Source code in src/freecad_mcp/bridge/socket.py
save_document(doc_name=None, path=None) async ¶
Save a document.
Source code in src/freecad_mcp/bridge/socket.py
set_view(view_angle, doc_name=None) async ¶
Set the 3D view angle.
Source code in src/freecad_mcp/bridge/socket.py
options: show_root_heading: true show_source: true
Embedded Bridge¶
Linux Only
The embedded bridge only works on Linux. See Connection Modes for details.
freecad_mcp.bridge.embedded ¶
Embedded bridge - runs FreeCAD in-process.
This bridge imports FreeCAD directly into the Robust MCP Server process, providing the fastest execution but limited to headless mode.
Based on learnings from competitive analysis: - Thread-safe execution using ThreadPoolExecutor (from neka-nat) - Comprehensive object info including shape geometry - Macro support with templates and validation
Classes¶
EmbeddedBridge ¶
Bases: FreecadBridge
Bridge that runs FreeCAD embedded in the Robust MCP Server process.
This bridge imports FreeCAD directly, providing fast execution but only supports headless mode (no GUI).
Attributes:
| Name | Type | Description |
|---|---|---|
freecad_path | Optional path to FreeCAD's lib directory. |
Source code in src/freecad_mcp/bridge/embedded.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 | |
Functions¶
__init__(freecad_path=None) ¶
Initialize the embedded bridge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freecad_path | str | None | Path to FreeCAD's lib directory. If provided, this path will be added to sys.path before importing. | None |
Source code in src/freecad_mcp/bridge/embedded.py
activate_workbench(workbench_name) async ¶
Activate a workbench.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workbench_name | str | Workbench internal name. | required |
Raises:
| Type | Description |
|---|---|
ValueError | If workbench not found. |
Source code in src/freecad_mcp/bridge/embedded.py
close_document(doc_name=None) async ¶
Close a document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc_name | str | None | Document name (uses active if None). | None |
Source code in src/freecad_mcp/bridge/embedded.py
connect() async ¶
Import and initialize FreeCAD.
Raises:
| Type | Description |
|---|---|
ConnectionError | If FreeCAD cannot be imported. |
Source code in src/freecad_mcp/bridge/embedded.py
create_document(name, label=None) async ¶
Create a new document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | Internal document name (no spaces). | required |
label | str | None | Display label (optional, defaults to name). | None |
Returns:
| Type | Description |
|---|---|
DocumentInfo | DocumentInfo for the created document. |
Source code in src/freecad_mcp/bridge/embedded.py
create_macro(name, code, description='') async ¶
Create a new macro.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | Macro name (without extension). | required |
code | str | Python code for the macro. | required |
description | str | Macro description. | '' |
Returns:
| Type | Description |
|---|---|
MacroInfo | MacroInfo for the created macro. |
Source code in src/freecad_mcp/bridge/embedded.py
create_object(type_id, name=None, properties=None, doc_name=None) async ¶
Create a new object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_id | str | FreeCAD type ID (e.g., "Part::Box", "Part::Cylinder"). | required |
name | str | None | Object name (auto-generated if None). | None |
properties | dict[str, Any] | None | Initial property values. | None |
doc_name | str | None | Target document (uses active if None). | None |
Returns:
| Type | Description |
|---|---|
ObjectInfo | ObjectInfo for the created object. |
Source code in src/freecad_mcp/bridge/embedded.py
delete_object(obj_name, doc_name=None) async ¶
Delete an object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj_name | str | Name of the object to delete. | required |
doc_name | str | None | Document name (uses active if None). | None |
Raises:
| Type | Description |
|---|---|
ValueError | If object not found. |
Source code in src/freecad_mcp/bridge/embedded.py
disconnect() async ¶
edit_object(obj_name, properties, doc_name=None) async ¶
Edit object properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj_name | str | Name of the object to edit. | required |
properties | dict[str, Any] | Property values to set. | required |
doc_name | str | None | Document name (uses active if None). | None |
Returns:
| Type | Description |
|---|---|
ObjectInfo | Updated ObjectInfo. |
Raises:
| Type | Description |
|---|---|
ValueError | If object not found. |
Source code in src/freecad_mcp/bridge/embedded.py
execute_python(code, timeout_ms=30000) async ¶
Execute Python code in FreeCAD context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code | str | Python code to execute. | required |
timeout_ms | int | Maximum execution time in milliseconds. | 30000 |
Returns:
| Type | Description |
|---|---|
ExecutionResult | ExecutionResult with execution outcome. |
Source code in src/freecad_mcp/bridge/embedded.py
get_active_document() async ¶
Get the active document.
Source code in src/freecad_mcp/bridge/embedded.py
get_console_output(lines=100) async ¶
Get recent console output.
Note: In embedded mode, we don't have direct access to FreeCAD's console history, so we return an empty list or captured output.
Source code in src/freecad_mcp/bridge/embedded.py
get_documents() async ¶
Get list of open documents.
Source code in src/freecad_mcp/bridge/embedded.py
get_freecad_version() async ¶
Get FreeCAD version information.
Source code in src/freecad_mcp/bridge/embedded.py
get_macros() async ¶
Get list of available macros.
Returns:
| Type | Description |
|---|---|
list[MacroInfo] | List of MacroInfo for each macro. |
Source code in src/freecad_mcp/bridge/embedded.py
get_object(obj_name, doc_name=None) async ¶
Get detailed object information.
Source code in src/freecad_mcp/bridge/embedded.py
get_objects(doc_name=None) async ¶
Get all objects in a document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc_name | str | None | Document name (uses active if None). | None |
Returns:
| Type | Description |
|---|---|
list[ObjectInfo] | List of ObjectInfo for each object. |
Source code in src/freecad_mcp/bridge/embedded.py
get_screenshot(view_angle=None, width=800, height=600, doc_name=None) async ¶
Capture a screenshot of the 3D view.
Note: In embedded headless mode, screenshots are typically not available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_angle | ViewAngle | None | View angle to set before capture. | None |
width | int | Image width in pixels. | 800 |
height | int | Image height in pixels. | 600 |
doc_name | str | None | Document name (uses active if None). | None |
Returns:
| Type | Description |
|---|---|
ScreenshotResult | ScreenshotResult with image data or error. |
Source code in src/freecad_mcp/bridge/embedded.py
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 | |
get_status() async ¶
Get detailed connection status.
Returns:
| Type | Description |
|---|---|
ConnectionStatus | ConnectionStatus with full status information. |
Source code in src/freecad_mcp/bridge/embedded.py
get_workbenches() async ¶
Get list of available workbenches.
Returns:
| Type | Description |
|---|---|
list[WorkbenchInfo] | List of WorkbenchInfo for each workbench. |
Source code in src/freecad_mcp/bridge/embedded.py
is_connected() async ¶
is_gui_available() async ¶
Check if GUI is available.
open_document(path) async ¶
Open an existing document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | Path to the .FCStd file. | required |
Returns:
| Type | Description |
|---|---|
DocumentInfo | DocumentInfo for the opened document. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError | If file doesn't exist. |
ValueError | If file is not a valid FreeCAD document. |
Source code in src/freecad_mcp/bridge/embedded.py
ping() async ¶
Ping FreeCAD to check connection and measure latency.
Returns:
| Type | Description |
|---|---|
float | Round-trip time in milliseconds. |
Raises:
| Type | Description |
|---|---|
ConnectionError | If not connected. |
Source code in src/freecad_mcp/bridge/embedded.py
run_macro(macro_name, args=None) async ¶
Run a macro by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
macro_name | str | Macro name (without .FCMacro extension). | required |
args | dict[str, Any] | None | Arguments to pass to the macro. | None |
Returns:
| Type | Description |
|---|---|
ExecutionResult | ExecutionResult from macro execution. |
Source code in src/freecad_mcp/bridge/embedded.py
save_document(doc_name=None, path=None) async ¶
Save a document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc_name | str | None | Document name (uses active if None). | None |
path | str | None | Save path (uses existing path if None). | None |
Returns:
| Type | Description |
|---|---|
str | Path where document was saved. |
Raises:
| Type | Description |
|---|---|
ValueError | If document not found or no path specified for new doc. |
Source code in src/freecad_mcp/bridge/embedded.py
set_view(view_angle, doc_name=None) async ¶
Set the 3D view angle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_angle | ViewAngle | View angle to set. | required |
doc_name | str | None | Document name (uses active if None). | None |
Source code in src/freecad_mcp/bridge/embedded.py
options: show_root_heading: true show_source: true