@atlisp/mcp 1.3.3 → 1.3.5

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.
@@ -462,7 +462,7 @@ async function evalLisp(code, withResult = false, encoding = null) {
462
462
  }
463
463
  return { content: [{ type: "text", text: "\u6267\u884C\u5931\u8D25\u6216\u65E0\u8FD4\u56DE\u503C" }], isError: true };
464
464
  } else {
465
- await cad.sendCommand("\x1B\x1B" + code + "\n");
465
+ await cad.sendCommand(code + "\n");
466
466
  return { content: [{ type: "text", text: `\u5DF2\u53D1\u9001\u547D\u4EE4: ${code}` }] };
467
467
  }
468
468
  } catch (e) {
@@ -479,7 +479,7 @@ async function getCadInfo() {
479
479
  }
480
480
  async function atCommand(command) {
481
481
  if (!cad.connected) return { content: [{ type: "text", text: "\u8BF7\u5148\u8FDE\u63A5 CAD" }], isError: true };
482
- await cad.sendCommand("\x1B\x1B" + command + "\n");
482
+ await cad.sendCommand(command + "\n");
483
483
  return { content: [{ type: "text", text: `\u5DF2\u53D1\u9001\u547D\u4EE4: ${command}` }] };
484
484
  }
485
485
  async function newDocument() {
@@ -510,7 +510,7 @@ async function installAtlisp() {
510
510
  }
511
511
  if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
512
512
  const installCode = `(progn(vl-load-com)(setq s strcat h "http" o(vlax-create-object (s"win"h".win"h"request.5.1"))v vlax-invoke e eval r read)(v o'open "get" (s h"://atlisp.""cn/@"):vlax-true)(v o'send)(v o'WaitforResponse 1000)(e(r(vlax-get-property o'ResponseText))))`;
513
- await cad.sendCommand("\x1B\x1B" + installCode + "\n");
513
+ await cad.sendCommand(installCode + "\n");
514
514
  return { content: [{ type: "text", text: "\u5DF2\u53D1\u9001 @lisp \u5B89\u88C5\u4EE3\u7801\u5230 CAD" }] };
515
515
  }
516
516
  async function listFunctionsInCad() {
@@ -540,7 +540,7 @@ async function initAtlisp() {
540
540
  (v o'WaitforResponse 1000)
541
541
  (e(r(vlax-get o'ResponseText)))))`;
542
542
  try {
543
- await cad.sendCommand("\x1B\x1B" + code + "\n");
543
+ await cad.sendCommand(code + "\n");
544
544
  return { content: [{ type: "text", text: "\u5DF2\u53D1\u9001 @lisp \u51FD\u6570\u5E93\u52A0\u8F7D\u4EE3\u7801\u5230 CAD" }] };
545
545
  } catch (e) {
546
546
  return { content: [{ type: "text", text: `\u9519\u8BEF: ${e.message}` }], isError: true };
@@ -154,7 +154,7 @@ const cadSendWithResult = edge.func(function() {/*
154
154
  dynamic doc = cad.ActiveDocument;
155
155
  if (doc != null) {
156
156
  // 加载 .lsp 文件执行
157
- doc.SendCommand("\x1b\x1b(load \"" + lispFile.Replace("\\", "\\\\") + "\")\n");
157
+ doc.SendCommand("(load \"" + lispFile.Replace("\\", "\\\\") + "\")\n");
158
158
 
159
159
  int retries = 10;
160
160
  string result = "";
@@ -440,21 +440,40 @@ async function handleMessage(msg) {
440
440
  if (!parenCheck.valid) {
441
441
  return { success: false, error: `括号错误: ${parenCheck.error} (位置 ${parenCheck.pos})` };
442
442
  }
443
- if (!(await waitForIdle(msg.platform || 'AutoCAD'))) {
444
- return { success: false, error: 'CAD is busy, timeout' };
443
+ if (msg.code.length > 255) {
444
+ log(`send (long code ${msg.code.length} chars, fallback to sendResult): ${msg.code.substring(0, 80)}...`);
445
+ const r = await new Promise((resolve, reject) => {
446
+ cadSendWithResult({ code: msg.code, platform: msg.platform || 'AutoCAD', encoding: '' }, (e, r) => {
447
+ if (e) reject(e);
448
+ else resolve(r);
449
+ });
450
+ });
451
+ log(`send result (long code): ${JSON.stringify(r)}`);
452
+ return r;
445
453
  }
446
- log(`send: ${msg.code}`);
447
- return new Promise((resolve, reject) => {
448
- cadSend({ code: msg.code, platform: msg.platform }, (e, r) => {
449
- if (e) {
450
- log(`send error: ${e.message}`);
451
- reject(e);
452
- } else {
454
+ const maxRetries = 3;
455
+ let lastError = null;
456
+ for (let i = 0; i < maxRetries; i++) {
457
+ const isBusy = await waitForIdle(msg.platform || 'AutoCAD');
458
+ if (isBusy) {
459
+ log(`send: ${msg.code}`);
460
+ try {
461
+ const r = await new Promise((resolve, reject) => {
462
+ cadSend({ code: msg.code, platform: msg.platform }, (e, r) => {
463
+ if (e) reject(e);
464
+ else resolve(r);
465
+ });
466
+ });
453
467
  log(`send result: ${JSON.stringify(r)}`);
454
- resolve(r);
468
+ return r;
469
+ } catch (e) {
470
+ log(`send error: ${e.message}`);
471
+ lastError = e;
455
472
  }
456
- });
457
- });
473
+ }
474
+ await new Promise(r => setTimeout(r, 500));
475
+ }
476
+ return { success: false, error: lastError?.message || '发送失败' };
458
477
  }
459
478
  if (msg.type === 'sendResult') {
460
479
  const docCheck = await new Promise((resolve, reject) => {
@@ -470,21 +489,29 @@ async function handleMessage(msg) {
470
489
  if (!parenCheck.valid) {
471
490
  return { success: false, error: `括号错误: ${parenCheck.error} (位置 ${parenCheck.pos})` };
472
491
  }
473
- if (!(await waitForIdle(msg.platform))) {
474
- return { success: false, error: 'CAD is busy, timeout' };
475
- }
476
- log(`sendResult: ${msg.code}`);
477
- return new Promise((resolve, reject) => {
478
- cadSendWithResult({ code: msg.code, platform: msg.platform, encoding: msg.encoding || '' }, (e, r) => {
479
- if (e) {
480
- log(`sendResult error: ${e.message}`);
481
- reject(e);
482
- } else {
492
+ const maxRetriesResult = 3;
493
+ let lastErrorResult = null;
494
+ for (let i = 0; i < maxRetriesResult; i++) {
495
+ const isBusy = await waitForIdle(msg.platform);
496
+ if (isBusy) {
497
+ log(`sendResult: ${msg.code}`);
498
+ try {
499
+ const r = await new Promise((resolve, reject) => {
500
+ cadSendWithResult({ code: msg.code, platform: msg.platform, encoding: msg.encoding || '' }, (e, r) => {
501
+ if (e) reject(e);
502
+ else resolve(r);
503
+ });
504
+ });
483
505
  log(`sendResult result: ${JSON.stringify(r)}`);
484
- resolve(r);
506
+ return r;
507
+ } catch (e) {
508
+ log(`sendResult error: ${e.message}`);
509
+ lastErrorResult = e;
485
510
  }
486
- });
487
- });
511
+ }
512
+ await new Promise(r => setTimeout(r, 500));
513
+ }
514
+ return { success: false, error: lastErrorResult?.message || '发送失败' };
488
515
  }
489
516
  if (msg.type === 'isBusy') {
490
517
  return new Promise((resolve, reject) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlisp/mcp",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "MCP Server for @lisp on CAD",
5
5
  "type": "module",
6
6
  "bin": {