@atlisp/mcp 1.0.18 → 1.0.19

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 CHANGED
@@ -257,6 +257,7 @@ curl http://localhost:8110/health
257
257
  | `HOST` | `0.0.0.0` | HTTP 模式监听地址 |
258
258
  | `MESSAGE_TIMEOUT` | `60000` | 消息超时(毫秒) |
259
259
  | `MCP_API_KEY` | (无) | API Key 认证(可选) |
260
+ | `ENABLE_SSE` | `false` | 启用 SSE 模式(默认禁用) |
260
261
 
261
262
  ---
262
263
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlisp/mcp",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "MCP Server for @lisp on CAD",
5
5
  "type": "module",
6
6
  "bin": {
package/src/atlisp-mcp.js CHANGED
@@ -27,7 +27,9 @@ const PORT = process.env.PORT || 8110;
27
27
  const HOST = process.env.HOST || '0.0.0.0';
28
28
  const TRANSPORT = process.env.TRANSPORT || 'http';
29
29
  const API_KEY = process.env.MCP_API_KEY || '';
30
+ const ENABLE_SSE = process.env.ENABLE_SSE === 'true';
30
31
  if (API_KEY) log('API Key authentication enabled');
32
+ if (ENABLE_SSE) log('SSE mode enabled');
31
33
 
32
34
  const sseSessionManager = new SseSessionManager();
33
35
 
@@ -36,7 +38,7 @@ export { CAD_PLATFORMS, FILE_EXTENSIONS, MOCK_PACKAGES } from './constants.js';
36
38
  const TOOL_HANDLERS = {
37
39
  connect_cad: () => cadHandlers.connectCad(),
38
40
  eval_lisp: (a) => cadHandlers.evalLisp(a.code),
39
- eval_lisp_with_result: (a) => cadHandlers.evalLisp(a.code, true),
41
+ eval_lisp_with_result: (a) => cadHandlers.evalLisp(a.code, true, a.encoding),
40
42
  get_cad_info: () => cadHandlers.getCadInfo(),
41
43
  list_packages: () => packageHandlers.listPackages(),
42
44
  search_packages: (a) => packageHandlers.searchPackages(a.query),
@@ -76,7 +78,10 @@ export const tools = [
76
78
  description: '在 CAD 中执行 AutoLISP 代码并返回结果',
77
79
  inputSchema: {
78
80
  type: 'object',
79
- properties: { code: { type: 'string', description: '要执行的 LISP 代码' } },
81
+ properties: {
82
+ code: { type: 'string', description: '要执行的 LISP 代码' },
83
+ encoding: { type: 'string', description: '结果编码,如 utf-8, gbk, gb2312, gb18030(可选,默认自动检测)' }
84
+ },
80
85
  required: ['code']
81
86
  }
82
87
  },
@@ -386,43 +391,45 @@ export async function startServer() {
386
391
 
387
392
  createMcpServer();
388
393
 
389
- app.get('/sse', (req, res) => {
390
- const clientId = req.get('mcp-session-id') || req.get('Last-Event-ID') || crypto.randomUUID();
391
-
392
- const session = new SseSession(res, { clientId });
393
-
394
- session.sendEndpoint('/mcp');
395
- session.sendCapabilities({
396
- protocolVersion: PROTOCOL_VERSION,
397
- capabilities: { tools: {}, resources: { subscribe: true, listChanged: true } },
398
- serverInfo: { name: SERVER_NAME, version: SERVER_VERSION }
399
- });
400
-
401
- sseSessionManager.add(clientId, session);
402
-
403
- res.on('close', () => {
404
- sseSessionManager.remove(clientId);
394
+ if (ENABLE_SSE) {
395
+ app.get('/sse', (req, res) => {
396
+ const clientId = req.get('mcp-session-id') || req.get('Last-Event-ID') || crypto.randomUUID();
397
+
398
+ const session = new SseSession(res, { clientId });
399
+
400
+ session.sendEndpoint('/mcp');
401
+ session.sendCapabilities({
402
+ protocolVersion: PROTOCOL_VERSION,
403
+ capabilities: { tools: {}, resources: { subscribe: true, listChanged: true } },
404
+ serverInfo: { name: SERVER_NAME, version: SERVER_VERSION }
405
+ });
406
+
407
+ sseSessionManager.add(clientId, session);
408
+
409
+ res.on('close', () => {
410
+ sseSessionManager.remove(clientId);
411
+ });
405
412
  });
406
- });
407
413
 
408
- ['/mcp/sse'].forEach(p => app.all(p, (req, res) => {
409
- const clientId = req.get('mcp-session-id') || req.get('Last-Event-ID') || crypto.randomUUID();
410
-
411
- const session = new SseSession(res, { clientId });
412
-
413
- session.sendEndpoint('/mcp');
414
- session.sendCapabilities({
415
- protocolVersion: PROTOCOL_VERSION,
416
- capabilities: { tools: {}, resources: { subscribe: true, listChanged: true } },
417
- serverInfo: { name: SERVER_NAME, version: SERVER_VERSION }
418
- });
419
-
420
- sseSessionManager.add(clientId, session);
421
-
422
- res.on('close', () => {
423
- sseSessionManager.remove(clientId);
424
- });
425
- }));
414
+ ['/mcp/sse'].forEach(p => app.all(p, (req, res) => {
415
+ const clientId = req.get('mcp-session-id') || req.get('Last-Event-ID') || crypto.randomUUID();
416
+
417
+ const session = new SseSession(res, { clientId });
418
+
419
+ session.sendEndpoint('/mcp');
420
+ session.sendCapabilities({
421
+ protocolVersion: PROTOCOL_VERSION,
422
+ capabilities: { tools: {}, resources: { subscribe: true, listChanged: true } },
423
+ serverInfo: { name: SERVER_NAME, version: SERVER_VERSION }
424
+ });
425
+
426
+ sseSessionManager.add(clientId, session);
427
+
428
+ res.on('close', () => {
429
+ sseSessionManager.remove(clientId);
430
+ });
431
+ }));
432
+ }
426
433
 
427
434
  app.post('/mcp', async (req, res) => {
428
435
  const body = req.body || {};
@@ -433,6 +440,10 @@ export async function startServer() {
433
440
  log(`${req.method} ${req.path} - session: ${sessionId} - method: ${method} - wantsSSE: ${wantsSse}`);
434
441
 
435
442
  if (wantsSse) {
443
+ if (!ENABLE_SSE) {
444
+ res.status(400).json({ error: 'SSE mode is disabled' });
445
+ return;
446
+ }
436
447
  res.setHeader('Content-Type', 'text/event-stream');
437
448
  res.setHeader('Cache-Control', 'no-cache');
438
449
  res.setHeader('Connection', 'keep-alive');
package/src/cad.js CHANGED
@@ -146,9 +146,9 @@ class CadConnection {
146
146
  throw new Error(result.error || '发送失败');
147
147
  }
148
148
 
149
- async sendCommandWithResult(code) {
149
+ async sendCommandWithResult(code, encoding = null) {
150
150
  if (!this.connected) throw new Error('未连接 CAD');
151
- const result = await sendMessage({ type: 'sendResult', code: code, platform: _platform, encoding: RESULT_ENCODING });
151
+ const result = await sendMessage({ type: 'sendResult', code: code, platform: _platform, encoding: encoding || '' });
152
152
  if (result.success) {
153
153
  return result.result || '';
154
154
  }
package/src/constants.js CHANGED
@@ -7,7 +7,7 @@ export const FILE_EXTENSIONS = {
7
7
 
8
8
  export const PROTOCOL_VERSION = '2024-11-05';
9
9
  export const SERVER_NAME = 'atlisp-mcp-server';
10
- export const SERVER_VERSION = '1.0.18';
10
+ export const SERVER_VERSION = '1.0.19';
11
11
 
12
12
  export const MOCK_PACKAGES = [
13
13
  { name: 'base', description: '基础函数库', version: '1.0.0' },
@@ -16,14 +16,14 @@ export async function connectCad() {
16
16
  return { content: [{ type: 'text', text: '未能连接或启动 CAD,请确保 CAD 已安装' }], isError: true };
17
17
  }
18
18
 
19
- export async function evalLisp(code, withResult = false) {
19
+ export async function evalLisp(code, withResult = false, encoding = null) {
20
20
  if (!cad.connected) { await cad.connect(); }
21
21
  if (!cad.connected) {
22
22
  return { content: [{ type: 'text', text: '未连接 CAD' }], isError: true };
23
23
  }
24
24
  try {
25
25
  if (withResult) {
26
- const result = await cad.sendCommandWithResult(code);
26
+ const result = await cad.sendCommandWithResult(code, encoding);
27
27
  if (result !== null) {
28
28
  return { content: [{ type: 'text', text: result }] };
29
29
  }