solidworks-mcp 0.1.1-beta.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/README.md +34 -0
- package/bin/solidworks-mcp-server.js +2 -0
- package/dist/bootstrap/bridge-bootstrap.d.ts +25 -0
- package/dist/bootstrap/bridge-bootstrap.d.ts.map +1 -0
- package/dist/bootstrap/bridge-bootstrap.js +175 -0
- package/dist/bootstrap/bridge-bootstrap.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +277 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/assembly-tools.d.ts +73 -0
- package/dist/tools/assembly-tools.d.ts.map +1 -0
- package/dist/tools/assembly-tools.js +92 -0
- package/dist/tools/assembly-tools.js.map +1 -0
- package/dist/tools/document-tools.d.ts +59 -0
- package/dist/tools/document-tools.d.ts.map +1 -0
- package/dist/tools/document-tools.js +82 -0
- package/dist/tools/document-tools.js.map +1 -0
- package/dist/tools/feature-tools.d.ts +83 -0
- package/dist/tools/feature-tools.d.ts.map +1 -0
- package/dist/tools/feature-tools.js +106 -0
- package/dist/tools/feature-tools.js.map +1 -0
- package/dist/tools/selection-tools.d.ts +58 -0
- package/dist/tools/selection-tools.d.ts.map +1 -0
- package/dist/tools/selection-tools.js +69 -0
- package/dist/tools/selection-tools.js.map +1 -0
- package/dist/tools/sketch-tools.d.ts +156 -0
- package/dist/tools/sketch-tools.d.ts.map +1 -0
- package/dist/tools/sketch-tools.js +123 -0
- package/dist/tools/sketch-tools.js.map +1 -0
- package/dist/transport/named-pipe-client.d.ts +53 -0
- package/dist/transport/named-pipe-client.d.ts.map +1 -0
- package/dist/transport/named-pipe-client.js +189 -0
- package/dist/transport/named-pipe-client.js.map +1 -0
- package/dist/types/solidworks.d.ts +60 -0
- package/dist/types/solidworks.d.ts.map +1 -0
- package/dist/types/solidworks.js +79 -0
- package/dist/types/solidworks.js.map +1 -0
- package/package.json +56 -0
- package/vendor/bridge/SolidWorks.Interop.sldworks.dll +0 -0
- package/vendor/bridge/SolidWorks.Interop.swconst.dll +0 -0
- package/vendor/bridge/SolidWorksBridge.deps.json +63 -0
- package/vendor/bridge/SolidWorksBridge.dll +0 -0
- package/vendor/bridge/SolidWorksBridge.exe +0 -0
- package/vendor/bridge/SolidWorksBridge.pdb +0 -0
- package/vendor/bridge/SolidWorksBridge.runtimeconfig.json +13 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { NamedPipeClient } from '../transport/named-pipe-client.js';
|
|
3
|
+
export interface SwSketchEntityInfo {
|
|
4
|
+
type: string;
|
|
5
|
+
id: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const InsertSketchSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
8
|
+
export declare const FinishSketchSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
9
|
+
export declare const AddPointSchema: z.ZodObject<{
|
|
10
|
+
x: z.ZodNumber;
|
|
11
|
+
y: z.ZodNumber;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
}, {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const AddEllipseSchema: z.ZodObject<{
|
|
20
|
+
cx: z.ZodNumber;
|
|
21
|
+
cy: z.ZodNumber;
|
|
22
|
+
majorX: z.ZodNumber;
|
|
23
|
+
majorY: z.ZodNumber;
|
|
24
|
+
minorX: z.ZodNumber;
|
|
25
|
+
minorY: z.ZodNumber;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
cx: number;
|
|
28
|
+
cy: number;
|
|
29
|
+
majorX: number;
|
|
30
|
+
majorY: number;
|
|
31
|
+
minorX: number;
|
|
32
|
+
minorY: number;
|
|
33
|
+
}, {
|
|
34
|
+
cx: number;
|
|
35
|
+
cy: number;
|
|
36
|
+
majorX: number;
|
|
37
|
+
majorY: number;
|
|
38
|
+
minorX: number;
|
|
39
|
+
minorY: number;
|
|
40
|
+
}>;
|
|
41
|
+
export declare const AddPolygonSchema: z.ZodObject<{
|
|
42
|
+
cx: z.ZodNumber;
|
|
43
|
+
cy: z.ZodNumber;
|
|
44
|
+
x: z.ZodNumber;
|
|
45
|
+
y: z.ZodNumber;
|
|
46
|
+
sides: z.ZodNumber;
|
|
47
|
+
inscribed: z.ZodDefault<z.ZodBoolean>;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
49
|
+
x: number;
|
|
50
|
+
y: number;
|
|
51
|
+
cx: number;
|
|
52
|
+
cy: number;
|
|
53
|
+
sides: number;
|
|
54
|
+
inscribed: boolean;
|
|
55
|
+
}, {
|
|
56
|
+
x: number;
|
|
57
|
+
y: number;
|
|
58
|
+
cx: number;
|
|
59
|
+
cy: number;
|
|
60
|
+
sides: number;
|
|
61
|
+
inscribed?: boolean | undefined;
|
|
62
|
+
}>;
|
|
63
|
+
export declare const AddTextSchema: z.ZodObject<{
|
|
64
|
+
x: z.ZodNumber;
|
|
65
|
+
y: z.ZodNumber;
|
|
66
|
+
text: z.ZodString;
|
|
67
|
+
}, "strip", z.ZodTypeAny, {
|
|
68
|
+
x: number;
|
|
69
|
+
y: number;
|
|
70
|
+
text: string;
|
|
71
|
+
}, {
|
|
72
|
+
x: number;
|
|
73
|
+
y: number;
|
|
74
|
+
text: string;
|
|
75
|
+
}>;
|
|
76
|
+
export declare const AddLineSchema: z.ZodObject<{
|
|
77
|
+
x1: z.ZodNumber;
|
|
78
|
+
y1: z.ZodNumber;
|
|
79
|
+
x2: z.ZodNumber;
|
|
80
|
+
y2: z.ZodNumber;
|
|
81
|
+
}, "strip", z.ZodTypeAny, {
|
|
82
|
+
x1: number;
|
|
83
|
+
y1: number;
|
|
84
|
+
x2: number;
|
|
85
|
+
y2: number;
|
|
86
|
+
}, {
|
|
87
|
+
x1: number;
|
|
88
|
+
y1: number;
|
|
89
|
+
x2: number;
|
|
90
|
+
y2: number;
|
|
91
|
+
}>;
|
|
92
|
+
export declare const AddCircleSchema: z.ZodObject<{
|
|
93
|
+
cx: z.ZodNumber;
|
|
94
|
+
cy: z.ZodNumber;
|
|
95
|
+
radius: z.ZodNumber;
|
|
96
|
+
}, "strip", z.ZodTypeAny, {
|
|
97
|
+
cx: number;
|
|
98
|
+
cy: number;
|
|
99
|
+
radius: number;
|
|
100
|
+
}, {
|
|
101
|
+
cx: number;
|
|
102
|
+
cy: number;
|
|
103
|
+
radius: number;
|
|
104
|
+
}>;
|
|
105
|
+
export declare const AddRectangleSchema: z.ZodObject<{
|
|
106
|
+
x1: z.ZodNumber;
|
|
107
|
+
y1: z.ZodNumber;
|
|
108
|
+
x2: z.ZodNumber;
|
|
109
|
+
y2: z.ZodNumber;
|
|
110
|
+
}, "strip", z.ZodTypeAny, {
|
|
111
|
+
x1: number;
|
|
112
|
+
y1: number;
|
|
113
|
+
x2: number;
|
|
114
|
+
y2: number;
|
|
115
|
+
}, {
|
|
116
|
+
x1: number;
|
|
117
|
+
y1: number;
|
|
118
|
+
x2: number;
|
|
119
|
+
y2: number;
|
|
120
|
+
}>;
|
|
121
|
+
export declare const AddArcSchema: z.ZodObject<{
|
|
122
|
+
cx: z.ZodNumber;
|
|
123
|
+
cy: z.ZodNumber;
|
|
124
|
+
x1: z.ZodNumber;
|
|
125
|
+
y1: z.ZodNumber;
|
|
126
|
+
x2: z.ZodNumber;
|
|
127
|
+
y2: z.ZodNumber;
|
|
128
|
+
direction: z.ZodEffects<z.ZodNumber, 1 | -1, number>;
|
|
129
|
+
}, "strip", z.ZodTypeAny, {
|
|
130
|
+
cx: number;
|
|
131
|
+
cy: number;
|
|
132
|
+
x1: number;
|
|
133
|
+
y1: number;
|
|
134
|
+
x2: number;
|
|
135
|
+
y2: number;
|
|
136
|
+
direction: 1 | -1;
|
|
137
|
+
}, {
|
|
138
|
+
cx: number;
|
|
139
|
+
cy: number;
|
|
140
|
+
x1: number;
|
|
141
|
+
y1: number;
|
|
142
|
+
x2: number;
|
|
143
|
+
y2: number;
|
|
144
|
+
direction: number;
|
|
145
|
+
}>;
|
|
146
|
+
export declare function swInsertSketch(client: NamedPipeClient): Promise<void>;
|
|
147
|
+
export declare function swFinishSketch(client: NamedPipeClient): Promise<void>;
|
|
148
|
+
export declare function swAddPoint(client: NamedPipeClient, params: z.infer<typeof AddPointSchema>): Promise<SwSketchEntityInfo>;
|
|
149
|
+
export declare function swAddEllipse(client: NamedPipeClient, params: z.infer<typeof AddEllipseSchema>): Promise<SwSketchEntityInfo>;
|
|
150
|
+
export declare function swAddPolygon(client: NamedPipeClient, params: z.infer<typeof AddPolygonSchema>): Promise<SwSketchEntityInfo>;
|
|
151
|
+
export declare function swAddText(client: NamedPipeClient, params: z.infer<typeof AddTextSchema>): Promise<SwSketchEntityInfo>;
|
|
152
|
+
export declare function swAddLine(client: NamedPipeClient, params: z.infer<typeof AddLineSchema>): Promise<SwSketchEntityInfo>;
|
|
153
|
+
export declare function swAddCircle(client: NamedPipeClient, params: z.infer<typeof AddCircleSchema>): Promise<SwSketchEntityInfo>;
|
|
154
|
+
export declare function swAddRectangle(client: NamedPipeClient, params: z.infer<typeof AddRectangleSchema>): Promise<SwSketchEntityInfo>;
|
|
155
|
+
export declare function swAddArc(client: NamedPipeClient, params: z.infer<typeof AddArcSchema>): Promise<SwSketchEntityInfo>;
|
|
156
|
+
//# sourceMappingURL=sketch-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sketch-tools.d.ts","sourceRoot":"","sources":["../../src/tools/sketch-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAIzE,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAA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aAAa,CAAC,GACpC,OAAO,CAAC,kBAAkB,CAAC,CAI7B;AAED,wBAAsB,SAAS,CAC7B,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,GACpC,OAAO,CAAC,kBAAkB,CAAC,CAI7B;AAED,wBAAsB,WAAW,CAC/B,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,GACtC,OAAO,CAAC,kBAAkB,CAAC,CAI7B;AAED,wBAAsB,cAAc,CAClC,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,GACzC,OAAO,CAAC,kBAAkB,CAAC,CAI7B;AAED,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,GACnC,OAAO,CAAC,kBAAkB,CAAC,CAI7B"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// ── Zod input schemas ───────────────────────────────────────────
|
|
3
|
+
export const InsertSketchSchema = z
|
|
4
|
+
.object({})
|
|
5
|
+
.describe('Open a new sketch on the currently selected plane or face');
|
|
6
|
+
export const FinishSketchSchema = z
|
|
7
|
+
.object({})
|
|
8
|
+
.describe('Close (finish) the currently open sketch');
|
|
9
|
+
export const AddPointSchema = z.object({
|
|
10
|
+
x: z.number().describe('Point X coordinate (meters)'),
|
|
11
|
+
y: z.number().describe('Point Y coordinate (meters)'),
|
|
12
|
+
});
|
|
13
|
+
export const AddEllipseSchema = z.object({
|
|
14
|
+
cx: z.number().describe('Ellipse center X coordinate (meters)'),
|
|
15
|
+
cy: z.number().describe('Ellipse center Y coordinate (meters)'),
|
|
16
|
+
majorX: z.number().describe('Major-axis point X coordinate (meters)'),
|
|
17
|
+
majorY: z.number().describe('Major-axis point Y coordinate (meters)'),
|
|
18
|
+
minorX: z.number().describe('Minor-axis point X coordinate (meters)'),
|
|
19
|
+
minorY: z.number().describe('Minor-axis point Y coordinate (meters)'),
|
|
20
|
+
});
|
|
21
|
+
export const AddPolygonSchema = z.object({
|
|
22
|
+
cx: z.number().describe('Polygon center X coordinate (meters)'),
|
|
23
|
+
cy: z.number().describe('Polygon center Y coordinate (meters)'),
|
|
24
|
+
x: z.number().describe('A point on the polygon perimeter X coordinate (meters)'),
|
|
25
|
+
y: z.number().describe('A point on the polygon perimeter Y coordinate (meters)'),
|
|
26
|
+
sides: z.number().int().min(3).describe('Number of polygon sides'),
|
|
27
|
+
inscribed: z.boolean().default(true).describe('True for inscribed polygon, false for circumscribed polygon'),
|
|
28
|
+
});
|
|
29
|
+
export const AddTextSchema = z.object({
|
|
30
|
+
x: z.number().describe('Text anchor X coordinate (meters)'),
|
|
31
|
+
y: z.number().describe('Text anchor Y coordinate (meters)'),
|
|
32
|
+
text: z.string().min(1).describe('Sketch text content'),
|
|
33
|
+
});
|
|
34
|
+
export const AddLineSchema = z.object({
|
|
35
|
+
x1: z.number().describe('Start X coordinate (meters)'),
|
|
36
|
+
y1: z.number().describe('Start Y coordinate (meters)'),
|
|
37
|
+
x2: z.number().describe('End X coordinate (meters)'),
|
|
38
|
+
y2: z.number().describe('End Y coordinate (meters)'),
|
|
39
|
+
});
|
|
40
|
+
export const AddCircleSchema = z.object({
|
|
41
|
+
cx: z.number().describe('Center X coordinate (meters)'),
|
|
42
|
+
cy: z.number().describe('Center Y coordinate (meters)'),
|
|
43
|
+
radius: z.number().positive().describe('Circle radius (meters)'),
|
|
44
|
+
});
|
|
45
|
+
export const AddRectangleSchema = z.object({
|
|
46
|
+
x1: z.number().describe('First corner X coordinate (meters)'),
|
|
47
|
+
y1: z.number().describe('First corner Y coordinate (meters)'),
|
|
48
|
+
x2: z.number().describe('Opposite corner X coordinate (meters)'),
|
|
49
|
+
y2: z.number().describe('Opposite corner Y coordinate (meters)'),
|
|
50
|
+
});
|
|
51
|
+
export const AddArcSchema = z.object({
|
|
52
|
+
cx: z.number().describe('Center X coordinate (meters)'),
|
|
53
|
+
cy: z.number().describe('Center Y coordinate (meters)'),
|
|
54
|
+
x1: z.number().describe('Start point X coordinate (meters)'),
|
|
55
|
+
y1: z.number().describe('Start point Y coordinate (meters)'),
|
|
56
|
+
x2: z.number().describe('End point X coordinate (meters)'),
|
|
57
|
+
y2: z.number().describe('End point Y coordinate (meters)'),
|
|
58
|
+
direction: z
|
|
59
|
+
.number()
|
|
60
|
+
.int()
|
|
61
|
+
.refine((v) => v === 1 || v === -1, { message: 'direction must be 1 (CCW) or -1 (CW)' })
|
|
62
|
+
.describe('Arc direction: 1 = counter-clockwise, -1 = clockwise'),
|
|
63
|
+
});
|
|
64
|
+
// ── Tool handler functions ──────────────────────────────────────
|
|
65
|
+
export async function swInsertSketch(client) {
|
|
66
|
+
const resp = await client.request('sw.sketch.insert');
|
|
67
|
+
if (resp.error)
|
|
68
|
+
throw new Error(`sw.sketch.insert failed: ${resp.error.message}`);
|
|
69
|
+
}
|
|
70
|
+
export async function swFinishSketch(client) {
|
|
71
|
+
const resp = await client.request('sw.sketch.finish');
|
|
72
|
+
if (resp.error)
|
|
73
|
+
throw new Error(`sw.sketch.finish failed: ${resp.error.message}`);
|
|
74
|
+
}
|
|
75
|
+
export async function swAddPoint(client, params) {
|
|
76
|
+
const resp = await client.request('sw.sketch.add_point', params);
|
|
77
|
+
if (resp.error)
|
|
78
|
+
throw new Error(`sw.sketch.add_point failed: ${resp.error.message}`);
|
|
79
|
+
return resp.result;
|
|
80
|
+
}
|
|
81
|
+
export async function swAddEllipse(client, params) {
|
|
82
|
+
const resp = await client.request('sw.sketch.add_ellipse', params);
|
|
83
|
+
if (resp.error)
|
|
84
|
+
throw new Error(`sw.sketch.add_ellipse failed: ${resp.error.message}`);
|
|
85
|
+
return resp.result;
|
|
86
|
+
}
|
|
87
|
+
export async function swAddPolygon(client, params) {
|
|
88
|
+
const resp = await client.request('sw.sketch.add_polygon', params);
|
|
89
|
+
if (resp.error)
|
|
90
|
+
throw new Error(`sw.sketch.add_polygon failed: ${resp.error.message}`);
|
|
91
|
+
return resp.result;
|
|
92
|
+
}
|
|
93
|
+
export async function swAddText(client, params) {
|
|
94
|
+
const resp = await client.request('sw.sketch.add_text', params);
|
|
95
|
+
if (resp.error)
|
|
96
|
+
throw new Error(`sw.sketch.add_text failed: ${resp.error.message}`);
|
|
97
|
+
return resp.result;
|
|
98
|
+
}
|
|
99
|
+
export async function swAddLine(client, params) {
|
|
100
|
+
const resp = await client.request('sw.sketch.add_line', params);
|
|
101
|
+
if (resp.error)
|
|
102
|
+
throw new Error(`sw.sketch.add_line failed: ${resp.error.message}`);
|
|
103
|
+
return resp.result;
|
|
104
|
+
}
|
|
105
|
+
export async function swAddCircle(client, params) {
|
|
106
|
+
const resp = await client.request('sw.sketch.add_circle', params);
|
|
107
|
+
if (resp.error)
|
|
108
|
+
throw new Error(`sw.sketch.add_circle failed: ${resp.error.message}`);
|
|
109
|
+
return resp.result;
|
|
110
|
+
}
|
|
111
|
+
export async function swAddRectangle(client, params) {
|
|
112
|
+
const resp = await client.request('sw.sketch.add_rectangle', params);
|
|
113
|
+
if (resp.error)
|
|
114
|
+
throw new Error(`sw.sketch.add_rectangle failed: ${resp.error.message}`);
|
|
115
|
+
return resp.result;
|
|
116
|
+
}
|
|
117
|
+
export async function swAddArc(client, params) {
|
|
118
|
+
const resp = await client.request('sw.sketch.add_arc', params);
|
|
119
|
+
if (resp.error)
|
|
120
|
+
throw new Error(`sw.sketch.add_arc failed: ${resp.error.message}`);
|
|
121
|
+
return resp.result;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=sketch-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sketch-tools.js","sourceRoot":"","sources":["../../src/tools/sketch-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUx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AK,CAAC,OAAO,EAAE,CAAC,CAAC;IACtF,OAAO,IAAI,CAAC,MAA4B,CAAC;AAC3C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAAuB,EACvB,MAA0C;IAE1C,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,yBAAyB,EAAE,MAAM,CAAC,CAAC;IACrE,IAAI,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACzF,OAAO,IAAI,CAAC,MAA4B,CAAC;AAC3C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,MAAuB,EACvB,MAAoC;IAEpC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;IAC/D,IAAI,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACnF,OAAO,IAAI,CAAC,MAA4B,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { PipeResponse } from '../types/solidworks.js';
|
|
2
|
+
export interface NamedPipeClientOptions {
|
|
3
|
+
pipeName?: string;
|
|
4
|
+
connectTimeout?: number;
|
|
5
|
+
requestTimeout?: number;
|
|
6
|
+
reconnect?: boolean;
|
|
7
|
+
reconnectDelay?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Named Pipe client for communicating with the C# SolidWorks Bridge.
|
|
11
|
+
* Protocol: [4-byte LE length prefix][UTF-8 JSON body]
|
|
12
|
+
* Supports request-response correlation via message IDs.
|
|
13
|
+
*/
|
|
14
|
+
export declare class NamedPipeClient {
|
|
15
|
+
private socket;
|
|
16
|
+
private readonly options;
|
|
17
|
+
private readonly pending;
|
|
18
|
+
private receiveBuffer;
|
|
19
|
+
private _connected;
|
|
20
|
+
private _connecting;
|
|
21
|
+
constructor(options?: NamedPipeClientOptions);
|
|
22
|
+
get connected(): boolean;
|
|
23
|
+
get pipePath(): string;
|
|
24
|
+
/**
|
|
25
|
+
* Connect to the Named Pipe server.
|
|
26
|
+
*/
|
|
27
|
+
connect(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Send a request and wait for the correlated response.
|
|
30
|
+
*/
|
|
31
|
+
request(method: string, params?: Record<string, unknown>): Promise<PipeResponse>;
|
|
32
|
+
/**
|
|
33
|
+
* Disconnect from the pipe server.
|
|
34
|
+
*/
|
|
35
|
+
disconnect(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Write a length-prefixed JSON message to the pipe.
|
|
38
|
+
*/
|
|
39
|
+
private writeMessage;
|
|
40
|
+
/**
|
|
41
|
+
* Handle incoming data: buffer and extract complete messages.
|
|
42
|
+
*/
|
|
43
|
+
private onData;
|
|
44
|
+
/**
|
|
45
|
+
* Match a response to its pending request by ID.
|
|
46
|
+
*/
|
|
47
|
+
private resolveResponse;
|
|
48
|
+
/**
|
|
49
|
+
* Handle pipe disconnection.
|
|
50
|
+
*/
|
|
51
|
+
private handleDisconnect;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=named-pipe-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"named-pipe-client.d.ts","sourceRoot":"","sources":["../../src/transport/named-pipe-client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAe,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGxE,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAUD;;;;GAIG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmC;IAC3D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAInB;IACL,OAAO,CAAC,aAAa,CAAmB;IACxC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAS;gBAEhB,OAAO,GAAE,sBAA2B;IAIhD,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAqC9B;;OAEG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC;IA0BtF;;OAEG;IACH,UAAU,IAAI,IAAI;IAoBlB;;OAEG;IACH,OAAO,CAAC,YAAY;IAUpB;;OAEG;IACH,OAAO,CAAC,MAAM;IAgCd;;OAEG;IACH,OAAO,CAAC,eAAe;IASvB;;OAEG;IACH,OAAO,CAAC,gBAAgB;CA2BzB"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import * as net from 'node:net';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { isPipeResponse } from '../types/solidworks.js';
|
|
4
|
+
const DEFAULT_OPTIONS = {
|
|
5
|
+
pipeName: 'SolidWorksMcpBridge',
|
|
6
|
+
connectTimeout: 10000,
|
|
7
|
+
requestTimeout: 30000,
|
|
8
|
+
reconnect: true,
|
|
9
|
+
reconnectDelay: 2000,
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Named Pipe client for communicating with the C# SolidWorks Bridge.
|
|
13
|
+
* Protocol: [4-byte LE length prefix][UTF-8 JSON body]
|
|
14
|
+
* Supports request-response correlation via message IDs.
|
|
15
|
+
*/
|
|
16
|
+
export class NamedPipeClient {
|
|
17
|
+
socket = null;
|
|
18
|
+
options;
|
|
19
|
+
pending = new Map();
|
|
20
|
+
receiveBuffer = Buffer.alloc(0);
|
|
21
|
+
_connected = false;
|
|
22
|
+
_connecting = false;
|
|
23
|
+
constructor(options = {}) {
|
|
24
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
25
|
+
}
|
|
26
|
+
get connected() {
|
|
27
|
+
return this._connected;
|
|
28
|
+
}
|
|
29
|
+
get pipePath() {
|
|
30
|
+
return `\\\\.\\pipe\\${this.options.pipeName}`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Connect to the Named Pipe server.
|
|
34
|
+
*/
|
|
35
|
+
async connect() {
|
|
36
|
+
if (this._connected)
|
|
37
|
+
return;
|
|
38
|
+
if (this._connecting)
|
|
39
|
+
return;
|
|
40
|
+
this._connecting = true;
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const timer = setTimeout(() => {
|
|
43
|
+
this.socket?.destroy();
|
|
44
|
+
this._connecting = false;
|
|
45
|
+
reject(new Error(`Connection timeout after ${this.options.connectTimeout}ms`));
|
|
46
|
+
}, this.options.connectTimeout);
|
|
47
|
+
this.socket = net.connect(this.pipePath, () => {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
this._connected = true;
|
|
50
|
+
this._connecting = false;
|
|
51
|
+
resolve();
|
|
52
|
+
});
|
|
53
|
+
this.socket.on('data', (data) => this.onData(data));
|
|
54
|
+
this.socket.on('error', (err) => {
|
|
55
|
+
clearTimeout(timer);
|
|
56
|
+
if (this._connecting) {
|
|
57
|
+
this._connecting = false;
|
|
58
|
+
reject(err);
|
|
59
|
+
}
|
|
60
|
+
this.handleDisconnect(err);
|
|
61
|
+
});
|
|
62
|
+
this.socket.on('close', () => {
|
|
63
|
+
this.handleDisconnect(new Error('Pipe closed'));
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Send a request and wait for the correlated response.
|
|
69
|
+
*/
|
|
70
|
+
async request(method, params) {
|
|
71
|
+
if (!this._connected || !this.socket) {
|
|
72
|
+
throw new Error('Not connected to pipe server');
|
|
73
|
+
}
|
|
74
|
+
const id = randomUUID();
|
|
75
|
+
const req = { id, method, params };
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
const timer = setTimeout(() => {
|
|
78
|
+
this.pending.delete(id);
|
|
79
|
+
reject(new Error(`Request timeout after ${this.options.requestTimeout}ms for method: ${method}`));
|
|
80
|
+
}, this.options.requestTimeout);
|
|
81
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
82
|
+
try {
|
|
83
|
+
this.writeMessage(req);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
this.pending.delete(id);
|
|
88
|
+
reject(err);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Disconnect from the pipe server.
|
|
94
|
+
*/
|
|
95
|
+
disconnect() {
|
|
96
|
+
this._connected = false;
|
|
97
|
+
this._connecting = false;
|
|
98
|
+
// Reject all pending requests
|
|
99
|
+
for (const [id, entry] of this.pending) {
|
|
100
|
+
clearTimeout(entry.timer);
|
|
101
|
+
entry.reject(new Error('Client disconnected'));
|
|
102
|
+
this.pending.delete(id);
|
|
103
|
+
}
|
|
104
|
+
if (this.socket) {
|
|
105
|
+
this.socket.removeAllListeners();
|
|
106
|
+
this.socket.destroy();
|
|
107
|
+
this.socket = null;
|
|
108
|
+
}
|
|
109
|
+
this.receiveBuffer = Buffer.alloc(0);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Write a length-prefixed JSON message to the pipe.
|
|
113
|
+
*/
|
|
114
|
+
writeMessage(msg) {
|
|
115
|
+
const bodyStr = JSON.stringify(msg);
|
|
116
|
+
const bodyBuf = Buffer.from(bodyStr, 'utf-8');
|
|
117
|
+
const lengthBuf = Buffer.alloc(4);
|
|
118
|
+
lengthBuf.writeInt32LE(bodyBuf.length, 0);
|
|
119
|
+
this.socket.write(lengthBuf);
|
|
120
|
+
this.socket.write(bodyBuf);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Handle incoming data: buffer and extract complete messages.
|
|
124
|
+
*/
|
|
125
|
+
onData(data) {
|
|
126
|
+
this.receiveBuffer = Buffer.concat([this.receiveBuffer, data]);
|
|
127
|
+
while (this.receiveBuffer.length >= 4) {
|
|
128
|
+
const msgLength = this.receiveBuffer.readInt32LE(0);
|
|
129
|
+
if (msgLength <= 0 || msgLength > 10 * 1024 * 1024) {
|
|
130
|
+
// Invalid message, clear buffer
|
|
131
|
+
this.receiveBuffer = Buffer.alloc(0);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (this.receiveBuffer.length < 4 + msgLength) {
|
|
135
|
+
break; // Wait for more data
|
|
136
|
+
}
|
|
137
|
+
const bodyBytes = this.receiveBuffer.subarray(4, 4 + msgLength);
|
|
138
|
+
this.receiveBuffer = this.receiveBuffer.subarray(4 + msgLength);
|
|
139
|
+
try {
|
|
140
|
+
const json = bodyBytes.toString('utf-8');
|
|
141
|
+
const response = JSON.parse(json);
|
|
142
|
+
if (isPipeResponse(response)) {
|
|
143
|
+
this.resolveResponse(response);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
// Malformed message, skip
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Match a response to its pending request by ID.
|
|
153
|
+
*/
|
|
154
|
+
resolveResponse(response) {
|
|
155
|
+
const entry = this.pending.get(response.id);
|
|
156
|
+
if (entry) {
|
|
157
|
+
clearTimeout(entry.timer);
|
|
158
|
+
this.pending.delete(response.id);
|
|
159
|
+
entry.resolve(response);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Handle pipe disconnection.
|
|
164
|
+
*/
|
|
165
|
+
handleDisconnect(err) {
|
|
166
|
+
const wasConnected = this._connected;
|
|
167
|
+
this._connected = false;
|
|
168
|
+
// Reject all pending
|
|
169
|
+
for (const [id, entry] of this.pending) {
|
|
170
|
+
clearTimeout(entry.timer);
|
|
171
|
+
entry.reject(new Error(`Pipe disconnected: ${err.message}`));
|
|
172
|
+
this.pending.delete(id);
|
|
173
|
+
}
|
|
174
|
+
if (this.socket) {
|
|
175
|
+
this.socket.removeAllListeners();
|
|
176
|
+
this.socket.destroy();
|
|
177
|
+
this.socket = null;
|
|
178
|
+
}
|
|
179
|
+
this.receiveBuffer = Buffer.alloc(0);
|
|
180
|
+
if (wasConnected && this.options.reconnect) {
|
|
181
|
+
setTimeout(() => {
|
|
182
|
+
this.connect().catch(() => {
|
|
183
|
+
// Reconnect failed silently; will retry on next request
|
|
184
|
+
});
|
|
185
|
+
}, this.options.reconnectDelay);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=named-pipe-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"named-pipe-client.js","sourceRoot":"","sources":["../../src/transport/named-pipe-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAUxD,MAAM,eAAe,GAAqC;IACxD,QAAQ,EAAE,qBAAqB;IAC/B,cAAc,EAAE,KAAK;IACrB,cAAc,EAAE,KAAK;IACrB,SAAS,EAAE,IAAI;IACf,cAAc,EAAE,IAAI;CACrB,CAAC;AAEF;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAClB,MAAM,GAAsB,IAAI,CAAC;IACxB,OAAO,CAAmC;IAC1C,OAAO,GAAG,IAAI,GAAG,EAI9B,CAAC;IACG,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAChC,UAAU,GAAG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aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAErC,IAAI,YAAY,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YAC3C,UAAU,CAAC,GAAG,EAAE;gBACd,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;oBACxB,wDAAwD;gBAC1D,CAAC,CAAC,CAAC;YACL,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IPC message types matching C# PipeMessage models.
|
|
3
|
+
* Protocol: [4-byte LE length][UTF-8 JSON body]
|
|
4
|
+
*/
|
|
5
|
+
export interface PipeRequest {
|
|
6
|
+
id: string;
|
|
7
|
+
method: string;
|
|
8
|
+
params?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface PipeResponse {
|
|
11
|
+
id: string;
|
|
12
|
+
result?: unknown;
|
|
13
|
+
error?: PipeError;
|
|
14
|
+
}
|
|
15
|
+
export interface PipeError {
|
|
16
|
+
code: number;
|
|
17
|
+
message: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const PipeErrorCodes: {
|
|
20
|
+
readonly MethodNotFound: -32601;
|
|
21
|
+
readonly InvalidParams: -32602;
|
|
22
|
+
readonly InternalError: -32603;
|
|
23
|
+
readonly SolidWorksNotConnected: -32000;
|
|
24
|
+
readonly SolidWorksOperationFailed: -32001;
|
|
25
|
+
};
|
|
26
|
+
export declare enum SwDocumentType {
|
|
27
|
+
Part = 1,
|
|
28
|
+
Assembly = 2,
|
|
29
|
+
Drawing = 3
|
|
30
|
+
}
|
|
31
|
+
export declare function swDocTypeFromExtension(ext: string): SwDocumentType | null;
|
|
32
|
+
export declare enum SwExportFormat {
|
|
33
|
+
STEP = "step",
|
|
34
|
+
IGES = "iges",
|
|
35
|
+
STL = "stl",
|
|
36
|
+
ThreeMF = "3mf",
|
|
37
|
+
Parasolid = "x_t",
|
|
38
|
+
PDF = "pdf",
|
|
39
|
+
DWG = "dwg",
|
|
40
|
+
DXF = "dxf",
|
|
41
|
+
PNG = "png",
|
|
42
|
+
BMP = "bmp"
|
|
43
|
+
}
|
|
44
|
+
export declare function isPipeResponse(obj: unknown): obj is PipeResponse;
|
|
45
|
+
export declare function isPipeError(error: unknown): error is PipeError;
|
|
46
|
+
export declare enum SwReferencePlane {
|
|
47
|
+
Front = "Front",
|
|
48
|
+
Top = "Top",
|
|
49
|
+
Right = "Right"
|
|
50
|
+
}
|
|
51
|
+
export declare enum SwMateType {
|
|
52
|
+
Coincident = 0,
|
|
53
|
+
Concentric = 1,
|
|
54
|
+
Perpendicular = 2,
|
|
55
|
+
Parallel = 3,
|
|
56
|
+
Tangent = 4,
|
|
57
|
+
Distance = 5,
|
|
58
|
+
Angle = 6
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=solidworks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solidworks.d.ts","sourceRoot":"","sources":["../../src/types/solidworks.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAID,eAAO,MAAM,cAAc;;;;;;CAMjB,CAAC;AAIX,oBAAY,cAAc;IACxB,IAAI,IAAI;IACR,QAAQ,IAAI;IACZ,OAAO,IAAI;CACZ;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