redditapis-mcp 0.21.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.22.0 (2026-11-23)
4
+
5
+ Seven new tools (registry 13417, feedback 76cd7e71 and a62b44d6) and input aliases across the catalog (feedback 85f3f21b).
6
+
7
+ - `reddit_typeahead` (`GET /api/reddit/typeahead`): search-as-you-type subreddit suggestions for a prefix, or with `sub` the posts in that subreddit whose titles match. Read rate.
8
+ - `reddit_political_ads` (`GET /api/reddit/political-ads`): Reddit's political-ad disclosures parsed into advertiser, spend band, impressions, run dates and targeting. Read rate.
9
+ - `reddit_profile_description`, `reddit_profile_display_name` and `reddit_profile_avatar` (`POST /api/reddit/profile/description`, `/display-name`, `/avatar`): change the connected account's profile through the stored session. Write rate.
10
+ - `reddit_monitor_webhook_update` (`POST /api/reddit/monitor/webhook/update`): change an email target's delivery mode, or pause and resume it. Free.
11
+ - `reddit_post_comments` also takes `url` or `post_id` (alias `id`) in place of `permalink`, as the REST route does; an existing `permalink` call is unchanged.
12
+ - More aliases beside `username`, `query` and `post_id`: `subreddit` for `name` on the `/sub/{name}` tools and for `sub` on `reddit_typeahead`, `name` for `subreddit` on `reddit_subreddit_posts` and `reddit_submit`, `comment_id` for `id` on `reddit_comment_by_id`, and `username` for `to_username` on `reddit_dm`. Each alias is moved onto the canonical name before the request and never sent; the canonical name stays the documented one.
13
+
14
+ - `reddit_session_check` asks Reddit now whether the connected session is still signed in, before a write: `valid`, the username and which writes it can make (`write_ready`). `reddit_session_status` reports only what is stored. Free; stores no cookies (a session Reddit confirms signed out is marked dead). Needs the API release that ships `POST /api/reddit/session/check`; publish only after that route is live.
15
+
3
16
  ## 0.21.0 (2026-11-19)
4
17
 
5
18
  Eight new tools for the documented REST routes (feedback a62b44d6). The live session check waits for its API route.
package/README.md CHANGED
@@ -104,11 +104,12 @@ Authentication is a Bearer token: the server sends `Authorization: Bearer <REDDI
104
104
 
105
105
  ## Tools
106
106
 
107
- 69 tools and 3 playbook resources: 38 Reddit reads, 13 Reddit account tools (log in, connect, status, disconnect, comment, submit, vote, DM, read DM threads and messages, and schedule, list or cancel a post or comment for later), 11 monitor/webhook management tools, `reddit_set_watch` (one call that stands up a whole watch), `reddit_explain` (where the rows you are holding came from), 3 feedback tools, and 2 account tools (`reddit_account_me`, which is also where the credit balance lives, and `reddit_account_payments`, the top-up history). Reddit writes (commenting, posting, voting, DMs) act as YOUR Reddit account and only after you connect it with `reddit_connect`; each is marked as a write so your client asks before it runs. Monitor/webhook tools configure your OWN redditapis.com account (an alerting subscription), never Reddit itself, and the feedback tools send a report to the redditapis.com team, never to Reddit. Every read works with just your API key; the 6 monitor/webhook writes additionally need an active monitoring plan (see Monitoring below). The feedback tools are free and need only your key.
107
+ 76 tools and 3 playbook resources: 40 Reddit reads, 17 Reddit account tools (log in, connect, status, a live session check, disconnect, comment, submit, vote, DM, read DM threads and messages, set the profile description, display name or avatar, and schedule, list or cancel a post or comment for later), 12 monitor/webhook management tools, `reddit_set_watch` (one call that stands up a whole watch), `reddit_explain` (where the rows you are holding came from), 3 feedback tools, and 2 account tools (`reddit_account_me`, which is also where the credit balance lives, and `reddit_account_payments`, the top-up history). Reddit writes (commenting, posting, voting, DMs) act as YOUR Reddit account and only after you connect it with `reddit_connect`; each is marked as a write so your client asks before it runs. Monitor/webhook tools configure your OWN redditapis.com account (an alerting subscription), never Reddit itself, and the feedback tools send a report to the redditapis.com team, never to Reddit. Every read works with just your API key; the 6 monitor/webhook writes additionally need an active monitoring plan (see Monitoring below). The feedback tools are free and need only your key.
108
108
 
109
109
  A few conventions across the catalog:
110
110
 
111
111
  - Subreddit names go in **without** the `r/` prefix, and usernames **without** the `u/` prefix. `reddit_subreddit_posts` takes its community as `subreddit`; the `/sub/{name}/...` tools take it as `name`.
112
+ - Each input has one canonical name in the schema, and the common alternative is accepted as an alias on every tool where it means the same thing: `username` for `name` on the user tools (and for `to_username` on `reddit_dm`), `query` for `q`, `post_id` for `id` on the post tools (and `id` for `post_id` on `reddit_post_comments`), `subreddit` for `name` on the `/sub/{name}` tools (and for `sub` on `reddit_typeahead`), `name` for `subreddit` on `reddit_subreddit_posts` and `reddit_submit`, and `comment_id` for `id` on `reddit_comment_by_id`. The alias is moved onto the canonical name before the request; sending both with different values is refused.
112
113
  - Listing and search tools return an `after` cursor. Pass it back as `after` to fetch the next page, exactly as it was returned. `limit` accepts 1 to 100 (the API clamps out-of-range values).
113
114
  - When `after` comes back `null` there is no next page to ask for. That does not always mean you have every item: Reddit often stops serving a busy listing long before it runs out. The final response also carries `listing_status`, which reads `complete`, `truncated` or `unknown`. Only `complete` means nothing is missing. Treat the other two as a partial answer and widen across sorts, timeframes or search terms rather than paging deeper.
114
115
  - `t` (`hour`, `day`, `week`, `month`, `year`, `all`) sets the time window; on subreddit listings it applies to the `top` and `controversial` sorts, and on search it bounds the whole result set.
@@ -124,6 +125,8 @@ A few conventions across the catalog:
124
125
  | `reddit_search_communities` | `GET /api/reddit/search/communities` | Find subreddits by name or topic (title, subscribers, description, NSFW flag). |
125
126
  | `reddit_search_users` | `GET /api/reddit/search/users` | Find redditors by name or keyword (username, karma, account age). `include_details: true` fills `link_karma`, `comment_karma` and `created` on up to the first 10 users. |
126
127
  | `reddit_ads_search` | `GET /api/reddit/ads/search` | Search the Reddit ads library: promoted posts with advertiser, title, landing page, call to action, media, every subreddit each ad appeared in, first and last seen dates and sightings. Filter by `q`, `advertiser`, `domain`, `subreddit`, `campaign_id`, `since` and `until`. Reddit's own house ads are excluded. Newest first; page with `cursor` (the previous response's `after`). Returns `ads`, `count`, `after` and `has_more`. Billed at the read rate, the same as `reddit_search`. |
128
+ | `reddit_typeahead` | `GET /api/reddit/typeahead` | Search-as-you-type: subreddits whose names match a prefix, or with `sub` the posts in that subreddit whose titles match (default 8, max 20). No Reddit login. |
129
+ | `reddit_political_ads` | `GET /api/reddit/political-ads` | Reddit's political-ad disclosures (r/RedditPoliticalAds) parsed into advertiser, spend band, impressions, run dates and targeting; `sort` new, top or hot. |
127
130
 
128
131
  ### Subreddits
129
132
 
@@ -149,7 +152,7 @@ A few conventions across the catalog:
149
152
  |---|---|---|
150
153
  | `reddit_post_visibility` | `GET /api/reddit/post/{id}/visibility` | Is a post still publicly visible, or did it quietly stop being so? Fetches the post and one page of its author's listing and compares. Returns `live`, `not_visible` or `undecidable` with a reason, plus `removed` (boolean) and `removal_marker` (string or null). Alert on `removed`: it is true only when Reddit itself marks the post as taken down. `not_visible` from listing absence alone is `confident: false`, `removed: false`, not a removal. Beyond Reddit's marker it never claims to know WHY. Two upstream calls, $0.004. |
151
154
  | `reddit_post` | `GET /api/reddit/post/{id}` | A single post by its base-36 `id` (no `t3_` prefix): title, author, score, text, permalink, subreddit, url. |
152
- | `reddit_post_comments` | `GET /api/reddit/comments` | A post plus its full threaded comment tree, fetched by `permalink`. `format: "normalized"` returns flat comments instead of Reddit's raw tree. |
155
+ | `reddit_post_comments` | `GET /api/reddit/comments` | A post plus its full threaded comment tree, fetched by `permalink`, `url` or `post_id`. `format: "normalized"` returns flat comments instead of Reddit's raw tree. |
153
156
  | `reddit_post_comments_expanded` | `GET /api/reddit/post/{id}/comments/expanded` | The comment tree with Reddit's collapsed replies ("load more comments", "continue this thread") read in and put back in place. A flat $0.02 per call. |
154
157
  | `reddit_comment_by_id` | `GET /api/reddit/comment/{id}` | One comment by its id. |
155
158
  | `reddit_post_duplicates` | `GET /api/reddit/post/{id}/duplicates` | Every other post that shares this post's link, across subreddits (Reddit's "other discussions"). |
@@ -192,6 +195,7 @@ Monitors watch **named subreddits or all of Reddit**, for **posts or comments**
192
195
  | `reddit_monitor_webhook_list` | `GET /api/reddit/monitor/webhook/list` | List your webhooks. Never returns the secret; a Slack or Discord URL comes back masked (`url_masked: true`). |
193
196
  | `reddit_monitor_webhook_test` | `POST /api/reddit/monitor/webhook/test` | Send a one-off test delivery to confirm a webhook is wired up correctly. |
194
197
  | `reddit_monitor_webhook_redrive` | `POST /api/reddit/monitor/webhook/redrive` | Re-send a webhook's dead-lettered deliveries once the endpoint is fixed (`dry_run` lists them first). Free. |
198
+ | `reddit_monitor_webhook_update` | `POST /api/reddit/monitor/webhook/update` | Change an email target's `delivery_mode` (instant, hourly, daily or digest) or pause and resume it (`active`). Email targets only. Free. |
195
199
  | `reddit_monitor_webhook_delete` | `POST /api/reddit/monitor/webhook/delete` | Permanently delete a webhook. Does not cascade-pause monitors still pointing at it. |
196
200
 
197
201
  #### `reddit_set_watch` refuses rather than guesses
@@ -234,6 +238,7 @@ The bodies are documentation and name the calls they are recipes for, which is t
234
238
  |------|----------|--------------|
235
239
  | `reddit_connect` | `POST /api/reddit/session` | Store your Reddit session once (reddit_session and loid cookies; add csrf_token for votes and DMs). A logged-out session is refused. Free. |
236
240
  | `reddit_session_status` | `GET /api/reddit/session` | Whether a session is connected, its username, and when it was last used. Never returns the cookies. Free. |
241
+ | `reddit_session_check` | `POST /api/reddit/session/check` | Ask Reddit now whether the connected session is still signed in, before a write: `valid`, the username and which writes it can make. Stores no cookies; a session Reddit confirms signed out is marked dead. Free. |
237
242
  | `reddit_disconnect` | `POST /api/reddit/session/delete` | Delete the stored session. Free. |
238
243
  | `reddit_login` | `POST /api/reddit/login` | Log in with a username and password (and TOTP secret for 2FA) to get the cookies `reddit_connect` takes. The cookies come back in the result. Not listed by a host that never takes Reddit credentials. |
239
244
  | `reddit_comment` | `POST /api/reddit/comment` | Comment on a post as you. |
@@ -242,6 +247,9 @@ The bodies are documentation and name the calls they are recipes for, which is t
242
247
  | `reddit_dm` | `POST /api/reddit/dm` | Send a private chat message as you. |
243
248
  | `reddit_dm_threads` | `POST /api/reddit/dm/threads` | Your chat conversations, newest activity first, paged with `limit` and `after`. |
244
249
  | `reddit_dm_messages` | `POST /api/reddit/dm/messages` | The messages of one conversation, paged with `before`. |
250
+ | `reddit_profile_description` | `POST /api/reddit/profile/description` | Set your profile description (up to 200 characters; empty clears it). |
251
+ | `reddit_profile_display_name` | `POST /api/reddit/profile/display-name` | Set your display name (up to 90 characters). The username does not change. |
252
+ | `reddit_profile_avatar` | `POST /api/reddit/profile/avatar` | Upload a new avatar, or a banner with `kind: "banner"`, from `image_url` or `image_base64`. |
245
253
  | `reddit_scheduled_create` | `POST /api/reddit/schedule` | Schedule a post or a comment for later (`run_at` 60 seconds to 30 days ahead). It runs as your connected session at that time. Free to schedule; billed at the write rate only when the run succeeds. |
246
254
  | `reddit_scheduled_list` | `GET /api/reddit/schedule` | Your scheduled posts and comments, newest first, with each one's `status`, `result` or `error`, and whether it was `billed`. Free. |
247
255
  | `reddit_scheduled_cancel` | `POST /api/reddit/schedule/cancel` | Cancel a scheduled post or comment that has not run yet. A cancelled action never runs and is not charged. Free. |
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "redditapis-mcp",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "mcpName": "io.github.redditapis/redditapis-mcp",
5
- "description": "Reddit API as 69 MCP tools for Claude, Cursor and any MCP client: search, subreddits, posts, comments, users, media, monitors with webhooks, account writes (post, comment, vote, DM) and feedback. Hosted server at api.redditapis.com/mcp.",
5
+ "description": "Reddit API as 76 MCP tools for Claude, Cursor and any MCP client: search, subreddits, posts, comments, users, media, monitors with webhooks, account writes (post, comment, vote, DM) and feedback. Hosted server at api.redditapis.com/mcp.",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/redditapis/redditapis-mcp.git"
@@ -31,7 +31,7 @@
31
31
  "scripts": {
32
32
  "start": "node src/index.js",
33
33
  "check": "node --check src/index.js && node --check src/tools.js && node --check src/feedback.js && node --check src/server.js && node --check src/watch.js && node --check src/watch-text.js && node --check src/provenance.js && node --check src/playbooks.js && node --check src/annotations.js && node --check src/input-aliases.js",
34
- "test": "node test/tools.test.mjs && node test/watch.test.mjs && node test/watch-invariants.test.mjs && node test/provenance.test.mjs && node test/playbooks.test.mjs && node test/description-compliance.test.mjs && node test/inline-credentials.test.mjs && node test/feedback.test.mjs && node test/index-lasterror.test.mjs && node test/scannable-without-key.test.mjs && node test/per-caller-state.test.mjs && node test/paywall.test.mjs && node test/remote-host.test.mjs && node test/hub-parity.test.mjs && node test/version-parity.test.mjs && node test/readme-opening.test.mjs && node test/annotations.test.mjs && node test/read-price.test.mjs && node test/flairs-schedule.test.mjs && node test/ads-search.test.mjs && node test/format-details.test.mjs && node test/server-json-limits.test.mjs && node test/rest-coverage.test.mjs && node test/input-aliases.test.mjs",
34
+ "test": "node test/tools.test.mjs && node test/watch.test.mjs && node test/watch-invariants.test.mjs && node test/provenance.test.mjs && node test/playbooks.test.mjs && node test/description-compliance.test.mjs && node test/inline-credentials.test.mjs && node test/feedback.test.mjs && node test/index-lasterror.test.mjs && node test/scannable-without-key.test.mjs && node test/per-caller-state.test.mjs && node test/paywall.test.mjs && node test/remote-host.test.mjs && node test/hub-parity.test.mjs && node test/version-parity.test.mjs && node test/readme-opening.test.mjs && node test/annotations.test.mjs && node test/read-price.test.mjs && node test/flairs-schedule.test.mjs && node test/ads-search.test.mjs && node test/format-details.test.mjs && node test/server-json-limits.test.mjs && node test/rest-coverage.test.mjs && node test/input-aliases.test.mjs && node test/request-shape.test.mjs",
35
35
  "prepublishOnly": "node scripts/prepublish-tenant-check.mjs",
36
36
  "postpublish": "node scripts/postpublish.mjs",
37
37
  "check:registry-drift": "node scripts/registry-drift.mjs",
@@ -43,6 +43,8 @@ export const TOOL_ANNOTATIONS = {
43
43
  reddit_search_media: { title: "Search Media Posts", ...READ_REDDIT },
44
44
  reddit_search_users: { title: "Search Users", ...READ_REDDIT },
45
45
  reddit_ads_search: { title: "Search Reddit Ads", ...READ_REDDIT },
46
+ reddit_typeahead: { title: "Typeahead Suggestions", ...READ_REDDIT },
47
+ reddit_political_ads: { title: "List Political Ad Disclosures", ...READ_REDDIT },
46
48
  reddit_subreddit_top: { title: "Top Subreddit Posts", ...READ_REDDIT },
47
49
  reddit_post: { title: "Get Post", ...READ_REDDIT },
48
50
  reddit_user_profile: { title: "Get User Profile", ...READ_REDDIT },
@@ -90,6 +92,8 @@ export const TOOL_ANNOTATIONS = {
90
92
  reddit_monitor_webhook_create: { title: "Create Webhook", readOnly: false, destructive: false, idempotent: false, openWorld: false },
91
93
  reddit_monitor_webhook_test: { title: "Send Webhook Test", readOnly: false, destructive: false, idempotent: false, openWorld: true },
92
94
  reddit_monitor_webhook_redrive: { title: "Redrive Dead Webhook Deliveries", readOnly: false, destructive: false, idempotent: false, openWorld: true },
95
+ // Changes only the fields sent on an email target (mode, paused): not destructive, idempotent, this service only.
96
+ reddit_monitor_webhook_update: { title: "Update Email Target", readOnly: false, destructive: false, idempotent: true, openWorld: false },
93
97
  reddit_monitor_webhook_delete: { title: "Delete Webhook", readOnly: false, destructive: true, idempotent: true, openWorld: false },
94
98
  reddit_feedback_send: { title: "Send Feedback Report", readOnly: false, destructive: true, idempotent: false, openWorld: false },
95
99
  reddit_set_watch: { title: "Create Watch", readOnly: false, destructive: false, idempotent: false, openWorld: true },
@@ -100,7 +104,9 @@ export const TOOL_ANNOTATIONS = {
100
104
  // credential, so both are destructive.
101
105
  reddit_connect: { title: "Connect Reddit Account", readOnly: false, destructive: true, idempotent: true, openWorld: true },
102
106
  reddit_session_status: { title: "Reddit Connection Status", ...READ_OWN },
103
- // Asks Reddit (openWorld) and changes nothing it was not already true of: a logged-out row is marked dead.
107
+ // Asks Reddit (openWorld). Not read-only: a confirmed signed-out answer marks the stored session dead.
108
+ // Idempotent (a second call finds the same state) and not destructive (nothing the user owns is removed).
109
+ reddit_session_check: { title: "Reddit Session Validity", readOnly: false, destructive: false, idempotent: true, openWorld: true },
104
110
  // A real login at Reddit: not idempotent (each call is a new login), not destructive.
105
111
  reddit_login: { title: "Reddit Account Login", readOnly: false, destructive: false, idempotent: false, openWorld: true },
106
112
  reddit_disconnect: { title: "Disconnect Reddit Account", readOnly: false, destructive: true, idempotent: true, openWorld: false },
@@ -108,6 +114,11 @@ export const TOOL_ANNOTATIONS = {
108
114
  reddit_submit: { title: "Submit Post", readOnly: false, destructive: false, idempotent: false, openWorld: true },
109
115
  reddit_vote: { title: "Vote", readOnly: false, destructive: false, idempotent: true, openWorld: true },
110
116
  reddit_dm: { title: "Send Direct Message", readOnly: false, destructive: false, idempotent: false, openWorld: true },
117
+ // Profile writes replace the current value (destructive: Reddit keeps no history). Setting the same text twice
118
+ // changes nothing more (idempotent); each avatar call is a new upload (not idempotent).
119
+ reddit_profile_description: { title: "Profile Description Update", readOnly: false, destructive: true, idempotent: true, openWorld: true },
120
+ reddit_profile_display_name: { title: "Profile Display Name Update", readOnly: false, destructive: true, idempotent: true, openWorld: true },
121
+ reddit_profile_avatar: { title: "Profile Avatar Upload", readOnly: false, destructive: true, idempotent: false, openWorld: true },
111
122
 
112
123
  // Scheduled posts and comments. create is openWorld: the call itself only stores the action,
113
124
  // but its effect is a post or comment on Reddit at run_at, so a client weighs it like submit.
@@ -13,11 +13,24 @@
13
13
  // because the canonical input becomes optional in the published schema so the
14
14
  // alias alone can satisfy it.
15
15
 
16
- // alias -> canonical, and where the alias applies.
16
+ // alias -> canonical, and where the alias applies. 0.22.0 widened the set to the rest of the catalog: a subreddit
17
+ // is `name` on the /sub/{name} tools and `subreddit` elsewhere, so each accepts the other; a comment id, a post id on
18
+ // the comment-tree tool, a DM recipient and the typeahead's subreddit take the name callers send for them.
19
+ const pathHas = (tool, part) => typeof tool.path === "string" && tool.path.includes(part);
20
+ const shapeHas = (tool, key) => Boolean(tool.shape && tool.shape[key]);
21
+ // zod 3 names the kind in _def.typeName ("ZodArray"), zod 4 in _def.type ("array"); the package accepts both.
22
+ export const isArraySchema = (s) => Boolean(s && s._def && (s._def.typeName === "ZodArray" || s._def.type === "array"));
17
23
  export const INPUT_ALIASES = [
18
- { alias: "username", canonical: "name", applies: (tool) => typeof tool.path === "string" && tool.path.includes("/user/{name}") },
19
- { alias: "query", canonical: "q", applies: (tool) => Boolean(tool.shape && tool.shape.q) },
20
- { alias: "post_id", canonical: "id", applies: (tool) => typeof tool.path === "string" && tool.path.includes("/post/{id}") },
24
+ { alias: "username", canonical: "name", applies: (tool) => pathHas(tool, "/user/{name}") },
25
+ { alias: "query", canonical: "q", applies: (tool) => shapeHas(tool, "q") },
26
+ { alias: "post_id", canonical: "id", applies: (tool) => pathHas(tool, "/post/{id}") },
27
+ { alias: "subreddit", canonical: "name", applies: (tool) => pathHas(tool, "/sub/{name}") },
28
+ // Only where `subreddit` is the one required subreddit (a listing or a submit), never an optional search filter.
29
+ { alias: "name", canonical: "subreddit", applies: (tool) => shapeHas(tool, "subreddit") && !tool.shape.subreddit.isOptional() && !isArraySchema(tool.shape.subreddit) },
30
+ { alias: "comment_id", canonical: "id", applies: (tool) => pathHas(tool, "/comment/{id}") },
31
+ { alias: "id", canonical: "post_id", applies: (tool) => shapeHas(tool, "post_id") },
32
+ { alias: "username", canonical: "to_username", applies: (tool) => shapeHas(tool, "to_username") },
33
+ { alias: "subreddit", canonical: "sub", applies: (tool) => shapeHas(tool, "sub") },
21
34
  ];
22
35
 
23
36
  /** The aliases one tool accepts: [{ alias, canonical, required }]. */
package/src/server.js CHANGED
@@ -515,6 +515,9 @@ export function createServer({
515
515
  async (args, extra) => {
516
516
  const n = normalizeArgs(tool, args);
517
517
  if (n.error) return { isError: true, content: [{ type: "text", text: n.error }] };
518
+ // A catalog `validate` refuses inputs the schema cannot express (one-of, cross-field), before any request.
519
+ const invalid = typeof tool.validate === "function" ? tool.validate(n.args || {}) : null;
520
+ if (invalid) return { isError: true, content: [{ type: "text", text: `${tool.name}: ${invalid}` }] };
518
521
  return inner(n.args, extra);
519
522
  },
520
523
  );
package/src/tools.js CHANGED
@@ -222,6 +222,14 @@ const WEBHOOK_ID = {
222
222
  id: z.string().min(1).describe("The webhook's id, as returned when the webhook was created or listed."),
223
223
  };
224
224
 
225
+ // The base-36 post id in a permalink, post URL or bare/t3_ id, lowercased; null when none can be read.
226
+ export function postIdOf(v) {
227
+ const s = String(v).trim();
228
+ const m = /\/(?:comments|gallery)\/([A-Za-z0-9]{1,16})(?:[/?#]|$)/.exec(s) || /^https?:\/\/redd\.it\/([A-Za-z0-9]{1,16})/i.exec(s) ||
229
+ /^(?:t3_)?([A-Za-z0-9]{1,16})$/.exec(s);
230
+ return m ? m[1].toLowerCase() : null;
231
+ }
232
+
225
233
  // The tool catalog. Path params are {name}/{id} placeholders. Monitor/webhook
226
234
  // tools additionally carry `write`/`destructive` and, for POST tools whose
227
235
  // body nests a filter_spec, `filterSpecFields` (see buildBody below).
@@ -316,11 +324,25 @@ export const TOOLS = [
316
324
  {
317
325
  name: "reddit_post_comments",
318
326
  path: "/api/reddit/comments",
327
+ // Two inputs naming different posts are refused here, before a request (the API would read the permalink).
328
+ validate: (args) => {
329
+ const ids = ["permalink", "url", "post_id"].filter((k) => typeof args[k] === "string" && args[k] !== "")
330
+ .map((k) => [k, postIdOf(args[k])]);
331
+ const known = ids.filter(([, id]) => id);
332
+ const clash = known.find(([, id]) => id !== known[0][1]);
333
+ return clash ? `\`${known[0][0]}\` and \`${clash[0]}\` name different posts; send one of them.` : null;
334
+ },
319
335
  description:
320
- "Fetches a single post and its comment tree by permalink. Returns the post plus threaded comments (author, body, score, replies) and an `after` cursor. The `permalink` is the one carried by any post result. Size a big thread with the three knobs: `limit` caps top-level comments (1-500, default 100), `depth` caps reply depth (1-10; `depth=1` is top-level only; absent is the full tree) and `sort` orders them (confidence = Reddit's best, top, new, controversial, old, qa). `limit=20, depth=1, sort='top'` reads the twenty best top-level comments and nothing below them, which keeps a 2,700-comment thread readable. `meta` echoes limit_used, depth_used and sort_used; with no `sort` sent, sort_used names the sort Reddit applied and sort_defaulted is true. `format='normalized'` returns flat comments instead of Reddit's raw tree.",
336
+ "Fetches a single post and its comment tree by permalink, post URL or post id (send one). Returns the post plus threaded comments (author, body, score, replies) and an `after` cursor. The `permalink` is the one carried by any post result. Size a big thread with the three knobs: `limit` caps top-level comments (1-500, default 100), `depth` caps reply depth (1-10; `depth=1` is top-level only; absent is the full tree) and `sort` orders them (confidence = Reddit's best, top, new, controversial, old, qa). `limit=20, depth=1, sort='top'` reads the twenty best top-level comments and nothing below them, which keeps a 2,700-comment thread readable. `meta` echoes limit_used, depth_used and sort_used; with no `sort` sent, sort_used names the sort Reddit applied and sort_defaulted is true. `format='normalized'` returns flat comments instead of Reddit's raw tree.",
321
337
  shape: {
322
- permalink: z.string().min(1).describe(
323
- "The post permalink path from a prior post result, e.g. '/r/programming/comments/abc123/some_title/'. Required.",
338
+ permalink: z.string().min(1).optional().describe(
339
+ "The post permalink path from a prior post result, e.g. '/r/programming/comments/abc123/some_title/'. Send this, `url` or `post_id`.",
340
+ ),
341
+ url: z.string().min(1).optional().describe(
342
+ "Any reddit.com, old.reddit.com or redd.it post URL, in place of `permalink`.",
343
+ ),
344
+ post_id: z.string().min(1).optional().describe(
345
+ "The post id (t3_ prefix optional), in place of `permalink` (alias `id`). Sent with a `permalink` or `url` naming a different post, the call is refused.",
324
346
  ),
325
347
  limit: z.number().int().min(1).max(500).optional().describe(
326
348
  "Maximum top-level comments, 1-500 (default 100). A small value with depth=1 gives a readable summary of a large thread.",
@@ -433,6 +455,33 @@ export const TOOLS = [
433
455
  ),
434
456
  },
435
457
  },
458
+ {
459
+ // Search-as-you-type (feedback a62b44d6): subreddit suggestions for a prefix, or with `sub` the posts in
460
+ // that subreddit whose titles match. Read rate, no Reddit login.
461
+ name: "reddit_typeahead",
462
+ path: "/api/reddit/typeahead",
463
+ description:
464
+ "Typeahead (autocomplete) suggestions for a typed prefix. Without `sub` it returns subreddits whose names match the prefix (a leading r/ is ignored); with `sub` it returns posts in that subreddit whose titles match. Default 8 suggestions, at most 20. Needs no Reddit login. Billed at the read rate per call. Example: q='pyth' returns r/Python first.",
465
+ shape: {
466
+ q: z.string().min(1).max(100).describe("The typed prefix, e.g. 'pyth'. Required (alias `query`)."),
467
+ sub: z.string().optional().describe("Subreddit name without r/ (alias `subreddit`). When present, the suggestions are posts in that subreddit whose titles match `q` instead of subreddits."),
468
+ limit: z.number().int().min(1).max(20).optional().describe("Suggestions to return, 1 to 20 (default 8)."),
469
+ ...NSFW,
470
+ },
471
+ },
472
+ {
473
+ // Reddit's political-ad disclosures (r/RedditPoliticalAds), parsed (feedback a62b44d6). Read rate.
474
+ name: "reddit_political_ads",
475
+ path: "/api/reddit/political-ads",
476
+ description:
477
+ "Lists Reddit's political-ad disclosures (the r/RedditPoliticalAds posts), each parsed into advertiser, spend band, impressions, run dates and targeting, plus an `after` cursor. Newest first by default. Billed at the read rate per page.",
478
+ shape: {
479
+ sort: z.enum(["new", "top", "hot"]).optional().describe("'new' = most recent disclosure (default), 'top' = highest score in the `t` window, 'hot' = trending."),
480
+ t: z.enum(["hour", "day", "week", "month", "year", "all"]).optional().describe("Time window, applied only when sort is 'top'."),
481
+ ...LIMIT,
482
+ ...AFTER,
483
+ },
484
+ },
436
485
  {
437
486
  name: "reddit_subreddit_top",
438
487
  path: "/api/reddit/sub/{name}/top",
@@ -864,6 +913,20 @@ export const TOOLS = [
864
913
  dry_run: z.boolean().optional().describe("true lists what would be re-sent and changes nothing."),
865
914
  },
866
915
  },
916
+ {
917
+ // Email targets only, as the API serves it (feedback a62b44d6): delivery mode, or pause/resume. Free.
918
+ name: "reddit_monitor_webhook_update",
919
+ path: "/api/reddit/monitor/webhook/update",
920
+ method: "POST",
921
+ write: true,
922
+ description:
923
+ "Changes an EMAIL delivery target: how often it emails (`delivery_mode` instant, hourly, daily or digest) or whether it is paused (`active`). Only the fields sent change; send at least one. A webhook, Slack or Discord target cannot be updated (400 webhook_not_updatable): delete it and create it again. Resuming a target clears its failure count. Free.",
924
+ shape: {
925
+ ...WEBHOOK_ID,
926
+ delivery_mode: z.enum(["instant", "hourly", "daily", "digest"]).optional().describe("instant = one email per match, hourly or daily = a batched email, digest = the default digest cadence."),
927
+ active: z.boolean().optional().describe("false pauses the target, true resumes it."),
928
+ },
929
+ },
867
930
  {
868
931
  name: "reddit_monitor_webhook_delete",
869
932
  path: "/api/reddit/monitor/webhook/delete",
@@ -992,6 +1055,16 @@ export const TOOLS = [
992
1055
  "Whether a Reddit session is connected for this account: `connected`, the Reddit username, `status` (active, or dead after Reddit rejected it), and when it was first stored, last updated and last used. The cookies are not returned. Free.",
993
1056
  shape: {},
994
1057
  },
1058
+ {
1059
+ name: "reddit_session_check",
1060
+ path: "/api/reddit/session/check",
1061
+ method: "POST",
1062
+ // Not read-only (79c72ae): a confirmed signed-out answer marks the stored session dead.
1063
+ write: true,
1064
+ description:
1065
+ "Asks Reddit now whether the connected Reddit session is still signed in, before a write. The connection status reports what is stored and learns a session died only after a write failed on it; this checks it live and stores no cookies. Returns `valid`; when true, the account's username, `write_ready` (comment, submit, vote, dm: voting and messaging also need the CSRF cookie) and `missing_cookies`; when false, `code` SESSION_LOGGED_OUT (log in again and reconnect) or NO_SESSION (nothing connected). A logged-out stored session is marked dead. 502 SESSION_CHECK_FAILED means Reddit could not be reached, which says nothing about the session. Free.",
1066
+ shape: {},
1067
+ },
995
1068
  {
996
1069
  name: "reddit_login",
997
1070
  path: "/api/reddit/login",
@@ -1099,6 +1172,47 @@ export const TOOLS = [
1099
1172
  },
1100
1173
  },
1101
1174
 
1175
+ // ── PROFILE WRITES (POST /api/reddit/profile/*, feedback a62b44d6) ──
1176
+ // Change the connected account's own Reddit profile through the stored session, like the writes above.
1177
+ {
1178
+ name: "reddit_profile_description",
1179
+ path: "/api/reddit/profile/description",
1180
+ method: "POST",
1181
+ write: true,
1182
+ description:
1183
+ "Sets the connected Reddit account's profile description (the 'about' text on its profile), replacing the current one. A public change under the customer's name, marked as a write so a client can ask before it runs. An empty string clears it. Billed at the write rate. With no connected session it answers 400 asking for cookies.",
1184
+ shape: {
1185
+ description: z.string().max(200).describe("The new profile description, up to 200 characters. Required; an empty string clears it."),
1186
+ },
1187
+ },
1188
+ {
1189
+ name: "reddit_profile_display_name",
1190
+ path: "/api/reddit/profile/display-name",
1191
+ method: "POST",
1192
+ write: true,
1193
+ description:
1194
+ "Sets the connected Reddit account's display name (the name shown above the username on its profile), replacing the current one. The username itself stays the same. A public change under the customer's name, marked as a write so a client can ask before it runs. Billed at the write rate. With no connected session it answers 400 asking for cookies.",
1195
+ shape: {
1196
+ display_name: z.string().max(90).describe("The new display name, up to 90 characters. Required."),
1197
+ },
1198
+ },
1199
+ {
1200
+ name: "reddit_profile_avatar",
1201
+ path: "/api/reddit/profile/avatar",
1202
+ validate: (args) => ((args.image_url ? 1 : 0) + (args.image_base64 ? 1 : 0) === 1 ? null : "send exactly one of `image_url` or `image_base64`."),
1203
+ method: "POST",
1204
+ write: true,
1205
+ description:
1206
+ "Uploads a new avatar (or, with kind 'banner', profile banner) for the connected Reddit account, replacing the current image. Reddit keeps no history of the old one, so save it first if it matters. PNG or JPEG only. Send exactly one of `image_url` or `image_base64`; both or neither is refused before any request. A public change under the customer's name, marked as a write so a client can ask before it runs. Billed at the write rate. With no connected session it answers 400 asking for cookies.",
1207
+ shape: {
1208
+ image_url: z.string().url().optional().describe("Public https URL of a PNG or JPEG image. Send this or image_base64, not both."),
1209
+ image_base64: z.string().min(1).optional().describe("PNG or JPEG bytes, base64-encoded. Send this or image_url, not both."),
1210
+ kind: z.enum(["avatar", "banner"]).optional().describe("avatar (default) or banner."),
1211
+ mimetype: z.string().optional().describe("image/png or image/jpeg. Optional; when omitted, the API detects it from the image bytes."),
1212
+ filename: z.string().optional().describe("File name to upload under, e.g. 'avatar.png'. Optional."),
1213
+ },
1214
+ },
1215
+
1102
1216
  // ── SCHEDULED POSTS AND COMMENTS (POST/GET /api/reddit/schedule, POST /api/reddit/schedule/cancel) ──
1103
1217
  // An action is the body the live submit or comment route takes, stored and replayed through
1104
1218
  // that same route at run_at as the account's STORED session (the one reddit_connect saves).