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. |
FindRelatedApiInput ¶
LookupApiInterfaceInput ¶
LookupApiMethodInput ¶
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
Methods:¶
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
_find_related_api_members ¶
Given an indexed interface or member name, return related members.
- An interface name -> its own members.
- A member name -> the other members of every interface that also exposes it (siblings commonly used together), plus name-substring matches elsewhere in the index.
Source code in src/solidworks_mcp/tools/docs_discovery.py
_index_is_stale ¶
True when an existing index file is older than max_age_days.
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
_lookup_interface ¶
Return every indexed member of an interface, or a no-match marker.
The index stores member names only (no signatures), so this returns the full method/property lists for the interface and nothing more.
Source code in src/solidworks_mcp/tools/docs_discovery.py
_lookup_method ¶
Confirm a method/property is indexed on an interface.
The index has no signatures, so parameters / return_type are always
reported as not indexed; the useful output is confirmation the member
exists on that interface plus its sibling members for context.
Source code in src/solidworks_mcp/tools/docs_discovery.py
_maybe_refresh_index ¶
_maybe_refresh_index(index: dict[str, Any] | None, index_file: Path | None, year: int | None, config: Any) -> tuple[dict[str, Any] | None, Path | None]
Rebuild the docs index if an existing one is stale and the config allows.
Only acts on an index file that exists but is older than
docs_index_max_age_days — a missing index is left to the caller's
auto_discover_if_missing opt-in. Returns the (possibly refreshed)
(index, index_file). A no-op without win32com / SolidWorks, or when
config.docs_index_auto_refresh is off; any failure leaves the original
index untouched.
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_interface ¶
Case-insensitively resolve an interface name to its (canonical_name, data).
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
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 950 951 952 953 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 | |
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
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 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 | |