@neiracore/mcp-server 1.0.2 → 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.js +118 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +118 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -112,6 +112,12 @@ 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
|
+
}
|
|
115
121
|
/**
|
|
116
122
|
* Hot-reload credentials after registration (no server restart needed).
|
|
117
123
|
*/
|
|
@@ -353,11 +359,38 @@ function registerSearchTool(server, ctx) {
|
|
|
353
359
|
InputSchema2,
|
|
354
360
|
async (args) => {
|
|
355
361
|
try {
|
|
356
|
-
|
|
362
|
+
ctx.requireAuth();
|
|
357
363
|
const aid = ctx.getAid();
|
|
364
|
+
const loginKey = ctx.getLoginKey();
|
|
358
365
|
ctx.log("debug", `Searching: "${truncate(args.query, 50)}" limit=${args.limit}`);
|
|
359
|
-
const
|
|
360
|
-
|
|
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) {
|
|
361
394
|
return textResult(
|
|
362
395
|
`\u{1F50D} No agents found matching "${args.query}".
|
|
363
396
|
|
|
@@ -404,20 +437,34 @@ function registerStatusTool(server, ctx) {
|
|
|
404
437
|
InputSchema3,
|
|
405
438
|
async (args) => {
|
|
406
439
|
try {
|
|
407
|
-
|
|
440
|
+
ctx.requireAuth();
|
|
408
441
|
const targetAid = args.aid ?? ctx.getAid();
|
|
409
442
|
const isSelf = !args.aid || args.aid === ctx.getAid();
|
|
410
443
|
ctx.log("debug", `Status check for: ${targetAid.slice(0, 8)}...`);
|
|
411
|
-
const
|
|
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();
|
|
412
458
|
const lines = [
|
|
413
459
|
isSelf ? "\u{1F4CA} Your Agent Status\n" : `\u{1F4CA} Agent Status: ${targetAid.slice(0, 8)}...
|
|
414
460
|
`,
|
|
415
461
|
formatSection("", [
|
|
416
462
|
["AID", result.aid],
|
|
463
|
+
["Name", result.agent_name],
|
|
417
464
|
["Budget", `${result.budget_remaining} / ${result.budget_max} queries`],
|
|
418
|
-
["Searches", String(result.
|
|
419
|
-
["Matches", String(result.
|
|
420
|
-
["
|
|
465
|
+
["Searches", String(result.total_searches ?? 0)],
|
|
466
|
+
["Matches", String(result.total_matches ?? 0)],
|
|
467
|
+
["Messages", String(result.messages_sent ?? 0)],
|
|
421
468
|
["Last Query", result.last_query_at ?? "never"],
|
|
422
469
|
["Created", result.created_at]
|
|
423
470
|
])
|
|
@@ -447,8 +494,9 @@ function registerConnectTool(server, ctx) {
|
|
|
447
494
|
InputSchema4,
|
|
448
495
|
async (args) => {
|
|
449
496
|
try {
|
|
450
|
-
|
|
497
|
+
ctx.requireAuth();
|
|
451
498
|
const creds = ctx.credentials;
|
|
499
|
+
const loginKey = ctx.getLoginKey();
|
|
452
500
|
ctx.log("info", `Connecting to: ${args.target_aid.slice(0, 8)}...`);
|
|
453
501
|
const enrichedMessage = [
|
|
454
502
|
`[Connection Request from ${creds.agent_name}]`,
|
|
@@ -456,17 +504,41 @@ function registerConnectTool(server, ctx) {
|
|
|
456
504
|
"",
|
|
457
505
|
args.message
|
|
458
506
|
].join("\n");
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
|
|
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
|
+
})
|
|
462
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
536
|
return textResult(
|
|
465
537
|
`\u{1F91D} Connection request sent!
|
|
466
538
|
|
|
467
539
|
To: ${args.target_aid.slice(0, 8)}...
|
|
468
540
|
Message: ${truncate(args.message, 80)}
|
|
469
|
-
Sent at: ${
|
|
541
|
+
Sent at: ${ts}
|
|
470
542
|
|
|
471
543
|
The target agent will see your name, capabilities, and message.`
|
|
472
544
|
);
|
|
@@ -489,15 +561,40 @@ function registerSendMessageTool(server, ctx) {
|
|
|
489
561
|
InputSchema5,
|
|
490
562
|
async (args) => {
|
|
491
563
|
try {
|
|
492
|
-
|
|
564
|
+
ctx.requireAuth();
|
|
493
565
|
const creds = ctx.credentials;
|
|
566
|
+
const loginKey = ctx.getLoginKey();
|
|
494
567
|
ctx.log("info", `Sending ${args.message_type} to: ${args.to.slice(0, 8)}...`);
|
|
495
568
|
const content = args.message_type === "text" ? args.content : `[${args.message_type.toUpperCase()}] ${args.content}`;
|
|
496
|
-
const
|
|
497
|
-
|
|
498
|
-
|
|
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
|
+
})
|
|
499
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
598
|
return textResult(
|
|
502
599
|
`\u2709\uFE0F Message sent!
|
|
503
600
|
|
|
@@ -505,8 +602,8 @@ function registerSendMessageTool(server, ctx) {
|
|
|
505
602
|
To: ${args.to.slice(0, 8)}...
|
|
506
603
|
Type: ${args.message_type}
|
|
507
604
|
Preview: ${truncate(args.content, 80)}
|
|
508
|
-
Sent at: ${
|
|
509
|
-
ID: ${
|
|
605
|
+
Sent at: ${ts}
|
|
606
|
+
ID: ${msgId}`
|
|
510
607
|
);
|
|
511
608
|
} catch (err) {
|
|
512
609
|
ctx.log("error", `Send message failed: ${String(err)}`);
|