Files
freecad-robust-mcp-fc111/docs/guide/resources.md
T
8c338f6da7 feat: MCP Bridge Workbench, just command cleanup, testing, etc. (#24)
* fix: lots of fixes and name refactoring

* feat: Add workbench preferences

* fix: MCP bridge status widget and just command fixes

* fix(tests): Use the correct mesa-glx package

* fix(ci): Add fontconfig to GUI test dependencies

FreeCAD GUI was failing to start with:
"Fontconfig error: Cannot load default config file: No such file"

Added fontconfig and fonts-dejavu-core packages to the GUI test job
dependencies to resolve the font configuration issue.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* refactor(addon): Extract path utilities into shared module

Create path_utils.py module that consolidates duplicated path-finding
logic from commands.py and InitGui.py:
- get_addon_path(): Find addon directory with caching and fallbacks
- get_icon_path(): Get full path to an icon file
- get_icons_dir(): Get path to icons directory
- get_workbench_icon(): Get path to workbench main icon

This removes ~100 lines of duplicated code while preserving the same
behavior including _addon_path_cache and all fallback methods.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix(addon): Prevent stale plugin state on startup failure

The StartMCPBridgeCommand.Activated method could leave _mcp_plugin in
a partially initialized state if FreecadMCPPlugin.start() failed after
the plugin was instantiated.

Changes:
- Create plugin in a local variable first
- Only assign to _mcp_plugin after start() succeeds
- Explicitly clear _mcp_plugin and _running_config in exception
  handlers to ensure clean state for subsequent retry attempts

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: Lot of broad improvements

* fix(ci): Use blocking headless_server.py for GUI tests

The GUI test was using startup_bridge.py which is non-blocking
(designed for interactive use). For CI, even in GUI mode, we need
the blocking headless_server.py that calls run_forever() to keep
FreeCAD running. GUI features are still available since we use
the 'freecad' executable instead of 'freecadcmd'.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* refactor(addon): Rename headless_server.py to blocking_bridge.py

The old name was misleading because:
- It works with both GUI (freecad) and headless (freecadcmd) modes
- The key characteristic is that it BLOCKS with run_forever()

New naming convention clarifies the difference:
- blocking_bridge.py: Starts bridge and blocks (for CI, servers)
- startup_bridge.py: Starts bridge and returns (for interactive GUI)

Updated all references across:
- GitHub workflow (macro-test.yaml)
- Just commands (freecad.just)
- Unit tests (test_addon_structure.py)
- Documentation (5 files)
- CLAUDE.md

Also improved the script to detect GUI mode dynamically using
FreeCAD.GuiUp and display the appropriate status message.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix(just): Remove erroneous rm of startup_bridge.py on error

The startup script is now a permanent source file in the repository,
not a generated temporary file. The rm -f would have deleted source
code if FreeCAD wasn't found.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: General improvements

* fix: Lots of general fixes and only stable to PyPi

* fix: small cleanup

* fix: Small fixes and hopefully fixes the GUI tests

* fix: Add proper library paths for FreeCAD GUI in CI

- Create wrapper scripts instead of symlinks for AppImage binaries
- Set LD_LIBRARY_PATH, QT_PLUGIN_PATH for GUI mode
- Add diagnostic output to identify startup failures

* fix: Use apprun for GUI tests in CI

* fix: Improving Xvfb tests

* fix: GUI tests worlk

* chore: remove invalid --no-splash comments

* fix: ARM64 architecture support and other fixes

* fix: cleanup

* test: just commands test suite

* test: improve just command tests

* fix: more general improvements

* fix: more cleanup

* fix: more updates

* fix: small tweaks

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 15:26:33 -08:00

336 lines
7.4 KiB
Markdown

# MCP Resources
The FreeCAD Robust MCP Server exposes several resources that allow AI assistants to query FreeCAD's state without executing code.
---
## Overview
MCP Resources are read-only endpoints that provide context about FreeCAD's current state. They're useful for:
- Understanding what documents and objects exist
- Getting system information
- Discovering available capabilities
---
## Available Resources
The Robust MCP Server provides 12 resources for querying FreeCAD state:
### freecad://capabilities
Returns a comprehensive JSON catalog of all available tools, resources, and prompts.
**Use case:** Understanding what the Robust MCP Server can do.
**Example response:**
```json
{
"tools": {
"execution": ["execute_python", "get_freecad_version", ...],
"documents": ["create_document", "open_document", ...],
...
},
"resources": ["freecad://capabilities", "freecad://documents", ...],
"prompts": ["freecad-help", "create-parametric-part", ...]
}
```
### freecad://version
Gets FreeCAD version and build information.
**Use case:** Checking FreeCAD compatibility and environment.
**Example response:**
```json
{
"version": "1.0.0",
"build_date": "2024-01-15",
"python_version": "3.11.6",
"gui_available": true
}
```
### freecad://status
Gets current FreeCAD connection and runtime status.
**Use case:** Verifying connection health and mode.
**Example response:**
```json
{
"connected": true,
"mode": "xmlrpc",
"freecad_version": "1.0.0",
"gui_available": true,
"last_ping_ms": 12.5,
"error": null
}
```
### freecad://documents
Lists all open FreeCAD documents with basic information.
**Use case:** Seeing what documents are currently open.
**Example response:**
```json
[
{
"name": "MyPart",
"label": "My Part Design",
"path": "/home/user/projects/mypart.FCStd",
"is_modified": true,
"object_count": 15,
"active_object": "Pad"
}
]
```
### freecad://documents/{name}
Gets detailed information about a specific document.
**Use case:** Examining a document's contents.
**Example response:**
```json
{
"name": "MyPart",
"label": "My Part Design",
"path": "/home/user/projects/mypart.FCStd",
"objects": ["Body", "Sketch", "Pad", "Fillet"],
"is_modified": true,
"active_object": "Fillet"
}
```
### freecad://documents/{name}/objects
Gets list of objects in a specific document.
**Use case:** Listing all objects in a document with their types.
**Example response:**
```json
[
{
"name": "Body",
"label": "Body",
"type_id": "PartDesign::Body",
"visibility": true
},
{
"name": "Sketch",
"label": "Sketch",
"type_id": "Sketcher::SketchObject",
"visibility": false
}
]
```
### freecad://objects/{doc_name}/{obj_name}
Gets detailed information about a specific object including properties and shape data.
**Use case:** Inspecting object properties and geometry.
**Example response:**
```json
{
"name": "Pad",
"label": "Pad",
"type_id": "PartDesign::Pad",
"properties": {
"Length": 10.0,
"Type": "Length",
"Symmetric": false
},
"shape_info": {
"shape_type": "Solid",
"volume": 1000.0,
"area": 600.0,
"is_valid": true
},
"children": [],
"parents": ["Sketch"],
"visibility": true
}
```
### freecad://active-document
Gets the currently active document.
**Use case:** Quick access to the document the user is working on.
**Example response:**
```json
{
"name": "MyPart",
"label": "My Part Design",
"path": "/home/user/projects/mypart.FCStd",
"objects": ["Body", "Sketch", "Pad"],
"is_modified": false,
"active_object": "Pad"
}
```
### freecad://workbenches
Gets list of available FreeCAD workbenches.
**Use case:** Understanding what workbenches are available.
**Example response:**
```json
[
{
"name": "PartDesignWorkbench",
"label": "Part Design",
"is_active": true
},
{
"name": "SketcherWorkbench",
"label": "Sketcher",
"is_active": false
}
]
```
### freecad://workbenches/active
Gets the currently active workbench.
**Use case:** Knowing which workbench context is active.
**Example response:**
```json
{
"name": "PartDesignWorkbench",
"label": "Part Design"
}
```
### freecad://macros
Gets list of available FreeCAD macros.
**Use case:** Discovering available automation macros.
**Example response:**
```json
[
{
"name": "MultiExport",
"path": "/home/user/.local/share/FreeCAD/Macro/MultiExport.FCMacro",
"description": "Export objects to multiple formats",
"is_system": false
}
]
```
### freecad://console
Gets recent FreeCAD console output.
**Use case:** Debugging and seeing FreeCAD messages.
**Example response:**
```json
{
"lines": [
"MCP Bridge started!",
" - XML-RPC: localhost:9875",
" - Socket: localhost:9876",
"Document created: MyPart"
],
"count": 4
}
```
---
## Using Resources in Prompts
When talking to an AI assistant connected via MCP, resources are automatically available. The AI can read them to understand context.
**Example conversation:**
```text
User: "What documents do I have open?"
AI: [Reads freecad://documents resource]
"You have two documents open:
1. 'Bracket' - modified, 12 objects
2. 'Housing' - saved, 8 objects"
```
---
## Resources vs Tools
| Aspect | Resources | Tools |
| ------------ | ----------------------- | -------------------- |
| Purpose | Query state (read-only) | Perform actions |
| Side effects | None | May modify documents |
| Response | Data/text | Operation result |
| Example | `freecad://documents` | `create_document()` |
---
## Resource URI Summary
| URI | Description |
| ----------------------------------------- | ---------------------------------------- |
| `freecad://capabilities` | All available tools, resources, prompts |
| `freecad://version` | FreeCAD version and build info |
| `freecad://status` | Connection status and mode |
| `freecad://documents` | List of open documents |
| `freecad://documents/{name}` | Single document details |
| `freecad://documents/{name}/objects` | Objects in a document |
| `freecad://objects/{doc_name}/{obj_name}` | Detailed object information |
| `freecad://active-document` | Currently active document |
| `freecad://workbenches` | Available workbenches |
| `freecad://workbenches/active` | Currently active workbench |
| `freecad://macros` | Available macros |
| `freecad://console` | Recent console output |
---
## Implementing Custom Resources
If you're extending the Robust MCP Server, you can add custom resources:
```python
@mcp.resource("freecad://custom/{param}")
async def my_custom_resource(param: str) -> str:
"""Return custom data based on param."""
# Query FreeCAD and return data
result = await bridge.execute_python(f"...")
return json.dumps(result)
```
---
## Next Steps
- [Tools Reference](tools.md) - Complete API for MCP tools
- [Connection Modes](connection-modes.md) - How to connect to FreeCAD