Skip to main content
Glama
Arindam200

Reddit MCP Server

join_subreddit

Subscribe to or unsubscribe from Reddit communities to customize your feed and manage content preferences.

Instructions

Join (subscribe to) or leave (unsubscribe from) a subreddit.

Args:
    subreddit_name: Name of the subreddit to join/leave (with or without 'r/' prefix)
    unsubscribe: If True, leave the subreddit instead of joining

Returns:
    Dictionary containing information about the action and subreddit

Raises:
    ValueError: If subreddit name is invalid or subreddit not found
    RuntimeError: For other errors during the operation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
subreddit_nameYes
unsubscribeNo

Implementation Reference

  • The handler function implementing the 'join_subreddit' tool. It subscribes or unsubscribes the authenticated Reddit user to/from the specified subreddit using PRAW's subreddit.subscribe() and subreddit.unsubscribe() methods. Includes input validation, error handling, and logging. Registered via @mcp.tool() decorator and protected by @require_write_access.
    @mcp.tool()
    @require_write_access
    def join_subreddit(subreddit_name: str, unsubscribe: bool = False) -> Dict[str, Any]:
        """Join (subscribe to) or leave (unsubscribe from) a subreddit.
    
        Args:
            subreddit_name: Name of the subreddit to join/leave (with or without 'r/' prefix)
            unsubscribe: If True, leave the subreddit instead of joining
    
        Returns:
            Dictionary containing information about the action and subreddit
    
        Raises:
            ValueError: If subreddit name is invalid or subreddit not found
            RuntimeError: For other errors during the operation
        """
        manager = RedditClientManager()
        if not manager.client:
            raise RuntimeError("Reddit client not initialized")
    
        if not subreddit_name or not isinstance(subreddit_name, str):
            raise ValueError("Subreddit name is required")
    
        # Clean up subreddit name
        clean_name = subreddit_name[2:] if subreddit_name.startswith("r/") else subreddit_name
        action = "leave" if unsubscribe else "join"
    
        try:
            logger.info(f"Attempting to {action} r/{clean_name}")
            sub = manager.client.subreddit(clean_name)
    
            # Verify subreddit exists
            try:
                display_name = sub.display_name
            except Exception as e:
                raise ValueError(f"Subreddit r/{clean_name} not found or inaccessible") from e
    
            if unsubscribe:
                sub.unsubscribe()
                message = f"Successfully unsubscribed from r/{display_name}"
            else:
                sub.subscribe()
                message = f"Successfully subscribed to r/{display_name}"
    
            logger.info(message)
    
            return {
                "success": True,
                "action": action,
                "subreddit": display_name,
                "message": message,
                "metadata": {
                    "timestamp": time.time(),
                    "subscribers": getattr(sub, "subscribers", None)
                }
            }
    
        except Exception as e:
            logger.error(f"Error {action}ing r/{clean_name}: {e}")
            if isinstance(e, (ValueError, RuntimeError)):
                raise
            raise RuntimeError(f"Failed to {action} r/{clean_name}: {e}") from e
  • server.py:1497-1497 (registration)
    The @mcp.tool() decorator registers the join_subreddit function as an MCP tool.
    @mcp.tool()
  • The @require_write_access decorator used on join_subreddit to ensure the Reddit client has write access and proper authentication.
    def require_write_access(func: F) -> F:
        """Decorator to ensure write access is available."""
    
        @functools.wraps(func)
        def wrapper(*args: Any, **kwargs: Any) -> Any:
            reddit_manager = RedditClientManager()
            if reddit_manager.is_read_only:
                raise ValueError(
                    "Write operation not allowed in read-only mode. Please provide valid credentials."
                )
            if not reddit_manager.check_user_auth():
                raise Exception(
                    "Authentication required for write operations. "
                    "Please provide valid REDDIT_USERNAME and REDDIT_PASSWORD environment variables."
                )
            return func(*args, **kwargs)
    
        return cast(F, wrapper)
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions potential errors (ValueError, RuntimeError) and the return format (dictionary with action and subreddit info), which adds useful context. However, it lacks details on permissions, rate limits, or side effects (e.g., impact on user profile).

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 well-structured and front-loaded with the core purpose in the first sentence. Subsequent sections (Args, Returns, Raises) are organized efficiently, with each sentence providing essential information without redundancy. No wasted words.

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

Completeness4/5

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

Given the tool's moderate complexity (mutation with two parameters) and no annotations or output schema, the description is largely complete: it covers purpose, parameters, returns, and errors. However, it lacks details on authentication needs or rate limits, which are important for a mutation tool.

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

Parameters5/5

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

The schema description coverage is 0%, so the description must compensate. It fully explains both parameters: 'subreddit_name' (name with or without 'r/' prefix) and 'unsubscribe' (if True, leave instead of join). This adds critical meaning beyond the bare schema, clarifying format and default behavior.

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

Purpose5/5

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

The description clearly states the tool's purpose with specific verbs ('join/subscribe to' and 'leave/unsubscribe from') and identifies the resource ('a subreddit'). It distinguishes this tool from all sibling tools, which are primarily read-only or posting tools, by being the only one that modifies subscription status.

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

Usage Guidelines4/5

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

The description implicitly provides usage context by explaining the dual functionality (join vs. leave based on the 'unsubscribe' parameter). However, it does not explicitly state when to use this tool versus alternatives (e.g., no comparison to other subscription-related tools, though none exist among siblings), nor does it mention prerequisites like authentication or rate limits.

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

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