xiaozhou-chat 1.0.25 → 1.0.26

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 (3) hide show
  1. package/bin/cli.js +14 -2
  2. package/lib/chat.js +6 -12
  3. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -253,6 +253,13 @@ async function mainChat(input) {
253
253
  // 准备 Tools
254
254
  const tools = [...builtInTools];
255
255
 
256
+ // 合并 MCP Tools
257
+ for (const client of mcpClients.values()) {
258
+ if (client.initialized && client.tools.length > 0) {
259
+ tools.push(...client.getOpenAITools());
260
+ }
261
+ }
262
+
256
263
  abortController = new AbortController();
257
264
 
258
265
  const ctx = {
@@ -497,8 +504,13 @@ ${JSON.stringify(toCompress)}
497
504
  }
498
505
 
499
506
  // Default: Chat
500
- await mainChat(input);
501
- rl.prompt();
507
+ isProcessing = true;
508
+ try {
509
+ await mainChat(input);
510
+ } finally {
511
+ isProcessing = false;
512
+ rl.prompt();
513
+ }
502
514
  });
503
515
 
504
516
  function addToContext(content) {
package/lib/chat.js CHANGED
@@ -438,25 +438,19 @@ export async function chatStream(context, userInput = null, options = {}) {
438
438
 
439
439
  // 2. Try MCP
440
440
  if (!result && mcpClients) {
441
- // Find which client has this tool?
442
- // We assume caller knows or we iterate.
443
- // For now, simplify: mcpClients is a Map<name, client>
444
- // We need to know which client provides which tool.
445
- // Or we iterate all clients (slow?).
446
- // In original cli.js, it wasn't fully implemented for *execution* via MCP map iteration?
447
- // Ah, original cli.js didn't iterate mcpClients for execution in the snippet I saw.
448
- // It only had `builtInTools`.
449
- // But the todo said "integrate MCP support".
450
- // I should check if I missed MCP execution logic.
451
- // Assuming mcpClients have a `callTool` method.
452
441
  for (const client of mcpClients.values()) {
442
+ // Optimization: Check if client has the tool before calling
443
+ if (!client.tools.some(t => t.name === funcName)) continue;
444
+
453
445
  try {
454
446
  const mcpRes = await client.callTool(funcName, args);
455
447
  if (mcpRes) {
456
448
  result = JSON.stringify(mcpRes);
457
449
  break;
458
450
  }
459
- } catch {}
451
+ } catch (e) {
452
+ console.error(`MCP Call Error (${funcName}):`, e.message);
453
+ }
460
454
  }
461
455
  }
462
456
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xiaozhou-chat",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "description": "CLI chatbot based on NewAPI",
5
5
  "bin": {
6
6
  "xiaozhou-chat": "bin/cli.js"