Skip to main content
Glama

get_reddit_post

Fetch a specific Reddit post by providing its subreddit and post ID for content retrieval and analysis.

Instructions

Get a Reddit post

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
subredditYesThe subreddit to fetch posts from
post_idYesThe ID of the post to fetch

Implementation Reference

  • The primary handler function for the 'get_reddit_post' tool. It fetches the specified Reddit post using the Reddit client, formats the information, and returns a detailed markdown-formatted response including post details, content, stats, metadata, links, and engagement analysis.
    export async function getRedditPost(params: {
      subreddit: string;
      post_id: string;
    }) {
      const { subreddit, post_id } = params;
      const client = getRedditClient();
    
      if (!client) {
        throw new McpError(
          ErrorCode.InternalError,
          "Reddit client not initialized"
        );
      }
    
      try {
        console.log(`[Tool] Getting post ${post_id} from r/${subreddit}`);
        const post = await client.getPost(post_id, subreddit);
        const formattedPost = formatPostInfo(post);
    
        return {
          content: [
            {
              type: "text",
              text: `
    # Post from r/${formattedPost.subreddit}
    
    ## Post Details
    - Title: ${formattedPost.title}
    - Type: ${formattedPost.type}
    - Author: u/${formattedPost.author}
    
    ## Content
    ${formattedPost.content}
    
    ## Stats
    - Score: ${formattedPost.stats.score.toLocaleString()}
    - Upvote Ratio: ${(formattedPost.stats.upvoteRatio * 100).toFixed(1)}%
    - Comments: ${formattedPost.stats.comments.toLocaleString()}
    
    ## Metadata
    - Posted: ${formattedPost.metadata.posted}
    - Flags: ${
                formattedPost.metadata.flags.length
                  ? formattedPost.metadata.flags.join(", ")
                  : "None"
              }
    - Flair: ${formattedPost.metadata.flair}
    
    ## Links
    - Full Post: ${formattedPost.links.fullPost}
    - Short Link: ${formattedPost.links.shortLink}
    
    ## Engagement Analysis
    - ${formattedPost.engagementAnalysis.replace(/\n  - /g, "\n- ")}
    
    ## Best Time to Engage
    ${formattedPost.bestTimeToEngage}
              `,
            },
          ],
        };
      } catch (error) {
        console.error(`[Error] Error getting post: ${error}`);
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to fetch post data: ${error}`
        );
      }
    }
  • Defines the input schema for the 'get_reddit_post' tool in the listTools response, requiring 'subreddit' and 'post_id' as strings.
    {
      name: "get_reddit_post",
      description: "Get a Reddit post",
      inputSchema: {
        type: "object",
        properties: {
          subreddit: {
            type: "string",
            description: "The subreddit to fetch posts from",
          },
          post_id: {
            type: "string",
            description: "The ID of the post to fetch",
          },
        },
        required: ["subreddit", "post_id"],
      },
    },
  • src/index.ts:429-432 (registration)
    Registers and dispatches the 'get_reddit_post' tool call to the imported tools.getRedditPost function in the CallToolRequest handler.
    case "get_reddit_post":
      return await tools.getRedditPost(
        toolParams as { subreddit: string; post_id: string }
      );

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