@atlisp/mcp 1.1.0 → 1.1.1
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 +1 -1
- package/src/atlisp-mcp.js +85 -4
package/package.json
CHANGED
package/src/atlisp-mcp.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { fileURLToPath } from 'url';
|
|
2
1
|
import path from 'path';
|
|
3
|
-
import {
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
4
|
|
|
5
5
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
const { version } = require(path.join(__dirname, '..', 'package.json'));
|
|
6
8
|
|
|
7
9
|
if (process.argv[1]?.endsWith('atlisp-mcp.js')) {
|
|
8
10
|
const args = process.argv.slice(2);
|
|
9
11
|
for (let i = 0; i < args.length; i++) {
|
|
10
12
|
if (args[i] === '--version' || args[i] === '-v') {
|
|
11
|
-
console.log(`atlisp-mcp v${
|
|
13
|
+
console.log(`atlisp-mcp v${version}`);
|
|
12
14
|
process.exit(0);
|
|
13
15
|
} else if (args[i] === '--help' || args[i] === '-h') {
|
|
14
16
|
console.log(`
|
|
15
|
-
@lisp MCP Server v${
|
|
17
|
+
@lisp MCP Server v${version}
|
|
16
18
|
|
|
17
19
|
Usage: atlisp-mcp [options]
|
|
18
20
|
|
|
@@ -44,6 +46,7 @@ const { decode: charsetDecode, encodingExists } = iconv;
|
|
|
44
46
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
45
47
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
46
48
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
49
|
+
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
|
47
50
|
import {
|
|
48
51
|
ListToolsRequestSchema,
|
|
49
52
|
CallToolRequestSchema,
|
|
@@ -496,6 +499,84 @@ export async function startServer() {
|
|
|
496
499
|
}
|
|
497
500
|
});
|
|
498
501
|
|
|
502
|
+
const sseEndpoint = '/sse';
|
|
503
|
+
app.get(sseEndpoint, async (req, res) => {
|
|
504
|
+
const sseTransport = new SSEServerTransport(sseEndpoint, res);
|
|
505
|
+
try {
|
|
506
|
+
await mcpServer.connect(sseTransport);
|
|
507
|
+
await sseTransport.handleRequest(req, res);
|
|
508
|
+
} catch (error) {
|
|
509
|
+
log(`SSE transport error: ${error.message}`);
|
|
510
|
+
if (!res.headersSent) {
|
|
511
|
+
res.status(500).json({ error: 'Internal server error' });
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
app.post(sseEndpoint, mcpLimiter, async (req, res) => {
|
|
516
|
+
const sessionId = req.headers['mcp-session-id'];
|
|
517
|
+
const sseTransport = sessionId ? sseEndpoint + '?sessionId=' + sessionId : sseEndpoint;
|
|
518
|
+
try {
|
|
519
|
+
const transport = new SSEServerTransport(sseEndpoint, res);
|
|
520
|
+
await mcpServer.connect(transport);
|
|
521
|
+
await transport.handleRequest(req, res);
|
|
522
|
+
} catch (error) {
|
|
523
|
+
log(`SSE POST error: ${error.message}`);
|
|
524
|
+
if (!res.headersSent) {
|
|
525
|
+
res.status(500).json({ error: 'Internal server error' });
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
app.get('/mcp/sse', async (req, res) => {
|
|
531
|
+
const sseTransport = new SSEServerTransport('/mcp/sse', res);
|
|
532
|
+
try {
|
|
533
|
+
await mcpServer.connect(sseTransport);
|
|
534
|
+
await sseTransport.handleRequest(req, res);
|
|
535
|
+
} catch (error) {
|
|
536
|
+
log(`/mcp/sse transport error: ${error.message}`);
|
|
537
|
+
if (!res.headersSent) {
|
|
538
|
+
res.status(500).json({ error: 'Internal server error' });
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
app.post('/mcp/sse', mcpLimiter, async (req, res) => {
|
|
543
|
+
const sseTransport = new SSEServerTransport('/mcp/sse', res);
|
|
544
|
+
try {
|
|
545
|
+
await mcpServer.connect(sseTransport);
|
|
546
|
+
await sseTransport.handleRequest(req, res);
|
|
547
|
+
} catch (error) {
|
|
548
|
+
log(`/mcp/sse POST error: ${error.message}`);
|
|
549
|
+
if (!res.headersSent) {
|
|
550
|
+
res.status(500).json({ error: 'Internal server error' });
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
app.get('/mcp/stream', async (req, res) => {
|
|
556
|
+
try {
|
|
557
|
+
await transport.handleRequest(req, res, req.body);
|
|
558
|
+
} catch (error) {
|
|
559
|
+
log(`/mcp/stream error: ${error.message}`);
|
|
560
|
+
if (!res.headersSent) {
|
|
561
|
+
res.status(500).json({ error: 'Internal server error' });
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
app.post('/message', mcpLimiter, async (req, res) => {
|
|
567
|
+
try {
|
|
568
|
+
const sessionId = req.headers['mcp-session-id'];
|
|
569
|
+
const sseTransport = new SSEServerTransport('/message', res);
|
|
570
|
+
await mcpServer.connect(sseTransport);
|
|
571
|
+
await sseTransport.handleRequest(req, res);
|
|
572
|
+
} catch (error) {
|
|
573
|
+
log(`/message error: ${error.message}`);
|
|
574
|
+
if (!res.headersSent) {
|
|
575
|
+
res.status(500).json({ error: 'Internal server error' });
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
|
|
499
580
|
const httpServer = app.listen(config.port, config.host, async () => {
|
|
500
581
|
await initCadConnection();
|
|
501
582
|
console.error(`@lisp MCP Server 启动 - http://${config.host}:${config.port} - Streamable HTTP (SDK)`);
|