systemprompt-mcp-reddit
Version:
A specialized Model Context Protocol (MCP) server that enables you to search, read, and interact with Reddit content, leveraging an AI Agent to help with each operation.
73 lines • 2.82 kB
JavaScript
import { SystemPromptService } from "../../services/systemprompt-service.js";
import { sendSamplingCompleteNotification, updateBlocks } from "../notifications.js";
import { formatToolResponse } from "../tools/types.js";
const blockSchema = {
type: "object",
properties: {
id: { type: "string" },
content: { type: "string" },
type: { type: "string" },
prefix: { type: "string" },
metadata: {
type: "object",
properties: {
title: { type: "string" },
description: { type: "string" },
tag: { type: "array", items: { type: "string" } },
},
required: ["title", "description", "tag"],
},
},
required: ["id", "content", "type", "prefix", "metadata"],
};
function isTextContent(content) {
return (typeof content === "object" &&
content !== null &&
"type" in content &&
content.type === "text" &&
"text" in content &&
typeof content.text === "string");
}
export async function handleAnalyseSubredditCallback(result) {
const systemPromptService = SystemPromptService.getInstance();
try {
if (!isTextContent(result.content)) {
throw new Error("Invalid content format received from LLM");
}
const analysisData = JSON.parse(result.content.text);
if (!analysisData.subreddit ||
!analysisData.summary ||
!analysisData.trendingTopics ||
!analysisData.sentiment ||
!analysisData.recommendedActions) {
throw new Error("Invalid analysis data: missing required fields");
}
// Create a block to store the subreddit analysis
const analysisBlock = {
content: JSON.stringify(analysisData),
type: "block",
prefix: "reddit_subreddit_analysis",
metadata: {
title: `Analysis of r/${analysisData.subreddit}`,
description: `Generated analysis for r/${analysisData.subreddit}`,
tag: ["mcp_systemprompt_reddit"],
},
};
// Create new block
const savedBlock = await systemPromptService.createBlock(analysisBlock);
const message = `Reddit analysis created for r/${analysisData.subreddit}. Please read it to the user`;
const notificationResponse = formatToolResponse({
message: message,
result: savedBlock,
schema: blockSchema,
type: "sampling",
title: "Analyse Subreddit Callback",
});
await sendSamplingCompleteNotification(JSON.stringify(notificationResponse));
await updateBlocks();
}
catch (error) {
throw error;
}
}
//# sourceMappingURL=analyse-subreddit.js.map