@atlisp/mcp 1.4.1 → 1.4.3

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.
@@ -331,6 +331,42 @@ const cadBringToFront = edge.func(function() {/*
331
331
  }
332
332
  */});
333
333
 
334
+ const cadConnectByName = edge.func(function() {/*
335
+ async (input) => {
336
+ try {
337
+ string platform = input.ToString();
338
+ string progId = platform + ".Application";
339
+ dynamic cad = System.Runtime.InteropServices.Marshal.GetActiveObject(progId);
340
+ if (cad != null) {
341
+ string ver = cad.Version.ToString();
342
+ return new { success = true, platform = platform, version = ver, launched = false };
343
+ }
344
+ } catch (Exception ex) {
345
+ System.Diagnostics.Debug.WriteLine("cadConnectByName existing error: " + ex.Message);
346
+ }
347
+ try {
348
+ string platform = input.ToString();
349
+ string progId = platform + ".Application";
350
+ var type = System.Type.GetTypeFromProgID(progId);
351
+ if (type != null) {
352
+ dynamic cad = System.Activator.CreateInstance(type);
353
+ if (cad != null) {
354
+ for (int retry = 0; retry < 60; retry++) {
355
+ await System.Threading.Tasks.Task.Delay(500);
356
+ try {
357
+ string ver = cad.Version.ToString();
358
+ return new { success = true, platform = platform, version = ver, launched = true };
359
+ } catch {}
360
+ }
361
+ }
362
+ }
363
+ } catch (Exception ex) {
364
+ System.Diagnostics.Debug.WriteLine("cadConnectByName launch error: " + ex.Message);
365
+ }
366
+ return new { success = false, error = "Not found" };
367
+ }
368
+ */});
369
+
334
370
  async function waitForIdle(platform) {
335
371
  let retries = BUSY_RETRIES;
336
372
  while (retries > 0) {
@@ -379,11 +415,23 @@ export function checkParens(code) {
379
415
  return { valid: true };
380
416
  }
381
417
 
418
+ async function connectToPlatform(targetPlatform) {
419
+ return new Promise((resolve, reject) => {
420
+ cadConnectByName(targetPlatform, (e, r) => {
421
+ if (e) reject(e);
422
+ else resolve(r);
423
+ });
424
+ });
425
+ }
426
+
382
427
  async function handleMessage(msg) {
383
428
  if (msg.type === 'ping') {
384
429
  return { pong: true };
385
430
  }
386
431
  if (msg.type === 'connect') {
432
+ if (msg.platform) {
433
+ return await connectToPlatform(msg.platform);
434
+ }
387
435
  try {
388
436
  const result = await new Promise((resolve, reject) => {
389
437
  cadConnect({}, (e, r) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlisp/mcp",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "description": "MCP Server for @lisp on CAD",
5
5
  "type": "module",
6
6
  "bin": {