@atlisp/mcp 1.1.0 → 1.1.2

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.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "MCP Server for @lisp on CAD",
5
5
  "type": "module",
6
6
  "bin": {
package/src/atlisp-mcp.js CHANGED
@@ -1,18 +1,21 @@
1
- import { fileURLToPath } from 'url';
1
+ #!/usr/bin/env node
2
2
  import path from 'path';
3
- import { SERVER_VERSION } from './constants.js';
3
+ import { fileURLToPath } from 'url';
4
+ import { createRequire } from 'module';
4
5
 
5
6
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+ const require = createRequire(import.meta.url);
8
+ const { version } = require(path.join(__dirname, '..', 'package.json'));
6
9
 
7
10
  if (process.argv[1]?.endsWith('atlisp-mcp.js')) {
8
11
  const args = process.argv.slice(2);
9
12
  for (let i = 0; i < args.length; i++) {
10
13
  if (args[i] === '--version' || args[i] === '-v') {
11
- console.log(`atlisp-mcp v${SERVER_VERSION}`);
14
+ console.log(`atlisp-mcp v${version}`);
12
15
  process.exit(0);
13
16
  } else if (args[i] === '--help' || args[i] === '-h') {
14
17
  console.log(`
15
- @lisp MCP Server v${SERVER_VERSION}
18
+ @lisp MCP Server v${version}
16
19
 
17
20
  Usage: atlisp-mcp [options]
18
21
 
@@ -44,6 +47,7 @@ const { decode: charsetDecode, encodingExists } = iconv;
44
47
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
45
48
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
46
49
  import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
50
+ import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
47
51
  import {
48
52
  ListToolsRequestSchema,
49
53
  CallToolRequestSchema,
@@ -108,6 +112,17 @@ const TOOL_HANDLERS = {
108
112
  init_atlisp: () => cadHandlers.initAtlisp(),
109
113
  get_function_usage: (a) => functionHandlers.getFunctionUsage(a.name, a.package),
110
114
  list_functions: (a) => functionHandlers.listFunctions(a.package),
115
+ get_file_extensions: (a) => {
116
+ const exts = FILE_EXTENSIONS[a.platform];
117
+ if (!exts) return { content: [{ type: 'text', text: `平台 ${a.platform} 不支持` }], isError: true };
118
+ return { content: [{ type: 'text', text: `${a.platform} 文件扩展名: ${exts.join(', ')}` }] };
119
+ },
120
+ get_install_code: () => ({
121
+ content: [{
122
+ type: 'text',
123
+ text: `复制以下代码到 CAD 命令行加载:\n(load "atlisp" "atlisp")\n(vlax-create-object "atlisp.atlisp.1")`
124
+ }]
125
+ }),
111
126
  };
112
127
 
113
128
  export const tools = [
@@ -220,6 +235,22 @@ export const tools = [
220
235
  package: { type: 'string', description: '包名,如 string(可选)' }
221
236
  }
222
237
  }
238
+ },
239
+ {
240
+ name: 'get_file_extensions',
241
+ description: '获取 CAD 平台对应的文件扩展名',
242
+ inputSchema: {
243
+ type: 'object',
244
+ properties: {
245
+ platform: { type: 'string', description: 'CAD 平台,如 AutoCAD, ZWCAD, GStarCAD, BricsCAD' }
246
+ },
247
+ required: ['platform']
248
+ }
249
+ },
250
+ {
251
+ name: 'get_install_code',
252
+ description: '获取 @lisp 安装代码',
253
+ inputSchema: { type: 'object', properties: {} }
223
254
  }
224
255
  ];
225
256
 
@@ -496,6 +527,84 @@ export async function startServer() {
496
527
  }
497
528
  });
498
529
 
530
+ const sseEndpoint = '/sse';
531
+ app.get(sseEndpoint, async (req, res) => {
532
+ const sseTransport = new SSEServerTransport(sseEndpoint, res);
533
+ try {
534
+ await mcpServer.connect(sseTransport);
535
+ await sseTransport.handleRequest(req, res);
536
+ } catch (error) {
537
+ log(`SSE transport error: ${error.message}`);
538
+ if (!res.headersSent) {
539
+ res.status(500).json({ error: 'Internal server error' });
540
+ }
541
+ }
542
+ });
543
+ app.post(sseEndpoint, mcpLimiter, async (req, res) => {
544
+ const sessionId = req.headers['mcp-session-id'];
545
+ const sseTransport = sessionId ? sseEndpoint + '?sessionId=' + sessionId : sseEndpoint;
546
+ try {
547
+ const transport = new SSEServerTransport(sseEndpoint, res);
548
+ await mcpServer.connect(transport);
549
+ await transport.handleRequest(req, res);
550
+ } catch (error) {
551
+ log(`SSE POST error: ${error.message}`);
552
+ if (!res.headersSent) {
553
+ res.status(500).json({ error: 'Internal server error' });
554
+ }
555
+ }
556
+ });
557
+
558
+ app.get('/mcp/sse', async (req, res) => {
559
+ const sseTransport = new SSEServerTransport('/mcp/sse', res);
560
+ try {
561
+ await mcpServer.connect(sseTransport);
562
+ await sseTransport.handleRequest(req, res);
563
+ } catch (error) {
564
+ log(`/mcp/sse transport error: ${error.message}`);
565
+ if (!res.headersSent) {
566
+ res.status(500).json({ error: 'Internal server error' });
567
+ }
568
+ }
569
+ });
570
+ app.post('/mcp/sse', mcpLimiter, async (req, res) => {
571
+ const sseTransport = new SSEServerTransport('/mcp/sse', res);
572
+ try {
573
+ await mcpServer.connect(sseTransport);
574
+ await sseTransport.handleRequest(req, res);
575
+ } catch (error) {
576
+ log(`/mcp/sse POST error: ${error.message}`);
577
+ if (!res.headersSent) {
578
+ res.status(500).json({ error: 'Internal server error' });
579
+ }
580
+ }
581
+ });
582
+
583
+ app.get('/mcp/stream', async (req, res) => {
584
+ try {
585
+ await transport.handleRequest(req, res, req.body);
586
+ } catch (error) {
587
+ log(`/mcp/stream error: ${error.message}`);
588
+ if (!res.headersSent) {
589
+ res.status(500).json({ error: 'Internal server error' });
590
+ }
591
+ }
592
+ });
593
+
594
+ app.post('/message', mcpLimiter, async (req, res) => {
595
+ try {
596
+ const sessionId = req.headers['mcp-session-id'];
597
+ const sseTransport = new SSEServerTransport('/message', res);
598
+ await mcpServer.connect(sseTransport);
599
+ await sseTransport.handleRequest(req, res);
600
+ } catch (error) {
601
+ log(`/message error: ${error.message}`);
602
+ if (!res.headersSent) {
603
+ res.status(500).json({ error: 'Internal server error' });
604
+ }
605
+ }
606
+ });
607
+
499
608
  const httpServer = app.listen(config.port, config.host, async () => {
500
609
  await initCadConnection();
501
610
  console.error(`@lisp MCP Server 启动 - http://${config.host}:${config.port} - Streamable HTTP (SDK)`);
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.27';
11
+ export const SERVER_VERSION = '1.1.2';
12
12
 
13
13
  export const MOCK_PACKAGES = [
14
14
  { name: 'base', description: '基础函数库', version: '1.0.0' },