Skip to content

get_subreddit_info crashes with KeyError: 'active_user_count' #6

@johntrandall

Description

@johntrandall

Description

get_subreddit_info raises a KeyError: 'active_user_count' for any subreddit. Reddit's API has removed the active_user_count field from subreddit responses, causing the underlying redditwarp library to crash during model construction.

Steps to Reproduce

Call the get_subreddit_info tool with any subreddit name:

{"name": "get_subreddit_info", "arguments": {"subreddit_name": "python"}}

Error

KeyError: 'active_user_count'

Root Cause

The crash originates in redditwarp (dependency), specifically in redditwarp/models/subreddit.py:

self.viewing_count: int = -1 if (x := d['active_user_count']) is None else x

This uses bracket access (d['active_user_count']) instead of .get(), so when Reddit's API no longer includes the field, it raises KeyError.

The call chain is:

  1. mcp-server-reddit calls self.client.p.subreddit.fetch_by_name(subreddit_name) in server.py
  2. redditwarp constructs a Subreddit model from the API response
  3. The model constructor does d['active_user_count'] on the raw JSON — crashes

Suggested Fix

Option A (upstream): File on Pyprohly/redditwarp to change d['active_user_count'] to d.get('active_user_count').

Option B (in this repo): Wrap the get_subreddit_info call in a try/except and return a degraded response (omitting active_user_count) when the field is missing.

Environment

  • mcp-server-reddit: v1.26.0
  • redditwarp: (latest via pip)
  • Transport: supergateway (Streamable HTTP)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions