solidworks-mcp-server 2.0.0
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.
- package/CHANGELOG.md +35 -0
- package/LICENSE +21 -0
- package/README.md +333 -0
- package/dist/cache/manager.d.ts +50 -0
- package/dist/cache/manager.d.ts.map +1 -0
- package/dist/cache/manager.js +127 -0
- package/dist/cache/manager.js.map +1 -0
- package/dist/db/connection.d.ts +48 -0
- package/dist/db/connection.d.ts.map +1 -0
- package/dist/db/connection.js +132 -0
- package/dist/db/connection.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +402 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge/chromadb.d.ts +16 -0
- package/dist/knowledge/chromadb.d.ts.map +1 -0
- package/dist/knowledge/chromadb.js +80 -0
- package/dist/knowledge/chromadb.js.map +1 -0
- package/dist/macro/index.d.ts +6 -0
- package/dist/macro/index.d.ts.map +1 -0
- package/dist/macro/index.js +6 -0
- package/dist/macro/index.js.map +1 -0
- package/dist/macro/recorder.d.ts +72 -0
- package/dist/macro/recorder.d.ts.map +1 -0
- package/dist/macro/recorder.js +228 -0
- package/dist/macro/recorder.js.map +1 -0
- package/dist/macro/types.d.ts +77 -0
- package/dist/macro/types.d.ts.map +1 -0
- package/dist/macro/types.js +5 -0
- package/dist/macro/types.js.map +1 -0
- package/dist/resources/base.d.ts +116 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/base.js +161 -0
- package/dist/resources/base.js.map +1 -0
- package/dist/resources/design-table.d.ts +384 -0
- package/dist/resources/design-table.d.ts.map +1 -0
- package/dist/resources/design-table.js +337 -0
- package/dist/resources/design-table.js.map +1 -0
- package/dist/resources/pdm.d.ts +1277 -0
- package/dist/resources/pdm.d.ts.map +1 -0
- package/dist/resources/pdm.js +358 -0
- package/dist/resources/pdm.js.map +1 -0
- package/dist/resources/registry.d.ts +59 -0
- package/dist/resources/registry.d.ts.map +1 -0
- package/dist/resources/registry.js +88 -0
- package/dist/resources/registry.js.map +1 -0
- package/dist/solidworks/api.d.ts +24 -0
- package/dist/solidworks/api.d.ts.map +1 -0
- package/dist/solidworks/api.js +226 -0
- package/dist/solidworks/api.js.map +1 -0
- package/dist/solidworks/types.d.ts +55 -0
- package/dist/solidworks/types.d.ts.map +1 -0
- package/dist/solidworks/types.js +2 -0
- package/dist/solidworks/types.js.map +1 -0
- package/dist/state/store.d.ts +101 -0
- package/dist/state/store.d.ts.map +1 -0
- package/dist/state/store.js +262 -0
- package/dist/state/store.js.map +1 -0
- package/dist/tools/analysis.d.ts +37 -0
- package/dist/tools/analysis.d.ts.map +1 -0
- package/dist/tools/analysis.js +169 -0
- package/dist/tools/analysis.js.map +1 -0
- package/dist/tools/drawing.d.ts +151 -0
- package/dist/tools/drawing.d.ts.map +1 -0
- package/dist/tools/drawing.js +171 -0
- package/dist/tools/drawing.js.map +1 -0
- package/dist/tools/export.d.ts +97 -0
- package/dist/tools/export.d.ts.map +1 -0
- package/dist/tools/export.js +128 -0
- package/dist/tools/export.js.map +1 -0
- package/dist/tools/modeling.d.ts +9 -0
- package/dist/tools/modeling.d.ts.map +1 -0
- package/dist/tools/modeling.js +120 -0
- package/dist/tools/modeling.js.map +1 -0
- package/dist/tools/vba.d.ts +123 -0
- package/dist/tools/vba.d.ts.map +1 -0
- package/dist/tools/vba.js +158 -0
- package/dist/tools/vba.js.map +1 -0
- package/dist/utils/config.d.ts +18 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +26 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/logger.d.ts +14 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +84 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +76 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2025-01-08
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of SolidWorks MCP Server
|
|
12
|
+
- Full SolidWorks API integration via COM
|
|
13
|
+
- VBA script generation from templates
|
|
14
|
+
- Support for modeling operations (create, modify, dimension control)
|
|
15
|
+
- Drawing automation tools
|
|
16
|
+
- Multi-format export capabilities (STEP, IGES, STL, PDF, DXF, DWG)
|
|
17
|
+
- Analysis tools (mass properties, interference, geometry checks)
|
|
18
|
+
- Batch processing capabilities
|
|
19
|
+
- Automatic Claude Desktop configuration
|
|
20
|
+
- Comprehensive TypeScript implementation
|
|
21
|
+
- Windows-native COM integration via winax
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
- 25+ MCP tools for SolidWorks automation
|
|
25
|
+
- Handlebars-based VBA template system
|
|
26
|
+
- Support for SolidWorks 2021-2025
|
|
27
|
+
- One-command npm installation
|
|
28
|
+
- Auto-configuration of Claude Desktop
|
|
29
|
+
- Type-safe TypeScript architecture
|
|
30
|
+
|
|
31
|
+
### Documentation
|
|
32
|
+
- Comprehensive README with examples
|
|
33
|
+
- Installation guide
|
|
34
|
+
- Contributing guidelines
|
|
35
|
+
- VBA template examples
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ESPO Corporation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
# SolidWorks MCP Server v2.0
|
|
2
|
+
|
|
3
|
+
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with SolidWorks CAD software, providing automated design capabilities, macro recording, design tables with SQL integration, VBA generation, and PDM configuration management.
|
|
4
|
+
|
|
5
|
+
## 🚀 Key Features
|
|
6
|
+
|
|
7
|
+
### Core Capabilities
|
|
8
|
+
- **Full SolidWorks Control** - Open, create, modify, and analyze CAD models
|
|
9
|
+
- **Macro Recording & Playback** - Record operations and generate reusable macros
|
|
10
|
+
- **Design Tables with SQL** - Create parametric designs driven by database data
|
|
11
|
+
- **PDM Integration** - Configure and manage SolidWorks PDM vaults
|
|
12
|
+
- **VBA Script Generation** - Generate VBA scripts from templates with AI assistance
|
|
13
|
+
- **State Management** - Persistent resource states with auto-save
|
|
14
|
+
- **Resource-Based Architecture** - Modular, extensible design pattern
|
|
15
|
+
|
|
16
|
+
### New in v2.0
|
|
17
|
+
- 🎯 **Macro Recording System** - Record actions and export to VBA
|
|
18
|
+
- 📊 **SQL-Driven Design Tables** - Connect to databases for parametric designs
|
|
19
|
+
- 🗄️ **PDM Configuration** - Manage vault operations, workflows, and automation
|
|
20
|
+
- 💾 **State Persistence** - Track and restore resource states
|
|
21
|
+
- 🏗️ **Resource Registry** - Dynamic resource type management
|
|
22
|
+
- 📝 **Enhanced Logging** - Comprehensive operation tracking
|
|
23
|
+
|
|
24
|
+
## 📋 Prerequisites
|
|
25
|
+
|
|
26
|
+
- Windows 10/11
|
|
27
|
+
- SolidWorks 2021-2025 (licensed installation)
|
|
28
|
+
- Node.js 20 or higher
|
|
29
|
+
- Claude Desktop
|
|
30
|
+
- Optional: SQL Server or PostgreSQL for design tables
|
|
31
|
+
- Optional: SolidWorks PDM for vault operations
|
|
32
|
+
|
|
33
|
+
## 🛠️ Installation
|
|
34
|
+
|
|
35
|
+
### 1. Install from npm
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install -g solidworks-mcp-server
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 2. Configure Claude Desktop
|
|
42
|
+
|
|
43
|
+
Add to your Claude Desktop configuration:
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"mcpServers": {
|
|
48
|
+
"solidworks": {
|
|
49
|
+
"command": "npx",
|
|
50
|
+
"args": ["solidworks-mcp-server"],
|
|
51
|
+
"env": {
|
|
52
|
+
"ENABLE_MACRO_RECORDING": "true",
|
|
53
|
+
"ENABLE_PDM": "true",
|
|
54
|
+
"SQL_CONNECTION": "mssql://server:1433/database"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 3. Environment Configuration
|
|
62
|
+
|
|
63
|
+
Create a `.env` file for advanced configuration:
|
|
64
|
+
|
|
65
|
+
```env
|
|
66
|
+
# SolidWorks Configuration
|
|
67
|
+
SOLIDWORKS_PATH=C:/Program Files/SOLIDWORKS Corp/SOLIDWORKS
|
|
68
|
+
SOLIDWORKS_VERSION=2024
|
|
69
|
+
|
|
70
|
+
# Feature Flags
|
|
71
|
+
ENABLE_MACRO_RECORDING=true
|
|
72
|
+
ENABLE_PDM=true
|
|
73
|
+
|
|
74
|
+
# Database Configuration (for Design Tables)
|
|
75
|
+
SQL_CONNECTION=mssql://localhost:1433/solidworks_db
|
|
76
|
+
|
|
77
|
+
# PDM Configuration
|
|
78
|
+
PDM_VAULT=Engineering
|
|
79
|
+
|
|
80
|
+
# State Management
|
|
81
|
+
STATE_FILE=.solidworks-state.json
|
|
82
|
+
|
|
83
|
+
# Logging
|
|
84
|
+
LOG_LEVEL=info
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 🚀 Usage Examples
|
|
88
|
+
|
|
89
|
+
### Macro Recording
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
"Start recording a macro called 'CreateBracket'"
|
|
93
|
+
"Create a sketch on the front plane"
|
|
94
|
+
"Add a rectangle 100mm x 50mm"
|
|
95
|
+
"Extrude 25mm"
|
|
96
|
+
"Stop recording and export to VBA"
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Design Tables with SQL
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
"Create a design table for parametric box configurations from SQL database"
|
|
103
|
+
"Use query: SELECT * FROM box_configurations"
|
|
104
|
+
"Map columns: length, width, height to dimensions"
|
|
105
|
+
"Generate all configurations"
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### PDM Operations
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
"Configure PDM vault 'Engineering' for automatic check-in/check-out"
|
|
112
|
+
"Set up workflow transition from 'Work in Progress' to 'Released'"
|
|
113
|
+
"Create folder structure with permissions for project team"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Advanced VBA Generation
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
"Generate VBA script that:
|
|
120
|
+
1. Opens all parts in folder
|
|
121
|
+
2. Updates material to Aluminum
|
|
122
|
+
3. Runs stress analysis
|
|
123
|
+
4. Exports results to Excel"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## 🔧 Available Tools
|
|
127
|
+
|
|
128
|
+
### Macro Tools
|
|
129
|
+
- `macro_start_recording` - Begin recording operations
|
|
130
|
+
- `macro_stop_recording` - End recording and save
|
|
131
|
+
- `macro_export_vba` - Export macro to VBA code
|
|
132
|
+
- `macro_execute` - Run recorded macro
|
|
133
|
+
|
|
134
|
+
### Design Table Tools
|
|
135
|
+
- `design_table_create` - Create parametric design table
|
|
136
|
+
- `design_table_refresh` - Update from SQL source
|
|
137
|
+
- `design_table_add_config` - Add configuration
|
|
138
|
+
- `design_table_export` - Export configurations
|
|
139
|
+
|
|
140
|
+
### PDM Tools
|
|
141
|
+
- `pdm_configure` - Set up vault configuration
|
|
142
|
+
- `pdm_checkin` - Check in files with comments
|
|
143
|
+
- `pdm_checkout` - Check out for editing
|
|
144
|
+
- `pdm_workflow` - Execute workflow transitions
|
|
145
|
+
- `pdm_create_structure` - Set up folder hierarchy
|
|
146
|
+
|
|
147
|
+
### Resource Management
|
|
148
|
+
- `resource_create` - Create new resource
|
|
149
|
+
- `resource_list` - List all resources
|
|
150
|
+
- `resource_get` - Get resource details
|
|
151
|
+
- `resource_update` - Update resource properties
|
|
152
|
+
- `resource_delete` - Remove resource
|
|
153
|
+
|
|
154
|
+
### Existing Tools
|
|
155
|
+
All original tools remain available:
|
|
156
|
+
- Modeling tools (create, modify, analyze)
|
|
157
|
+
- Drawing tools (views, dimensions, annotations)
|
|
158
|
+
- Export tools (STEP, IGES, STL, PDF, etc.)
|
|
159
|
+
- VBA tools (generate, execute scripts)
|
|
160
|
+
- Analysis tools (mass properties, interference)
|
|
161
|
+
|
|
162
|
+
## 📚 API Reference
|
|
163
|
+
|
|
164
|
+
### Resource Types
|
|
165
|
+
|
|
166
|
+
#### Design Table Resource
|
|
167
|
+
```typescript
|
|
168
|
+
{
|
|
169
|
+
type: 'design-table',
|
|
170
|
+
tableName: string,
|
|
171
|
+
parameters: Array<{
|
|
172
|
+
name: string,
|
|
173
|
+
type: 'dimension' | 'feature' | 'configuration',
|
|
174
|
+
dataType: 'number' | 'string' | 'boolean',
|
|
175
|
+
sqlColumn?: string,
|
|
176
|
+
formula?: string
|
|
177
|
+
}>,
|
|
178
|
+
dataSource?: {
|
|
179
|
+
type: 'sql' | 'file' | 'api',
|
|
180
|
+
connectionString?: string,
|
|
181
|
+
query?: string
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
#### PDM Configuration Resource
|
|
187
|
+
```typescript
|
|
188
|
+
{
|
|
189
|
+
type: 'pdm-configuration',
|
|
190
|
+
vaultName: string,
|
|
191
|
+
operations: {
|
|
192
|
+
checkIn?: { enabled: boolean, comment?: string },
|
|
193
|
+
checkOut?: { enabled: boolean, getLatestVersion?: boolean },
|
|
194
|
+
workflow?: {
|
|
195
|
+
enabled: boolean,
|
|
196
|
+
transitions: Array<{
|
|
197
|
+
name: string,
|
|
198
|
+
fromState: string,
|
|
199
|
+
toState: string
|
|
200
|
+
}>
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## 🧪 Development
|
|
207
|
+
|
|
208
|
+
### Building from Source
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
git clone https://github.com/vinnieespo/solidworks-mcp-server
|
|
212
|
+
cd solidworks-mcp-server
|
|
213
|
+
npm install
|
|
214
|
+
npm run build
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Running Tests
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
npm test # Run all tests
|
|
221
|
+
npm run test:unit # Unit tests only
|
|
222
|
+
npm run test:integration # Integration tests
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Adding Custom Resources
|
|
226
|
+
|
|
227
|
+
Create a new resource type:
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
import { SolidWorksResource } from './resources/base';
|
|
231
|
+
|
|
232
|
+
export class CustomResource extends SolidWorksResource {
|
|
233
|
+
readonly type = 'custom-type';
|
|
234
|
+
|
|
235
|
+
async execute(api: SolidWorksAPI) {
|
|
236
|
+
// Implementation
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
toVBACode(): string {
|
|
240
|
+
// Generate VBA
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Register the resource:
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
resourceRegistry.register({
|
|
249
|
+
type: 'custom-type',
|
|
250
|
+
name: 'Custom Resource',
|
|
251
|
+
schema: CustomSchema,
|
|
252
|
+
factory: (id, name, props) => new CustomResource(id, name, props)
|
|
253
|
+
});
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## 🐛 Troubleshooting
|
|
257
|
+
|
|
258
|
+
### Macro Recording Issues
|
|
259
|
+
- Ensure macro recording is enabled in environment
|
|
260
|
+
- Check that actions are supported for recording
|
|
261
|
+
- Verify VBA export permissions
|
|
262
|
+
|
|
263
|
+
### SQL Connection Problems
|
|
264
|
+
- Verify connection string format
|
|
265
|
+
- Check database permissions
|
|
266
|
+
- Ensure SQL drivers are installed
|
|
267
|
+
|
|
268
|
+
### PDM Integration
|
|
269
|
+
- Confirm PDM client is installed
|
|
270
|
+
- Verify vault access permissions
|
|
271
|
+
- Check network connectivity to PDM server
|
|
272
|
+
|
|
273
|
+
### State Management
|
|
274
|
+
- Check write permissions for state file
|
|
275
|
+
- Clear corrupted state with `resource_clear`
|
|
276
|
+
- Verify auto-save is enabled
|
|
277
|
+
|
|
278
|
+
## 📊 Performance Considerations
|
|
279
|
+
|
|
280
|
+
- **Batch Operations**: Use macro recording for repetitive tasks
|
|
281
|
+
- **SQL Queries**: Optimize queries for large datasets
|
|
282
|
+
- **State Storage**: Periodically clean old states
|
|
283
|
+
- **PDM Operations**: Use batch check-in/check-out
|
|
284
|
+
|
|
285
|
+
## 🔒 Security
|
|
286
|
+
|
|
287
|
+
- SQL connections use secure authentication
|
|
288
|
+
- PDM credentials are not stored in state
|
|
289
|
+
- Macro execution requires explicit permission
|
|
290
|
+
- State files can be encrypted (configure in .env)
|
|
291
|
+
|
|
292
|
+
## 📄 License
|
|
293
|
+
|
|
294
|
+
MIT License - see LICENSE file
|
|
295
|
+
|
|
296
|
+
## 🤝 Contributing
|
|
297
|
+
|
|
298
|
+
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
|
|
299
|
+
|
|
300
|
+
### Areas for Contribution
|
|
301
|
+
- Additional resource types
|
|
302
|
+
- Enhanced SQL integrations
|
|
303
|
+
- More VBA templates
|
|
304
|
+
- PDM workflow automation
|
|
305
|
+
- Testing improvements
|
|
306
|
+
|
|
307
|
+
## 📞 Support
|
|
308
|
+
|
|
309
|
+
- Issues: [GitHub Issues](https://github.com/vinnieespo/solidworks-mcp-server/issues)
|
|
310
|
+
- Discussions: [GitHub Discussions](https://github.com/vinnieespo/solidworks-mcp-server/discussions)
|
|
311
|
+
- Email: support@solidworksmcp.dev
|
|
312
|
+
|
|
313
|
+
## 🚀 Roadmap
|
|
314
|
+
|
|
315
|
+
### v2.1 (Q2 2024)
|
|
316
|
+
- [ ] Real-time collaboration features
|
|
317
|
+
- [ ] Cloud storage integration
|
|
318
|
+
- [ ] Advanced simulation tools
|
|
319
|
+
- [ ] Custom property management
|
|
320
|
+
|
|
321
|
+
### v2.2 (Q3 2024)
|
|
322
|
+
- [ ] AI-powered design suggestions
|
|
323
|
+
- [ ] Automated testing framework
|
|
324
|
+
- [ ] Performance optimization tools
|
|
325
|
+
- [ ] Extended PDM capabilities
|
|
326
|
+
|
|
327
|
+
## 📖 Changelog
|
|
328
|
+
|
|
329
|
+
See [CHANGELOG.md](CHANGELOG.md) for version history.
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
Built with ❤️ for the SolidWorks community
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Manager for SolidWorks MCP Server
|
|
3
|
+
* Provides caching capabilities for resource operations
|
|
4
|
+
*/
|
|
5
|
+
export interface CacheEntry {
|
|
6
|
+
key: string;
|
|
7
|
+
value: any;
|
|
8
|
+
timestamp: number;
|
|
9
|
+
ttl: number;
|
|
10
|
+
hits: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class CacheManager {
|
|
13
|
+
private cache;
|
|
14
|
+
private maxSize;
|
|
15
|
+
private defaultTTL;
|
|
16
|
+
constructor(maxSize?: number, defaultTTL?: number);
|
|
17
|
+
/**
|
|
18
|
+
* Get value from cache
|
|
19
|
+
*/
|
|
20
|
+
get(key: string): any | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Set value in cache
|
|
23
|
+
*/
|
|
24
|
+
set(key: string, value: any, ttl?: number): void;
|
|
25
|
+
/**
|
|
26
|
+
* Delete from cache
|
|
27
|
+
*/
|
|
28
|
+
delete(key: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Clear entire cache
|
|
31
|
+
*/
|
|
32
|
+
clear(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Get cache statistics
|
|
35
|
+
*/
|
|
36
|
+
getStats(): any;
|
|
37
|
+
/**
|
|
38
|
+
* Cleanup expired entries
|
|
39
|
+
*/
|
|
40
|
+
private cleanup;
|
|
41
|
+
/**
|
|
42
|
+
* Evict least recently used entry
|
|
43
|
+
*/
|
|
44
|
+
private evictLRU;
|
|
45
|
+
/**
|
|
46
|
+
* Check if key exists and is valid
|
|
47
|
+
*/
|
|
48
|
+
has(key: string): boolean;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/cache/manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,GAAG,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAsC;IACnD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAS;gBAEf,OAAO,GAAE,MAAa,EAAE,UAAU,GAAE,MAAgB;IAUhE;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS;IAkBjC;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAiBhD;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI5B;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;OAEG;IACH,QAAQ,IAAI,GAAG;IAkBf;;OAEG;IACH,OAAO,CAAC,OAAO;IAgBf;;OAEG;IACH,OAAO,CAAC,QAAQ;IAehB;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;CAe1B"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Manager for SolidWorks MCP Server
|
|
3
|
+
* Provides caching capabilities for resource operations
|
|
4
|
+
*/
|
|
5
|
+
import { logger } from '../utils/logger.js';
|
|
6
|
+
export class CacheManager {
|
|
7
|
+
cache = new Map();
|
|
8
|
+
maxSize;
|
|
9
|
+
defaultTTL;
|
|
10
|
+
constructor(maxSize = 1000, defaultTTL = 3600000) {
|
|
11
|
+
this.maxSize = maxSize;
|
|
12
|
+
this.defaultTTL = defaultTTL;
|
|
13
|
+
// Start cleanup interval
|
|
14
|
+
const cleanupInterval = setInterval(() => this.cleanup(), 60000); // Cleanup every minute
|
|
15
|
+
// Store interval for cleanup (if needed in the future)
|
|
16
|
+
this._cleanupInterval = cleanupInterval;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get value from cache
|
|
20
|
+
*/
|
|
21
|
+
get(key) {
|
|
22
|
+
const entry = this.cache.get(key);
|
|
23
|
+
if (!entry) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
// Check if expired
|
|
27
|
+
if (Date.now() - entry.timestamp > entry.ttl) {
|
|
28
|
+
this.cache.delete(key);
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
// Update hit count
|
|
32
|
+
entry.hits++;
|
|
33
|
+
return entry.value;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Set value in cache
|
|
37
|
+
*/
|
|
38
|
+
set(key, value, ttl) {
|
|
39
|
+
// Check size limit
|
|
40
|
+
if (this.cache.size >= this.maxSize) {
|
|
41
|
+
this.evictLRU();
|
|
42
|
+
}
|
|
43
|
+
this.cache.set(key, {
|
|
44
|
+
key,
|
|
45
|
+
value,
|
|
46
|
+
timestamp: Date.now(),
|
|
47
|
+
ttl: ttl || this.defaultTTL,
|
|
48
|
+
hits: 0
|
|
49
|
+
});
|
|
50
|
+
logger.debug(`Cache set: ${key}`);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Delete from cache
|
|
54
|
+
*/
|
|
55
|
+
delete(key) {
|
|
56
|
+
return this.cache.delete(key);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Clear entire cache
|
|
60
|
+
*/
|
|
61
|
+
clear() {
|
|
62
|
+
this.cache.clear();
|
|
63
|
+
logger.info('Cache cleared');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get cache statistics
|
|
67
|
+
*/
|
|
68
|
+
getStats() {
|
|
69
|
+
const entries = Array.from(this.cache.values());
|
|
70
|
+
const totalHits = entries.reduce((sum, e) => sum + e.hits, 0);
|
|
71
|
+
return {
|
|
72
|
+
size: this.cache.size,
|
|
73
|
+
maxSize: this.maxSize,
|
|
74
|
+
totalHits,
|
|
75
|
+
averageHits: entries.length > 0 ? totalHits / entries.length : 0,
|
|
76
|
+
oldestEntry: entries.reduce((oldest, e) => !oldest || e.timestamp < oldest.timestamp ? e : oldest, null),
|
|
77
|
+
mostUsed: entries.reduce((most, e) => !most || e.hits > most.hits ? e : most, null)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Cleanup expired entries
|
|
82
|
+
*/
|
|
83
|
+
cleanup() {
|
|
84
|
+
const now = Date.now();
|
|
85
|
+
let removed = 0;
|
|
86
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
87
|
+
if (now - entry.timestamp > entry.ttl) {
|
|
88
|
+
this.cache.delete(key);
|
|
89
|
+
removed++;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (removed > 0) {
|
|
93
|
+
logger.debug(`Cache cleanup: removed ${removed} expired entries`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Evict least recently used entry
|
|
98
|
+
*/
|
|
99
|
+
evictLRU() {
|
|
100
|
+
let lru = null;
|
|
101
|
+
for (const entry of this.cache.values()) {
|
|
102
|
+
if (!lru || entry.timestamp < lru.timestamp) {
|
|
103
|
+
lru = entry;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (lru) {
|
|
107
|
+
this.cache.delete(lru.key);
|
|
108
|
+
logger.debug(`Cache evicted LRU: ${lru.key}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Check if key exists and is valid
|
|
113
|
+
*/
|
|
114
|
+
has(key) {
|
|
115
|
+
const entry = this.cache.get(key);
|
|
116
|
+
if (!entry) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
// Check if expired
|
|
120
|
+
if (Date.now() - entry.timestamp > entry.ttl) {
|
|
121
|
+
this.cache.delete(key);
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/cache/manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAU5C,MAAM,OAAO,YAAY;IACf,KAAK,GAA4B,IAAI,GAAG,EAAE,CAAC;IAC3C,OAAO,CAAS;IAChB,UAAU,CAAS;IAE3B,YAAY,UAAkB,IAAI,EAAE,aAAqB,OAAO;QAC9D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAE7B,yBAAyB;QACzB,MAAM,eAAe,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,uBAAuB;QACzF,uDAAuD;QACtD,IAAY,CAAC,gBAAgB,GAAG,eAAe,CAAC;IACnD,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,GAAW;QACb,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,mBAAmB;QACnB,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;YAC7C,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACvB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,mBAAmB;QACnB,KAAK,CAAC,IAAI,EAAE,CAAC;QACb,OAAO,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,GAAW,EAAE,KAAU,EAAE,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K,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC3B,MAAM,CAAC,KAAK,CAAC,sBAAsB,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,GAAW;QACb,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,KAAK,CAAC;QACf,CAAC;QAED,mBAAmB;QACnB,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;YAC7C,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACvB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database Connection Manager for Design Tables
|
|
3
|
+
* Supports SQL Server and PostgreSQL
|
|
4
|
+
*/
|
|
5
|
+
export interface DBConnection {
|
|
6
|
+
query(sql: string, params?: any[]): Promise<any[]>;
|
|
7
|
+
close(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare class PostgreSQLConnection implements DBConnection {
|
|
10
|
+
private client;
|
|
11
|
+
constructor(connectionString: string);
|
|
12
|
+
connect(): Promise<void>;
|
|
13
|
+
query(sql: string, params?: any[]): Promise<any[]>;
|
|
14
|
+
close(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export declare class SQLServerConnection implements DBConnection {
|
|
17
|
+
private pool;
|
|
18
|
+
private config;
|
|
19
|
+
constructor(connectionString: string);
|
|
20
|
+
connect(): Promise<void>;
|
|
21
|
+
query(sql: string, params?: any[]): Promise<any[]>;
|
|
22
|
+
close(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare class DatabaseManager {
|
|
25
|
+
private connections;
|
|
26
|
+
/**
|
|
27
|
+
* Create a database connection
|
|
28
|
+
*/
|
|
29
|
+
createConnection(name: string, connectionString: string): Promise<DBConnection>;
|
|
30
|
+
/**
|
|
31
|
+
* Get an existing connection
|
|
32
|
+
*/
|
|
33
|
+
getConnection(name: string): DBConnection | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Close a connection
|
|
36
|
+
*/
|
|
37
|
+
closeConnection(name: string): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Close all connections
|
|
40
|
+
*/
|
|
41
|
+
closeAll(): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Execute a query on a named connection
|
|
44
|
+
*/
|
|
45
|
+
query(connectionName: string, sql: string, params?: any[]): Promise<any[]>;
|
|
46
|
+
}
|
|
47
|
+
export declare const dbManager: DatabaseManager;
|
|
48
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/db/connection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,MAAM,WAAW,YAAY;IAE3B,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACnD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,qBAAa,oBAAqB,YAAW,YAAY;IACvD,OAAO,CAAC,MAAM,CAAY;gBAEd,gBAAgB,EAAE,MAAM;IAI9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAKxB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAKlD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAI7B;AAED,qBAAa,mBAAoB,YAAW,YAAY;IACtD,OAAO,CAAC,IAAI,CAAqC;IAC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