@constructorfleet/sketchforge3d 1.32.0 → 1.33.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.
Files changed (42) hide show
  1. package/README.md +60 -3
  2. package/dist/cli.d.ts +3 -1
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/cli.js +97 -6
  5. package/dist/cli.js.map +1 -1
  6. package/dist/client.d.ts +41 -2
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/client.js +63 -0
  9. package/dist/client.js.map +1 -1
  10. package/dist/errors.d.ts +39 -1
  11. package/dist/errors.d.ts.map +1 -1
  12. package/dist/errors.js +105 -2
  13. package/dist/errors.js.map +1 -1
  14. package/dist/index.d.ts +3 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +3 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/resources/configurations.d.ts +21 -0
  19. package/dist/resources/configurations.d.ts.map +1 -0
  20. package/dist/resources/configurations.js +44 -0
  21. package/dist/resources/configurations.js.map +1 -0
  22. package/dist/resources/parameters.d.ts +16 -0
  23. package/dist/resources/parameters.d.ts.map +1 -0
  24. package/dist/resources/parameters.js +53 -0
  25. package/dist/resources/parameters.js.map +1 -0
  26. package/dist/resources/sketch-constraints.d.ts +11 -0
  27. package/dist/resources/sketch-constraints.d.ts.map +1 -0
  28. package/dist/resources/sketch-constraints.js +24 -0
  29. package/dist/resources/sketch-constraints.js.map +1 -0
  30. package/dist/types.d.ts +160 -4
  31. package/dist/types.d.ts.map +1 -1
  32. package/dist/types.js +1 -0
  33. package/dist/types.js.map +1 -1
  34. package/examples/parametric-box.macro.mjs +44 -0
  35. package/mcp/hosted.d.mts +1 -0
  36. package/mcp/hosted.mjs +4 -3
  37. package/mcp/localEngine.mjs +10 -2
  38. package/mcp/operation-parity.mjs +12 -1
  39. package/mcp/parameterTools.mjs +253 -0
  40. package/mcp/toolCatalog.mjs +180 -0
  41. package/mcp/tools.mjs +8 -6
  42. package/package.json +2 -2
@@ -0,0 +1,253 @@
1
+ /**
2
+ * Runs the parameter and expression tools over REST v1, or over the local engine.
3
+ *
4
+ * Both modes run one tool flow against a `request(method, path, { query, body })`.
5
+ * Local mode answers it with the engine's own REST helpers (`apiErrors`,
6
+ * `apiParameters`, `apiShapeSummary`), so replies and refusals match.
7
+ */
8
+
9
+ export const PARAMETER_TOOL_NAMES = new Set([
10
+ "sketchforge_list_parameters",
11
+ "sketchforge_set_parameter",
12
+ "sketchforge_rename_parameter",
13
+ "sketchforge_delete_parameter",
14
+ "sketchforge_set_shape_expression",
15
+ "sketchforge_bind_sketch_constraint",
16
+ "sketchforge_list_parameter_configurations",
17
+ "sketchforge_create_parameter_configuration",
18
+ "sketchforge_rename_parameter_configuration",
19
+ "sketchforge_set_configuration_override",
20
+ "sketchforge_delete_parameter_configuration",
21
+ "sketchforge_activate_parameter_configuration",
22
+ ]);
23
+
24
+ const CREATE_HINT = "Pass expression and dimension together to create it.";
25
+
26
+ /** Formats as `message [code]`, then the detail JSON on the next line. */
27
+ export class McpToolError extends Error {
28
+ constructor(headline, code, detail = {}) {
29
+ const extra = Object.keys(detail).length ? `\n${JSON.stringify(detail)}` : "";
30
+ super(`${headline}${code ? ` [${code}]` : ""}${extra}`);
31
+ this.headline = headline;
32
+ this.code = code;
33
+ this.detail = detail;
34
+ }
35
+ }
36
+
37
+ function withCreateHint(error) {
38
+ if (!(error instanceof McpToolError) || error.code !== "parameter_not_found") return error;
39
+ return new McpToolError(`${error.headline} ${CREATE_HINT}`, error.code, error.detail);
40
+ }
41
+
42
+ function requireText(args, key) {
43
+ if (typeof args[key] !== "string" || !args[key].trim()) throw new McpToolError(`${key} is required.`, "invalid_request");
44
+ return args[key];
45
+ }
46
+
47
+ /** Requires an expression string or null; shapeId is left to the request checks, as REST checks it. */
48
+ function requireExpression(args) {
49
+ if (args.expression !== null && typeof args.expression !== "string") {
50
+ throw new McpToolError("expression is required: an expression string, or null to clear the binding.", "invalid_request");
51
+ }
52
+ return args.expression;
53
+ }
54
+
55
+ /**
56
+ * Returns a configuration name bound for `?name=`. A query would stringify a
57
+ * number, so a non-string is refused here; a missing one is left to the request checks.
58
+ */
59
+ function configurationQueryName(args) {
60
+ if (args.name !== undefined && args.name !== null && typeof args.name !== "string") {
61
+ throw new McpToolError("name must be a configuration name string.", "invalid_request");
62
+ }
63
+ return args.name;
64
+ }
65
+
66
+ /** Splits a set request into a create (both fields) or a change (either one). */
67
+ function parameterChanges(args) {
68
+ const changes = {
69
+ ...(typeof args.expression === "string" ? { expression: args.expression } : {}),
70
+ ...(typeof args.dimension === "string" ? { dimension: args.dimension } : {}),
71
+ };
72
+ if (!Object.keys(changes).length) throw new McpToolError("Pass expression, dimension, or both.", "invalid_request");
73
+ return { changes, create: "expression" in changes && "dimension" in changes };
74
+ }
75
+
76
+ /** Runs one parameter tool. `request` throws McpToolError for a refusal. */
77
+ export async function callParameterTool(name, args, request) {
78
+ const projectId = args.projectId;
79
+ switch (name) {
80
+ case "sketchforge_list_parameters":
81
+ return request("GET", "/parameters", { query: { projectId } });
82
+ case "sketchforge_set_parameter": {
83
+ const parameterName = requireText(args, "name");
84
+ const { changes, create } = parameterChanges(args);
85
+ // An upsert: an existing name is overwritten, not refused.
86
+ if (create) {
87
+ try {
88
+ return { created: true, ...await request("POST", "/parameters", { query: { projectId }, body: { name: parameterName, ...changes } }) };
89
+ } catch (error) {
90
+ if (!(error instanceof McpToolError) || error.code !== "parameter_exists") throw error;
91
+ }
92
+ }
93
+ try {
94
+ return { created: false, ...await request("PATCH", "/parameters", { query: { projectId, name: parameterName }, body: changes }) };
95
+ } catch (error) {
96
+ throw create ? error : withCreateHint(error);
97
+ }
98
+ }
99
+ case "sketchforge_rename_parameter":
100
+ return request("PATCH", "/parameters", {
101
+ query: { projectId, name: requireText(args, "name") },
102
+ body: { name: requireText(args, "newName") },
103
+ });
104
+ case "sketchforge_delete_parameter":
105
+ return request("DELETE", "/parameters", { query: { projectId, name: requireText(args, "name") } });
106
+ case "sketchforge_set_shape_expression": {
107
+ // field is a key of the body, not a query value, so it is checked here.
108
+ const field = requireText(args, "field");
109
+ const expression = requireExpression(args);
110
+ return request("PATCH", "/shapes", { query: { projectId, shapeId: args.shapeId }, body: { expressions: { [field]: expression } } });
111
+ }
112
+ case "sketchforge_bind_sketch_constraint": {
113
+ const expression = requireExpression(args);
114
+ return request("PATCH", "/sketch-constraints", { query: { projectId, shapeId: args.shapeId, constraintId: args.constraintId }, body: { expression } });
115
+ }
116
+ // Configuration bodies go to the request checks unread, so both modes refuse them as REST does.
117
+ case "sketchforge_list_parameter_configurations":
118
+ return request("GET", "/parameter-configurations", { query: { projectId } });
119
+ case "sketchforge_create_parameter_configuration":
120
+ return request("POST", "/parameter-configurations", { query: { projectId }, body: { name: args.name, overrides: args.overrides } });
121
+ case "sketchforge_rename_parameter_configuration":
122
+ return request("PATCH", "/parameter-configurations", { query: { projectId, name: configurationQueryName(args) }, body: { name: args.newName } });
123
+ case "sketchforge_set_configuration_override":
124
+ return request("PATCH", "/parameter-configurations", {
125
+ query: { projectId, name: configurationQueryName(args) },
126
+ body: { parameter: args.parameter, expression: args.expression },
127
+ });
128
+ case "sketchforge_delete_parameter_configuration":
129
+ return request("DELETE", "/parameter-configurations", { query: { projectId, name: configurationQueryName(args) } });
130
+ case "sketchforge_activate_parameter_configuration":
131
+ return request("POST", "/parameter-configurations/activate", { query: { projectId }, body: { name: args.name } });
132
+ default:
133
+ throw new Error(`Unknown tool: ${name}`);
134
+ }
135
+ }
136
+
137
+ /** A query value as the URL carries it: absent, or a string. */
138
+ function queryText(value) {
139
+ return value === undefined || value === null ? undefined : String(value);
140
+ }
141
+
142
+ /**
143
+ * Answers the requests `callParameterTool` makes, as the REST v1 routes do.
144
+ * `api` is the engine package; its helpers are the ones the routes call.
145
+ */
146
+ export function localParameterRequest(engine, api) {
147
+ const refusal = (reply) => new McpToolError(reply.message, reply.code, reply.detail);
148
+ const unwrap = async (result, toError = (failure) => api.engineFailureToApiError(failure)) => {
149
+ if (result.ok) return result.value;
150
+ throw refusal(toError(result.failure));
151
+ };
152
+ const requireProject = (query) => {
153
+ const projectId = api.apiProjectId(queryText(query.projectId));
154
+ if (!projectId) throw new McpToolError(api.API_ERROR_MESSAGES.invalidProjectId, "invalid_project_id");
155
+ return projectId;
156
+ };
157
+ const requireShape = (query) => {
158
+ const shapeId = api.apiShapeId(queryText(query.shapeId));
159
+ if (!shapeId) throw new McpToolError(api.API_ERROR_MESSAGES.shapeIdRequired, "invalid_shape_id");
160
+ return shapeId;
161
+ };
162
+ const requireConfigurationName = (query) => {
163
+ const configuration = api.apiConfigurationName(queryText(query.name));
164
+ if (configuration === undefined) throw new McpToolError(api.API_CONFIGURATION_MESSAGES.nameRequired, "invalid_request");
165
+ return configuration;
166
+ };
167
+ const requireName = (query) => {
168
+ const parameterName = api.apiParameterName(queryText(query.name));
169
+ if (!parameterName) throw new McpToolError(api.API_PARAMETER_MESSAGES.nameRequired, "invalid_request");
170
+ return parameterName;
171
+ };
172
+
173
+ return async function request(method, route, { query = {}, body } = {}) {
174
+ // The same JSON a remote call would carry: undefined fields drop out.
175
+ const sent = body === undefined ? undefined : JSON.parse(JSON.stringify(body));
176
+ switch (`${method} ${route}`) {
177
+ case "GET /parameters":
178
+ return api.apiParameterList(await unwrap(await engine.project(requireProject(query))));
179
+ case "POST /parameters": {
180
+ const projectId = requireProject(query);
181
+ if (!api.isApiParameterCreateRequest(sent)) throw new McpToolError(api.API_PARAMETER_MESSAGES.create, "invalid_request");
182
+ return api.apiParametersWritten(await unwrap(await engine.addParameter(projectId, sent)), sent.name);
183
+ }
184
+ case "PATCH /parameters": {
185
+ const projectId = requireProject(query);
186
+ const parameterName = requireName(query);
187
+ if (!api.isApiParameterChangeRequest(sent)) throw new McpToolError(api.API_PARAMETER_MESSAGES.change, "invalid_request");
188
+ if (typeof sent.name === "string") {
189
+ return api.apiParametersWritten(await unwrap(await engine.renameParameter(projectId, parameterName, sent.name)), sent.name);
190
+ }
191
+ return api.apiParametersWritten(await unwrap(await engine.updateParameter(projectId, parameterName, sent)), parameterName);
192
+ }
193
+ case "DELETE /parameters": {
194
+ const projectId = requireProject(query);
195
+ const parameterName = requireName(query);
196
+ const { parameters, shapes, revision } = api.apiParametersWritten(await unwrap(await engine.deleteParameter(projectId, parameterName)), parameterName);
197
+ return { deleted: true, name: parameterName, parameters, shapes, revision };
198
+ }
199
+ case "PATCH /shapes": {
200
+ const projectId = requireProject(query);
201
+ const shapeId = requireShape(query);
202
+ const changed = await unwrap(
203
+ await engine.changeShape(projectId, shapeId, sent),
204
+ (failure) => api.shapeChangeApiError(failure, shapeId),
205
+ );
206
+ return api.apiShapeChanged(changed);
207
+ }
208
+ case "PATCH /sketch-constraints": {
209
+ const projectId = requireProject(query);
210
+ const shapeId = requireShape(query);
211
+ const constraintId = api.apiConstraintId(queryText(query.constraintId));
212
+ if (!constraintId) throw new McpToolError(api.API_SKETCH_CONSTRAINT_MESSAGES.constraintIdRequired, "invalid_request");
213
+ if (!api.isApiSketchConstraintBindRequest(sent)) throw new McpToolError(api.API_SKETCH_CONSTRAINT_MESSAGES.body, "invalid_request");
214
+ const bound = await unwrap(
215
+ await engine.bindSketchConstraint(projectId, shapeId, constraintId, sent.expression),
216
+ (failure) => api.sketchConstraintApiError(failure),
217
+ );
218
+ return api.apiSketchConstraintBound(bound, constraintId);
219
+ }
220
+ case "GET /parameter-configurations":
221
+ return api.apiConfigurationList(await unwrap(await engine.project(requireProject(query))));
222
+ case "POST /parameter-configurations": {
223
+ const projectId = requireProject(query);
224
+ if (!api.isApiConfigurationCreateRequest(sent)) throw new McpToolError(api.API_CONFIGURATION_MESSAGES.create, "invalid_request");
225
+ return api.apiConfigurationsWritten(await unwrap(await engine.addConfiguration(projectId, sent.name, sent.overrides)), sent.name);
226
+ }
227
+ case "PATCH /parameter-configurations": {
228
+ const projectId = requireProject(query);
229
+ const configuration = requireConfigurationName(query);
230
+ if (!api.isApiConfigurationChangeRequest(sent)) throw new McpToolError(api.API_CONFIGURATION_MESSAGES.change, "invalid_request");
231
+ if ("name" in sent) {
232
+ return api.apiConfigurationsWritten(await unwrap(await engine.renameConfiguration(projectId, configuration, sent.name)), sent.name);
233
+ }
234
+ const changed = sent.expression === null
235
+ ? await engine.clearConfigurationOverride(projectId, configuration, sent.parameter)
236
+ : await engine.setConfigurationOverride(projectId, configuration, sent.parameter, sent.expression);
237
+ return api.apiConfigurationsWritten(await unwrap(changed), configuration);
238
+ }
239
+ case "DELETE /parameter-configurations": {
240
+ const projectId = requireProject(query);
241
+ const configuration = requireConfigurationName(query);
242
+ return { deleted: true, name: configuration, ...api.apiConfigurationsWritten(await unwrap(await engine.deleteConfiguration(projectId, configuration))) };
243
+ }
244
+ case "POST /parameter-configurations/activate": {
245
+ const projectId = requireProject(query);
246
+ if (!api.isApiConfigurationActivateRequest(sent)) throw new McpToolError(api.API_CONFIGURATION_MESSAGES.activate, "invalid_request");
247
+ return api.apiConfigurationsWritten(await unwrap(await engine.activateConfiguration(projectId, sent.name)));
248
+ }
249
+ default:
250
+ throw new Error(`No local route for ${method} ${route}.`);
251
+ }
252
+ };
253
+ }
@@ -32,6 +32,12 @@ const resultAttributeProperties = {
32
32
  color: { type: "string", description: "Color for the result, stored as given as create_shape stores its color, such as #2a9d8f (default the first solid's color)." },
33
33
  };
34
34
 
35
+ const urlProperty = { type: "string", description: "Optional SketchForge server URL. Omit to work offline with local project files." };
36
+ const projectIdProperty = { type: "string", description: "The project id." };
37
+ const PARAMETER_DIMENSIONS = ["length", "angle", "unitless"];
38
+ const WORKS_BOTH_WAYS = "Works offline or against a server when url is supplied.";
39
+ const REFUSAL_FORMAT = "A refusal ends its first line with [code]; a second line, when present, is JSON detail.";
40
+
35
41
  export const engineTools = [
36
42
  {
37
43
  name: "sketchforge_list_projects",
@@ -575,4 +581,178 @@ export const engineTools = [
575
581
  },
576
582
  },
577
583
  },
584
+ {
585
+ name: "sketchforge_list_parameters",
586
+ description: `List the project's named parameters: name, expression, dimension, resolved value (null for a stale entry) and error, if any. bindingIssues lists shape bindings that no longer resolve. ${REFUSAL_FORMAT} ${WORKS_BOTH_WAYS}`,
587
+ inputSchema: {
588
+ type: "object",
589
+ required: ["projectId"],
590
+ properties: { url: urlProperty, projectId: projectIdProperty },
591
+ },
592
+ },
593
+ {
594
+ name: "sketchforge_set_parameter",
595
+ description: [
596
+ "Create a parameter, or change the expression or dimension of an existing one.",
597
+ "Send expression and dimension to create. An existing name is overwritten, not refused; created says which happened. Either one alone changes an existing parameter.",
598
+ "A bare number takes the dimension's unit, so 3 in a length parameter is 3 mm.",
599
+ "The reply has created, the parameter, the whole table, and the shapes the change rebuilt.",
600
+ REFUSAL_FORMAT,
601
+ "Codes: invalid_expression (bad syntax, an unknown name, the wrong dimension or a cycle; expressionError has the span and any cycle path), parameter_not_found (a change to a name that does not exist), invalid_request (a bad name or dimension, or an empty or over-long expression), limit_exceeded (the table is full), shape_locked (a bound shape is locked; detail names shapeId and fields), geometry_failed (a bound sketch cannot be solved; detail names shapeId and constraintIds).",
602
+ WORKS_BOTH_WAYS,
603
+ ].join(" "),
604
+ inputSchema: {
605
+ type: "object",
606
+ required: ["projectId", "name"],
607
+ properties: {
608
+ url: urlProperty,
609
+ projectId: projectIdProperty,
610
+ name: { type: "string", description: "Parameter name: a letter or underscore, then letters, digits or underscores." },
611
+ expression: { type: "string", description: 'For example "2", "3 mm", "wall * 2 + 1" or "max(wall, 2)". Units: mm, cm, m, in, ft, deg, rad.' },
612
+ dimension: { type: "string", enum: PARAMETER_DIMENSIONS, description: "length values are in mm and angle values in degrees." },
613
+ },
614
+ },
615
+ },
616
+ {
617
+ name: "sketchforge_rename_parameter",
618
+ description: `Rename a parameter, rewriting every parameter expression and shape binding that uses it. ${REFUSAL_FORMAT} Codes: parameter_not_found, parameter_exists (newName is taken), invalid_request (newName is not a valid name). ${WORKS_BOTH_WAYS}`,
619
+ inputSchema: {
620
+ type: "object",
621
+ required: ["projectId", "name", "newName"],
622
+ properties: {
623
+ url: urlProperty,
624
+ projectId: projectIdProperty,
625
+ name: { type: "string", description: "The current name." },
626
+ newName: { type: "string", description: "The new name." },
627
+ },
628
+ },
629
+ },
630
+ {
631
+ name: "sketchforge_delete_parameter",
632
+ description: `Delete a parameter that nothing uses. ${REFUSAL_FORMAT} Codes: parameter_not_found; parameter_in_use while anything references it, with dependents (parameter names), shapeDependents (shapeId and fields), sketchConstraintDependents (shapeId and constraintIds) and configurationDependents (configuration names) to change or clear first. ${WORKS_BOTH_WAYS}`,
633
+ inputSchema: {
634
+ type: "object",
635
+ required: ["projectId", "name"],
636
+ properties: { url: urlProperty, projectId: projectIdProperty, name: { type: "string", description: "The parameter to delete." } },
637
+ },
638
+ },
639
+ {
640
+ name: "sketchforge_set_shape_expression",
641
+ description: [
642
+ "Bind one field of a stored shape to a parameter expression and apply its value, or pass expression null to clear the binding and keep the current number.",
643
+ "A changed parameter then rebuilds the shape. Bindable fields: x, z, elevation, width, depth, height, rotation, rotationX, rotationZ, kind parameters such as sides or bevel, revolve.startAngle, revolve.sweepAngle and the other revolve settings, draftPrismAngle and faceDraft.angle.",
644
+ "The reply has the shape, as GET /api/v1/shapes reports it, and the revision. Repeating the stored expression writes nothing.",
645
+ REFUSAL_FORMAT,
646
+ "Codes: unapplicable_fields (this shape cannot bind the field), invalid_expression (detail names shapeId and field, with expressionError, or value, min and max for a result out of range), shape_not_found, shape_locked (detail names shapeId and fields).",
647
+ WORKS_BOTH_WAYS,
648
+ ].join(" "),
649
+ inputSchema: {
650
+ type: "object",
651
+ required: ["projectId", "shapeId", "field", "expression"],
652
+ properties: {
653
+ url: urlProperty,
654
+ projectId: projectIdProperty,
655
+ shapeId: { type: "string", description: "The shape id." },
656
+ field: { type: "string", description: 'The field to bind, such as "width" or "revolve.sweepAngle".' },
657
+ expression: { type: ["string", "null"], description: 'For example "wall * 5". null clears the binding.' },
658
+ },
659
+ },
660
+ },
661
+ {
662
+ name: "sketchforge_bind_sketch_constraint",
663
+ description: [
664
+ "Bind one dimensional constraint of a stored shape's sketch (distance, radius, diameter or angle) to a parameter expression, re-solve the sketch and rebuild the shape; or pass expression null to unbind it and keep its value.",
665
+ "A changed parameter then re-solves the sketch. shapeId is the sketch output or its sketchSourceId.",
666
+ "The reply has the rebuilt shape, as GET /api/v1/shapes reports it, the constraint as { id, kind, value, expression }, and the revision.",
667
+ REFUSAL_FORMAT,
668
+ "Codes: invalid_expression (bad syntax, an unknown name, the wrong dimension, or outOfRange; detail names shapeId and constraintId), unapplicable_fields (the constraint cannot bind, the sketch cannot be rebuilt, or conflictingBinding: a bound size of the same output drives that dimension; detail lists those fields), invalid_request (constraintId missing or unknown, or a bad body), geometry_failed (the sketch cannot be solved; detail lists constraintIds), shape_not_found, invalid_shape_id (shapeId missing or blank), shape_locked (detail shapeId names the locked shape or the locked group holding it; when that one is nested, the sentence names the top-level group to ungroup).",
669
+ WORKS_BOTH_WAYS,
670
+ ].join(" "),
671
+ inputSchema: {
672
+ type: "object",
673
+ required: ["projectId", "shapeId", "constraintId", "expression"],
674
+ properties: {
675
+ url: urlProperty,
676
+ projectId: projectIdProperty,
677
+ shapeId: { type: "string", description: "The sketch output shape, or its sketchSourceId." },
678
+ constraintId: { type: "string", description: 'The constraint id in the sketch profile, such as "width".' },
679
+ expression: { type: ["string", "null"], description: 'For example "w * 2". null removes the binding.' },
680
+ },
681
+ },
682
+ },
683
+ {
684
+ name: "sketchforge_list_parameter_configurations",
685
+ description: `List the project's parameter configurations: named sets of parameter expression overrides. The reply has configurations, activeConfiguration (null for the base table), the parameter table as the active configuration resolves it, and issues for overrides that no longer resolve. ${REFUSAL_FORMAT} ${WORKS_BOTH_WAYS}`,
686
+ inputSchema: { type: "object", required: ["projectId"], properties: { url: urlProperty, projectId: projectIdProperty } },
687
+ },
688
+ {
689
+ name: "sketchforge_create_parameter_configuration",
690
+ description: [
691
+ "Create a parameter configuration, optionally with overrides that map parameter names to expressions. Creating one does not activate it.",
692
+ "The reply has the configuration and the whole configuration state.",
693
+ REFUSAL_FORMAT,
694
+ "Codes: configuration_exists, invalid_request (a bad name or overrides body), invalid_expression (an override that does not resolve; detail names parameter and configuration), parameter_not_found (an override for a parameter that does not exist), limit_exceeded.",
695
+ WORKS_BOTH_WAYS,
696
+ ].join(" "),
697
+ inputSchema: {
698
+ type: "object",
699
+ required: ["projectId", "name"],
700
+ properties: {
701
+ url: urlProperty,
702
+ projectId: projectIdProperty,
703
+ name: { type: "string", description: "The configuration name, 1 to 100 characters." },
704
+ overrides: { type: "object", additionalProperties: { type: "string" }, description: 'Parameter name to expression, for example { "wall": "3 mm" }.' },
705
+ },
706
+ },
707
+ },
708
+ {
709
+ name: "sketchforge_rename_parameter_configuration",
710
+ description: `Rename a parameter configuration; an active one stays active under its new name. ${REFUSAL_FORMAT} Codes: configuration_not_found, configuration_exists (newName is taken), invalid_request. ${WORKS_BOTH_WAYS}`,
711
+ inputSchema: {
712
+ type: "object",
713
+ required: ["projectId", "name", "newName"],
714
+ properties: { url: urlProperty, projectId: projectIdProperty, name: { type: "string", description: "The configuration name, 1 to 100 characters." }, newName: { type: "string", description: "The configuration name, 1 to 100 characters." } },
715
+ },
716
+ },
717
+ {
718
+ name: "sketchforge_set_configuration_override",
719
+ description: [
720
+ "Set one parameter's expression in a configuration, or pass expression null to remove that override so the base expression applies.",
721
+ "If the configuration is active, every shape bound to the changed value is rebuilt in the same write and returned in the reply's shapes.",
722
+ REFUSAL_FORMAT,
723
+ "Codes: configuration_not_found, parameter_not_found, invalid_expression (detail has expressionError), shape_locked (a bound shape the change would rebuild is locked), invalid_request.",
724
+ WORKS_BOTH_WAYS,
725
+ ].join(" "),
726
+ inputSchema: {
727
+ type: "object",
728
+ required: ["projectId", "name", "parameter", "expression"],
729
+ properties: {
730
+ url: urlProperty,
731
+ projectId: projectIdProperty,
732
+ name: { type: "string", description: "The configuration name, 1 to 100 characters." },
733
+ parameter: { type: "string", description: "The parameter to override." },
734
+ expression: { type: ["string", "null"], description: 'For example "3 mm". null removes the override.' },
735
+ },
736
+ },
737
+ },
738
+ {
739
+ name: "sketchforge_delete_parameter_configuration",
740
+ description: `Delete a parameter configuration. Deleting the active one returns the project to the base table and rebuilds bound shapes, so it can be refused as an activation can. ${REFUSAL_FORMAT} Codes: configuration_not_found, invalid_request, and for the active one invalid_expression (a bound result out of range), shape_locked (a bound shape that would change is locked) and geometry_failed (a bound sketch cannot be solved). ${WORKS_BOTH_WAYS}`,
741
+ inputSchema: { type: "object", required: ["projectId", "name"], properties: { url: urlProperty, projectId: projectIdProperty, name: { type: "string", description: "The configuration name, 1 to 100 characters." } } },
742
+ },
743
+ {
744
+ name: "sketchforge_activate_parameter_configuration",
745
+ description: [
746
+ "Activate a parameter configuration, or pass name null to return to the base table. Every bound shape is re-resolved and rebuilt in the same write, and the reply lists the rebuilt shapes.",
747
+ "A refused activation leaves the project, the active configuration and the geometry unchanged.",
748
+ REFUSAL_FORMAT,
749
+ "Codes: configuration_not_found, invalid_expression (an override, or a bound result such as an out-of-range size; detail names it), shape_locked (a bound shape that would change is locked), geometry_failed (a bound sketch cannot be solved), invalid_request.",
750
+ WORKS_BOTH_WAYS,
751
+ ].join(" "),
752
+ inputSchema: {
753
+ type: "object",
754
+ required: ["projectId", "name"],
755
+ properties: { url: urlProperty, projectId: projectIdProperty, name: { type: ["string", "null"], description: "The configuration to activate, or null for the base table." } },
756
+ },
757
+ },
578
758
  ];
package/mcp/tools.mjs CHANGED
@@ -3,6 +3,7 @@ import path from "node:path";
3
3
  import { resolveMcpReadPath, resolveMcpWritePath } from "./filesystemPaths.mjs";
4
4
  import { listMacros, macroTools, runMacroByName } from "./macroTools.mjs";
5
5
  import { callLocalEngineTool } from "./localEngine.mjs";
6
+ import { callParameterTool, McpToolError, PARAMETER_TOOL_NAMES } from "./parameterTools.mjs";
6
7
  import { engineTools } from "./toolCatalog.mjs";
7
8
 
8
9
  const MCP_ROUTE = "/api/sketchforge-mcp";
@@ -23,7 +24,7 @@ const API_TOKEN_ENV = "SKETCHFORGE_API_TOKEN";
23
24
  * to ask one for. The token is the same one the server was started with, and
24
25
  * without it every route answers 404 rather than saying it is switched off.
25
26
  */
26
- async function restRequest(method, path, { query = {}, body, baseUrl } = {}) {
27
+ async function restRequest(method, path, { query = {}, body, baseUrl, withDetail = false } = {}) {
27
28
  const token = process.env[API_TOKEN_ENV];
28
29
  if (!token) {
29
30
  throw new Error(
@@ -43,11 +44,9 @@ async function restRequest(method, path, { query = {}, body, baseUrl } = {}) {
43
44
  if (!response.ok) {
44
45
  // The sentence is for whoever reads the log; the code is the half a client
45
46
  // can act on, so carry both rather than flattening to a status.
46
- throw new Error(
47
- payload?.error
48
- ? `${payload.error}${payload.code ? ` [${payload.code}]` : ""}`
49
- : `SketchForge API returned HTTP ${response.status}`,
50
- );
47
+ if (!payload?.error) throw new McpToolError(`SketchForge API returned HTTP ${response.status}`);
48
+ const { error, code, ...detail } = payload;
49
+ throw new McpToolError(error, code, withDetail ? detail : {});
51
50
  }
52
51
  return payload;
53
52
  }
@@ -99,6 +98,9 @@ async function bridgeCommand(action, args = {}, defaultTimeoutMs = 15000, baseUr
99
98
  }
100
99
 
101
100
  async function callRemoteTool(name, args, baseUrl) {
101
+ if (PARAMETER_TOOL_NAMES.has(name)) {
102
+ return callParameterTool(name, args, (method, route, options) => restRequest(method, route, { ...options, baseUrl, withDetail: true }));
103
+ }
102
104
  switch (name) {
103
105
  case "sketchforge_list_editors":
104
106
  return bridgeGet(baseUrl);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructorfleet/sketchforge3d",
3
- "version": "1.32.0",
3
+ "version": "1.33.0",
4
4
  "description": "Typed client and macro runner for the SketchForge REST API.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "author": {
@@ -19,7 +19,7 @@
19
19
  "client"
20
20
  ],
21
21
  "dependencies": {
22
- "@constructorfleet/sketchforge-engine": "1.32.0",
22
+ "@constructorfleet/sketchforge-engine": "1.33.0",
23
23
  "fflate": "^0.8.3",
24
24
  "sharp": "^0.35.5"
25
25
  },