Skip to main content
Glama

Reddit MCP Server

by ozipi
suggest-action.ts1.5 kB
import type { CreateMessageResult, TextContent } from '@modelcontextprotocol/sdk/types.js'; import { sendSamplingCompleteNotification } from '../notifications.js'; import { formatToolResponse } from '../tools/types.js'; // Interface for suggested action response export interface GeneratedSuggestAction { action: string; subreddit?: string; reasoning: string; content?: string; id?: string; [key: string]: any; } function isTextContent(content: unknown): content is TextContent { return ( typeof content === "object" && content !== null && 'type' in content && (content as any).type === "text" && 'text' in content && typeof (content as any).text === "string" ); } export async function handleSuggestActionCallback(result: CreateMessageResult, sessionId: string): Promise<string> { try { if (!isTextContent(result.content)) { throw new Error("Invalid content format received from LLM"); } const actionData = JSON.parse(result.content.text) as GeneratedSuggestAction; if (!actionData.action || !actionData.reasoning) { throw new Error("Invalid action data: missing required fields (action or reasoning)"); } const message = `Reddit action suggestion generated: ${actionData.action}`; await sendSamplingCompleteNotification(message, sessionId); return JSON.stringify( formatToolResponse({ message: message, result: actionData, }), ); } catch (error) { throw error; } }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ozipi/brainloop-mcp-server-v2'

If you have feedback or need assistance with the MCP directory API, please join our Discord server