@neiracore/mcp-server 1.0.3 → 1.1.0

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/dist/index.js CHANGED
@@ -112,12 +112,6 @@ var ServerContext = class {
112
112
  getAid() {
113
113
  return this.credentials?.aid ?? null;
114
114
  }
115
- /**
116
- * Get the current login key (nk_...) or null.
117
- */
118
- getLoginKey() {
119
- return this.credentials?.login_key ?? null;
120
- }
121
115
  /**
122
116
  * Hot-reload credentials after registration (no server restart needed).
123
117
  */
@@ -359,38 +353,11 @@ function registerSearchTool(server, ctx) {
359
353
  InputSchema2,
360
354
  async (args) => {
361
355
  try {
362
- ctx.requireAuth();
356
+ const client = ctx.requireAuth();
363
357
  const aid = ctx.getAid();
364
- const loginKey = ctx.getLoginKey();
365
358
  ctx.log("debug", `Searching: "${truncate(args.query, 50)}" limit=${args.limit}`);
366
- const body = {
367
- aid,
368
- looking_for: args.query
369
- };
370
- if (args.limit !== void 0) body.limit = args.limit;
371
- const headers = {
372
- "Content-Type": "application/json"
373
- };
374
- if (loginKey) {
375
- headers["Authorization"] = `Bearer ${loginKey}`;
376
- }
377
- const res = await fetch(`${ctx.getBaseUrl()}/api/acsp/search`, {
378
- method: "POST",
379
- headers,
380
- body: JSON.stringify(body)
381
- });
382
- if (!res.ok) {
383
- const text = await res.text();
384
- let msg = `Search failed (HTTP ${res.status})`;
385
- try {
386
- const err = JSON.parse(text);
387
- if (err.message) msg = err.message;
388
- } catch {
389
- }
390
- return textResult(`\u274C ${msg}`);
391
- }
392
- const result = await res.json();
393
- if (!result.matches || result.matches.length === 0) {
359
+ const result = await client.search(args.query, args.limit, aid);
360
+ if (result.matches.length === 0) {
394
361
  return textResult(
395
362
  `\u{1F50D} No agents found matching "${args.query}".
396
363
 
@@ -437,24 +404,11 @@ function registerStatusTool(server, ctx) {
437
404
  InputSchema3,
438
405
  async (args) => {
439
406
  try {
440
- ctx.requireAuth();
407
+ const client = ctx.requireAuth();
441
408
  const targetAid = args.aid ?? ctx.getAid();
442
409
  const isSelf = !args.aid || args.aid === ctx.getAid();
443
410
  ctx.log("debug", `Status check for: ${targetAid.slice(0, 8)}...`);
444
- const res = await fetch(
445
- `${ctx.getBaseUrl()}/api/acsp/status?aid=${targetAid}`
446
- );
447
- if (!res.ok) {
448
- const text = await res.text();
449
- let msg = `Status check failed (HTTP ${res.status})`;
450
- try {
451
- const err = JSON.parse(text);
452
- if (err.message) msg = err.message;
453
- } catch {
454
- }
455
- return textResult(`\u274C ${msg}`);
456
- }
457
- const result = await res.json();
411
+ const result = await client.status(targetAid);
458
412
  const lines = [
459
413
  isSelf ? "\u{1F4CA} Your Agent Status\n" : `\u{1F4CA} Agent Status: ${targetAid.slice(0, 8)}...
460
414
  `,
@@ -494,9 +448,8 @@ function registerConnectTool(server, ctx) {
494
448
  InputSchema4,
495
449
  async (args) => {
496
450
  try {
497
- ctx.requireAuth();
451
+ const client = ctx.requireAuth();
498
452
  const creds = ctx.credentials;
499
- const loginKey = ctx.getLoginKey();
500
453
  ctx.log("info", `Connecting to: ${args.target_aid.slice(0, 8)}...`);
501
454
  const enrichedMessage = [
502
455
  `[Connection Request from ${creds.agent_name}]`,
@@ -504,41 +457,17 @@ function registerConnectTool(server, ctx) {
504
457
  "",
505
458
  args.message
506
459
  ].join("\n");
507
- const headers = {
508
- "Content-Type": "application/json"
509
- };
510
- if (loginKey) {
511
- headers["Authorization"] = `Bearer ${loginKey}`;
512
- }
513
- const res = await fetch(`${ctx.getBaseUrl()}/api/acsp/message/send`, {
514
- method: "POST",
515
- headers,
516
- body: JSON.stringify({
517
- sender_aid: creds.aid,
518
- recipient_aid: args.target_aid,
519
- content: enrichedMessage
520
- })
460
+ const result = await client.message.send({
461
+ to: args.target_aid,
462
+ content: enrichedMessage
521
463
  });
522
- if (!res.ok) {
523
- const text = await res.text();
524
- let msg = `Connect failed (HTTP ${res.status})`;
525
- try {
526
- const err = JSON.parse(text);
527
- if (err.message) msg = err.message;
528
- } catch {
529
- }
530
- return textResult(`\u274C ${msg}`);
531
- }
532
- const result = await res.json();
533
- const msgId = result.message_id ?? result.id ?? "sent";
534
- const ts = result.created_at ?? result.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
535
- ctx.log("info", `Connection sent: ${msgId}`);
464
+ ctx.log("info", `Connection sent: ${result.message_id}`);
536
465
  return textResult(
537
466
  `\u{1F91D} Connection request sent!
538
467
 
539
468
  To: ${args.target_aid.slice(0, 8)}...
540
469
  Message: ${truncate(args.message, 80)}
541
- Sent at: ${ts}
470
+ ID: ${result.message_id}
542
471
 
543
472
  The target agent will see your name, capabilities, and message.`
544
473
  );
@@ -561,40 +490,15 @@ function registerSendMessageTool(server, ctx) {
561
490
  InputSchema5,
562
491
  async (args) => {
563
492
  try {
564
- ctx.requireAuth();
493
+ const client = ctx.requireAuth();
565
494
  const creds = ctx.credentials;
566
- const loginKey = ctx.getLoginKey();
567
495
  ctx.log("info", `Sending ${args.message_type} to: ${args.to.slice(0, 8)}...`);
568
496
  const content = args.message_type === "text" ? args.content : `[${args.message_type.toUpperCase()}] ${args.content}`;
569
- const headers = {
570
- "Content-Type": "application/json"
571
- };
572
- if (loginKey) {
573
- headers["Authorization"] = `Bearer ${loginKey}`;
574
- }
575
- const res = await fetch(`${ctx.getBaseUrl()}/api/acsp/message/send`, {
576
- method: "POST",
577
- headers,
578
- body: JSON.stringify({
579
- sender_aid: creds.aid,
580
- recipient_aid: args.to,
581
- content
582
- })
497
+ const result = await client.message.send({
498
+ to: args.to,
499
+ content
583
500
  });
584
- if (!res.ok) {
585
- const text = await res.text();
586
- let msg = `Send failed (HTTP ${res.status})`;
587
- try {
588
- const err = JSON.parse(text);
589
- if (err.message) msg = err.message;
590
- } catch {
591
- }
592
- return textResult(`\u274C ${msg}`);
593
- }
594
- const result = await res.json();
595
- const msgId = result.message_id ?? result.id ?? "sent";
596
- const ts = result.created_at ?? result.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
597
- ctx.log("info", `Message sent: ${msgId}`);
501
+ ctx.log("info", `Message sent: ${result.message_id}`);
598
502
  return textResult(
599
503
  `\u2709\uFE0F Message sent!
600
504
 
@@ -602,8 +506,7 @@ function registerSendMessageTool(server, ctx) {
602
506
  To: ${args.to.slice(0, 8)}...
603
507
  Type: ${args.message_type}
604
508
  Preview: ${truncate(args.content, 80)}
605
- Sent at: ${ts}
606
- ID: ${msgId}`
509
+ ID: ${result.message_id}`
607
510
  );
608
511
  } catch (err) {
609
512
  ctx.log("error", `Send message failed: ${String(err)}`);