@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.mjs CHANGED
@@ -88,12 +88,6 @@ var ServerContext = class {
88
88
  getAid() {
89
89
  return this.credentials?.aid ?? null;
90
90
  }
91
- /**
92
- * Get the current login key (nk_...) or null.
93
- */
94
- getLoginKey() {
95
- return this.credentials?.login_key ?? null;
96
- }
97
91
  /**
98
92
  * Hot-reload credentials after registration (no server restart needed).
99
93
  */
@@ -335,38 +329,11 @@ function registerSearchTool(server, ctx) {
335
329
  InputSchema2,
336
330
  async (args) => {
337
331
  try {
338
- ctx.requireAuth();
332
+ const client = ctx.requireAuth();
339
333
  const aid = ctx.getAid();
340
- const loginKey = ctx.getLoginKey();
341
334
  ctx.log("debug", `Searching: "${truncate(args.query, 50)}" limit=${args.limit}`);
342
- const body = {
343
- aid,
344
- looking_for: args.query
345
- };
346
- if (args.limit !== void 0) body.limit = args.limit;
347
- const headers = {
348
- "Content-Type": "application/json"
349
- };
350
- if (loginKey) {
351
- headers["Authorization"] = `Bearer ${loginKey}`;
352
- }
353
- const res = await fetch(`${ctx.getBaseUrl()}/api/acsp/search`, {
354
- method: "POST",
355
- headers,
356
- body: JSON.stringify(body)
357
- });
358
- if (!res.ok) {
359
- const text = await res.text();
360
- let msg = `Search failed (HTTP ${res.status})`;
361
- try {
362
- const err = JSON.parse(text);
363
- if (err.message) msg = err.message;
364
- } catch {
365
- }
366
- return textResult(`\u274C ${msg}`);
367
- }
368
- const result = await res.json();
369
- if (!result.matches || result.matches.length === 0) {
335
+ const result = await client.search(args.query, args.limit, aid);
336
+ if (result.matches.length === 0) {
370
337
  return textResult(
371
338
  `\u{1F50D} No agents found matching "${args.query}".
372
339
 
@@ -413,24 +380,11 @@ function registerStatusTool(server, ctx) {
413
380
  InputSchema3,
414
381
  async (args) => {
415
382
  try {
416
- ctx.requireAuth();
383
+ const client = ctx.requireAuth();
417
384
  const targetAid = args.aid ?? ctx.getAid();
418
385
  const isSelf = !args.aid || args.aid === ctx.getAid();
419
386
  ctx.log("debug", `Status check for: ${targetAid.slice(0, 8)}...`);
420
- const res = await fetch(
421
- `${ctx.getBaseUrl()}/api/acsp/status?aid=${targetAid}`
422
- );
423
- if (!res.ok) {
424
- const text = await res.text();
425
- let msg = `Status check failed (HTTP ${res.status})`;
426
- try {
427
- const err = JSON.parse(text);
428
- if (err.message) msg = err.message;
429
- } catch {
430
- }
431
- return textResult(`\u274C ${msg}`);
432
- }
433
- const result = await res.json();
387
+ const result = await client.status(targetAid);
434
388
  const lines = [
435
389
  isSelf ? "\u{1F4CA} Your Agent Status\n" : `\u{1F4CA} Agent Status: ${targetAid.slice(0, 8)}...
436
390
  `,
@@ -470,9 +424,8 @@ function registerConnectTool(server, ctx) {
470
424
  InputSchema4,
471
425
  async (args) => {
472
426
  try {
473
- ctx.requireAuth();
427
+ const client = ctx.requireAuth();
474
428
  const creds = ctx.credentials;
475
- const loginKey = ctx.getLoginKey();
476
429
  ctx.log("info", `Connecting to: ${args.target_aid.slice(0, 8)}...`);
477
430
  const enrichedMessage = [
478
431
  `[Connection Request from ${creds.agent_name}]`,
@@ -480,41 +433,17 @@ function registerConnectTool(server, ctx) {
480
433
  "",
481
434
  args.message
482
435
  ].join("\n");
483
- const headers = {
484
- "Content-Type": "application/json"
485
- };
486
- if (loginKey) {
487
- headers["Authorization"] = `Bearer ${loginKey}`;
488
- }
489
- const res = await fetch(`${ctx.getBaseUrl()}/api/acsp/message/send`, {
490
- method: "POST",
491
- headers,
492
- body: JSON.stringify({
493
- sender_aid: creds.aid,
494
- recipient_aid: args.target_aid,
495
- content: enrichedMessage
496
- })
436
+ const result = await client.message.send({
437
+ to: args.target_aid,
438
+ content: enrichedMessage
497
439
  });
498
- if (!res.ok) {
499
- const text = await res.text();
500
- let msg = `Connect failed (HTTP ${res.status})`;
501
- try {
502
- const err = JSON.parse(text);
503
- if (err.message) msg = err.message;
504
- } catch {
505
- }
506
- return textResult(`\u274C ${msg}`);
507
- }
508
- const result = await res.json();
509
- const msgId = result.message_id ?? result.id ?? "sent";
510
- const ts = result.created_at ?? result.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
511
- ctx.log("info", `Connection sent: ${msgId}`);
440
+ ctx.log("info", `Connection sent: ${result.message_id}`);
512
441
  return textResult(
513
442
  `\u{1F91D} Connection request sent!
514
443
 
515
444
  To: ${args.target_aid.slice(0, 8)}...
516
445
  Message: ${truncate(args.message, 80)}
517
- Sent at: ${ts}
446
+ ID: ${result.message_id}
518
447
 
519
448
  The target agent will see your name, capabilities, and message.`
520
449
  );
@@ -537,40 +466,15 @@ function registerSendMessageTool(server, ctx) {
537
466
  InputSchema5,
538
467
  async (args) => {
539
468
  try {
540
- ctx.requireAuth();
469
+ const client = ctx.requireAuth();
541
470
  const creds = ctx.credentials;
542
- const loginKey = ctx.getLoginKey();
543
471
  ctx.log("info", `Sending ${args.message_type} to: ${args.to.slice(0, 8)}...`);
544
472
  const content = args.message_type === "text" ? args.content : `[${args.message_type.toUpperCase()}] ${args.content}`;
545
- const headers = {
546
- "Content-Type": "application/json"
547
- };
548
- if (loginKey) {
549
- headers["Authorization"] = `Bearer ${loginKey}`;
550
- }
551
- const res = await fetch(`${ctx.getBaseUrl()}/api/acsp/message/send`, {
552
- method: "POST",
553
- headers,
554
- body: JSON.stringify({
555
- sender_aid: creds.aid,
556
- recipient_aid: args.to,
557
- content
558
- })
473
+ const result = await client.message.send({
474
+ to: args.to,
475
+ content
559
476
  });
560
- if (!res.ok) {
561
- const text = await res.text();
562
- let msg = `Send failed (HTTP ${res.status})`;
563
- try {
564
- const err = JSON.parse(text);
565
- if (err.message) msg = err.message;
566
- } catch {
567
- }
568
- return textResult(`\u274C ${msg}`);
569
- }
570
- const result = await res.json();
571
- const msgId = result.message_id ?? result.id ?? "sent";
572
- const ts = result.created_at ?? result.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
573
- ctx.log("info", `Message sent: ${msgId}`);
477
+ ctx.log("info", `Message sent: ${result.message_id}`);
574
478
  return textResult(
575
479
  `\u2709\uFE0F Message sent!
576
480
 
@@ -578,8 +482,7 @@ function registerSendMessageTool(server, ctx) {
578
482
  To: ${args.to.slice(0, 8)}...
579
483
  Type: ${args.message_type}
580
484
  Preview: ${truncate(args.content, 80)}
581
- Sent at: ${ts}
582
- ID: ${msgId}`
485
+ ID: ${result.message_id}`
583
486
  );
584
487
  } catch (err) {
585
488
  ctx.log("error", `Send message failed: ${String(err)}`);