Skip to main content
Glama

reply_to_post

Post a reply to an existing Reddit post by providing the post ID and your response content to engage in discussions.

Instructions

Post a reply to an existing Reddit post

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesThe content of the reply
post_idYesThe ID of the post to reply to
subredditNoThe subreddit name if known (for validation)

Implementation Reference

  • The MCP tool handler function that processes 'reply_to_post' parameters, calls RedditClient.replyToPost, formats the success response, and handles errors.
    export async function replyToPost(params: { post_id: string; content: string; subreddit?: string; }) { const { post_id, content, subreddit } = params; const client = getRedditClient(); if (!client) { throw new McpError( ErrorCode.InternalError, "Reddit client not initialized" ); } try { console.log(`[Tool] Replying to post ${post_id}`); const comment = await client.replyToPost(post_id, content); const formattedComment = formatCommentInfo(comment); return { content: [ { type: "text", text: ` # Reply Posted Successfully ## Comment Details - Author: u/${formattedComment.author} - Subreddit: r/${formattedComment.context.subreddit} - Thread: ${formattedComment.context.thread} - Link: ${formattedComment.link} Your reply has been successfully posted. `, }, ], }; } catch (error) { console.error(`[Error] Error replying to post: ${error}`); throw new McpError( ErrorCode.InternalError, `Failed to reply to post: ${error}` ); } }
  • Input schema and metadata definition for the 'reply_to_post' tool, registered in the MCP server's tool list.
    name: "reply_to_post", description: "Post a reply to an existing Reddit post", inputSchema: { type: "object", properties: { post_id: { type: "string", description: "The ID of the post to reply to", }, content: { type: "string", description: "The content of the reply", }, subreddit: { type: "string", description: "The subreddit name if known (for validation)", }, }, required: ["post_id", "content"], }, },
  • src/index.ts:464-471 (registration)
    Dispatch logic in the CallToolRequestSchema handler that routes 'reply_to_post' calls to the tools.replyToPost function.
    case "reply_to_post": return await tools.replyToPost( toolParams as { post_id: string; content: string; subreddit?: string; } );
  • Low-level RedditClient method that handles authentication, post existence check, and API call to create the reply comment via Reddit's /api/comment endpoint.
    async replyToPost(postId: string, content: string): Promise<RedditComment> { await this.authenticate(); if (!this.username || !this.password) { throw new Error("User authentication required for posting replies"); } try { if (!(await this.checkPostExists(postId))) { throw new Error( `Post with ID ${postId} does not exist or is not accessible` ); } const params = new URLSearchParams(); params.append("thing_id", `t3_${postId}`); params.append("text", content); const response = await this.api.post("/api/comment", params, { headers: { "Content-Type": "application/x-www-form-urlencoded", }, }); // Extract comment data from response const commentData = response.data; return { id: commentData.id, author: this.username, body: content, score: 1, controversiality: 0, subreddit: commentData.subreddit, submissionTitle: commentData.link_title, createdUtc: Date.now() / 1000, edited: false, isSubmitter: false, permalink: commentData.permalink, }; } catch (error) { console.error(`[Error] Failed to reply to post ${postId}:`, error); throw new Error(`Failed to reply to post ${postId}`); } }

Latest Blog Posts

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/samy-clivolt/reddit-mcp-server'

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