solidworks_mcp.tools.docs_discovery¶
solidworks_mcp.tools.docs_discovery ¶
Docs discovery tool for SolidWorks COM and VBA command indexing.
This module provides functionality to discover and catalog all available COM objects, methods, and properties for the installed SolidWorks version, as well as VBA library references. Useful for building context for MCP server operations and enabling intelligent tool selection.
Attributes¶
_KNOWN_SW_INTERFACES
module-attribute
¶
_KNOWN_SW_INTERFACES: dict[str, dict[str, list[str]]] = {'ISldWorks': {'methods': ['OpenDoc6', 'CloseDoc', 'ActivateDoc3', 'GetActiveObject', 'GetFirstDocument', 'GetDocumentCount', 'NewDocument', 'SendMsgToUser2', 'GetProcessID', 'ExitApp', 'RevisionNumber', 'GetUserTypeLibraryFile', 'CreateNewDocument'], 'properties': ['Visible', 'ActiveDoc', 'FrameState']}, 'IModelDoc2': {'methods': ['ShowNamedView2', 'ViewZoomToFit2', 'SaveBitmapWithVariableSize', 'SaveAs3', 'GetTitle', 'GetPathName', 'GetType', 'GetFeatureCount', 'GetActiveConfiguration', 'Extension', 'SketchManager', 'FeatureManager', 'SelectionManager', 'GetMassProperties', 'Close', 'SetSaveAsFileName', 'ResolveAllLightweightComponents', 'InsertSketch2', 'SketchAddConstraints', 'ClearSelection2'], 'properties': ['ActiveView', 'ActiveLayer']}, 'IPartDoc': {'methods': ['CreateFeatureFromSketch2', 'AddMateReference', 'GetBodies2', 'GetEntityByName', 'InsertSmartComponents', 'Material'], 'properties': []}, 'IAssemblyDoc': {'methods': ['AddComponent4', 'AddComponent5', 'InsertNewPart3', 'LayoutToAssembly', 'ResolveAllLightweightComponents', 'AddMate5', 'GetComponents', 'GetComponentCount'], 'properties': []}, 'IDrawingDoc': {'methods': ['CreateDrawViewFromModelView3', 'InsertModelAnnotations3', 'GenerateViewPalette', 'Get3DDrawingView'], 'properties': []}, 'IFeatureManager': {'methods': ['FeatureExtrusion3', 'FeatureCut3', 'FeatureRevolve2', 'InsertProtrusionBlend4', 'InsertShell', 'InsertFillet3', 'InsertChamfer', 'InsertDraftXpert3', 'FeatureMirror3', 'FeatureCircularPattern2', 'FeatureLinearPattern3', 'InsertBoss', 'FeatureSweep5', 'FeatureLoft3'], 'properties': []}, 'ISketchManager': {'methods': ['InsertSketch', 'CreateLine', 'CreateArc', 'CreateCircle', 'CreateRectangle', 'CreateEllipse', 'CreateSpline', 'CreateCenterLine', 'SketchMirror', 'SketchOffset', 'AddToDB', 'InsertSketch2'], 'properties': ['ActiveSketch']}, 'IModelView': {'methods': ['SaveBitmapWithVariableSize', 'ZoomToFit', 'ZoomToSheet', 'OrientView', 'SetCameraParameters'], 'properties': ['Orientation3', 'Translation3']}, 'IExtensionManager': {'methods': ['SaveAs2', 'SelectByID2', 'MultiSelect2'], 'properties': []}, 'IFeature': {'methods': ['GetNextFeature', 'GetName', 'GetTypeName2', 'SetSuppression2', 'IsSuppressed2', 'GetDefinition'], 'properties': ['Name']}, 'IBody2': {'methods': ['GetFaceCount', 'GetEdgeCount', 'GetVertexCount', 'GetMassProperties', 'GetType'], 'properties': []}, 'ISketchSegment': {'methods': ['GetStartPoint2', 'GetEndPoint2', 'GetType', 'SetEndPoint'], 'properties': []}}
Classes¶
CompatInput ¶
Bases: BaseModel
Base schema allowing legacy/extra fields used by existing tests.
Attributes:
| Name | Type | Description |
|---|---|---|
model_config |
Any
|
The model config value. |
DiscoverDocsInput ¶
Bases: CompatInput
Input schema for docs discovery.
Attributes:
| Name | Type | Description |
|---|---|---|
include_vba |
bool
|
The include vba value. |
output_dir |
str | None
|
The output dir value. |
year |
int | None
|
The year value. |
SearchApiHelpInput ¶
Bases: CompatInput
Input schema for SolidWorks API help search.
Attributes:
| Name | Type | Description |
|---|---|---|
auto_discover_if_missing |
bool
|
The auto discover if missing value. |
index_file |
str | None
|
The index file value. |
max_results |
int
|
The max results value. |
query |
str
|
The query value. |
year |
int | None
|
The year value. |
SolidWorksDocsDiscovery ¶
Discover and index SolidWorks COM and VBA documentation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
Path | None
|
The output dir value. Defaults to None. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
output_dir |
Any
|
The output dir value. |
sw_app |
Any
|
The sw app value. |
Initialize docs discovery.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
Path | None
|
The output dir value. Defaults to None. |
None
|
Source code in src/solidworks_mcp/tools/docs_discovery.py
Functions¶
connect_to_solidworks ¶
Connect to running SolidWorks instance.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if connect to solidworks, otherwise False. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
create_search_summary ¶
Create a summary of indexed documentation for search/reference.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary containing the resulting values. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
discover_all ¶
Run full discovery of COM and VBA documentation.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary containing the resulting values. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
discover_com_objects ¶
Discover all COM objects and their methods/properties.
Uses ITypeInfo enumeration via pythoncom for ISldWorks, then supplements with the active document's interface if a model is open. Falls back to the known-interface catalogue when typelib introspection is unavailable.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary containing the resulting values. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
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 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
discover_vba_references ¶
Discover VBA/TypeLib references via the Windows Registry.
Scans HKEY_CLASSES_ROOT\TypeLib for SolidWorks and common Office/VBA type libraries.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary containing the resulting values. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
save_index ¶
Save discovered documentation to JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The filename value. Defaults to "solidworks_docs_index.json". |
'solidworks_docs_index.json'
|
Returns:
| Type | Description |
|---|---|
Path | None
|
Path | None: The result produced by the operation. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
Functions¶
_detect_installed_solidworks_year ¶
Detect the latest installed SolidWorks year from the public samples path.
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: The result produced by the operation. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
_discover_com_via_typeinfo ¶
Enumerate ISldWorks methods/properties via ITypeInfo.
Returns a COM index dict keyed by interface name, with the same shape as the rest of the
index (methods, properties, method_count, property_count).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sw_app
|
Any
|
The sw app value. |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any], int, int]
|
tuple[dict[str, Any], int, int]: com_index, total_methods, total_properties. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
_discover_vba_references_via_registry ¶
Enumerate VBA/TypeLib references via the Windows Registry.
Scans HKEY_CLASSES_ROOT\TypeLib for entries whose name or GUID matches SolidWorks or common Office/VBA libraries.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary containing the resulting values. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
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 | |
_enumerate_typeinfo_members ¶
Enumerate methods and properties from a COM ITypeInfo object.
Uses raw ITypeInfo via pythoncom to walk the function table, which works reliably for both early-bound and late-bound COM objects.
Returns (methods, properties) as sorted de-duped lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
typeinfo
|
Any
|
The typeinfo value. |
required |
Returns:
| Type | Description |
|---|---|
tuple[list[str], list[str]]
|
tuple[list[str], list[str]]: A tuple containing the resulting values. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
_extract_year ¶
Extract a 4-digit year from any string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | None
|
The value value. |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: The result produced by the operation. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
_fallback_help_for_query ¶
Provide coherent fallback help when no docs index is available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Query text used for the operation. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary containing the resulting values. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
_find_index_file ¶
Find the most appropriate index file for a requested year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int | None
|
The year value. |
required |
explicit_index_file
|
str | None
|
The explicit index file value. |
required |
Returns:
| Type | Description |
|---|---|
Path | None
|
Path | None: The result produced by the operation. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
_load_index_file ¶
Load docs index JSON from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_file
|
Path
|
The index file value. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
dict[str, Any] | None: A dictionary containing the resulting values. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
_normalize_input ¶
Normalize dict/model payloads for direct tool invocation paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
|
Any
|
The input data value. |
required |
model_type
|
type[CompatInputT]
|
The model type value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
CompatInputT |
CompatInputT
|
The result produced by the operation. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
_resolve_solidworks_year ¶
Resolve SolidWorks year from explicit request, config, then local installation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requested_year
|
int | None
|
The requested year value. |
required |
config
|
Any
|
Configuration values for the operation. |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: The result produced by the operation. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
_search_index ¶
Search indexed COM objects/members for a query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
dict[str, Any]
|
The index value. |
required |
query
|
str
|
Query text used for the operation. |
required |
max_results
|
int
|
The max results value. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: A list containing the resulting items. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 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 | |
register_docs_discovery_tools
async
¶
Register docs discovery tool with FastMCP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mcp
|
Any
|
The mcp value. |
required |
adapter
|
Any
|
Adapter instance used for the operation. |
required |
config
|
dict[str, Any]
|
Configuration values for the operation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The computed numeric result. |
Source code in src/solidworks_mcp/tools/docs_discovery.py
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 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 | |