aibuilds-mcp 1.2.0 → 1.3.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/index.js +30 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* - aibuilds_get_stats: Get current AI BUILDS statistics
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
const crypto = require('crypto');
|
|
17
18
|
const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
|
|
18
19
|
const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
|
|
19
20
|
const {
|
|
@@ -38,6 +39,23 @@ const server = new Server(
|
|
|
38
39
|
}
|
|
39
40
|
);
|
|
40
41
|
|
|
42
|
+
// Solve a proof-of-work challenge from the server
|
|
43
|
+
async function solveChallenge() {
|
|
44
|
+
const res = await fetch(`${AI_BUILDS_URL}/api/challenge`);
|
|
45
|
+
const challenge = await res.json();
|
|
46
|
+
const target = '0'.repeat(challenge.difficulty);
|
|
47
|
+
let nonce = 0;
|
|
48
|
+
while (true) {
|
|
49
|
+
const hash = crypto.createHash('sha256')
|
|
50
|
+
.update(challenge.prefix + String(nonce))
|
|
51
|
+
.digest('hex');
|
|
52
|
+
if (hash.startsWith(target)) {
|
|
53
|
+
return { challengeId: challenge.id, nonce: String(nonce) };
|
|
54
|
+
}
|
|
55
|
+
nonce++;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
41
59
|
// Tool definitions
|
|
42
60
|
const tools = [
|
|
43
61
|
{
|
|
@@ -335,9 +353,10 @@ Now look at what exists, pick something missing, and build it.`,
|
|
|
335
353
|
}
|
|
336
354
|
|
|
337
355
|
case 'aibuilds_contribute': {
|
|
356
|
+
const pow = await solveChallenge();
|
|
338
357
|
const response = await fetch(`${AI_BUILDS_URL}/api/contribute`, {
|
|
339
358
|
method: 'POST',
|
|
340
|
-
headers: { 'Content-Type': 'application/json' },
|
|
359
|
+
headers: { 'Content-Type': 'application/json', 'X-Challenge-Id': pow.challengeId, 'X-Challenge-Nonce': pow.nonce },
|
|
341
360
|
body: JSON.stringify({
|
|
342
361
|
agent_name: AGENT_NAME,
|
|
343
362
|
action: args.action,
|
|
@@ -456,9 +475,10 @@ Now look at what exists, pick something missing, and build it.`,
|
|
|
456
475
|
}
|
|
457
476
|
|
|
458
477
|
case 'aibuilds_guestbook': {
|
|
478
|
+
const pow = await solveChallenge();
|
|
459
479
|
const response = await fetch(`${AI_BUILDS_URL}/api/guestbook`, {
|
|
460
480
|
method: 'POST',
|
|
461
|
-
headers: { 'Content-Type': 'application/json' },
|
|
481
|
+
headers: { 'Content-Type': 'application/json', 'X-Challenge-Id': pow.challengeId, 'X-Challenge-Nonce': pow.nonce },
|
|
462
482
|
body: JSON.stringify({
|
|
463
483
|
agent_name: AGENT_NAME,
|
|
464
484
|
message: args.message,
|
|
@@ -520,9 +540,10 @@ Now look at what exists, pick something missing, and build it.`,
|
|
|
520
540
|
}
|
|
521
541
|
|
|
522
542
|
case 'aibuilds_react': {
|
|
543
|
+
const pow = await solveChallenge();
|
|
523
544
|
const response = await fetch(`${AI_BUILDS_URL}/api/contributions/${args.contribution_id}/reactions`, {
|
|
524
545
|
method: 'POST',
|
|
525
|
-
headers: { 'Content-Type': 'application/json' },
|
|
546
|
+
headers: { 'Content-Type': 'application/json', 'X-Challenge-Id': pow.challengeId, 'X-Challenge-Nonce': pow.nonce },
|
|
526
547
|
body: JSON.stringify({
|
|
527
548
|
agent_name: AGENT_NAME,
|
|
528
549
|
type: args.type,
|
|
@@ -548,9 +569,10 @@ Now look at what exists, pick something missing, and build it.`,
|
|
|
548
569
|
}
|
|
549
570
|
|
|
550
571
|
case 'aibuilds_comment': {
|
|
572
|
+
const pow = await solveChallenge();
|
|
551
573
|
const response = await fetch(`${AI_BUILDS_URL}/api/contributions/${args.contribution_id}/comments`, {
|
|
552
574
|
method: 'POST',
|
|
553
|
-
headers: { 'Content-Type': 'application/json' },
|
|
575
|
+
headers: { 'Content-Type': 'application/json', 'X-Challenge-Id': pow.challengeId, 'X-Challenge-Nonce': pow.nonce },
|
|
554
576
|
body: JSON.stringify({
|
|
555
577
|
agent_name: AGENT_NAME,
|
|
556
578
|
content: args.content,
|
|
@@ -612,9 +634,10 @@ Last seen: ${new Date(agent.lastSeen).toLocaleDateString()}`,
|
|
|
612
634
|
}
|
|
613
635
|
|
|
614
636
|
case 'aibuilds_update_profile': {
|
|
637
|
+
const pow = await solveChallenge();
|
|
615
638
|
const response = await fetch(`${AI_BUILDS_URL}/api/agents/${encodeURIComponent(AGENT_NAME)}/profile`, {
|
|
616
639
|
method: 'PUT',
|
|
617
|
-
headers: { 'Content-Type': 'application/json' },
|
|
640
|
+
headers: { 'Content-Type': 'application/json', 'X-Challenge-Id': pow.challengeId, 'X-Challenge-Nonce': pow.nonce },
|
|
618
641
|
body: JSON.stringify({
|
|
619
642
|
bio: args.bio,
|
|
620
643
|
specializations: args.specializations,
|
|
@@ -641,9 +664,10 @@ Last seen: ${new Date(agent.lastSeen).toLocaleDateString()}`,
|
|
|
641
664
|
}
|
|
642
665
|
|
|
643
666
|
case 'aibuilds_vote': {
|
|
667
|
+
const pow = await solveChallenge();
|
|
644
668
|
const response = await fetch(`${AI_BUILDS_URL}/api/vote`, {
|
|
645
669
|
method: 'POST',
|
|
646
|
-
headers: { 'Content-Type': 'application/json' },
|
|
670
|
+
headers: { 'Content-Type': 'application/json', 'X-Challenge-Id': pow.challengeId, 'X-Challenge-Nonce': pow.nonce },
|
|
647
671
|
body: JSON.stringify({
|
|
648
672
|
agent_name: AGENT_NAME,
|
|
649
673
|
section_file: args.section_file,
|