solidworks-mcp-python 1.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. solidworks_mcp/__init__.py +57 -0
  2. solidworks_mcp/adapters/__init__.py +40 -0
  3. solidworks_mcp/adapters/base.py +1882 -0
  4. solidworks_mcp/adapters/circuit_breaker.py +2052 -0
  5. solidworks_mcp/adapters/com_executor.py +252 -0
  6. solidworks_mcp/adapters/complexity_analyzer.py +272 -0
  7. solidworks_mcp/adapters/connection_pool.py +1884 -0
  8. solidworks_mcp/adapters/factory.py +366 -0
  9. solidworks_mcp/adapters/intelligent_router.py +218 -0
  10. solidworks_mcp/adapters/mock_adapter.py +4016 -0
  11. solidworks_mcp/adapters/pywin32_adapter.py +2842 -0
  12. solidworks_mcp/adapters/solidworks/__init__.py +17 -0
  13. solidworks_mcp/adapters/solidworks/bitmap.py +180 -0
  14. solidworks_mcp/adapters/solidworks/com_utils.py +56 -0
  15. solidworks_mcp/adapters/solidworks/dimension_layout.py +753 -0
  16. solidworks_mcp/adapters/solidworks/documentation.py +1476 -0
  17. solidworks_mcp/adapters/solidworks/drawing_standard.py +1993 -0
  18. solidworks_mcp/adapters/solidworks/face_selection.py +392 -0
  19. solidworks_mcp/adapters/solidworks/features.py +3362 -0
  20. solidworks_mcp/adapters/solidworks/io.py +3649 -0
  21. solidworks_mcp/adapters/solidworks/rebuild_diagnostics.py +269 -0
  22. solidworks_mcp/adapters/solidworks/rebuild_inspector.py +146 -0
  23. solidworks_mcp/adapters/solidworks/selection.py +308 -0
  24. solidworks_mcp/adapters/solidworks/sketch.py +2545 -0
  25. solidworks_mcp/adapters/sw_feature_errors.py +66 -0
  26. solidworks_mcp/adapters/sw_type_info.py +317 -0
  27. solidworks_mcp/adapters/vba_adapter.py +318 -0
  28. solidworks_mcp/adapters/vba_macro_executor.py +215 -0
  29. solidworks_mcp/agents/__init__.py +68 -0
  30. solidworks_mcp/agents/design_knowledge/assembly_patterns.md +127 -0
  31. solidworks_mcp/agents/design_knowledge/hinges.md +118 -0
  32. solidworks_mcp/agents/design_knowledge/snap_fits.md +93 -0
  33. solidworks_mcp/agents/design_knowledge/solidworks_basics.md +3 -0
  34. solidworks_mcp/agents/design_knowledge/tolerancing.md +128 -0
  35. solidworks_mcp/agents/harness.py +216 -0
  36. solidworks_mcp/agents/history_db.py +1508 -0
  37. solidworks_mcp/agents/retrieval_index.py +164 -0
  38. solidworks_mcp/agents/schemas.py +165 -0
  39. solidworks_mcp/agents/smoke_test.py +285 -0
  40. solidworks_mcp/agents/soc_exporter.py +650 -0
  41. solidworks_mcp/agents/soc_pickup.py +332 -0
  42. solidworks_mcp/agents/soc_rewind.py +221 -0
  43. solidworks_mcp/agents/vector_rag.py +665 -0
  44. solidworks_mcp/cache/__init__.py +5 -0
  45. solidworks_mcp/cache/response_cache.py +164 -0
  46. solidworks_mcp/config.py +729 -0
  47. solidworks_mcp/exceptions.py +37 -0
  48. solidworks_mcp/security/__init__.py +68 -0
  49. solidworks_mcp/security/auth.py +128 -0
  50. solidworks_mcp/security/cors.py +27 -0
  51. solidworks_mcp/security/rate_limiting.py +90 -0
  52. solidworks_mcp/security/runtime.py +155 -0
  53. solidworks_mcp/server.py +777 -0
  54. solidworks_mcp/server_cli_fixed.py +120 -0
  55. solidworks_mcp/setup/__init__.py +1 -0
  56. solidworks_mcp/setup/cli.py +399 -0
  57. solidworks_mcp/setup/clients.py +157 -0
  58. solidworks_mcp/setup/config_file.py +230 -0
  59. solidworks_mcp/setup/handshake.py +202 -0
  60. solidworks_mcp/setup/launcher.py +102 -0
  61. solidworks_mcp/setup/legacy.py +100 -0
  62. solidworks_mcp/setup/registration.py +193 -0
  63. solidworks_mcp/setup/solidworks.py +49 -0
  64. solidworks_mcp/tools/__init__.py +64 -0
  65. solidworks_mcp/tools/analysis.py +723 -0
  66. solidworks_mcp/tools/automation.py +578 -0
  67. solidworks_mcp/tools/docs_discovery.py +1476 -0
  68. solidworks_mcp/tools/drawing.py +1015 -0
  69. solidworks_mcp/tools/drawing_analysis.py +456 -0
  70. solidworks_mcp/tools/drawing_automation.py +627 -0
  71. solidworks_mcp/tools/engineering_data.py +466 -0
  72. solidworks_mcp/tools/error_classifier.py +232 -0
  73. solidworks_mcp/tools/export.py +833 -0
  74. solidworks_mcp/tools/file_facts.py +40 -0
  75. solidworks_mcp/tools/file_management.py +1473 -0
  76. solidworks_mcp/tools/input_compat.py +17 -0
  77. solidworks_mcp/tools/macro_recording.py +464 -0
  78. solidworks_mcp/tools/modeling.py +2360 -0
  79. solidworks_mcp/tools/sketching.py +1422 -0
  80. solidworks_mcp/tools/template_management.py +367 -0
  81. solidworks_mcp/tools/tool_boundary.py +280 -0
  82. solidworks_mcp/tools/vba_generation.py +1145 -0
  83. solidworks_mcp/ui/__init__.py +9 -0
  84. solidworks_mcp/ui/local_llm.py +725 -0
  85. solidworks_mcp/ui/routers/__init__.py +10 -0
  86. solidworks_mcp/ui/routers/checkpoint.py +24 -0
  87. solidworks_mcp/ui/routers/docs.py +47 -0
  88. solidworks_mcp/ui/routers/llm.py +83 -0
  89. solidworks_mcp/ui/routers/local_model.py +69 -0
  90. solidworks_mcp/ui/routers/model.py +75 -0
  91. solidworks_mcp/ui/routers/preview.py +38 -0
  92. solidworks_mcp/ui/routers/session.py +161 -0
  93. solidworks_mcp/ui/routers/viewer.py +154 -0
  94. solidworks_mcp/ui/schemas.py +502 -0
  95. solidworks_mcp/ui/server.py +298 -0
  96. solidworks_mcp/ui/service.py +481 -0
  97. solidworks_mcp/ui/services/__init__.py +136 -0
  98. solidworks_mcp/ui/services/_utils.py +958 -0
  99. solidworks_mcp/ui/services/checkpoint_service.py +1110 -0
  100. solidworks_mcp/ui/services/docs_service.py +282 -0
  101. solidworks_mcp/ui/services/llm_service.py +956 -0
  102. solidworks_mcp/ui/services/model_service.py +459 -0
  103. solidworks_mcp/ui/services/parameter_repair_service.py +314 -0
  104. solidworks_mcp/ui/services/preview_service.py +489 -0
  105. solidworks_mcp/ui/services/session_service.py +1389 -0
  106. solidworks_mcp/utils/__init__.py +9 -0
  107. solidworks_mcp/utils/feature_tree_classifier.py +342 -0
  108. solidworks_mcp/utils/logging.py +76 -0
  109. solidworks_mcp/utils/validation.py +77 -0
  110. solidworks_mcp/version.py +8 -0
  111. solidworks_mcp_python-1.5.0.dist-info/METADATA +410 -0
  112. solidworks_mcp_python-1.5.0.dist-info/RECORD +115 -0
  113. solidworks_mcp_python-1.5.0.dist-info/WHEEL +4 -0
  114. solidworks_mcp_python-1.5.0.dist-info/entry_points.txt +3 -0
  115. solidworks_mcp_python-1.5.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,128 @@
1
+ # FDM Tolerancing and Clearance Guide for SolidWorks
2
+
3
+ ## Overview
4
+
5
+ FDM (Fused Deposition Modeling) printed parts have dimensional error sources that injection-molded
6
+ parts do not. Understanding these helps design parts that fit on the first print.
7
+
8
+ ## Sources of Dimensional Error in FDM
9
+
10
+ 1. **Line width expansion**: Extruded lines are slightly wider than nozzle diameter. A 0.4 mm
11
+ nozzle typically produces 0.42–0.48 mm lines.
12
+ 2. **First-layer squish**: The first layer is intentionally compressed for adhesion, widening it
13
+ by 0.05–0.15 mm.
14
+ 3. **Thermal shrinkage**: Parts shrink slightly on cooling. PLA ~0.1–0.3%, ABS ~0.5–1.0%,
15
+ PETG ~0.2–0.4%.
16
+ 4. **Elephant foot**: First few layers bow outward by 0.1–0.3 mm radius at base.
17
+ 5. **Hole undersizing**: Circular holes are undersized by 0.1–0.3 mm diameter (typical).
18
+ 6. **Overhangs and support artifacts**: Overhangs > 45° add surface roughness of 0.2–0.5 mm.
19
+
20
+ ## Recommended Clearances by Fit Class
21
+
22
+ ### Sliding Fit (e.g., drawer, lid that slides)
23
+
24
+ | Material | Clearance per side | Total gap |
25
+ |-------------------|--------------------|-----------|
26
+ | PLA | 0.15–0.25 mm | 0.30–0.50 mm |
27
+ | PETG | 0.20–0.30 mm | 0.40–0.60 mm |
28
+ | ABS | 0.15–0.25 mm | 0.30–0.50 mm |
29
+ | Nylon | 0.20–0.30 mm | 0.40–0.60 mm |
30
+
31
+ ### Rotating Fit (axle in bearing or hole — free spin)
32
+
33
+ | Material | Clearance per side |
34
+ |-------------------|--------------------|
35
+ | PLA | 0.20–0.30 mm |
36
+ | PETG | 0.25–0.35 mm |
37
+ | ABS | 0.20–0.30 mm |
38
+
39
+ ### Press Fit (e.g., insert or shaft pressed in without heat)
40
+
41
+ | Material | Interference per side |
42
+ |-------------------|-----------------------|
43
+ | PLA | 0.00–0.15 mm |
44
+ | PETG | 0.05–0.20 mm |
45
+ | ABS | 0.05–0.20 mm |
46
+
47
+ ### Mating Parts (two printed surfaces that touch but don't move)
48
+
49
+ Minimum clearance to avoid fusion/welding: 0.15 mm per side (0.30 mm total).
50
+
51
+ ### Hole Diameter Correction
52
+
53
+ Because holes print undersized, add the following to nominal hole diameters:
54
+
55
+ | Hole type | Correction |
56
+ |-----------------|-----------|
57
+ | Vertical holes | +0.2 mm |
58
+ | Horizontal holes | +0.3 mm |
59
+ | Hex nut trap | +0.3 mm on flat-to-flat, +0.1 mm on height |
60
+ | M3 clearance | Print at 3.4 mm (nominal 3.2 mm + compensation) |
61
+ | M4 clearance | Print at 4.5 mm |
62
+ | M5 clearance | Print at 5.6 mm |
63
+
64
+ ## Material-Specific Notes
65
+
66
+ ### PLA
67
+ - Easy to print, dimensionally accurate (~0.2% shrinkage)
68
+ - Paint the clearance table values above as starting points
69
+ - PLA warps minimally; well-calibrated machines may use the lower end of clearance ranges
70
+
71
+ ### PETG
72
+ - More flexible than PLA; use the mid-range clearances
73
+ - PETG sticks to itself: always use ≥ 0.3 mm gap on support or mating faces
74
+ - PETG absorbs moisture slightly; store dry for best dimensional stability
75
+
76
+ ### ABS
77
+ - Significant shrinkage (~0.5%); use an enclosure to reduce warp
78
+ - Increase clearances by 0.05–0.10 mm vs PLA
79
+ - Post-process with acetone vapor for tighter fits
80
+
81
+ ### Nylon (PA12, PA6)
82
+ - Absorbs moisture aggressively; prints MUST dried (70°C/12h in oven before printing)
83
+ - Dimensional stability excellent when dry; expands ~0.2% when wet
84
+ - Use the upper end of clearance ranges
85
+
86
+ ### TPU/TPE
87
+ - Flexible; normal clearance rules don't apply
88
+ - For rigid-to-flexible interface: use 0.0–0.1 mm clearance (flexible part compresses)
89
+ - Use Shore A hardness to gauge stiffness: 95A is nearly rigid, 70A is very soft
90
+
91
+ ## Thread Design
92
+
93
+ ### Printed Threads (in-part)
94
+ - Use coarse threads (M3–M8 typical)
95
+ - For best results: cut threads with a tap after printing
96
+ - Printed thread pitch: use M3×0.5, M4×0.7 — coarser pitch = more material, stronger
97
+ - Add 0.2 mm clearance on thread form radius when printing both mating threads
98
+
99
+ ### Heat-Set Inserts (preferred for mechanical joints)
100
+ | Insert size | Hole diameter | Depth |
101
+ |-------------|---------------|-------|
102
+ | M2 | 3.2 mm | 4.0 mm |
103
+ | M3 | 4.2 mm | 5.7 mm |
104
+ | M4 | 5.6 mm | 7.0 mm |
105
+ | M5 | 6.4 mm | 8.0 mm |
106
+
107
+ Knurled M3 inserts (Ruthex RX-M3×5.7 or similar): dominant choice for robust joints.
108
+
109
+ ## SolidWorks Parametric Tolerancing Approach
110
+
111
+ Use a **global equation** for clearance to drive all mating geometry:
112
+
113
+ ```
114
+ "print_clearance" = 0.30mm ' adjust per material and printer
115
+ "hole_comp" = 0.20mm ' hole undersizing compensation
116
+ "press_fit_interference" = 0.10mm
117
+ ```
118
+
119
+ Then reference these equations on all mating extrudes, holes, and cuts. A single value
120
+ change recalibrates the entire assembly.
121
+
122
+ ## Recommended Test Protocol Before Final Print
123
+
124
+ 1. Print a **tolerance test coupon** (25 mm cube with holes at 3 mm, 4 mm, 5 mm and
125
+ slots at 0.2, 0.3, 0.4, 0.5 mm clearances)
126
+ 2. Measure with calipers; compare to print_clearance global variable
127
+ 3. Update the global variable to match reality
128
+ 4. Reprint coupon once to confirm, then proceed to final part
@@ -0,0 +1,216 @@
1
+ """PydanticAI harness for validating custom agent prompt responses."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import uuid
7
+ from pathlib import Path
8
+ from typing import Any
9
+
10
+ from pydantic import BaseModel
11
+
12
+ from .history_db import ErrorRecord, insert_error, insert_run
13
+ from .schemas import RecoverableFailure
14
+
15
+ try:
16
+ from pydantic_ai import Agent
17
+
18
+ IMPORT_ERROR: ImportError | None = None
19
+ except ImportError as exc:
20
+ Agent = None # type: ignore[assignment, misc]
21
+ IMPORT_ERROR = exc
22
+
23
+
24
+ AGENTS_DIR = Path(".github") / "agents"
25
+
26
+
27
+ def _load_agent_prompt(agent_file_name: str) -> str:
28
+ """Build internal agent prompt.
29
+
30
+ Args:
31
+ agent_file_name (str): The agent file name value.
32
+
33
+ Returns:
34
+ str: The resulting text value.
35
+ """
36
+
37
+ path = AGENTS_DIR / agent_file_name
38
+ raw = path.read_text(encoding="utf-8")
39
+
40
+ # Strip YAML frontmatter and keep only instruction body.
41
+ if raw.startswith("---"):
42
+ parts = raw.split("---", 2)
43
+ if len(parts) == 3:
44
+ return parts[2].strip()
45
+ return raw.strip()
46
+
47
+
48
+ def _extract_data(result: Any) -> Any:
49
+ """Build internal extract data.
50
+
51
+ Args:
52
+ result (Any): The result value.
53
+
54
+ Returns:
55
+ Any: The result produced by the operation.
56
+ """
57
+
58
+ if hasattr(result, "data"):
59
+ return result.data
60
+ if hasattr(result, "output"):
61
+ return result.output
62
+ return result
63
+
64
+
65
+ async def run_validated_prompt[TModel: BaseModel](
66
+ *,
67
+ agent_file_name: str,
68
+ model_name: str,
69
+ user_prompt: str,
70
+ result_type: type[TModel],
71
+ max_retries_on_recoverable: int = 1,
72
+ db_path: Path | None = None,
73
+ ) -> TModel | RecoverableFailure:
74
+ """Run one prompt through PydanticAI and validate the output schema.
75
+
76
+ Args:
77
+ agent_file_name (str): The agent file name value.
78
+ model_name (str): Embedding model name to use.
79
+ user_prompt (str): The user prompt value.
80
+ result_type (type[TModel]): The result type value.
81
+ max_retries_on_recoverable (int): The max retries on recoverable value. Defaults to
82
+ 1.
83
+ db_path (Path | None): The db path value. Defaults to None.
84
+
85
+ Returns:
86
+ TModel | RecoverableFailure: The result produced by the operation.
87
+
88
+ Raises:
89
+ RuntimeError: Pydantic_ai is not importable. Install dependencies and retry.
90
+ """
91
+ if Agent is None:
92
+ raise RuntimeError(
93
+ "pydantic_ai is not importable. Install dependencies and retry."
94
+ ) from IMPORT_ERROR
95
+
96
+ base_run_id = str(uuid.uuid4())
97
+ instructions = _load_agent_prompt(agent_file_name)
98
+ system_prompt = (
99
+ f"{instructions}\n\n"
100
+ "If you cannot safely produce the requested structured output, return "
101
+ "a RecoverableFailure with concrete remediation steps and a focused retry hint."
102
+ )
103
+
104
+ attempt = 0
105
+ current_prompt = user_prompt
106
+
107
+ while True:
108
+ attempt += 1
109
+ run_id = f"{base_run_id}-a{attempt}"
110
+
111
+ prompt_snapshot = current_prompt
112
+
113
+ agent = Agent(
114
+ model_name,
115
+ system_prompt=system_prompt,
116
+ output_type=[result_type, RecoverableFailure],
117
+ )
118
+
119
+ try:
120
+ result = await agent.run(current_prompt)
121
+ payload = _extract_data(result)
122
+
123
+ if isinstance(payload, RecoverableFailure):
124
+ insert_run(
125
+ run_id=run_id,
126
+ agent_name=agent_file_name,
127
+ prompt=prompt_snapshot,
128
+ status="recoverable_failure",
129
+ output_json=payload.model_dump_json(indent=2),
130
+ model_name=model_name,
131
+ db_path=db_path,
132
+ )
133
+ insert_error(
134
+ ErrorRecord(
135
+ source="pydantic_ai",
136
+ tool_name="run_validated_prompt",
137
+ error_type="RecoverableFailure",
138
+ error_message=payload.explanation,
139
+ root_cause=payload.explanation,
140
+ remediation="; ".join(payload.remediation_steps)
141
+ if payload.remediation_steps
142
+ else "Follow retry_focus guidance and retry with narrower scope.",
143
+ ),
144
+ run_id=run_id,
145
+ db_path=db_path,
146
+ )
147
+ if payload.should_retry and attempt <= max_retries_on_recoverable:
148
+ retry_hint = (
149
+ payload.retry_focus or "Narrow scope and clarify assumptions."
150
+ )
151
+ remediation = "\n".join(
152
+ f"- {step}" for step in payload.remediation_steps
153
+ )
154
+ current_prompt = (
155
+ f"{user_prompt}\n\n"
156
+ "Retry context from previous recoverable failure:\n"
157
+ f"Explanation: {payload.explanation}\n"
158
+ f"Retry focus: {retry_hint}\n"
159
+ f"Remediation steps:\n{remediation}"
160
+ )
161
+ continue
162
+ return payload
163
+
164
+ validated = (
165
+ payload
166
+ if isinstance(payload, result_type)
167
+ else result_type.model_validate(payload)
168
+ )
169
+
170
+ insert_run(
171
+ run_id=run_id,
172
+ agent_name=agent_file_name,
173
+ prompt=prompt_snapshot,
174
+ status="success",
175
+ output_json=validated.model_dump_json(indent=2),
176
+ model_name=model_name,
177
+ db_path=db_path,
178
+ )
179
+ return validated
180
+ except Exception as exc:
181
+ insert_run(
182
+ run_id=run_id,
183
+ agent_name=agent_file_name,
184
+ prompt=current_prompt,
185
+ status="error",
186
+ output_json=None,
187
+ model_name=model_name,
188
+ db_path=db_path,
189
+ )
190
+ insert_error(
191
+ ErrorRecord(
192
+ source="pydantic_ai",
193
+ tool_name="run_validated_prompt",
194
+ error_type=exc.__class__.__name__,
195
+ error_message=str(exc),
196
+ root_cause="Agent output failed schema validation or model invocation",
197
+ remediation=(
198
+ "Review response schema, verify model provider credentials, and re-run with a narrower prompt."
199
+ ),
200
+ ),
201
+ run_id=run_id,
202
+ db_path=db_path,
203
+ )
204
+ raise
205
+
206
+
207
+ def pretty_json(model: BaseModel) -> str:
208
+ """Return pretty JSON for test output snapshots.
209
+
210
+ Args:
211
+ model (BaseModel): The model value.
212
+
213
+ Returns:
214
+ str: The resulting text value.
215
+ """
216
+ return json.dumps(model.model_dump(mode="json"), indent=2)