solidworks_mcp.ui.service¶
solidworks_mcp.ui.service ¶
Compatibility shim for legacy imports from solidworks_mcp.ui.service.
The UI backend was split into focused modules under solidworks_mcp.ui.services. This module preserves historical import paths used by tests and external callers.
Attributes¶
DEFAULT_API_ORIGIN
module-attribute
¶
DEFAULT_UPLOADED_MODEL_DIR
module-attribute
¶
DEFAULT_USER_GOAL
module-attribute
¶
DEFAULT_USER_GOAL = 'Design a printable mounting component with documented constraints and fastener strategy.'
SUPPORTED_MODEL_UPLOAD_SUFFIXES
module-attribute
¶
_normalize_feature_targets
module-attribute
¶
_sanitize_preview_viewer_url
module-attribute
¶
Classes¶
CheckpointCandidate ¶
Bases: BaseModel
One suggested execution checkpoint.
Attributes:
| Name | Type | Description |
|---|---|---|
title |
str
|
Short human-readable label. |
allowed_tools |
list[str]
|
MCP tool names allowed at this checkpoint. |
rationale |
str
|
Reasoning for including this step. |
execution |
dict[str, Any]
|
Optional structured execution hints used by checkpoint runner. |
ClarificationResponse ¶
Bases: BaseModel
LLM response for goal clarification.
Attributes:
| Name | Type | Description |
|---|---|---|
normalized_brief |
str
|
Concise manufacturing-ready description of the design goal. |
questions |
list[str]
|
Follow-up questions that unblock the next modelling step. |
FamilyInspection ¶
Bases: BaseModel
LLM response for feature-family classification.
Attributes:
| Name | Type | Description |
|---|---|---|
family |
str
|
Detected SolidWorks feature family name. |
confidence |
Literal['low', 'medium', 'high']
|
Model confidence level. |
evidence |
list[str]
|
Supporting evidence lines. |
warnings |
list[str]
|
Contradictory or low-confidence warnings. |
checkpoints |
list[CheckpointCandidate]
|
Suggested checkpoint plan for human review. |
_AgentRecoverableFailure ¶
Bases: BaseModel
Typed failure output used when agent needs user-guided retry.
Attributes:
| Name | Type | Description |
|---|---|---|
explanation |
str
|
The explanation value. |
remediation_steps |
list[str]
|
The remediation steps value. |
retry_focus |
str | None
|
The retry focus value. |
should_retry |
bool
|
The should retry value. |
Functions¶
_build_agent_model ¶
Source code in src/solidworks_mcp/ui/service.py
_chunk_text ¶
Split long text into overlapping chunks for simple local retrieval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input text processed by the operation. |
required |
chunk_size
|
int
|
Maximum number of characters to keep in each chunk. Defaults to 1000. |
1000
|
overlap
|
int
|
Number of overlapping characters between chunks. Defaults to 150. |
150
|
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: A list containing the resulting items. |
Source code in src/solidworks_mcp/agents/retrieval_index.py
_context_file_path ¶
_context_file_path(session_id: str, *, context_name: str | None = None, context_dir: Path | None = None) -> Path
Source code in src/solidworks_mcp/ui/service.py
_context_file_path_impl ¶
_context_file_path_impl(session_id: str, *, context_name: str | None = None, context_dir: Path | None = None) -> Path
Return the canonical path for a context snapshot JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Session identifier used as the default filename. |
required |
context_name
|
str | None
|
Optional override name (will be slugified). |
None
|
context_dir
|
Path | None
|
Override directory for context files. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
|
Source code in src/solidworks_mcp/ui/services/_utils.py
_default_model_for_profile ¶
Source code in src/solidworks_mcp/ui/service.py
_ensure_provider_credentials ¶
Verify that the required provider credential is present, raising otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Provider-qualified model name (e.g. |
required |
local_endpoint
|
str | None
|
Optional base URL for a local LLM server. |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
When the required credential is missing. |
Source code in src/solidworks_mcp/ui/services/llm_service.py
_feature_grounding_warning_text ¶
_feature_grounding_warning_text(*, active_model_path: str, feature_target_text: str, feature_tree_count: int) -> str
Return a warning string when feature grounding cannot proceed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
active_model_path
|
str
|
Currently attached model path. |
required |
feature_target_text
|
str
|
Raw feature target refs from UI. |
required |
feature_tree_count
|
int
|
Number of rows in the current feature tree snapshot. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Warning message, or |
Source code in src/solidworks_mcp/ui/services/_utils.py
_feature_target_status ¶
_feature_target_status(features: list[dict[str, Any]], feature_target_text: str | None) -> tuple[str, list[str], list[str]]
Compute matched / missing feature target status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
list[dict[str, Any]]
|
Feature tree rows from the active snapshot. |
required |
feature_target_text
|
str | None
|
Raw feature target input from the UI. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, list[str], list[str]]
|
Three-tuple of (status_message, matched_names, missing_names). |
Source code in src/solidworks_mcp/ui/services/_utils.py
_filter_docs_text ¶
Filter plain-text docs content to lines most relevant to query.
Returns up to max_chars characters of the most relevant lines, scored
by how many query tokens they contain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Full plain-text docs content. |
required |
query
|
str
|
Space-separated keyword query. |
required |
max_chars
|
int
|
Maximum characters to return. |
4000
|
Returns:
| Type | Description |
|---|---|
str
|
Filtered and truncated text snippet. |
Source code in src/solidworks_mcp/ui/services/_utils.py
_looks_like_path_token ¶
Return True if token looks like a filesystem path rather than a feature name.
Source code in src/solidworks_mcp/ui/services/_utils.py
_materialize_uploaded_model ¶
_materialize_uploaded_model(session_id: str, uploaded_files: list[dict[str, Any]] | None, *, upload_dir: Path | None = None) -> Path
Source code in src/solidworks_mcp/ui/service.py
_materialize_uploaded_model_impl ¶
_materialize_uploaded_model_impl(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
_normalize_model_name_for_provider ¶
_normalize_model_name_for_provider(model_name: str | None, *, provider: str | None, profile: str | None = None) -> str
Normalise a free-form model name into a provider-qualified routing string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str | None
|
Raw model name from UI state, may be None or unqualified. |
required |
provider
|
str | None
|
Explicit provider override ( |
required |
profile
|
str | None
|
Profile tier used as fallback when model_name is empty. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Provider-qualified model name (e.g. |
Source code in src/solidworks_mcp/ui/services/_utils.py
_parse_json_blob ¶
Parse a JSON string into a dict, returning an empty dict on any failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
str | None
|
Raw JSON string, or |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed dict, or |
Source code in src/solidworks_mcp/ui/services/_utils.py
_provider_from_model_name ¶
Infer the provider prefix from a provider-qualified model name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Model name such as |
required |
Returns:
| Type | Description |
|---|---|
str
|
Provider string: |
str
|
|
Source code in src/solidworks_mcp/ui/services/_utils.py
_provider_has_credentials ¶
Check whether the required credentials exist for the given model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Provider-qualified model name. |
required |
local_endpoint
|
str | None
|
Local API endpoint URL (required for |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/solidworks_mcp/ui/services/_utils.py
_read_reference_source ¶
_read_reference_url ¶
Source code in src/solidworks_mcp/ui/service.py
_run_checkpoint_tools
async
¶
Source code in src/solidworks_mcp/ui/service.py
_run_structured_agent
async
¶
Source code in src/solidworks_mcp/ui/service.py
_sanitize_ui_text ¶
Return a clean string from value, using fallback for empty/invalid inputs.
Strips template placeholders such as {{ field }}, bare quotes, and
pydantic-ai expression strings that sometimes leak into UI state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Arbitrary input (str, None, etc.). |
required |
fallback
|
str
|
Value to return when value is empty or invalid. |
''
|
Returns:
| Type | Description |
|---|---|
str
|
Cleaned string, or fallback. |
Source code in src/solidworks_mcp/ui/services/_utils.py
_temporary_module_bindings ¶
Source code in src/solidworks_mcp/ui/service.py
_trace_json ¶
Serialise value to a pretty-printed JSON string for operator trace panels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Any JSON-serialisable value. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Indented JSON string. |
Source code in src/solidworks_mcp/ui/services/_utils.py
_trace_json_default ¶
_trace_session_row ¶
Return a copy of session_row with the bulky metadata_json field removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_row
|
dict[str, Any] | None
|
Raw session row dict from the database. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Filtered dict suitable for debug display. |
Source code in src/solidworks_mcp/ui/services/_utils.py
_trace_tool_records ¶
Return the last ten tool-call records as lean trace dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
list[dict[str, Any]]
|
Full list of tool-call records for the session. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
Trimmed list of trace-friendly dicts (id, tool_name, success, …). |
Source code in src/solidworks_mcp/ui/services/_utils.py
_workflow_copy ¶
Return display copy for the workflow selector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_mode
|
str
|
Normalised workflow mode string. |
required |
active_model_path
|
str | None
|
Currently attached model path, if any. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[str, str, str]
|
Three-tuple of (label, guidance_text, flow_header_text). |
Source code in src/solidworks_mcp/ui/services/_utils.py
accept_family_choice ¶
accept_family_choice(session_id: str, family: str | None = None, *, db_path: Path | None = None) -> dict[str, Any]
Accept the proposed family classification and advance session status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
required |
family
|
str | None
|
Family name to accept; falls back to |
None
|
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Full dashboard state payload. |
Source code in src/solidworks_mcp/ui/services/session_service.py
approve_design_brief ¶
approve_design_brief(session_id: str, user_goal: str, *, db_path: Path | None = None) -> dict[str, Any]
Persist the accepted design goal and return updated dashboard state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
required |
user_goal
|
str
|
Design goal text approved by the user. |
required |
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Full dashboard state payload. |
Source code in src/solidworks_mcp/ui/services/session_service.py
build_dashboard_state ¶
build_dashboard_state(session_id: str = DEFAULT_SESSION_ID, *, db_path: Path | None = None, api_origin: str = DEFAULT_API_ORIGIN) -> dict[str, Any]
Assemble the complete dashboard payload consumed by the Prefab UI renderer.
This function is the single read-path for all UI state: it reads the session
database, merges every sub-component (checkpoints, evidence, snapshots, preview
URLs, provider readiness), and returns the DashboardUIState model as a dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
DEFAULT_SESSION_ID
|
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
api_origin
|
str
|
Base URL used to construct preview and viewer URLs. |
DEFAULT_API_ORIGIN
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
|
Source code in src/solidworks_mcp/ui/services/session_service.py
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 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 | |
build_dashboard_trace_payload ¶
build_dashboard_trace_payload(session_id: str = DEFAULT_SESSION_ID, *, db_path: Path | None = None, api_origin: str = DEFAULT_API_ORIGIN) -> dict[str, Any]
Assemble the verbose debug/trace payload for the operator trace panel.
Includes the raw session row, full metadata, complete tool-call history, and the
assembled DashboardUIState — all serialised to both Python dicts and
pretty-printed JSON strings for easy inspection in the UI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
DEFAULT_SESSION_ID
|
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
api_origin
|
str
|
API origin used for URL generation. |
DEFAULT_API_ORIGIN
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with |
Source code in src/solidworks_mcp/ui/services/session_service.py
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 = '', db_path: Path | None = None, api_origin: str = DEFAULT_API_ORIGIN) -> dict[str, Any]
Source code in src/solidworks_mcp/ui/service.py
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_context_dir ¶
ensure_dashboard_session ¶
ensure_dashboard_session(session_id: str = DEFAULT_SESSION_ID, *, user_goal: str | None = None, db_path: Path | None = None) -> dict[str, Any]
Ensure one dashboard session row and default checkpoints exist.
Creates the session row on first call and inserts default checkpoints when
none are present yet. On subsequent calls it updates the user_goal column
when the supplied goal differs from the stored one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
DEFAULT_SESSION_ID
|
user_goal
|
str | None
|
Optional initial or updated design goal. |
None
|
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The current session row dict. |
Source code in src/solidworks_mcp/ui/services/session_service.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
ensure_uploaded_model_dir ¶
execute_next_checkpoint
async
¶
Source code in src/solidworks_mcp/ui/service.py
feature_grounding_warning_text ¶
feature_grounding_warning_text(*, active_model_path: str, feature_target_text: str, feature_tree_count: int) -> str
Return a warning string when feature grounding cannot proceed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
active_model_path
|
str
|
Currently attached model path. |
required |
feature_target_text
|
str
|
Raw feature target refs from UI. |
required |
feature_tree_count
|
int
|
Number of rows in the current feature tree snapshot. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Warning message, or |
Source code in src/solidworks_mcp/ui/services/_utils.py
feature_target_status ¶
feature_target_status(features: list[dict[str, Any]], feature_target_text: str | None) -> tuple[str, list[str], list[str]]
Compute matched / missing feature target status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
list[dict[str, Any]]
|
Feature tree rows from the active snapshot. |
required |
feature_target_text
|
str | None
|
Raw feature target input from the UI. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, list[str], list[str]]
|
Three-tuple of (status_message, matched_names, missing_names). |
Source code in src/solidworks_mcp/ui/services/_utils.py
fetch_docs_context ¶
fetch_docs_context(session_id: str, *, docs_query: str = '', db_path: Path | None = None, api_origin: str = DEFAULT_API_ORIGIN) -> dict[str, Any]
Source code in src/solidworks_mcp/ui/service.py
filter_docs_text ¶
Filter plain-text docs content to lines most relevant to query.
Returns up to max_chars characters of the most relevant lines, scored
by how many query tokens they contain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Full plain-text docs content. |
required |
query
|
str
|
Space-separated keyword query. |
required |
max_chars
|
int
|
Maximum characters to return. |
4000
|
Returns:
| Type | Description |
|---|---|
str
|
Filtered and truncated text snippet. |
Source code in src/solidworks_mcp/ui/services/_utils.py
get_design_session ¶
Return one session row as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
dict[str, Any] | None: A dictionary containing the resulting values. |
Source code in src/solidworks_mcp/agents/history_db.py
highlight_feature
async
¶
highlight_feature(session_id: str, feature_name: str, *, db_path: Path | None = None, api_origin: str = DEFAULT_API_ORIGIN) -> dict[str, Any]
Select and highlight a named feature in the active SolidWorks model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
required |
feature_name
|
str
|
Name of the feature to select (must match the feature-tree entry). |
required |
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/preview_service.py
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 | |
ingest_reference_source ¶
ingest_reference_source(session_id: str, *, source_path: str, namespace: str, chunk_size: int = 1200, overlap: int = 200, db_path: Path | None = None) -> dict[str, Any]
Source code in src/solidworks_mcp/ui/service.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
inspect_family
async
¶
inspect_family(session_id: str, user_goal: str, *, model_name: str | None = None, db_path: Path | None = None) -> dict[str, Any]
Source code in src/solidworks_mcp/ui/service.py
is_url_reference ¶
Return True when source_path is an http/https URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_path
|
str
|
Raw source path string from the UI. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/solidworks_mcp/ui/services/_utils.py
list_plan_checkpoints ¶
List all checkpoints for a session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: A list containing the resulting items. |
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
load_session_context ¶
load_session_context(session_id: str, *, context_file: str | None = None, db_path: Path | None = None, context_dir: Path | None = None, api_origin: str = DEFAULT_API_ORIGIN) -> dict[str, Any]
Load a previously saved context snapshot back into session metadata.
Selectively merges the workflow_mode, assumptions_text, model path,
feature targets, provider settings, notes, and docs query from the snapshot.
Does not overwrite live execution state or checkpoint results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
required |
context_file
|
str | None
|
Path to the JSON snapshot file; defaults to the canonical location. |
None
|
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
context_dir
|
Path | None
|
Override directory for context snapshot files. |
None
|
api_origin
|
str
|
API origin used for URL generation. |
DEFAULT_API_ORIGIN
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Full dashboard state payload. |
Source code in src/solidworks_mcp/ui/services/session_service.py
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 | |
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
normalize_feature_targets ¶
Parse a comma- or newline-separated feature target string into a list.
Strips @ prefixes and filters out tokens that look like file paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature_target_text
|
str | None
|
Raw input such as |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of normalised feature name strings. |
Source code in src/solidworks_mcp/ui/services/_utils.py
normalize_workflow_mode ¶
Normalise a raw workflow mode string to a known value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_mode
|
str | None
|
Raw mode string from UI state. |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
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 = '', db_path: Path | None = None, api_origin: str = DEFAULT_API_ORIGIN) -> dict[str, Any]
Source code in src/solidworks_mcp/ui/service.py
parse_json_blob ¶
Parse a JSON string into a dict, returning an empty dict on any failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
str | None
|
Raw JSON string, or |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed dict, or |
Source code in src/solidworks_mcp/ui/services/_utils.py
persist_ui_action ¶
persist_ui_action(session_id: str, *, tool_name: str, db_path: Path | None = None, metadata_updates: dict[str, Any] | None = None, user_goal: str | None = None, input_payload: dict[str, Any] | None = None, output_payload: dict[str, Any] | None = None, output_metadata: bool = False, success: bool = True, checkpoint_id: int | None = None) -> dict[str, Any]
Persist metadata updates and a matching tool-call audit record atomically.
Combines :func:merge_metadata and insert_tool_call_record so callers
can update session state and write an audit entry in a single call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Target session identifier. |
required |
tool_name
|
str
|
Logical name for the audit record (e.g. |
required |
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
metadata_updates
|
dict[str, Any] | None
|
Key-value pairs to merge into session metadata. |
None
|
user_goal
|
str | None
|
When provided, also updates the |
None
|
input_payload
|
dict[str, Any] | None
|
Dict serialised as the |
None
|
output_payload
|
dict[str, Any] | None
|
Dict serialised as the |
None
|
output_metadata
|
bool
|
When |
False
|
success
|
bool
|
Whether the action succeeded. |
True
|
checkpoint_id
|
int | None
|
Optional FK to the associated plan checkpoint. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The merged metadata dict after the write. |
Source code in src/solidworks_mcp/ui/services/_utils.py
provider_from_model_name ¶
Infer the provider prefix from a provider-qualified model name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Model name such as |
required |
Returns:
| Type | Description |
|---|---|
str
|
Provider string: |
str
|
|
Source code in src/solidworks_mcp/ui/services/_utils.py
provider_has_credentials ¶
Check whether the required credentials exist for the given model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Provider-qualified model name. |
required |
local_endpoint
|
str | None
|
Local API endpoint URL (required for |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/solidworks_mcp/ui/services/_utils.py
read_reference_source ¶
Read the text content of a local file (PDF, markdown, text).
PDF extraction requires the optional pypdf package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_path
|
Path
|
Local file path to read. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Extracted plain text content. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
When a PDF is supplied but |
Source code in src/solidworks_mcp/ui/services/_utils.py
read_reference_url ¶
Fetch content from a URL and return (text, label).
Handles HTML (stripped), PDF (requires pypdf), and plain text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_url
|
str
|
http/https URL to fetch. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
Tuple of (plain_text_content, label) where label is derived from the URL path. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
When a PDF is served but |
Source code in src/solidworks_mcp/ui/services/_utils.py
reconcile_manual_edits ¶
Compare the two most-recent snapshots and summarise any detected changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
required |
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Full dashboard state payload. |
Source code in src/solidworks_mcp/ui/services/session_service.py
refresh_preview
async
¶
refresh_preview(session_id: str, *, orientation: str = DEFAULT_PREVIEW_ORIENTATION, db_path: Path | None = None, preview_dir: Path | None = None, api_origin: str = DEFAULT_API_ORIGIN) -> dict[str, Any]
Source code in src/solidworks_mcp/ui/service.py
request_clarifications
async
¶
request_clarifications(session_id: str, user_goal: str, *, user_answer: str = '', model_name: str | None = None, db_path: Path | None = None) -> dict[str, Any]
Source code in src/solidworks_mcp/ui/service.py
run_go_orchestration
async
¶
run_go_orchestration(session_id: str, *, user_goal: str, assumptions_text: str | None = None, user_answer: str = '', db_path: Path | None = None, api_origin: str = DEFAULT_API_ORIGIN) -> dict[str, Any]
Run a single end-to-end pass: approve brief, update preferences, clarify, inspect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
required |
user_goal
|
str
|
Free-text description of the design intent. |
required |
assumptions_text
|
str | None
|
Optional manufacturing assumptions to persist. |
None
|
user_answer
|
str
|
Any previous answers the user has already provided. |
''
|
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/llm_service.py
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 | |
safe_context_name ¶
Normalise a context name to a safe filesystem slug.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context_name
|
str | None
|
User-supplied context name, may be None. |
required |
session_id
|
str
|
Fallback identifier. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Alphanumeric + hyphen slug, never empty. |
Source code in src/solidworks_mcp/ui/services/_utils.py
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 |
Source code in src/solidworks_mcp/ui/services/_utils.py
sanitize_preview_viewer_url ¶
Validate and return a preview viewer URL, or "" if it looks wrong.
Rejects URLs pointing at unexpected origins or session IDs to prevent open-redirect-style issues in the embedded viewer iframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Raw URL string from session metadata. |
required |
session_id
|
str
|
Expected session ID segment in the path. |
required |
api_origin
|
str
|
Allowed API origin (scheme + host + port). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Validated URL string, or |
Source code in src/solidworks_mcp/ui/services/_utils.py
sanitize_ui_text ¶
Return a clean string from value, using fallback for empty/invalid inputs.
Strips template placeholders such as {{ field }}, bare quotes, and
pydantic-ai expression strings that sometimes leak into UI state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Arbitrary input (str, None, etc.). |
required |
fallback
|
str
|
Value to return when value is empty or invalid. |
''
|
Returns:
| Type | Description |
|---|---|
str
|
Cleaned string, or fallback. |
Source code in src/solidworks_mcp/ui/services/_utils.py
save_session_context ¶
save_session_context(session_id: str, *, context_name: str | None = None, db_path: Path | None = None, context_dir: Path | None = None, api_origin: str = DEFAULT_API_ORIGIN) -> dict[str, Any]
Persist the current dashboard state to a plain JSON snapshot file.
The snapshot can later be loaded with :func:load_session_context to restore
the same session state across restarts or share it between machines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
required |
context_name
|
str | None
|
Optional human-readable name for the snapshot file. |
None
|
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
context_dir
|
Path | None
|
Override directory for context snapshot files. |
None
|
api_origin
|
str
|
API origin used for URL generation. |
DEFAULT_API_ORIGIN
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Full dashboard state payload. |
Source code in src/solidworks_mcp/ui/services/session_service.py
select_workflow_mode ¶
select_workflow_mode(session_id: str, *, workflow_mode: str, db_path: Path | None = None) -> dict[str, Any]
Persist the onboarding workflow branch and reset new-design state when switching.
Selecting "new_design" resets all model-attachment, preview, and clarification
state so the user starts with a blank slate for the new part.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
required |
workflow_mode
|
str
|
Target mode ( |
required |
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Full dashboard state payload. |
Source code in src/solidworks_mcp/ui/services/session_service.py
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 | |
trace_json ¶
Serialise value to a pretty-printed JSON string for operator trace panels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Any JSON-serialisable value. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Indented JSON string. |
Source code in src/solidworks_mcp/ui/services/_utils.py
trace_session_row ¶
Return a copy of session_row with the bulky metadata_json field removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_row
|
dict[str, Any] | None
|
Raw session row dict from the database. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Filtered dict suitable for debug display. |
Source code in src/solidworks_mcp/ui/services/_utils.py
trace_tool_records ¶
Return the last ten tool-call records as lean trace dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
list[dict[str, Any]]
|
Full list of tool-call records for the session. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
Trimmed list of trace-friendly dicts (id, tool_name, success, …). |
Source code in src/solidworks_mcp/ui/services/_utils.py
update_session_notes ¶
update_session_notes(session_id: str, *, notes_text: str, db_path: Path | None = None, api_origin: str = DEFAULT_API_ORIGIN) -> dict[str, Any]
Persist free-form engineering notes in session metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
required |
notes_text
|
str
|
Free-text engineering notes content. |
required |
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
api_origin
|
str
|
API origin used for URL generation in the returned state. |
DEFAULT_API_ORIGIN
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Full dashboard state payload. |
Source code in src/solidworks_mcp/ui/services/session_service.py
update_ui_preferences ¶
update_ui_preferences(session_id: str, *, assumptions_text: str | None = None, model_provider: str | None = None, model_profile: str | None = None, model_name: str | None = None, local_endpoint: str | None = None, db_path: Path | None = None) -> dict[str, Any]
Persist manufacturing assumptions and LLM provider preferences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
required |
assumptions_text
|
str | None
|
Free-form manufacturing assumption text. |
None
|
model_provider
|
str | None
|
LLM provider identifier ( |
None
|
model_profile
|
str | None
|
Capability tier ( |
None
|
model_name
|
str | None
|
Explicit provider-qualified model name override. |
None
|
local_endpoint
|
str | None
|
Ollama / local API base URL. |
None
|
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Full dashboard state payload. |
Source code in src/solidworks_mcp/ui/services/session_service.py
upsert_design_session ¶
upsert_design_session(*, session_id: str, user_goal: str, source_mode: str = 'model', accepted_family: str | None = None, status: str = 'active', current_checkpoint_index: int = 0, metadata_json: str | None = None, db_path: Path | None = None) -> None
Create or update one interactive design session row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
user_goal
|
str
|
The user goal value. |
required |
source_mode
|
str
|
The source mode value. Defaults to "model". |
'model'
|
accepted_family
|
str | None
|
The accepted family value. Defaults to None. |
None
|
status
|
str
|
The status value. Defaults to "active". |
'active'
|
current_checkpoint_index
|
int
|
The current checkpoint index value. Defaults to 0. |
0
|
metadata_json
|
str | None
|
The metadata 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
workflow_copy ¶
Return display copy for the workflow selector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_mode
|
str
|
Normalised workflow mode string. |
required |
active_model_path
|
str | None
|
Currently attached model path, if any. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[str, str, str]
|
Three-tuple of (label, guidance_text, flow_header_text). |