@hasna/microservices 0.0.6 → 0.0.8
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/microservices/microservice-domains/src/lib/brandsight.ts +138 -73
- package/microservices/microservice-domains/src/lib/godaddy.ts +149 -139
- package/microservices/microservice-domains/src/lib/namecheap.ts +63 -275
- package/microservices/microservice-social/package.json +2 -1
- package/microservices/microservice-social/src/cli/index.ts +906 -12
- package/microservices/microservice-social/src/db/migrations.ts +72 -0
- package/microservices/microservice-social/src/db/social.ts +33 -3
- package/microservices/microservice-social/src/lib/audience.ts +353 -0
- package/microservices/microservice-social/src/lib/content-ai.ts +278 -0
- package/microservices/microservice-social/src/lib/media.ts +311 -0
- package/microservices/microservice-social/src/lib/mentions.ts +434 -0
- package/microservices/microservice-social/src/lib/metrics-sync.ts +264 -0
- package/microservices/microservice-social/src/lib/publisher.ts +377 -0
- package/microservices/microservice-social/src/lib/scheduler.ts +229 -0
- package/microservices/microservice-social/src/lib/sentiment.ts +256 -0
- package/microservices/microservice-social/src/lib/threads.ts +291 -0
- package/microservices/microservice-social/src/mcp/index.ts +776 -6
- package/microservices/microservice-social/src/server/index.ts +441 -0
- package/package.json +1 -1
|
@@ -35,6 +35,17 @@ import {
|
|
|
35
35
|
getHashtagStats,
|
|
36
36
|
PLATFORM_LIMITS,
|
|
37
37
|
} from "../db/social.js";
|
|
38
|
+
import {
|
|
39
|
+
startScheduler,
|
|
40
|
+
stopScheduler,
|
|
41
|
+
getSchedulerStatus,
|
|
42
|
+
runOnce as runSchedulerOnce,
|
|
43
|
+
} from "../lib/scheduler.js";
|
|
44
|
+
import {
|
|
45
|
+
validateMedia,
|
|
46
|
+
getSupportedFormats,
|
|
47
|
+
uploadMedia,
|
|
48
|
+
} from "../lib/media.js";
|
|
38
49
|
|
|
39
50
|
const PlatformEnum = z.enum(["x", "linkedin", "instagram", "threads", "bluesky"]);
|
|
40
51
|
const PostStatusEnum = z.enum(["draft", "scheduled", "published", "failed", "pending_review"]);
|
|
@@ -268,18 +279,135 @@ server.registerTool(
|
|
|
268
279
|
"publish_post",
|
|
269
280
|
{
|
|
270
281
|
title: "Publish Post",
|
|
271
|
-
description: "
|
|
282
|
+
description: "Publish a post. Set live=true to send via platform API (X, Meta), otherwise marks as published locally.",
|
|
272
283
|
inputSchema: {
|
|
273
284
|
id: z.string(),
|
|
274
285
|
platform_post_id: z.string().optional(),
|
|
286
|
+
live: z.boolean().optional().describe("If true, publish via the platform API instead of just marking locally"),
|
|
275
287
|
},
|
|
276
288
|
},
|
|
277
|
-
async ({ id, platform_post_id }) => {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
289
|
+
async ({ id, platform_post_id, live }) => {
|
|
290
|
+
try {
|
|
291
|
+
let post;
|
|
292
|
+
if (live) {
|
|
293
|
+
const { publishToApi } = await import("../lib/publisher.js");
|
|
294
|
+
post = await publishToApi(id);
|
|
295
|
+
} else {
|
|
296
|
+
post = publishPost(id, platform_post_id);
|
|
297
|
+
}
|
|
298
|
+
if (!post) {
|
|
299
|
+
return { content: [{ type: "text", text: `Post '${id}' not found.` }], isError: true };
|
|
300
|
+
}
|
|
301
|
+
return { content: [{ type: "text", text: JSON.stringify(post, null, 2) }] };
|
|
302
|
+
} catch (error) {
|
|
303
|
+
return {
|
|
304
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
305
|
+
isError: true,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
// --- Threads ---
|
|
312
|
+
|
|
313
|
+
server.registerTool(
|
|
314
|
+
"create_thread",
|
|
315
|
+
{
|
|
316
|
+
title: "Create Thread",
|
|
317
|
+
description: "Create a thread of multiple posts linked by thread_id, ordered sequentially.",
|
|
318
|
+
inputSchema: {
|
|
319
|
+
contents: z.array(z.string()).describe("Content for each post in the thread"),
|
|
320
|
+
account_id: z.string(),
|
|
321
|
+
scheduled_at: z.string().optional(),
|
|
322
|
+
tags: z.array(z.string()).optional(),
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
async ({ contents, account_id, scheduled_at, tags }) => {
|
|
326
|
+
try {
|
|
327
|
+
const { createThread } = await import("../lib/threads.js");
|
|
328
|
+
const result = createThread(contents, account_id, { scheduledAt: scheduled_at, tags });
|
|
329
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
330
|
+
} catch (error) {
|
|
331
|
+
return {
|
|
332
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
333
|
+
isError: true,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
server.registerTool(
|
|
340
|
+
"get_thread",
|
|
341
|
+
{
|
|
342
|
+
title: "Get Thread",
|
|
343
|
+
description: "Get all posts in a thread ordered by position.",
|
|
344
|
+
inputSchema: {
|
|
345
|
+
thread_id: z.string(),
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
async ({ thread_id }) => {
|
|
349
|
+
try {
|
|
350
|
+
const { getThread } = await import("../lib/threads.js");
|
|
351
|
+
const posts = getThread(thread_id);
|
|
352
|
+
return {
|
|
353
|
+
content: [
|
|
354
|
+
{ type: "text", text: JSON.stringify({ thread_id, posts, count: posts.length }, null, 2) },
|
|
355
|
+
],
|
|
356
|
+
};
|
|
357
|
+
} catch (error) {
|
|
358
|
+
return {
|
|
359
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
360
|
+
isError: true,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
server.registerTool(
|
|
367
|
+
"publish_thread",
|
|
368
|
+
{
|
|
369
|
+
title: "Publish Thread",
|
|
370
|
+
description: "Publish a thread sequentially via platform APIs. X chains tweets as replies; Meta posts first then comments.",
|
|
371
|
+
inputSchema: {
|
|
372
|
+
thread_id: z.string(),
|
|
373
|
+
},
|
|
374
|
+
},
|
|
375
|
+
async ({ thread_id }) => {
|
|
376
|
+
try {
|
|
377
|
+
const { publishThread } = await import("../lib/threads.js");
|
|
378
|
+
const result = await publishThread(thread_id);
|
|
379
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
380
|
+
} catch (error) {
|
|
381
|
+
return {
|
|
382
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
383
|
+
isError: true,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
server.registerTool(
|
|
390
|
+
"create_carousel",
|
|
391
|
+
{
|
|
392
|
+
title: "Create Carousel",
|
|
393
|
+
description: "Create a carousel post with multiple images (Instagram/LinkedIn format).",
|
|
394
|
+
inputSchema: {
|
|
395
|
+
images: z.array(z.string()).describe("Image URLs for the carousel"),
|
|
396
|
+
captions: z.array(z.string()).optional().describe("Captions for the images"),
|
|
397
|
+
account_id: z.string(),
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
async ({ images, captions, account_id }) => {
|
|
401
|
+
try {
|
|
402
|
+
const { createCarousel } = await import("../lib/threads.js");
|
|
403
|
+
const post = createCarousel(images, captions || [], account_id);
|
|
404
|
+
return { content: [{ type: "text", text: JSON.stringify(post, null, 2) }] };
|
|
405
|
+
} catch (error) {
|
|
406
|
+
return {
|
|
407
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
408
|
+
isError: true,
|
|
409
|
+
};
|
|
281
410
|
}
|
|
282
|
-
return { content: [{ type: "text", text: JSON.stringify(post, null, 2) }] };
|
|
283
411
|
}
|
|
284
412
|
);
|
|
285
413
|
|
|
@@ -642,6 +770,648 @@ server.registerTool(
|
|
|
642
770
|
}
|
|
643
771
|
);
|
|
644
772
|
|
|
773
|
+
// --- Publisher Bridge ---
|
|
774
|
+
|
|
775
|
+
server.registerTool(
|
|
776
|
+
"check_providers",
|
|
777
|
+
{
|
|
778
|
+
title: "Check Providers",
|
|
779
|
+
description: "Check which platform API providers have env vars configured (X, Meta).",
|
|
780
|
+
inputSchema: {},
|
|
781
|
+
},
|
|
782
|
+
async () => {
|
|
783
|
+
const { checkProviders } = await import("../lib/publisher.js");
|
|
784
|
+
const providers = checkProviders();
|
|
785
|
+
return { content: [{ type: "text", text: JSON.stringify(providers, null, 2) }] };
|
|
786
|
+
}
|
|
787
|
+
);
|
|
788
|
+
|
|
789
|
+
server.registerTool(
|
|
790
|
+
"sync_post_metrics",
|
|
791
|
+
{
|
|
792
|
+
title: "Sync Post Metrics",
|
|
793
|
+
description: "Fetch engagement metrics from the platform API and update the post in DB.",
|
|
794
|
+
inputSchema: { id: z.string() },
|
|
795
|
+
},
|
|
796
|
+
async ({ id }) => {
|
|
797
|
+
try {
|
|
798
|
+
const { syncPostMetrics } = await import("../lib/publisher.js");
|
|
799
|
+
const post = await syncPostMetrics(id);
|
|
800
|
+
return { content: [{ type: "text", text: JSON.stringify(post, null, 2) }] };
|
|
801
|
+
} catch (error) {
|
|
802
|
+
return {
|
|
803
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
804
|
+
isError: true,
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
);
|
|
809
|
+
|
|
810
|
+
// --- Scheduler ---
|
|
811
|
+
|
|
812
|
+
server.registerTool(
|
|
813
|
+
"start_scheduler",
|
|
814
|
+
{
|
|
815
|
+
title: "Start Scheduler",
|
|
816
|
+
description: "Start the auto-publish scheduler that checks for due posts at a regular interval.",
|
|
817
|
+
inputSchema: {
|
|
818
|
+
interval_ms: z.number().optional(),
|
|
819
|
+
},
|
|
820
|
+
},
|
|
821
|
+
async ({ interval_ms }) => {
|
|
822
|
+
try {
|
|
823
|
+
startScheduler(interval_ms || 60000);
|
|
824
|
+
const status = getSchedulerStatus();
|
|
825
|
+
return { content: [{ type: "text", text: JSON.stringify({ message: "Scheduler started", ...status }, null, 2) }] };
|
|
826
|
+
} catch (error) {
|
|
827
|
+
return {
|
|
828
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
829
|
+
isError: true,
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
);
|
|
834
|
+
|
|
835
|
+
server.registerTool(
|
|
836
|
+
"stop_scheduler",
|
|
837
|
+
{
|
|
838
|
+
title: "Stop Scheduler",
|
|
839
|
+
description: "Stop the auto-publish scheduler.",
|
|
840
|
+
inputSchema: {},
|
|
841
|
+
},
|
|
842
|
+
async () => {
|
|
843
|
+
stopScheduler();
|
|
844
|
+
const status = getSchedulerStatus();
|
|
845
|
+
return { content: [{ type: "text", text: JSON.stringify({ message: "Scheduler stopped", ...status }, null, 2) }] };
|
|
846
|
+
}
|
|
847
|
+
);
|
|
848
|
+
|
|
849
|
+
server.registerTool(
|
|
850
|
+
"scheduler_status",
|
|
851
|
+
{
|
|
852
|
+
title: "Scheduler Status",
|
|
853
|
+
description: "Get the current status of the auto-publish scheduler.",
|
|
854
|
+
inputSchema: {},
|
|
855
|
+
},
|
|
856
|
+
async () => {
|
|
857
|
+
const status = getSchedulerStatus();
|
|
858
|
+
return { content: [{ type: "text", text: JSON.stringify(status, null, 2) }] };
|
|
859
|
+
}
|
|
860
|
+
);
|
|
861
|
+
|
|
862
|
+
// --- Media ---
|
|
863
|
+
|
|
864
|
+
server.registerTool(
|
|
865
|
+
"upload_media",
|
|
866
|
+
{
|
|
867
|
+
title: "Upload Media",
|
|
868
|
+
description: "Upload a media file to a social media platform.",
|
|
869
|
+
inputSchema: {
|
|
870
|
+
file_path: z.string(),
|
|
871
|
+
platform: PlatformEnum,
|
|
872
|
+
page_id: z.string().optional(),
|
|
873
|
+
},
|
|
874
|
+
},
|
|
875
|
+
async ({ file_path, platform, page_id }) => {
|
|
876
|
+
try {
|
|
877
|
+
const validation = validateMedia(file_path, platform);
|
|
878
|
+
if (!validation.valid) {
|
|
879
|
+
return {
|
|
880
|
+
content: [{ type: "text", text: JSON.stringify({ valid: false, errors: validation.errors }, null, 2) }],
|
|
881
|
+
isError: true,
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
const result = await uploadMedia(file_path, platform, page_id);
|
|
886
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
887
|
+
} catch (error) {
|
|
888
|
+
return {
|
|
889
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
890
|
+
isError: true,
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
);
|
|
895
|
+
|
|
896
|
+
server.registerTool(
|
|
897
|
+
"validate_media",
|
|
898
|
+
{
|
|
899
|
+
title: "Validate Media",
|
|
900
|
+
description: "Validate a media file for a specific platform without uploading.",
|
|
901
|
+
inputSchema: {
|
|
902
|
+
file_path: z.string(),
|
|
903
|
+
platform: PlatformEnum,
|
|
904
|
+
},
|
|
905
|
+
},
|
|
906
|
+
async ({ file_path, platform }) => {
|
|
907
|
+
const result = validateMedia(file_path, platform);
|
|
908
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
909
|
+
}
|
|
910
|
+
);
|
|
911
|
+
|
|
912
|
+
server.registerTool(
|
|
913
|
+
"get_supported_formats",
|
|
914
|
+
{
|
|
915
|
+
title: "Get Supported Formats",
|
|
916
|
+
description: "Get supported media formats for a platform.",
|
|
917
|
+
inputSchema: {
|
|
918
|
+
platform: PlatformEnum,
|
|
919
|
+
},
|
|
920
|
+
},
|
|
921
|
+
async ({ platform }) => {
|
|
922
|
+
const formats = getSupportedFormats(platform);
|
|
923
|
+
return { content: [{ type: "text", text: JSON.stringify({ platform, formats }, null, 2) }] };
|
|
924
|
+
}
|
|
925
|
+
);
|
|
926
|
+
|
|
927
|
+
// --- Metrics Sync ---
|
|
928
|
+
|
|
929
|
+
server.registerTool(
|
|
930
|
+
"sync_all_metrics",
|
|
931
|
+
{
|
|
932
|
+
title: "Sync All Metrics",
|
|
933
|
+
description: "Sync engagement metrics for all published posts from the last 7 days via platform APIs.",
|
|
934
|
+
inputSchema: {},
|
|
935
|
+
},
|
|
936
|
+
async () => {
|
|
937
|
+
try {
|
|
938
|
+
const { syncAllMetrics } = await import("../lib/metrics-sync.js");
|
|
939
|
+
const report = await syncAllMetrics();
|
|
940
|
+
return { content: [{ type: "text", text: JSON.stringify(report, null, 2) }] };
|
|
941
|
+
} catch (error) {
|
|
942
|
+
return {
|
|
943
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
944
|
+
isError: true,
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
);
|
|
949
|
+
|
|
950
|
+
server.registerTool(
|
|
951
|
+
"sync_account_metrics",
|
|
952
|
+
{
|
|
953
|
+
title: "Sync Account Metrics",
|
|
954
|
+
description: "Pull follower count and profile data from platform API for a specific account.",
|
|
955
|
+
inputSchema: {
|
|
956
|
+
account_id: z.string(),
|
|
957
|
+
},
|
|
958
|
+
},
|
|
959
|
+
async ({ account_id }) => {
|
|
960
|
+
try {
|
|
961
|
+
const { syncAccountMetrics } = await import("../lib/metrics-sync.js");
|
|
962
|
+
const account = await syncAccountMetrics(account_id);
|
|
963
|
+
if (!account) {
|
|
964
|
+
return { content: [{ type: "text", text: `Account '${account_id}' not found.` }], isError: true };
|
|
965
|
+
}
|
|
966
|
+
return { content: [{ type: "text", text: JSON.stringify(account, null, 2) }] };
|
|
967
|
+
} catch (error) {
|
|
968
|
+
return {
|
|
969
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
970
|
+
isError: true,
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
);
|
|
975
|
+
|
|
976
|
+
server.registerTool(
|
|
977
|
+
"metrics_sync_status",
|
|
978
|
+
{
|
|
979
|
+
title: "Metrics Sync Status",
|
|
980
|
+
description: "Get the current status of the metrics sync worker, including sync report.",
|
|
981
|
+
inputSchema: {},
|
|
982
|
+
},
|
|
983
|
+
async () => {
|
|
984
|
+
const { getMetricsSyncStatus, getSyncReport } = await import("../lib/metrics-sync.js");
|
|
985
|
+
const status = getMetricsSyncStatus();
|
|
986
|
+
const report = getSyncReport();
|
|
987
|
+
return { content: [{ type: "text", text: JSON.stringify({ status, report }, null, 2) }] };
|
|
988
|
+
}
|
|
989
|
+
);
|
|
990
|
+
|
|
991
|
+
// --- Mentions ---
|
|
992
|
+
|
|
993
|
+
const MentionTypeEnum = z.enum(["mention", "reply", "quote", "dm"]);
|
|
994
|
+
|
|
995
|
+
server.registerTool(
|
|
996
|
+
"list_mentions",
|
|
997
|
+
{
|
|
998
|
+
title: "List Mentions",
|
|
999
|
+
description: "List mentions for an account with optional filters (unread, type, platform).",
|
|
1000
|
+
inputSchema: {
|
|
1001
|
+
account_id: z.string().optional(),
|
|
1002
|
+
unread: z.boolean().optional(),
|
|
1003
|
+
type: MentionTypeEnum.optional(),
|
|
1004
|
+
platform: z.string().optional(),
|
|
1005
|
+
limit: z.number().optional(),
|
|
1006
|
+
},
|
|
1007
|
+
},
|
|
1008
|
+
async ({ account_id, ...filters }) => {
|
|
1009
|
+
const { listMentions } = await import("../lib/mentions.js");
|
|
1010
|
+
const mentions = listMentions(account_id, filters);
|
|
1011
|
+
return {
|
|
1012
|
+
content: [
|
|
1013
|
+
{ type: "text", text: JSON.stringify({ mentions, count: mentions.length }, null, 2) },
|
|
1014
|
+
],
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
1017
|
+
);
|
|
1018
|
+
|
|
1019
|
+
server.registerTool(
|
|
1020
|
+
"reply_to_mention",
|
|
1021
|
+
{
|
|
1022
|
+
title: "Reply to Mention",
|
|
1023
|
+
description: "Reply to a mention via the platform API (X or Meta).",
|
|
1024
|
+
inputSchema: {
|
|
1025
|
+
mention_id: z.string(),
|
|
1026
|
+
content: z.string(),
|
|
1027
|
+
},
|
|
1028
|
+
},
|
|
1029
|
+
async ({ mention_id, content }) => {
|
|
1030
|
+
try {
|
|
1031
|
+
const { replyToMention } = await import("../lib/mentions.js");
|
|
1032
|
+
const result = await replyToMention(mention_id, content);
|
|
1033
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1034
|
+
} catch (error) {
|
|
1035
|
+
return {
|
|
1036
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
1037
|
+
isError: true,
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
);
|
|
1042
|
+
|
|
1043
|
+
server.registerTool(
|
|
1044
|
+
"mark_mention_read",
|
|
1045
|
+
{
|
|
1046
|
+
title: "Mark Mention Read",
|
|
1047
|
+
description: "Mark a single mention as read, or all mentions for an account.",
|
|
1048
|
+
inputSchema: {
|
|
1049
|
+
mention_id: z.string().optional(),
|
|
1050
|
+
account_id: z.string().optional(),
|
|
1051
|
+
},
|
|
1052
|
+
},
|
|
1053
|
+
async ({ mention_id, account_id }) => {
|
|
1054
|
+
const { markRead, markAllRead } = await import("../lib/mentions.js");
|
|
1055
|
+
if (account_id) {
|
|
1056
|
+
const count = markAllRead(account_id);
|
|
1057
|
+
return { content: [{ type: "text", text: JSON.stringify({ account_id, marked_read: count }, null, 2) }] };
|
|
1058
|
+
}
|
|
1059
|
+
if (mention_id) {
|
|
1060
|
+
const mention = markRead(mention_id);
|
|
1061
|
+
if (!mention) {
|
|
1062
|
+
return { content: [{ type: "text", text: `Mention '${mention_id}' not found.` }], isError: true };
|
|
1063
|
+
}
|
|
1064
|
+
return { content: [{ type: "text", text: JSON.stringify(mention, null, 2) }] };
|
|
1065
|
+
}
|
|
1066
|
+
return { content: [{ type: "text", text: "Provide either mention_id or account_id." }], isError: true };
|
|
1067
|
+
}
|
|
1068
|
+
);
|
|
1069
|
+
|
|
1070
|
+
server.registerTool(
|
|
1071
|
+
"poll_mentions",
|
|
1072
|
+
{
|
|
1073
|
+
title: "Poll Mentions",
|
|
1074
|
+
description: "Start or stop the background mention poller.",
|
|
1075
|
+
inputSchema: {
|
|
1076
|
+
action: z.enum(["start", "stop", "status"]),
|
|
1077
|
+
interval_ms: z.number().optional(),
|
|
1078
|
+
},
|
|
1079
|
+
},
|
|
1080
|
+
async ({ action, interval_ms }) => {
|
|
1081
|
+
const { pollMentions, stopPolling, isPolling } = await import("../lib/mentions.js");
|
|
1082
|
+
try {
|
|
1083
|
+
if (action === "start") {
|
|
1084
|
+
pollMentions(interval_ms || 120000);
|
|
1085
|
+
return { content: [{ type: "text", text: JSON.stringify({ status: "started", interval_ms: interval_ms || 120000 }, null, 2) }] };
|
|
1086
|
+
} else if (action === "stop") {
|
|
1087
|
+
stopPolling();
|
|
1088
|
+
return { content: [{ type: "text", text: JSON.stringify({ status: "stopped" }, null, 2) }] };
|
|
1089
|
+
} else {
|
|
1090
|
+
return { content: [{ type: "text", text: JSON.stringify({ running: isPolling() }, null, 2) }] };
|
|
1091
|
+
}
|
|
1092
|
+
} catch (error) {
|
|
1093
|
+
return {
|
|
1094
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
1095
|
+
isError: true,
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
);
|
|
1100
|
+
|
|
1101
|
+
server.registerTool(
|
|
1102
|
+
"mention_stats",
|
|
1103
|
+
{
|
|
1104
|
+
title: "Mention Stats",
|
|
1105
|
+
description: "Get mention statistics for an account (total, unread, by type, by sentiment).",
|
|
1106
|
+
inputSchema: {
|
|
1107
|
+
account_id: z.string(),
|
|
1108
|
+
},
|
|
1109
|
+
},
|
|
1110
|
+
async ({ account_id }) => {
|
|
1111
|
+
const { getMentionStats } = await import("../lib/mentions.js");
|
|
1112
|
+
const stats = getMentionStats(account_id);
|
|
1113
|
+
return { content: [{ type: "text", text: JSON.stringify(stats, null, 2) }] };
|
|
1114
|
+
}
|
|
1115
|
+
);
|
|
1116
|
+
|
|
1117
|
+
// --- AI Content Generation ---
|
|
1118
|
+
|
|
1119
|
+
const ToneEnum = z.enum(["professional", "casual", "witty"]);
|
|
1120
|
+
|
|
1121
|
+
server.registerTool(
|
|
1122
|
+
"generate_post",
|
|
1123
|
+
{
|
|
1124
|
+
title: "Generate Post with AI",
|
|
1125
|
+
description: "Generate a social media post using AI. Provide a topic and platform; get back content, hashtags, and a suggested media prompt.",
|
|
1126
|
+
inputSchema: {
|
|
1127
|
+
topic: z.string(),
|
|
1128
|
+
platform: PlatformEnum,
|
|
1129
|
+
tone: ToneEnum.optional(),
|
|
1130
|
+
includeHashtags: z.boolean().optional(),
|
|
1131
|
+
includeEmoji: z.boolean().optional(),
|
|
1132
|
+
language: z.string().optional(),
|
|
1133
|
+
},
|
|
1134
|
+
},
|
|
1135
|
+
async ({ topic, platform, ...options }) => {
|
|
1136
|
+
try {
|
|
1137
|
+
const { generatePost } = await import("../lib/content-ai.js");
|
|
1138
|
+
const result = await generatePost(topic, platform, options);
|
|
1139
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1140
|
+
} catch (error) {
|
|
1141
|
+
return {
|
|
1142
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
1143
|
+
isError: true,
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
);
|
|
1148
|
+
|
|
1149
|
+
server.registerTool(
|
|
1150
|
+
"suggest_hashtags",
|
|
1151
|
+
{
|
|
1152
|
+
title: "Suggest Hashtags",
|
|
1153
|
+
description: "Analyze post content and suggest relevant hashtags using AI.",
|
|
1154
|
+
inputSchema: {
|
|
1155
|
+
content: z.string(),
|
|
1156
|
+
platform: PlatformEnum,
|
|
1157
|
+
count: z.number().optional(),
|
|
1158
|
+
},
|
|
1159
|
+
},
|
|
1160
|
+
async ({ content, platform, count }) => {
|
|
1161
|
+
try {
|
|
1162
|
+
const { suggestHashtags } = await import("../lib/content-ai.js");
|
|
1163
|
+
const hashtags = await suggestHashtags(content, platform, count || 5);
|
|
1164
|
+
return { content: [{ type: "text", text: JSON.stringify({ hashtags }, null, 2) }] };
|
|
1165
|
+
} catch (error) {
|
|
1166
|
+
return {
|
|
1167
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
1168
|
+
isError: true,
|
|
1169
|
+
};
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
);
|
|
1173
|
+
|
|
1174
|
+
server.registerTool(
|
|
1175
|
+
"optimize_post",
|
|
1176
|
+
{
|
|
1177
|
+
title: "Optimize Post",
|
|
1178
|
+
description: "Rewrite a post for better engagement using AI. Returns optimized content and a list of improvements.",
|
|
1179
|
+
inputSchema: {
|
|
1180
|
+
content: z.string(),
|
|
1181
|
+
platform: PlatformEnum,
|
|
1182
|
+
},
|
|
1183
|
+
},
|
|
1184
|
+
async ({ content, platform }) => {
|
|
1185
|
+
try {
|
|
1186
|
+
const { optimizePost } = await import("../lib/content-ai.js");
|
|
1187
|
+
const result = await optimizePost(content, platform);
|
|
1188
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1189
|
+
} catch (error) {
|
|
1190
|
+
return {
|
|
1191
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
1192
|
+
isError: true,
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
);
|
|
1197
|
+
|
|
1198
|
+
server.registerTool(
|
|
1199
|
+
"generate_thread",
|
|
1200
|
+
{
|
|
1201
|
+
title: "Generate Thread",
|
|
1202
|
+
description: "Generate a multi-tweet thread using AI. Each tweet stays within 280 chars.",
|
|
1203
|
+
inputSchema: {
|
|
1204
|
+
topic: z.string(),
|
|
1205
|
+
tweet_count: z.number().optional(),
|
|
1206
|
+
},
|
|
1207
|
+
},
|
|
1208
|
+
async ({ topic, tweet_count }) => {
|
|
1209
|
+
try {
|
|
1210
|
+
const { generateThread } = await import("../lib/content-ai.js");
|
|
1211
|
+
const tweets = await generateThread(topic, tweet_count || 5);
|
|
1212
|
+
return { content: [{ type: "text", text: JSON.stringify({ tweets, count: tweets.length }, null, 2) }] };
|
|
1213
|
+
} catch (error) {
|
|
1214
|
+
return {
|
|
1215
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
1216
|
+
isError: true,
|
|
1217
|
+
};
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
);
|
|
1221
|
+
|
|
1222
|
+
server.registerTool(
|
|
1223
|
+
"repurpose_post",
|
|
1224
|
+
{
|
|
1225
|
+
title: "Repurpose Post",
|
|
1226
|
+
description: "Adapt a post from one platform's style to another using AI (e.g., X to LinkedIn).",
|
|
1227
|
+
inputSchema: {
|
|
1228
|
+
content: z.string(),
|
|
1229
|
+
source_platform: PlatformEnum,
|
|
1230
|
+
target_platform: PlatformEnum,
|
|
1231
|
+
},
|
|
1232
|
+
},
|
|
1233
|
+
async ({ content, source_platform, target_platform }) => {
|
|
1234
|
+
try {
|
|
1235
|
+
const { repurposePost } = await import("../lib/content-ai.js");
|
|
1236
|
+
const result = await repurposePost(content, source_platform, target_platform);
|
|
1237
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1238
|
+
} catch (error) {
|
|
1239
|
+
return {
|
|
1240
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
1241
|
+
isError: true,
|
|
1242
|
+
};
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
);
|
|
1246
|
+
|
|
1247
|
+
// --- Audience ---
|
|
1248
|
+
|
|
1249
|
+
server.registerTool(
|
|
1250
|
+
"sync_followers",
|
|
1251
|
+
{
|
|
1252
|
+
title: "Sync Followers",
|
|
1253
|
+
description: "Sync followers from the platform API for an account. Returns sync results including new and unfollowed counts.",
|
|
1254
|
+
inputSchema: {
|
|
1255
|
+
account_id: z.string(),
|
|
1256
|
+
},
|
|
1257
|
+
},
|
|
1258
|
+
async ({ account_id }) => {
|
|
1259
|
+
try {
|
|
1260
|
+
const { syncFollowers } = await import("../lib/audience.js");
|
|
1261
|
+
const result = syncFollowers(account_id);
|
|
1262
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1263
|
+
} catch (error) {
|
|
1264
|
+
return {
|
|
1265
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
1266
|
+
isError: true,
|
|
1267
|
+
};
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
);
|
|
1271
|
+
|
|
1272
|
+
server.registerTool(
|
|
1273
|
+
"audience_insights",
|
|
1274
|
+
{
|
|
1275
|
+
title: "Audience Insights",
|
|
1276
|
+
description: "Get audience insights for an account: total followers, growth rates, new/lost followers, and top followers.",
|
|
1277
|
+
inputSchema: {
|
|
1278
|
+
account_id: z.string(),
|
|
1279
|
+
},
|
|
1280
|
+
},
|
|
1281
|
+
async ({ account_id }) => {
|
|
1282
|
+
try {
|
|
1283
|
+
const { getAudienceInsights } = await import("../lib/audience.js");
|
|
1284
|
+
const insights = getAudienceInsights(account_id);
|
|
1285
|
+
return { content: [{ type: "text", text: JSON.stringify(insights, null, 2) }] };
|
|
1286
|
+
} catch (error) {
|
|
1287
|
+
return {
|
|
1288
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
1289
|
+
isError: true,
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
);
|
|
1294
|
+
|
|
1295
|
+
server.registerTool(
|
|
1296
|
+
"follower_growth",
|
|
1297
|
+
{
|
|
1298
|
+
title: "Follower Growth Chart",
|
|
1299
|
+
description: "Get follower growth data points over a number of days for charting.",
|
|
1300
|
+
inputSchema: {
|
|
1301
|
+
account_id: z.string(),
|
|
1302
|
+
days: z.number().optional(),
|
|
1303
|
+
},
|
|
1304
|
+
},
|
|
1305
|
+
async ({ account_id, days }) => {
|
|
1306
|
+
try {
|
|
1307
|
+
const { getFollowerGrowthChart } = await import("../lib/audience.js");
|
|
1308
|
+
const chart = getFollowerGrowthChart(account_id, days || 30);
|
|
1309
|
+
return { content: [{ type: "text", text: JSON.stringify(chart, null, 2) }] };
|
|
1310
|
+
} catch (error) {
|
|
1311
|
+
return {
|
|
1312
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
1313
|
+
isError: true,
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
);
|
|
1318
|
+
|
|
1319
|
+
server.registerTool(
|
|
1320
|
+
"top_followers",
|
|
1321
|
+
{
|
|
1322
|
+
title: "Top Followers",
|
|
1323
|
+
description: "Get top followers for an account, sorted by their follower count (most influential first).",
|
|
1324
|
+
inputSchema: {
|
|
1325
|
+
account_id: z.string(),
|
|
1326
|
+
limit: z.number().optional(),
|
|
1327
|
+
},
|
|
1328
|
+
},
|
|
1329
|
+
async ({ account_id, limit }) => {
|
|
1330
|
+
try {
|
|
1331
|
+
const { getTopFollowers } = await import("../lib/audience.js");
|
|
1332
|
+
const followers = getTopFollowers(account_id, limit || 10);
|
|
1333
|
+
return { content: [{ type: "text", text: JSON.stringify({ followers, count: followers.length }, null, 2) }] };
|
|
1334
|
+
} catch (error) {
|
|
1335
|
+
return {
|
|
1336
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
1337
|
+
isError: true,
|
|
1338
|
+
};
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
);
|
|
1342
|
+
|
|
1343
|
+
// --- Sentiment Analysis ---
|
|
1344
|
+
|
|
1345
|
+
server.registerTool(
|
|
1346
|
+
"analyze_sentiment",
|
|
1347
|
+
{
|
|
1348
|
+
title: "Analyze Sentiment",
|
|
1349
|
+
description: "Analyze the sentiment of a text using AI. Returns sentiment label (positive/neutral/negative), score (0-1), and emotional keywords.",
|
|
1350
|
+
inputSchema: {
|
|
1351
|
+
text: z.string().describe("The text to analyze for sentiment"),
|
|
1352
|
+
},
|
|
1353
|
+
},
|
|
1354
|
+
async ({ text }) => {
|
|
1355
|
+
try {
|
|
1356
|
+
const { analyzeSentiment } = await import("../lib/sentiment.js");
|
|
1357
|
+
const result = await analyzeSentiment(text);
|
|
1358
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1359
|
+
} catch (error) {
|
|
1360
|
+
return {
|
|
1361
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
1362
|
+
isError: true,
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
);
|
|
1367
|
+
|
|
1368
|
+
server.registerTool(
|
|
1369
|
+
"sentiment_report",
|
|
1370
|
+
{
|
|
1371
|
+
title: "Sentiment Report",
|
|
1372
|
+
description: "Get an aggregated sentiment report for an account's mentions. Shows positive/neutral/negative percentages, trending keywords, and most positive/negative mentions.",
|
|
1373
|
+
inputSchema: {
|
|
1374
|
+
account_id: z.string(),
|
|
1375
|
+
days: z.number().optional().describe("Number of days to look back (default: all time)"),
|
|
1376
|
+
},
|
|
1377
|
+
},
|
|
1378
|
+
async ({ account_id, days }) => {
|
|
1379
|
+
try {
|
|
1380
|
+
const { getSentimentReport } = await import("../lib/sentiment.js");
|
|
1381
|
+
const report = getSentimentReport(account_id, days);
|
|
1382
|
+
return { content: [{ type: "text", text: JSON.stringify(report, null, 2) }] };
|
|
1383
|
+
} catch (error) {
|
|
1384
|
+
return {
|
|
1385
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
1386
|
+
isError: true,
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
);
|
|
1391
|
+
|
|
1392
|
+
server.registerTool(
|
|
1393
|
+
"auto_analyze_mention",
|
|
1394
|
+
{
|
|
1395
|
+
title: "Auto-Analyze Mention Sentiment",
|
|
1396
|
+
description: "Analyze a mention's content for sentiment and store the result in the mention record. Returns the sentiment analysis result.",
|
|
1397
|
+
inputSchema: {
|
|
1398
|
+
mention_id: z.string(),
|
|
1399
|
+
},
|
|
1400
|
+
},
|
|
1401
|
+
async ({ mention_id }) => {
|
|
1402
|
+
try {
|
|
1403
|
+
const { autoAnalyzeMention } = await import("../lib/sentiment.js");
|
|
1404
|
+
const result = await autoAnalyzeMention(mention_id);
|
|
1405
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1406
|
+
} catch (error) {
|
|
1407
|
+
return {
|
|
1408
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
1409
|
+
isError: true,
|
|
1410
|
+
};
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
);
|
|
1414
|
+
|
|
645
1415
|
// --- Start ---
|
|
646
1416
|
async function main() {
|
|
647
1417
|
const transport = new StdioServerTransport();
|