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.

69 lines 2.71 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 handleCreateRedditMessageCallback(result) { const systemPromptService = SystemPromptService.getInstance(); try { if (!isTextContent(result.content)) { throw new Error("Invalid content format received from LLM"); } const messageData = JSON.parse(result.content.text); if (!messageData.recipient || !messageData.subject || !messageData.content) { throw new Error("Invalid message data: missing required fields (recipient, subject, or content)"); } // Create a block to store the message const messageBlock = { content: JSON.stringify(messageData), type: "block", prefix: "reddit_message", metadata: { title: `Message to u/${messageData.recipient}`, description: `Generated Reddit message to u/${messageData.recipient}`, tag: ["mcp_systemprompt_reddit"], }, }; // Create new block const savedBlock = await systemPromptService.createBlock(messageBlock); const message = `Reddit message created for u/${messageData.recipient}. Please read it to the user`; const notificationResponse = formatToolResponse({ message: message, result: savedBlock, schema: blockSchema, type: "sampling", title: "Create Reddit Message Callback", }); await sendSamplingCompleteNotification(JSON.stringify(notificationResponse)); await updateBlocks(); } catch (error) { throw error; } } //# sourceMappingURL=create-message.js.map