nodebb-plugin-integration 0.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.
@@ -0,0 +1,654 @@
1
+ "use strict";
2
+
3
+ /*
4
+
5
+ NodeBB Integration Layer
6
+
7
+
8
+ MCP Tools
9
+
10
+
11
+
12
+ */
13
+
14
+
15
+
16
+
17
+ const Meta =
18
+ require("../nodebb/meta");
19
+
20
+ const Posts =
21
+ require("../nodebb/posts");
22
+
23
+ const Topics =
24
+ require("../nodebb/topics");
25
+
26
+ const Users =
27
+ require("../nodebb/users");
28
+
29
+ const Search =
30
+ require("../ai/search");
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+ const definitions = [
45
+
46
+ {
47
+
48
+
49
+ name:
50
+
51
+ "get_forum_info",
52
+
53
+
54
+
55
+ description:
56
+
57
+ "Get NodeBB forum information",
58
+
59
+
60
+
61
+ inputSchema:
62
+
63
+ {
64
+
65
+ type:
66
+
67
+ "object",
68
+
69
+ properties: {}
70
+
71
+ }
72
+
73
+
74
+
75
+ },
76
+
77
+
78
+
79
+
80
+
81
+ {
82
+
83
+
84
+ name:
85
+
86
+ "get_post",
87
+
88
+
89
+
90
+ description:
91
+
92
+ "Get NodeBB post by pid",
93
+
94
+
95
+
96
+ inputSchema:
97
+
98
+ {
99
+
100
+ type:
101
+
102
+ "object",
103
+
104
+
105
+ properties:
106
+
107
+ {
108
+
109
+
110
+ pid:
111
+
112
+ {
113
+
114
+ type:
115
+
116
+ "number"
117
+
118
+ }
119
+
120
+
121
+ },
122
+
123
+
124
+ required:
125
+
126
+ [
127
+
128
+ "pid"
129
+
130
+ ]
131
+
132
+ }
133
+
134
+
135
+
136
+ },
137
+
138
+
139
+
140
+
141
+
142
+ {
143
+
144
+
145
+ name:
146
+
147
+ "get_topic",
148
+
149
+
150
+
151
+ description:
152
+
153
+ "Get NodeBB topic by tid",
154
+
155
+
156
+
157
+ inputSchema:
158
+
159
+ {
160
+
161
+ type:
162
+
163
+ "object",
164
+
165
+
166
+ properties:
167
+
168
+ {
169
+
170
+
171
+ tid:
172
+
173
+ {
174
+
175
+ type:
176
+
177
+ "number"
178
+
179
+ }
180
+
181
+
182
+ },
183
+
184
+
185
+ required:
186
+
187
+ [
188
+
189
+ "tid"
190
+
191
+ ]
192
+
193
+ }
194
+
195
+
196
+
197
+ },
198
+
199
+
200
+
201
+
202
+
203
+ {
204
+
205
+
206
+ name:
207
+
208
+ "get_user",
209
+
210
+
211
+
212
+ description:
213
+
214
+ "Get NodeBB user by uid",
215
+
216
+
217
+
218
+ inputSchema:
219
+
220
+ {
221
+
222
+ type:
223
+
224
+ "object",
225
+
226
+
227
+ properties:
228
+
229
+ {
230
+
231
+
232
+ uid:
233
+
234
+ {
235
+
236
+ type:
237
+
238
+ "number"
239
+
240
+ }
241
+
242
+
243
+ },
244
+
245
+
246
+ required:
247
+
248
+ [
249
+
250
+ "uid"
251
+
252
+ ]
253
+
254
+ }
255
+
256
+
257
+
258
+ },
259
+
260
+
261
+
262
+
263
+
264
+ {
265
+
266
+
267
+ name:
268
+
269
+ "search_knowledge",
270
+
271
+
272
+
273
+ description:
274
+
275
+ "Semantic search in forum knowledge base",
276
+
277
+
278
+
279
+ inputSchema:
280
+
281
+ {
282
+
283
+ type:
284
+
285
+ "object",
286
+
287
+
288
+ properties:
289
+
290
+ {
291
+
292
+
293
+ query:
294
+
295
+ {
296
+
297
+ type:
298
+
299
+ "string"
300
+
301
+ },
302
+
303
+
304
+ limit:
305
+
306
+ {
307
+
308
+ type:
309
+
310
+ "number"
311
+
312
+ }
313
+
314
+
315
+ },
316
+
317
+
318
+ required:
319
+
320
+ [
321
+
322
+ "query"
323
+
324
+ ]
325
+
326
+ }
327
+
328
+
329
+
330
+ }
331
+
332
+
333
+
334
+
335
+ ];
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
+
348
+
349
+ async function execute(
350
+
351
+ name,
352
+
353
+ args = {}
354
+
355
+ ) {
356
+
357
+
358
+
359
+
360
+ switch(name) {
361
+
362
+
363
+
364
+ case "get_forum_info":
365
+
366
+
367
+
368
+ return Meta.getInfo();
369
+
370
+
371
+
372
+
373
+
374
+
375
+
376
+ case "get_post":
377
+
378
+
379
+
380
+ return Posts.getPost(
381
+
382
+ args.pid
383
+
384
+ );
385
+
386
+
387
+
388
+
389
+
390
+
391
+
392
+ case "get_topic":
393
+
394
+
395
+
396
+ return Topics.getTopic(
397
+
398
+ args.tid
399
+
400
+ );
401
+
402
+
403
+
404
+
405
+
406
+
407
+
408
+ case "get_user":
409
+
410
+
411
+
412
+ return Users.getUser(
413
+
414
+ args.uid
415
+
416
+ );
417
+
418
+
419
+
420
+
421
+
422
+
423
+
424
+ case "search_knowledge":
425
+
426
+
427
+
428
+ return Search.searchText(
429
+
430
+ args.query,
431
+
432
+ args.limit || 5
433
+
434
+ );
435
+
436
+
437
+
438
+
439
+
440
+
441
+
442
+ default:
443
+
444
+
445
+
446
+ throw new Error(
447
+
448
+ `Unknown MCP tool: ${name}`
449
+
450
+ );
451
+
452
+
453
+
454
+ }
455
+
456
+
457
+
458
+
459
+ }
460
+
461
+
462
+
463
+
464
+
465
+
466
+
467
+
468
+
469
+
470
+
471
+
472
+
473
+ function register(server) {
474
+
475
+
476
+
477
+
478
+ /*
479
+ * MCP SDK 1.x compatibility
480
+ */
481
+
482
+
483
+ if(
484
+
485
+ typeof server.setRequestHandler !== "function"
486
+
487
+ ) {
488
+
489
+
490
+
491
+ throw new Error(
492
+
493
+ "Invalid MCP server instance"
494
+
495
+ );
496
+
497
+
498
+ }
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+ server.setRequestHandler(
508
+
509
+ {
510
+
511
+ method:
512
+
513
+ "tools/list"
514
+
515
+
516
+ },
517
+
518
+
519
+ async () => ({
520
+
521
+
522
+ tools:
523
+
524
+ definitions
525
+
526
+
527
+ })
528
+
529
+ );
530
+
531
+
532
+
533
+
534
+
535
+
536
+
537
+
538
+ server.setRequestHandler(
539
+
540
+ {
541
+
542
+ method:
543
+
544
+ "tools/call"
545
+
546
+
547
+ },
548
+
549
+
550
+ async request => {
551
+
552
+
553
+
554
+ const result =
555
+
556
+ await execute(
557
+
558
+ request.params.name,
559
+
560
+ request.params.arguments || {}
561
+
562
+ );
563
+
564
+
565
+
566
+
567
+
568
+
569
+
570
+ return {
571
+
572
+
573
+ content:
574
+
575
+ [
576
+
577
+ {
578
+
579
+
580
+ type:
581
+
582
+ "text",
583
+
584
+
585
+
586
+ text:
587
+
588
+ JSON.stringify(
589
+
590
+ result,
591
+
592
+ null,
593
+
594
+ 2
595
+
596
+ )
597
+
598
+
599
+ }
600
+
601
+ ]
602
+
603
+ };
604
+
605
+
606
+
607
+ }
608
+
609
+ );
610
+
611
+
612
+
613
+
614
+
615
+
616
+
617
+
618
+ console.log(
619
+
620
+ "[MCP] tools registered"
621
+
622
+ );
623
+
624
+
625
+
626
+
627
+ }
628
+
629
+
630
+
631
+
632
+
633
+
634
+
635
+
636
+
637
+
638
+
639
+
640
+
641
+ module.exports = {
642
+
643
+ register,
644
+
645
+
646
+ execute,
647
+
648
+
649
+ definitions
650
+
651
+
652
+
653
+
654
+ };