Skip to main content
Glama
jordanburke

reddit-mcp-server

create_post

Create a new post in a specified subreddit with a title and content, supporting both text and link submissions.

Instructions

Create a new post in a subreddit

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesContent of the post (text for self posts, URL for link posts)
is_selfNoWhether this is a self (text) post (true) or link post (false)
subredditYesName of the subreddit to post in
titleYesTitle of the post

Implementation Reference

  • src/index.ts:497-532 (registration)
    MCP tool registration for 'create_post', including schema and inline handler function
    server.addTool({
      name: "create_post",
      description: "Create a new post in a subreddit (requires REDDIT_USERNAME and REDDIT_PASSWORD)",
      parameters: z.object({
        subreddit: z.string().describe("The subreddit name (without r/ prefix)"),
        title: z.string().describe("The post title"),
        content: z.string().describe("The post content (text for self posts, URL for link posts)"),
        is_self: z.boolean().default(true).describe("Whether this is a self post (text) or link post"),
      }),
      execute: async (args) => {
        const client = getRedditClient()
        if (!client) {
          throw new Error("Reddit client not initialized")
        }
    
        // Check if user credentials are configured
        if (!process.env.REDDIT_USERNAME || !process.env.REDDIT_PASSWORD) {
          throw new Error(
            "User authentication required. Please set REDDIT_USERNAME and REDDIT_PASSWORD environment variables.",
          )
        }
    
        const post = await client.createPost(args.subreddit, args.title, args.content, args.is_self)
        const formattedPost = formatPostInfo(post)
    
        return `# Post Created Successfully
    
    ## Post Details
    - Title: ${formattedPost.title}
    - Subreddit: r/${formattedPost.subreddit}
    - Type: ${formattedPost.type}
    - Link: ${formattedPost.links.fullPost}
    
    Your post has been successfully submitted to r/${formattedPost.subreddit}.`
      },
    })
  • Core handler in RedditClient that performs the actual POST /api/submit to Reddit API
    async createPost(subreddit: string, title: string, content: string, isSelf: boolean = true): Promise<RedditPost> {
      await this.authenticate()
    
      if (!this.username || !this.password) {
        throw new Error("User authentication required for posting")
      }
    
      try {
        const kind = isSelf ? "self" : "link"
        const params = new URLSearchParams()
        params.append("sr", subreddit)
        params.append("kind", kind)
        params.append("title", title)
        params.append(isSelf ? "text" : "url", content)
        params.append("api_type", "json") // Request standard JSON response format
    
        const response = await this.makeRequest("/api/submit", {
          method: "POST",
          headers: {
            "Content-Type": "application/x-www-form-urlencoded",
          },
          body: params.toString(),
        })
    
        if (!response.ok) {
          const errorText = await response.text()
          console.error(`[Reddit API] Create post failed: ${response.status} ${response.statusText}`)
          console.error(`[Reddit API] Error response: ${errorText}`)
          throw new Error(`HTTP ${response.status}: ${errorText}`)
        }
    
        const json = (await response.json()) as any
        console.error(`[Reddit API] Create post response:`, JSON.stringify(json, null, 2))
    
        // With api_type=json, response has json.data.id or json.errors
        if (json.json?.errors && json.json.errors.length > 0) {
          const errors = json.json.errors.map((e: any) => e.join(": ")).join(", ")
          console.error(`[Reddit API] Post creation errors: ${errors}`)
          throw new Error(`Reddit API errors: ${errors}`)
        }
    
        // Extract post ID from standard JSON response
        const postId = json.json?.data?.id || json.json?.data?.name?.replace("t3_", "")
    
        if (!postId) {
          console.error(`[Reddit API] No post ID in response`)
          throw new Error("No post ID returned from Reddit")
        }
    
        console.error(`[Reddit API] Post created with ID: ${postId}`)
        return await this.getPost(postId, subreddit)
      } catch (error) {
        // Log and re-throw the actual error
        console.error(`[Reddit API] Create post exception:`, error)
        if (error instanceof Error && error.message.includes("HTTP")) {
          throw error
        }
        throw new Error(
          `Failed to create post in ${subreddit}: ${error instanceof Error ? error.message : String(error)}`,
        )
      }
    }
  • Input schema validation using Zod for the create_post tool parameters
    parameters: z.object({
      subreddit: z.string().describe("The subreddit name (without r/ prefix)"),
      title: z.string().describe("The post title"),
      content: z.string().describe("The post content (text for self posts, URL for link posts)"),
      is_self: z.boolean().default(true).describe("Whether this is a self post (text) or link post"),
    }),
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions creation but fails to describe critical behaviors like authentication requirements, rate limits, error conditions (e.g., invalid subreddit), or what happens upon success (e.g., returns a post ID). This leaves significant gaps for an agent to understand how to use it safely and effectively.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's front-loaded and wastes no space, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a creation tool with no annotations and no output schema, the description is inadequate. It doesn't cover behavioral aspects like authentication, error handling, or return values, leaving the agent with insufficient information to use the tool correctly in context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional meaning beyond implying 'subreddit' and 'post' context, which is minimal value. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Create') and target resource ('new post in a subreddit'), making the purpose immediately understandable. However, it doesn't distinguish this tool from potential alternatives like 'reply_to_post' or specify what type of post (text vs. link) beyond what the schema indicates, preventing a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'reply_to_post' or 'search_reddit', nor does it mention prerequisites such as authentication or subreddit permissions. It simply states what the tool does without contextual usage instructions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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

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