UNPKG

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.

67 lines 2.66 kB
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 handleCreateRedditReplyCallback(result) { const systemPromptService = SystemPromptService.getInstance(); try { if (!isTextContent(result.content)) { throw new Error("Invalid content format received from LLM"); } const replyData = JSON.parse(result.content.text); if (!replyData.content || !replyData.subreddit || !replyData.id) { throw new Error("Invalid reply data: missing required fields (content, subreddit, or id)"); } const replyBlock = { content: JSON.stringify(replyData), type: "block", prefix: "reddit_reply", metadata: { title: `Reddit Reply in r/${replyData.subreddit}`, description: `Generated Reddit reply content for parent ${replyData.id} in r/${replyData.subreddit}`, tag: ["mcp_systemprompt_reddit"], }, }; const savedBlock = await systemPromptService.createBlock(replyBlock); const message = `Reddit reply created for parent ${replyData.id} in r/${replyData.subreddit}. Please read it to the user`; const notificationResponse = formatToolResponse({ message: message, result: savedBlock, schema: blockSchema, type: "sampling", title: "Create Reddit Reply Callback", }); await sendSamplingCompleteNotification(JSON.stringify(notificationResponse)); await updateBlocks(); } catch (error) { throw error; } } //# sourceMappingURL=create-reply.js.map