@atlisp/mcp 1.0.21 → 1.0.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlisp/mcp",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "description": "MCP Server for @lisp on CAD",
5
5
  "type": "module",
6
6
  "bin": {
package/src/atlisp-mcp.js CHANGED
@@ -382,11 +382,11 @@ async function handleMcpRequest(session, method, params, id) {
382
382
  }
383
383
 
384
384
  export async function startServer() {
385
- if (transport === 'stdio') {
385
+ if (config.transport === 'stdio') {
386
386
  await initCadConnection();
387
387
  const mcpServer = createMcpServer();
388
- const transport = new StdioServerTransport();
389
- await mcpServer.connect(transport);
388
+ const stdioTransport = new StdioServerTransport();
389
+ await mcpServer.connect(stdioTransport);
390
390
  console.log(`${SERVER_NAME} 运行在 stdio 模式`);
391
391
  } else {
392
392
  const app = express();
package/src/cad-worker.js CHANGED
@@ -137,7 +137,7 @@ const cadSendWithResult = edge.func(function() {/*
137
137
 
138
138
  // 生成 LISP 代码:执行 code,将结果打印到 tempFile
139
139
  // 使用 princ 输出原始字符串
140
- string lispCode = "(progn(setq f(open \"" + tempFile.Replace("\\", "\\\\") + "\" \"w\"))(princ " + code + " f)(close f)(princ))";
140
+ string lispCode = "(progn(setq f(open \"" + tempFile.Replace("\\", "\\\\") + "\" \"w\"))(princ (progn " + code + ") f)(close f)(princ))";
141
141
 
142
142
  // 使用系统 ANSI 编码以兼容 GstarCAD / ZWCAD
143
143
  System.IO.File.WriteAllText(lispFile, lispCode, System.Text.Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage));
@@ -337,22 +337,22 @@ async function waitForIdle(platform) {
337
337
  function checkParens(code) {
338
338
  let depth = 0;
339
339
  let inString = false;
340
- let escapeNext = false;
341
340
  for (let i = 0; i < code.length; i++) {
342
341
  const ch = code[i];
343
- if (escapeNext) {
344
- escapeNext = false;
345
- continue;
346
- }
347
- if (ch === '\\') {
348
- escapeNext = true;
342
+ if (inString) {
343
+ if (ch === '\\' && i + 1 < code.length) {
344
+ i++;
345
+ continue;
346
+ }
347
+ if (ch === '"') {
348
+ inString = false;
349
+ }
349
350
  continue;
350
351
  }
351
352
  if (ch === '"') {
352
- inString = !inString;
353
+ inString = true;
353
354
  continue;
354
355
  }
355
- if (inString) continue;
356
356
  if (ch === ';') {
357
357
  while (i < code.length && code[i] !== '\n') i++;
358
358
  continue;
@@ -427,7 +427,7 @@ async function handleMessage(msg) {
427
427
  if (!parenCheck.valid) {
428
428
  return { success: false, error: `括号错误: ${parenCheck.error} (位置 ${parenCheck.pos})` };
429
429
  }
430
- if (!(await waitForIdle(msg.platform))) {
430
+ if (!(await waitForIdle(msg.platform || 'AutoCAD'))) {
431
431
  return { success: false, error: 'CAD is busy, timeout' };
432
432
  }
433
433
  log(`send: ${msg.code}`);
package/src/constants.js CHANGED
@@ -8,7 +8,7 @@ export const FILE_EXTENSIONS = {
8
8
 
9
9
  export const PROTOCOL_VERSION = '2024-11-05';
10
10
  export const SERVER_NAME = 'atlisp-mcp-server';
11
- export const SERVER_VERSION = '1.0.20';
11
+ export const SERVER_VERSION = '1.0.24';
12
12
 
13
13
  export const MOCK_PACKAGES = [
14
14
  { name: 'base', description: '基础函数库', version: '1.0.0' },
@@ -312,16 +312,29 @@ async function getDwgPath() {
312
312
  if (!cad.connected) return { path: null, name: null };
313
313
 
314
314
  try {
315
- const code = `(strcat (vl-princ-to-string (getvar "dwgprefix")) (vl-princ-to-string (getvar "dwgname")))`;
316
- const fullPath = await cad.sendCommandWithResult(code);
315
+ const code = `(progn
316
+ (setq prefix (vl-princ-to-string (getvar "dwgprefix")))
317
+ (setq name (vl-princ-to-string (getvar "dwgname")))
318
+ (list (strcat prefix name) name)
319
+ )`;
320
+ const result = await cad.sendCommandWithResult(code);
317
321
 
318
- const nameCode = `(vl-princ-to-string (getvar "dwgname"))`;
319
- const name = await cad.sendCommandWithResult(nameCode);
322
+ if (!result || result === "nil" || result === "") {
323
+ return { path: null, name: null };
324
+ }
325
+
326
+ let parsed = null;
327
+ try { parsed = JSON.parse(result); } catch {}
328
+ if (!parsed) {
329
+ const listResult = parseLispList(result);
330
+ if (listResult && listResult.length >= 2) parsed = listResult;
331
+ }
332
+
333
+ if (parsed && Array.isArray(parsed) && parsed.length >= 2) {
334
+ return { path: String(parsed[0]), name: String(parsed[1]) };
335
+ }
320
336
 
321
- return {
322
- path: fullPath || null,
323
- name: name || null
324
- };
337
+ return { path: result, name: result };
325
338
  } catch (e) {
326
339
  return { path: null, name: null };
327
340
  }
@@ -197,7 +197,7 @@ export class SseSession {
197
197
  }
198
198
 
199
199
  sendEndpoint(path) {
200
- return this._write(`: endpoint ${path}\n\n`);
200
+ return this.sendEvent(SSE_EVENTS.ENDPOINT, path);
201
201
  }
202
202
 
203
203
  sendError(code, message, id = null) {
@@ -205,7 +205,7 @@ export class SseSession {
205
205
  }
206
206
 
207
207
  sendPing() {
208
- return this._write(': ping ' + Date.now() + '\n\n');
208
+ return this.sendEvent(SSE_EVENTS.PING, { timestamp: Date.now() });
209
209
  }
210
210
 
211
211
  sendProgress(current, total, message = '') {
@@ -213,7 +213,7 @@ export class SseSession {
213
213
  }
214
214
 
215
215
  sendCapabilities(capabilities) {
216
- return this._write(`: capabilities ${JSON.stringify(capabilities)}\n\n`);
216
+ return this.sendEvent(SSE_EVENTS.CAPABILITIES, capabilities);
217
217
  }
218
218
 
219
219
  sendResponse(jsonrpcResponse, id = null) {