tylerstoltz/SW_MCP
If you are the rightful owner of SW_MCP and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
A comprehensive Model Context Protocol (MCP) server for SolidWorks 2020, enabling natural language control of SolidWorks through Claude Desktop and other MCP clients.
SolidWorks MCP Server
A comprehensive Model Context Protocol (MCP) server for SolidWorks 2020, enabling natural language control of SolidWorks through Claude Desktop and other MCP clients.
Architecture
This server implements a 4-tool types that combines high-level workflow tools with flexible, dynamic API execution:
1: High-Level Workflow Tools
Simple, deterministic tools for common operations:
create_part- Create new part documentscreate_assembly- Create new assembly documentscreate_sketch- Create sketches on planescreate_extrude- Create extrusion featurescreate_rectangle- Add rectangles to sketchescreate_circle- Add circles to sketchescreate_line- Add lines to sketchescreate_base_flange- Create sheet metal base flange features (first feature in sheet metal parts)create_edge_flange- Create edge flanges on sheet metal parts - Doesn't work due to failure to select / maintain edge selectionget_model_info- Get document informationsave_document- Save documents - depends on process / directory permissions
2: Dynamic API Execution
Flexible tools for arbitrary SolidWorks API calls:
execute_solidworks_api- Execute any SolidWorks API method - barely works, no good for anything complex (yet)access_solidworks_property- Get/set properties on interfaces - works on some stuff
3: Resources for State Inspection
Expose SolidWorks state as readable data:
get_active_document_resource- Current document infoget_feature_tree_resource- Feature list and hierarchy
Note: Additional resource methods (selection, sketches, configurations) are available in SolidWorksResources.cs.bak but require API signature adjustments for SolidWorks 2020.
4: API Documentation Search
Self-documenting capabilities:
search_solidworks_api- Full-text search of API documentation - needs improvementget_interface_documentation- Get interface detailsget_method_documentation- Get method detailsget_code_examples- Find C# code exampleslist_common_interfaces- List common SolidWorks interfacesget_workflow_guidance- Get workflow guidance for common tasks
Prerequisites
- SolidWorks 2020 installed (does not need to be running - the server will connect/start it)
- .NET 8.0 SDK or later
- Windows OS (required for COM interop)
- SolidWorks API DLLs in the correct location:
- Default:
C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\api\redist\ - Files:
SolidWorks.Interop.sldworks.dll,SolidWorks.Interop.swconst.dll
- Default:
- SolidWorks API Documentation (optional but recommended for search features):
- Path:
Path\to\solidworks\Solidworks-SDK\docs\api\- convert from CHM if needed - Be sure to update this in "ApiDocumentationService.cs":
_apiDocsPath = @"Path\\to\\solidworks\\Solidworks-SDK\\docs\\api\\";is placeholder (add to config later)
- Path:
Installation
1. Build the Project
cd "Path\\To\\SW_MCP"
dotnet restore
dotnet build -c Release
2. Verify SolidWorks API DLL Paths
If your SolidWorks installation is in a different location, update the paths in SolidWorksMCP.csproj:
<Reference Include="SolidWorks.Interop.sldworks">
<HintPath>YOUR_PATH_HERE\SolidWorks.Interop.sldworks.dll</HintPath>
<EmbedInteropTypes>false</EmbedInteropTypes>
</Reference>
3. Configure Claude Desktop
Add the following to your Claude Desktop configuration file:
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"solidworks": {
"command": "dotnet",
"args": [
"run",
"--project",
"Path\\To\\SW_MCP\\SolidWorksMCP.csproj"
]
}
}
}
Or use the built executable:
{
"mcpServers": {
"solidworks": {
"command": "Path\\To\\SW_MCP\\bin\\Release\\net8.0\\SolidWorksMCP.exe"
}
}
}
4. Restart Claude Desktop
Restart Claude Desktop to load the new MCP server.
Usage
Basic Workflow Example
User: "Create a new part and draw a 100mm x 50mm rectangle, then extrude it 25mm"
Claude will:
1. Use create_part to create a new part
2. Use create_sketch to start a sketch on the Front plane
3. Use create_rectangle with coordinates (0, 0) to (0.1, 0.05) [meters]
4. Use create_extrude with depth 0.025 [meters]
Sheet Metal Example
User: "Create a sheet metal part with a 100mm x 80mm base flange, 2mm thick"
Claude will:
1. Use create_part to create a new part
2. Use create_sketch to start a sketch on the Front plane
3. Use create_rectangle with coordinates (0, 0) to (0.1, 0.08) [meters]
4. Use create_base_flange with thickness 0.002 [meters]
Advanced API Calls - barely works
User: "Use the SolidWorks API to create a fillet with radius 5mm on the selected edges"
Claude will:
1. Use search_solidworks_api to find fillet-related methods
2. Use execute_solidworks_api to call IFeatureManager.FeatureFillet with appropriate parameters
Inspecting State
User: "What features are in the current model?"
Claude will use get_feature_tree_resource to list all features.
Learning the API - needs improvement
User: "How do I create a mate in an assembly?"
Claude will:
1. Use get_workflow_guidance with workflowType: "assembly"
2. Or search_solidworks_api for "mate"
3. Or get_code_examples for "add mate"
Units
IMPORTANT: All dimensions in the SolidWorks API are in meters, regardless of the document units.
- 1 mm = 0.001 meters
- 1 inch = 0.0254 meters
The workflow tools expect dimensions in meters. Convert your dimensions accordingly.
Architecture Details
Connection Management
The server connects to SolidWorks using COM interop via Type.GetTypeFromProgID("SldWorks.Application") and Activator.CreateInstance(). This will either connect to a running instance or start SolidWorks if it's not running. The connection is established on server startup and maintained throughout the session.
Error Handling
All tools return structured responses with success boolean and error messages:
{
"success": true,
"message": "Operation completed successfully"
}
Or on failure:
{
"success": false,
"error": "Error message describing what went wrong"
}
API Documentation Search
The documentation search service indexes the HTML documentation files on first use and caches the results for the session. It uses:
- Full-text search across 13,000+ HTML files (need to convert from CHM)
- Relevance scoring based on term frequency and file names
- Extraction of descriptions, syntax, and remarks from structured documentation
Troubleshooting
"Not connected to SolidWorks" Error
Solution: Ensure SolidWorks is installed properly. The server will attempt to start it automatically.
"Could not connect to SolidWorks" on Startup
Solutions:
- Verify SolidWorks 2020 is installed (check COM registration)
- Check that the SolidWorks API DLLs are in the correct location
- Try running Claude Desktop as Administrator
- Ensure SolidWorks license is valid and activated
- Check Windows Event Viewer for COM-related errors
"No active document" Error
Solution: Open or create a document in SolidWorks before performing document-specific operations.
API Documentation Not Found
Solution: Update the documentation path in ApiDocumentationService.cs:
_apiDocsPath = @"YOUR_DOCS_PATH_HERE";
Build Errors Related to SolidWorks Interop DLLs
Solutions:
- Verify DLL paths in
.csprojfile - Check that SolidWorks 2020 is installed (not just viewer)
- Ensure you have access to the
api\redistfolder
Development
Project Structure
SolidWorksMCP/
├── Program.cs # Entry point and DI configuration
├── SolidWorksMCP.csproj # Project file with dependencies
├── Services/
│ ├── ISolidWorksConnection.cs # Connection interface
│ ├── SolidWorksConnection.cs # COM connection implementation
│ ├── IApiDocumentationService.cs # Documentation search interface
│ └── ApiDocumentationService.cs # Documentation search implementation
├── Tools/
│ ├── WorkflowTools.cs # Tier 1: High-level workflow tools
│ ├── DynamicApiTool.cs # Tier 2: Dynamic API execution
│ └── ApiDocumentationTool.cs # Tier 4: Documentation search tools
└── Resources/
└── SolidWorksResources.cs # Tier 3: State inspection resources
Adding New Tools
- Create a new static class in the
Tools/folder - Decorate the class with
[McpServerToolType] - Add static methods decorated with
[McpServerTool] - Use
[Description(...)]attributes for parameter documentation - Inject services like
ISolidWorksConnectionas method parameters
Example:
[McpServerToolType]
public class MyCustomTools
{
[McpServerTool]
[Description("Does something useful")]
public static object MyTool(
ISolidWorksConnection connection,
[Description("A parameter")] string param1)
{
// Implementation
return new { success = true, result = "..." };
}
}
Extending Interface Mappings
To support more interface types in execute_solidworks_api, add mappings in DynamicApiTool.GetInterfaceInstance():
return interfaceName.ToLowerInvariant() switch
{
// ... existing mappings ...
"imynewinterface" => GetMyNewInterface(connection),
_ => null
};
Limitations
- Single Instance: Connects to one running SolidWorks instance
- No Macro Recording: Does not record operations as macros
- Synchronous Execution: Operations block until complete
- COM Limitations: Subject to COM threading and marshaling constraints
- Read-Only COM Objects: Some COM objects cannot be fully serialized in responses
License
This project is provided as-is for use with SolidWorks 2020. Ensure compliance with SolidWorks API licensing terms. Do whateveryh you want with what's provided here, it's all from publicly available documentation.