-
Notifications
You must be signed in to change notification settings - Fork 30
Description
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 xThis 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:
mcp-server-redditcallsself.client.p.subreddit.fetch_by_name(subreddit_name)inserver.pyredditwarpconstructs aSubredditmodel from the API response- 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)