solidworks_mcp.ui.services.model_service¶
solidworks_mcp.ui.services.model_service ¶
Model connection and upload service for the Prefab CAD assistant dashboard.
Handles opening a target SolidWorks model (open-only) and connecting to it (open + inspect feature tree + trigger preview refresh).
Attributes¶
DEFAULT_API_ORIGIN
module-attribute
¶
Functions¶
_resolve_model_path ¶
_resolve_model_path(session_id: str, *, model_path: str | None, uploaded_files: list[dict[str, Any]] | None, feature_target_text: str | None, db_path: Path | None, api_origin: str) -> Path | None
Resolve and validate the model path from either upload payload or explicit path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
required |
model_path
|
str | None
|
Explicit absolute path string. |
required |
uploaded_files
|
list[dict[str, Any]] | None
|
Optional list of upload dicts. |
required |
feature_target_text
|
str | None
|
Optional feature target annotation. |
required |
db_path
|
Path | None
|
Optional SQLite path override. |
required |
api_origin
|
str
|
Base URL of the running FastAPI server. |
required |
Returns:
| Type | Description |
|---|---|
Path | None
|
Resolved |
Path | None
|
already persisted to the session). |
Source code in src/solidworks_mcp/ui/services/model_service.py
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 | |
classify_feature_tree_snapshot ¶
classify_feature_tree_snapshot(model_info: Mapping[str, Any] | None, features: list[Mapping[str, Any]] | None) -> dict[str, Any]
Classify a model family from model-info and feature-tree snapshots.
The output is intentionally simple and explainable so agents can use it as a planning primitive rather than as a black-box prediction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_info
|
Mapping[str, Any] | None
|
The model info value. |
required |
features
|
list[Mapping[str, Any]] | None
|
The features value. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary containing the resulting values. |
Source code in src/solidworks_mcp/utils/feature_tree_classifier.py
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 | |
connect_target_model
async
¶
connect_target_model(session_id: str, *, model_path: str | None = None, uploaded_files: list[dict[str, Any]] | None = None, feature_target_text: str | None = None, db_path: Path | None = None, api_origin: str = DEFAULT_API_ORIGIN) -> dict[str, Any]
Open a target model, inspect its feature tree, and trigger a preview refresh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
required |
model_path
|
str | None
|
Absolute path to the SolidWorks model file. |
None
|
uploaded_files
|
list[dict[str, Any]] | None
|
List of base64-encoded file upload dicts. |
None
|
feature_target_text
|
str | None
|
Optional comma-separated feature target references. |
None
|
db_path
|
Path | None
|
Optional SQLite path override. |
None
|
api_origin
|
str
|
Base URL of the running FastAPI server. |
DEFAULT_API_ORIGIN
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Full dashboard state payload (includes preview state after the refresh). |
Source code in src/solidworks_mcp/ui/services/model_service.py
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 | |
create_adapter
async
¶
Async factory function for creating SolidWorks adapters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
SolidWorksMCPConfig
|
Configuration values for the operation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolidWorksAdapter |
SolidWorksAdapter
|
The result produced by the operation. |
Source code in src/solidworks_mcp/adapters/factory.py
ensure_preview_dir ¶
Create and return the preview image directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preview_dir
|
Path | None
|
Override directory; defaults to |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Resolved |
Source code in src/solidworks_mcp/ui/services/_utils.py
insert_evidence_link ¶
insert_evidence_link(*, session_id: str, source_type: str, source_id: str, checkpoint_id: int | None = None, relevance_score: float | None = None, rationale: str | None = None, payload_json: str | None = None, db_path: Path | None = None) -> None
Insert one evidence row used by planning/classification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
source_type
|
str
|
The source type value. |
required |
source_id
|
str
|
The source id value. |
required |
checkpoint_id
|
int | None
|
The checkpoint id value. Defaults to None. |
None
|
relevance_score
|
float | None
|
The relevance score value. Defaults to None. |
None
|
rationale
|
str | None
|
The rationale value. Defaults to None. |
None
|
payload_json
|
str | None
|
The payload json value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Source code in src/solidworks_mcp/agents/history_db.py
insert_model_state_snapshot ¶
insert_model_state_snapshot(*, session_id: str, checkpoint_id: int | None = None, model_path: str | None = None, feature_tree_json: str | None = None, mass_properties_json: str | None = None, screenshot_path: str | None = None, state_fingerprint: str | None = None, db_path: Path | None = None) -> int
Insert model snapshot row and return snapshot ID for rollback tracking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
checkpoint_id
|
int | None
|
The checkpoint id value. Defaults to None. |
None
|
model_path
|
str | None
|
The model path value. Defaults to None. |
None
|
feature_tree_json
|
str | None
|
The feature tree json value. Defaults to None. |
None
|
mass_properties_json
|
str | None
|
The mass properties json value. Defaults to None. |
None
|
screenshot_path
|
str | None
|
The screenshot path value. Defaults to None. |
None
|
state_fingerprint
|
str | None
|
The state fingerprint value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The computed numeric result. |
Source code in src/solidworks_mcp/agents/history_db.py
insert_tool_call_record ¶
insert_tool_call_record(*, session_id: str, tool_name: str, checkpoint_id: int | None = None, run_id: str | None = None, input_json: str | None = None, output_json: str | None = None, success: bool = True, latency_ms: float | None = None, db_path: Path | None = None) -> None
Insert one tool call execution record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
tool_name
|
str
|
The tool name value. |
required |
checkpoint_id
|
int | None
|
The checkpoint id value. Defaults to None. |
None
|
run_id
|
str | None
|
The run id value. Defaults to None. |
None
|
input_json
|
str | None
|
The input json value. Defaults to None. |
None
|
output_json
|
str | None
|
The output json value. Defaults to None. |
None
|
success
|
bool
|
The success value. Defaults to True. |
True
|
latency_ms
|
float | None
|
The latency ms value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Source code in src/solidworks_mcp/agents/history_db.py
load_config ¶
Load configuration from file and environment variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file
|
str | None
|
The config file value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
SolidWorksMCPConfig |
SolidWorksMCPConfig
|
The result produced by the operation. |
Source code in src/solidworks_mcp/config.py
materialize_uploaded_model ¶
materialize_uploaded_model(session_id: str, uploaded_files: list[dict[str, Any]] | None, *, upload_dir: Path | None = None) -> Path
Decode a base64-encoded uploaded model file and write it to the staging directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier used as a staging subdirectory. |
required |
uploaded_files
|
list[dict[str, Any]] | None
|
List of file payload dicts, each with |
required |
upload_dir
|
Path | None
|
Override for the upload staging directory. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path pointing at the decoded file on disk. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
When no file is provided, the name is missing, the suffix is unsupported, or the data field is not valid base64. |
Source code in src/solidworks_mcp/ui/services/_utils.py
merge_metadata ¶
merge_metadata(session_id: str, *, db_path: Path | None = None, user_goal: str | None = None, **updates: Any) -> dict[str, Any]
Read session metadata, merge updates into it, and write it back.
Implements the optimistic read-modify-write pattern used across all service functions that need to update one or more metadata keys without overwriting unrelated keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Target session identifier. |
required |
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
user_goal
|
str | None
|
When provided, also updates the |
None
|
**updates
|
Any
|
Arbitrary key-value pairs to merge into metadata. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The merged metadata dict after the write. |
Source code in src/solidworks_mcp/ui/services/_utils.py
open_target_model
async
¶
open_target_model(session_id: str, *, model_path: str | None = None, uploaded_files: list[dict[str, Any]] | None = None, feature_target_text: str | None = None, db_path: Path | None = None, api_origin: str = DEFAULT_API_ORIGIN) -> dict[str, Any]
Open a target model in SolidWorks and persist session state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
required |
model_path
|
str | None
|
Absolute path to the SolidWorks model file. |
None
|
uploaded_files
|
list[dict[str, Any]] | None
|
List of base64-encoded file upload dicts. |
None
|
feature_target_text
|
str | None
|
Optional comma-separated feature target references. |
None
|
db_path
|
Path | None
|
Optional SQLite path override. |
None
|
api_origin
|
str
|
Base URL of the running FastAPI server. |
DEFAULT_API_ORIGIN
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Full dashboard state payload. |
Source code in src/solidworks_mcp/ui/services/model_service.py
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 | |
sanitize_model_path_text ¶
Strip surrounding quotes from a model path string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Raw model path value from UI state. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Cleaned path string, or |