Server API Reference¶
freecad_mcp.server ¶
FreeCAD Robust MCP Server - Main entry point.
This module provides the main Robust MCP Server implementation for FreeCAD integration with AI assistants (Claude, GPT, and other MCP-compatible tools). It exposes tools, resources, and prompts for interacting with FreeCAD.
Features
- Full Python console access (GUI and headless modes)
- Document and object management
- PartDesign workflow (sketches, pads, pockets, fillets)
- Import/export (STEP, STL, OBJ, IGES)
- Macro management
- Screenshot capture
- Multiple connection modes (embedded, XML-RPC, socket)
Example
Run as a module::
$ python -m freecad_mcp.server
Or use the installed command::
$ freecad-mcp
With environment variables::
$ FREECAD_MODE=socket FREECAD_SOCKET_HOST=localhost freecad-mcp
Show help::
$ freecad-mcp --help
Classes¶
Functions¶
apply_cli_args_to_env(args) ¶
Apply CLI arguments as environment variables.
CLI arguments override existing environment variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args | Namespace | Parsed command-line arguments. | required |
Source code in src/freecad_mcp/server.py
check_freecad_connection(mode=None, host=None, port=None) async ¶
Test FreeCAD bridge connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode | str | None | Connection mode override (xmlrpc, socket, embedded). | None |
host | str | None | Host override for connection. | None |
port | int | None | Port override for connection. | None |
Returns:
| Type | Description |
|---|---|
bool | True if connection successful, False otherwise. |
Source code in src/freecad_mcp/server.py
get_bridge() async ¶
Get the active FreeCAD bridge.
Returns:
| Type | Description |
|---|---|
FreecadBridge | The active FreecadBridge instance. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If bridge is not initialized. |
Source code in src/freecad_mcp/server.py
get_instance_id() ¶
Get the unique instance ID for this Robust MCP Server process.
Returns:
| Type | Description |
|---|---|
str | The UUID string that uniquely identifies this server instance. |
lifespan(_server) async ¶
Manage FreeCAD bridge lifecycle.
This async context manager initializes the FreeCAD bridge on startup and disconnects it on shutdown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_server | FastMCP | The FastMCP server instance (unused). | required |
Yields:
| Type | Description |
|---|---|
AsyncIterator[None] | None - the bridge is stored in the global _bridge variable. |
Source code in src/freecad_mcp/server.py
main() ¶
Run the FreeCAD Robust MCP Server.
Source code in src/freecad_mcp/server.py
parse_args() ¶
Parse command-line arguments.
Returns:
| Type | Description |
|---|---|
Namespace | Parsed arguments namespace. |
Source code in src/freecad_mcp/server.py
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 | |
register_all_components() ¶
Register all MCP components (tools, resources, prompts).
Source code in src/freecad_mcp/server.py
options: show_root_heading: true show_source: true members: - mcp - get_bridge - startup - shutdown