agent2agent-cli 0.3.3 → 0.3.5

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/a2a-mcp.js +33 -7
  2. package/a2a.js +28 -0
  3. package/package.json +1 -1
package/a2a-mcp.js CHANGED
@@ -24,7 +24,7 @@ const fs = require('fs');
24
24
  const path = require('path');
25
25
  const readline = require('readline');
26
26
 
27
- const VERSION = '0.3.3';
27
+ const VERSION = '0.3.5';
28
28
  const PROTOCOL_VERSION = '2024-11-05'; // MCP 当前稳定协议版本
29
29
 
30
30
  /* ------------------------------------------------------------------ *
@@ -357,12 +357,29 @@ async function apiText(config, pathName) {
357
357
  /* ------------------------------------------------------------------ *
358
358
  * MCP stdio 传输(换行分隔 JSON-RPC 2.0)
359
359
  * ------------------------------------------------------------------ */
360
+ // 兼容的 MCP 协议版本(Cursor 可能请求较新版本,回显客户端请求值)
361
+ const KNOWN_PROTOCOLS = ['2024-11-05', '2025-03-26', '2025-06-18'];
362
+
363
+ /* 崩溃兜底:任何未捕获异常/拒绝都打印真实堆栈到 stderr(Cursor 会显示出来),便于定位 */
364
+ process.on('uncaughtException', (err) => {
365
+ console.error('[a2a-mcp] uncaughtException:', err && err.stack ? err.stack : err);
366
+ process.exit(1);
367
+ });
368
+ process.on('unhandledRejection', (err) => {
369
+ console.error('[a2a-mcp] unhandledRejection:', err && err.stack ? err.stack : err);
370
+ process.exit(1);
371
+ });
372
+
360
373
  function main() {
374
+ // 找不到配置不再退出:server 照常启动(tools 可用),调用工具时才给出明确指引
361
375
  const config = resolveConfig();
362
- if (!config.url) {
363
- console.error('[a2a-mcp] 未找到平台配置:请在项目根运行(含 .a2a.json),或设置 A2A_URL / A2A_TOKEN / A2A_ACCOUNT');
364
- console.error('[a2a-mcp] 首次接入:a2a init');
365
- process.exit(1);
376
+ const cfgMissing = !config.url;
377
+ if (cfgMissing) {
378
+ console.error(`[a2a-mcp v${VERSION}] 当前工作目录: ${process.cwd()}`);
379
+ console.error('[a2a-mcp] 未找到平台配置(.a2a.json):请在含 .a2a.json 的项目目录使用;');
380
+ console.error('[a2a-mcp] 或设置 A2A_URL / A2A_TOKEN / A2A_ACCOUNT 环境变量;首次接入:a2a init');
381
+ } else {
382
+ console.error(`[a2a-mcp v${VERSION}] 已加载配置: ${config.url}(账号: ${config.accountId || '?'})`);
366
383
  }
367
384
 
368
385
  const rl = readline.createInterface({ input: process.stdin, crlfDelay: Infinity });
@@ -397,14 +414,18 @@ function main() {
397
414
  err && err.message ? err.message : String(err));
398
415
 
399
416
  switch (method) {
400
- case 'initialize':
417
+ case 'initialize': {
401
418
  serverReady = true;
419
+ // 协议版本协商:回显客户端请求的已知版本,避免较新客户端不兼容
420
+ const reqVer = params && params.protocolVersion;
421
+ const ver = KNOWN_PROTOCOLS.includes(reqVer) ? reqVer : PROTOCOL_VERSION;
402
422
  finish({
403
- protocolVersion: PROTOCOL_VERSION,
423
+ protocolVersion: ver,
404
424
  capabilities: { tools: { listChanged: false } },
405
425
  serverInfo: { name: 'a2a-mcp', version: VERSION },
406
426
  });
407
427
  break;
428
+ }
408
429
  case 'ping':
409
430
  finish({});
410
431
  break;
@@ -413,6 +434,11 @@ function main() {
413
434
  break;
414
435
  case 'tools/call': {
415
436
  const { name, arguments: args } = params || {};
437
+ if (cfgMissing) {
438
+ const errText = '平台未配置:请在含 .a2a.json 的项目目录使用本 MCP(Cursor 的项目级 .cursor/mcp.json 会把工作目录设为项目根),或设置 A2A_URL/A2A_TOKEN/A2A_ACCOUNT 环境变量。首次接入运行 a2a init。';
439
+ finish({ isError: true, content: [{ type: 'text', text: errText }] });
440
+ break;
441
+ }
416
442
  callTool(config, name, args || {})
417
443
  .then((result) => {
418
444
  const text = typeof result === 'string' ? result : JSON.stringify(result, null, 2);
package/a2a.js CHANGED
@@ -1371,6 +1371,29 @@ async function cmdHeartbeat(opts, ctx) {
1371
1371
  );
1372
1372
  }
1373
1373
 
1374
+ /** `a2a mcp-setup`:在当前项目生成 .cursor/mcp.json(Cursor/Windsurf 用),使用绝对路径免 PATH 问题 */
1375
+ async function cmdMcpSetup() {
1376
+ const nodePath = process.execPath; // 当前 node 绝对路径(避免 Cursor 环境 PATH 无 node/nvm)
1377
+ const mcpPath = path.join(__dirname, 'a2a-mcp.js');
1378
+ if (!fs.existsSync(mcpPath)) {
1379
+ fail('未找到 a2a-mcp.js(' + mcpPath + ')。请使用 npm 全局安装:npm install -g agent2agent-cli');
1380
+ }
1381
+ const config = {
1382
+ mcpServers: {
1383
+ a2a: { command: nodePath, args: [mcpPath] },
1384
+ },
1385
+ };
1386
+ const dir = path.join(process.cwd(), '.cursor');
1387
+ fs.mkdirSync(dir, { recursive: true });
1388
+ const target = path.join(dir, 'mcp.json');
1389
+ fs.writeFileSync(target, JSON.stringify(config, null, 2) + '\n');
1390
+ console.log(paint(C.green, `已生成 ${target}`));
1391
+ console.log(' server: a2a(command=' + nodePath + ')');
1392
+ console.log('说明:该配置随项目提交,团队 clone 后无需再配;');
1393
+ console.log(' 请在当前项目(含 .a2a.json)使用,a2a-mcp 会自动匹配该项目账号。');
1394
+ console.log('重启 Cursor 后生效(MCP 面板应显示 13 个工具)。');
1395
+ }
1396
+
1374
1397
  /* ------------------------------------------------------------------------- *
1375
1398
  * 帮助
1376
1399
  * ------------------------------------------------------------------------- */
@@ -1397,6 +1420,7 @@ function printHelp() {
1397
1420
  ['sync', '双向镜像同步本地 doc 目录 ↔ 平台'],
1398
1421
  ['memory', '记忆(get / set)'],
1399
1422
  ['heartbeat', '心跳'],
1423
+ ['mcp-setup', '生成 .cursor/mcp.json(Cursor/Windsurf MCP 接入)'],
1400
1424
  ['update-check', '检查各组件是否有新版本'],
1401
1425
  ['update', '一键更新 CLI + skills'],
1402
1426
  ['update-skills', '更新已安装的 skills(--to 指定目录 / --yes 免确认)'],
@@ -1491,6 +1515,10 @@ async function main() {
1491
1515
  await cmdUpdate(opts);
1492
1516
  return;
1493
1517
  }
1518
+ if (cmd === 'mcp-setup') {
1519
+ await cmdMcpSetup();
1520
+ return;
1521
+ }
1494
1522
  if (cmd === 'update-check') {
1495
1523
  // 有 .a2a.json 则附带平台版本对比;无配置只检查 CLI / skills
1496
1524
  let cfg = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent2agent-cli",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Agent2Agent 统一 CLI(命令名 a2a):跨 AI 编程代理协作平台的命令行客户端 — 异步消息、任务看板、文档双向同步、持久记忆",
5
5
  "bin": {
6
6
  "a2a": "a2a.js",