@atlisp/mcp 1.0.8 → 1.0.9

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +25 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlisp/mcp",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "MCP Server for @lisp on CAD",
5
5
  "type": "module",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -198,8 +198,8 @@ async function handleToolCall(name, args) {
198
198
 
199
199
  case 'at_command':
200
200
  if (!cad.connected) return { content: [{ type: 'text', text: '请先连接 CAD' }], isError: true };
201
- await cad.sendCommand(`@${args.command}\n`);
202
- return { content: [{ type: 'text', text: `已发送命令: @${args.command}` }] };
201
+ await cad.sendCommand(`${args.command}\n`);
202
+ return { content: [{ type: 'text', text: `已发送命令: ${args.command}` }] };
203
203
 
204
204
  case 'new_document':
205
205
  if (!cad.connected) { await cad.connect(); }
@@ -239,7 +239,7 @@ async function initCadConnection() {
239
239
 
240
240
  function createMcpServer() {
241
241
  const server = new Server(
242
- { name: 'atlisp-mcp-server', version: '1.0.8' },
242
+ { name: 'atlisp-mcp-server', version: '1.0.9' },
243
243
  { capabilities: { tools: {} } }
244
244
  );
245
245
 
@@ -264,7 +264,7 @@ if (TRANSPORT === 'stdio') {
264
264
  app.use(express.json({ type: ['application/json', 'application/json-rpc'] }));
265
265
 
266
266
  app.get('/health', (req, res) => {
267
- return res.json({ status: 'ok', cad: cad.connected ? 'connected' : 'disconnected' });
267
+ res.json({ status: 'ok', cad: cad.connected ? 'connected' : 'disconnected' });
268
268
  });
269
269
 
270
270
  let mcpServer = null;
@@ -276,29 +276,41 @@ if (TRANSPORT === 'stdio') {
276
276
  }
277
277
 
278
278
  const { method, params, id } = req.body || {};
279
+ const accept = req.get('Accept') || '';
280
+ log('accept: "' + accept + '", wantsSSE: ' + accept.includes('text/event-stream'));
279
281
 
280
- res.setHeader('Content-Type', 'application/json');
281
282
  res.setHeader('mcp-session-id', sessionId);
282
283
 
284
+ const sendResponse = (data) => {
285
+ const json = JSON.stringify(data);
286
+ if (accept.includes('text/event-stream')) {
287
+ res.setHeader('Content-Type', 'text/event-stream');
288
+ return res.end('data: ' + json + '\n\n');
289
+ } else {
290
+ res.setHeader('Content-Type', 'application/json');
291
+ return res.end(json);
292
+ }
293
+ };
294
+
283
295
  if (!id) {
284
296
  return res.status(204).end();
285
297
  }
286
298
 
287
299
  try {
288
300
  if (method === 'initialize') {
289
- return res.json({
301
+ sendResponse({
290
302
  jsonrpc: '2.0',
291
303
  id,
292
304
  result: {
293
305
  protocolVersion: '2024-11-05',
294
306
  capabilities: { tools: {} },
295
- serverInfo: { name: 'atlisp-mcp-server', version: '1.0.8' }
307
+ serverInfo: { name: 'atlisp-mcp-server', version: '1.0.9' }
296
308
  }
297
309
  });
298
310
  }
299
311
 
300
312
  if (method === 'tools/list') {
301
- return res.json({
313
+ sendResponse({
302
314
  jsonrpc: '2.0',
303
315
  id,
304
316
  result: { tools }
@@ -308,18 +320,20 @@ if (TRANSPORT === 'stdio') {
308
320
  if (method === 'tools/call') {
309
321
  const toolName = params?.name;
310
322
  if (!toolName) {
311
- return res.json({
323
+ sendResponse({
312
324
  jsonrpc: '2.0',
313
325
  id,
314
326
  error: { code: -32602, message: 'Invalid params: missing tool name' }
315
327
  });
328
+ return;
316
329
  }
317
330
  const toolArgs = params?.arguments || {};
318
331
  const result = await handleToolCall(toolName, toolArgs);
319
- return res.json({ jsonrpc: '2.0', id, result });
332
+ sendResponse({ jsonrpc: '2.0', id, result });
333
+ return;
320
334
  }
321
335
 
322
- return res.json({
336
+ sendResponse({
323
337
  jsonrpc: '2.0',
324
338
  id,
325
339
  error: { code: -32601, message: 'Method not found' }