@neiracore/mcp-server 1.0.1 → 1.0.3

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,6 +88,12 @@ 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
+ }
91
97
  /**
92
98
  * Hot-reload credentials after registration (no server restart needed).
93
99
  */
@@ -329,11 +335,38 @@ function registerSearchTool(server, ctx) {
329
335
  InputSchema2,
330
336
  async (args) => {
331
337
  try {
332
- const client = ctx.requireAuth();
338
+ ctx.requireAuth();
333
339
  const aid = ctx.getAid();
340
+ const loginKey = ctx.getLoginKey();
334
341
  ctx.log("debug", `Searching: "${truncate(args.query, 50)}" limit=${args.limit}`);
335
- const result = await client.search(args.query, args.limit, aid);
336
- if (result.matches.length === 0) {
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) {
337
370
  return textResult(
338
371
  `\u{1F50D} No agents found matching "${args.query}".
339
372
 
@@ -380,20 +413,34 @@ function registerStatusTool(server, ctx) {
380
413
  InputSchema3,
381
414
  async (args) => {
382
415
  try {
383
- const client = ctx.requireAuth();
416
+ ctx.requireAuth();
384
417
  const targetAid = args.aid ?? ctx.getAid();
385
418
  const isSelf = !args.aid || args.aid === ctx.getAid();
386
419
  ctx.log("debug", `Status check for: ${targetAid.slice(0, 8)}...`);
387
- const result = await client.status(targetAid);
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();
388
434
  const lines = [
389
435
  isSelf ? "\u{1F4CA} Your Agent Status\n" : `\u{1F4CA} Agent Status: ${targetAid.slice(0, 8)}...
390
436
  `,
391
437
  formatSection("", [
392
438
  ["AID", result.aid],
439
+ ["Name", result.agent_name],
393
440
  ["Budget", `${result.budget_remaining} / ${result.budget_max} queries`],
394
- ["Searches", String(result.total_stage0_queries)],
395
- ["Matches", String(result.total_stage1_pairs)],
396
- ["Proposals", String(result.total_proposes)],
441
+ ["Searches", String(result.total_searches ?? 0)],
442
+ ["Matches", String(result.total_matches ?? 0)],
443
+ ["Messages", String(result.messages_sent ?? 0)],
397
444
  ["Last Query", result.last_query_at ?? "never"],
398
445
  ["Created", result.created_at]
399
446
  ])
@@ -423,8 +470,9 @@ function registerConnectTool(server, ctx) {
423
470
  InputSchema4,
424
471
  async (args) => {
425
472
  try {
426
- const client = ctx.requireAuth();
473
+ ctx.requireAuth();
427
474
  const creds = ctx.credentials;
475
+ const loginKey = ctx.getLoginKey();
428
476
  ctx.log("info", `Connecting to: ${args.target_aid.slice(0, 8)}...`);
429
477
  const enrichedMessage = [
430
478
  `[Connection Request from ${creds.agent_name}]`,
@@ -432,17 +480,41 @@ function registerConnectTool(server, ctx) {
432
480
  "",
433
481
  args.message
434
482
  ].join("\n");
435
- const result = await client.message.send({
436
- to: args.target_aid,
437
- content: enrichedMessage
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
+ })
438
497
  });
439
- ctx.log("info", `Connection sent: ${result.id}`);
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
512
  return textResult(
441
513
  `\u{1F91D} Connection request sent!
442
514
 
443
515
  To: ${args.target_aid.slice(0, 8)}...
444
516
  Message: ${truncate(args.message, 80)}
445
- Sent at: ${result.timestamp}
517
+ Sent at: ${ts}
446
518
 
447
519
  The target agent will see your name, capabilities, and message.`
448
520
  );
@@ -465,15 +537,40 @@ function registerSendMessageTool(server, ctx) {
465
537
  InputSchema5,
466
538
  async (args) => {
467
539
  try {
468
- const client = ctx.requireAuth();
540
+ ctx.requireAuth();
469
541
  const creds = ctx.credentials;
542
+ const loginKey = ctx.getLoginKey();
470
543
  ctx.log("info", `Sending ${args.message_type} to: ${args.to.slice(0, 8)}...`);
471
544
  const content = args.message_type === "text" ? args.content : `[${args.message_type.toUpperCase()}] ${args.content}`;
472
- const result = await client.message.send({
473
- to: args.to,
474
- 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
+ })
475
559
  });
476
- ctx.log("info", `Message sent: ${result.id}`);
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
574
  return textResult(
478
575
  `\u2709\uFE0F Message sent!
479
576
 
@@ -481,8 +578,8 @@ function registerSendMessageTool(server, ctx) {
481
578
  To: ${args.to.slice(0, 8)}...
482
579
  Type: ${args.message_type}
483
580
  Preview: ${truncate(args.content, 80)}
484
- Sent at: ${result.timestamp}
485
- ID: ${result.id}`
581
+ Sent at: ${ts}
582
+ ID: ${msgId}`
486
583
  );
487
584
  } catch (err) {
488
585
  ctx.log("error", `Send message failed: ${String(err)}`);