redditapis-mcp 0.10.3 → 0.12.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,82 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.12.0 (2026-10-18)
4
+
5
+ ### The read price in the server instructions is passed in, never written
6
+
7
+ The instructions said "most $0.002", a figure written into this file. The day
8
+ read plans moved the read rate to $0.0015, every MCP client would have been told
9
+ a price the API no longer bills. The hosted server now passes the rate
10
+ its own billing charges (`createServer({ readRateUsd })`, the rate the API bills), and the local server names no figure and points at
11
+ redditapis.com/pricing. A missing, non-positive or non-finite rate falls back to
12
+ the figure-free sentence. test/read-price.test.mjs covers both modes and refuses
13
+ a price literal in src/server.js. The instructions stay under the 2048-character
14
+ budget (2044 local, 1853 hosted).
15
+
16
+ The README states the launch prices: $0.0015 per read pay as you go, monthly
17
+ read plans from $19 for 30,000 reads, and 1,000 free reads a month.
18
+
19
+ ## 0.11.0 (2026-10-16)
20
+
21
+ Released to npm as 0.11.0: the changes below plus reddit_account_payments (#23), which makes this a minor release (the version-class gate refuses a patch that adds a tool).
22
+
23
+ ### A read the API answers 503 upstream_timeout is retried once
24
+
25
+ The API now answers a read whose wall-clock budget ran out with `503` and
26
+ `Retry-After`, keeping the `upstream_timeout` error value (it was `408`,
27
+ which told the client its own request was slow). The read retry knew only
28
+ `503 upstream_unavailable` and `408 upstream_timeout`, so this answer lost its
29
+ one retry and got the generic 5xx hint. `(503, upstream_timeout)` is now
30
+ retried once like the other two, and carries the "did not complete in time"
31
+ hint. The wait is the body's `retry_after`, else the `Retry-After` header,
32
+ clamped to 1 to 5 seconds. The retry is sent only when at least 3 seconds of
33
+ `REDDITAPIS_TIMEOUT_MS` are left after the wait, and that attempt is aborted
34
+ at what is left, so the whole tool call ends inside the client timeout; a
35
+ refusal that arrives too late is answered at once with its hint. Writes are
36
+ never retried. `test/remote-host.test.mjs` covers the retry, the hint, the
37
+ header, the write control and the timeout bound. The same bound now covers the
38
+ gateway-page and refused-connection retries too: each is sent only when at least
39
+ 3 s of `REDDITAPIS_TIMEOUT_MS` are left after its wait, so with a client timeout
40
+ under about 3 s plus the delay those retries are no longer sent at all.
41
+
42
+ ### README opening for the listings (README only)
43
+
44
+ The first paragraph is what Glama, mcpservers.org, the MCP Registry and npm
45
+ copy word for word. It now says in one paragraph what the server does and
46
+ costs, followed by the install line, the hosted sign-in line and the website.
47
+ Three FAQ answers replace the old developer-account and posting answers, and
48
+ the FAQ's "Of the other 15" is now "Of the other 17" (47 tools: 30 Reddit
49
+ reads plus 17 others). `server.json` `websiteUrl` is now
50
+ https://www.redditapis.com/mcp, and `package-lock.json`, which still said
51
+ 0.9.1, now carries the package version. `test/readme-opening.test.mjs` (in
52
+ `npm test`) checks the opening, the Website line against `websiteUrl`, every
53
+ tool count the README states against `src/tools.js`, and one version across
54
+ `package.json`, `server.json` and `package-lock.json`. No tool change.
55
+
56
+ ### Every tool has a title and all four annotation hints
57
+
58
+ Each of the 47 tools now registers a short, human-readable `title` (for
59
+ example "Search Posts", "Delete Webhook") and the four MCP tool annotation
60
+ hints: `readOnlyHint`, `destructiveHint`, `idempotentHint` and
61
+ `openWorldHint`. Reads of Reddit data are read-only and open-world; reads of
62
+ the account's own state (balance, payments, monitors, webhooks, deliveries,
63
+ feedback) are read-only and closed-world. Writes are marked destructive when
64
+ they delete, discard or overwrite (`reddit_monitor_remove`,
65
+ `reddit_monitor_webhook_delete`, `reddit_monitor_update`, whose filter
66
+ replaces the old one, and `reddit_feedback_send`, which can discard drafts),
67
+ and idempotent only where repeating the call changes nothing more. Before
68
+ this, every tool's title was its own name and only two hints were set. Tool
69
+ names, input schemas and behaviour are unchanged. A new test fails if any
70
+ registered tool lacks a title or a hint.
71
+
72
+ ### reddit_account_payments
73
+
74
+ The top-up history of the account behind this API key: each payment's amount,
75
+ the credits it added, its status and when it happened, newest first. Free and
76
+ never metered, like `reddit_account_me`, which gives the balance. Backed by
77
+ `GET /account/payments`, verified live (401 without a key, while an unknown
78
+ `/account/*` path is 404). 47 tools.
79
+
3
80
  ## 0.10.3 (2026-10-14)
4
81
 
5
82
  ### reddit_post_comments takes limit, depth and sort
package/README.md CHANGED
@@ -4,9 +4,13 @@
4
4
  [![npm downloads](https://img.shields.io/npm/dm/redditapis-mcp)](https://www.npmjs.com/package/redditapis-mcp)
5
5
  [![license](https://img.shields.io/npm/l/redditapis-mcp)](./LICENSE)
6
6
 
7
- Official **Model Context Protocol** server for [redditapis.com](https://www.redditapis.com), the Reddit API as native tools for Claude, Cursor, Windsurf, and any MCP client. It turns Reddit reads (search, subreddit listings, comment trees, user profiles, community metadata) into typed tools your agent can call directly, plus (since 0.2.0) managing your own redditapis.com monitors and webhooks, and (since 0.4.0) sending the team product feedback the agent drafted and you reviewed.
7
+ redditapis-mcp is the official MCP server for RedditAPIs, built for developers and AI agents that need live Reddit data in Claude, Cursor, Windsurf, VS Code or any MCP client, with no Reddit developer app. Your agent can search posts and comments, read subreddit feeds and rules, expand comment trees, look up users and communities, and set up monitors that send new matching posts to your webhook. Reads cost $0.0015 per call (or a monthly read plan from $19 for 30,000 reads), every account gets 1,000 free reads a month, and new accounts get $0.50 of free credit with no card. The server only reads Reddit; posting, commenting and voting stay on the RedditAPIs REST API. Every tool maps to one endpoint at api.redditapis.com.
8
8
 
9
- Ask your agent to search Reddit for a topic, read a community's top posts of the week, pull a user's comment history, surface the redditors talking about a product, or read a subreddit's rules before you engage, and it calls the API for you. It can also set up a monitor that watches a subreddit for new posts matching a filter and delivers them to a webhook, then check what it's actually delivered. Every tool maps to a REST endpoint at `https://api.redditapis.com`; the server holds no state and forwards your API key on each call.
9
+ Install: `npx -y redditapis-mcp@latest` with `REDDITAPIS_KEY` from https://www.redditapis.com
10
+
11
+ Hosted, sign in instead of pasting a key (Claude Code): `claude mcp add --transport http reddit https://api.redditapis.com/mcp` (carries every tool except the 5 that read your own account)
12
+
13
+ Website: https://www.redditapis.com/mcp
10
14
 
11
15
  ## Quick start
12
16
 
@@ -100,7 +104,7 @@ Authentication is a Bearer token: the server sends `Authorization: Bearer <REDDI
100
104
 
101
105
  ## Tools
102
106
 
103
- 46 tools and 3 playbook resources: 30 Reddit reads, 10 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 1 account tool (`reddit_account_me`, which is also where the credit balance lives). Reddit writes (posting, commenting, voting, DMs) remain a separate authenticated surface and are intentionally out of scope here -- 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
+ 47 tools and 3 playbook resources: 30 Reddit reads, 10 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 (posting, commenting, voting, DMs) remain a separate authenticated surface and are intentionally out of scope here -- 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.
104
108
 
105
109
  A few conventions across the catalog:
106
110
 
@@ -222,6 +226,7 @@ Modelled on Claude Code's own feedback tool. When a call fails in a way that is
222
226
  | `reddit_feedback_send` | `POST /feedback` | `action: "draft"` (default) queues a report locally and sends nothing; `"list"` shows the queue; `"send"` posts only the drafts you name; `"discard"` drops them. |
223
227
  | `reddit_explain` | none (in-process) | Provenance for the rows already fetched in this session: per completed call, the tool, the endpoint, when the response arrived, how old that copy now is, the upstream request id and the response size. The read path holds no response cache, so the age is the age of your copy, not of a stored row. |
224
228
  | `reddit_account_me` | `GET /account/me` | How much credit this key has left, before spending any. Free, never metered. |
229
+ | `reddit_account_payments` | `GET /account/payments` | Every top-up on this key: amount, credits added, status and date, newest first. Free, never metered. |
225
230
  | `reddit_feedback_get` | `GET /feedback/{id}` | Read a sent report's status (`new`, `triaged`, `shipped`, `declined`) and the team's response. |
226
231
 
227
232
  ## Usage examples
@@ -317,7 +322,7 @@ Reads need nothing but your API key -- no account linking, login, or cookie step
317
322
 
318
323
  **`HTTP 429 (rate limited)`** Wait a few seconds and retry, or reduce request frequency. For bulk work, space out calls and raise `REDDITAPIS_TIMEOUT_MS`.
319
324
 
320
- **`HTTP 408 (upstream_timeout)`** The read did not finish in time and was not billed. The server already retried once after `retry_after`; call the tool again shortly. A `503 upstream_unavailable` on a read gets the same one retry.
325
+ **`HTTP 408` or `HTTP 503` with `upstream_timeout`** The read did not finish in time and was not billed (a 503 means the API's own read budget ran out). The server already retried once after `retry_after` (or the `Retry-After` header), when that retry can still finish inside `REDDITAPIS_TIMEOUT_MS`; call the tool again shortly. A `503 upstream_unavailable` on a read gets the same one retry.
321
326
 
322
327
  **`Request failed: timed out after 30000ms`** The default timeout is 30 seconds. For large `reddit_deep_comment_search` or paginated fetches, set `REDDITAPIS_TIMEOUT_MS` higher (for example `60000`).
323
328
 
@@ -339,9 +344,11 @@ npm start # run the stdio server (needs REDDITAPIS_KEY)
339
344
 
340
345
  ## FAQ
341
346
 
342
- **Do I need a Reddit developer account?** No. Get an API key at [redditapis.com](https://www.redditapis.com); there is no application or approval step.
347
+ **Do I need a Reddit developer app?** No. One RedditAPIs key covers every read, with no Reddit developer app to register.
348
+
349
+ **What does it cost?** $0.0015 per read pay as you go, or a monthly read plan from $19 for 30,000 reads; every account gets 1,000 free reads a month, plus $0.50 of free credit at signup and no card. Monitors need a monitoring plan, which has no free tier.
343
350
 
344
- **Can it post, comment, or vote?** No. All 30 Reddit-facing tools read Reddit; posting, commenting, voting, and DMs are a separate authenticated surface and are not exposed here. Of the other 14, the 10 monitor/webhook tools manage your OWN redditapis.com monitors and webhooks (a write, but never a write to Reddit itself), the 3 feedback tools send or read a report to the redditapis.com team, and `reddit_account_me` reads your own balance and plan.
351
+ **Can it post, comment or vote?** Not through this server. It reads Reddit only; writes are on the RedditAPIs REST API. All 30 Reddit-facing tools read Reddit; posting, commenting, voting, and DMs are a separate authenticated surface and are not exposed here. Of the other 17, the 10 monitor/webhook tools manage your OWN redditapis.com monitors and webhooks (a write, but never a write to Reddit itself), `reddit_set_watch` sets up a whole watch in one call, `reddit_explain` says where the rows you hold came from, the 3 feedback tools send or read a report to the redditapis.com team, and `reddit_account_me` and `reddit_account_payments` read your own balance, plan and top-up history.
345
352
 
346
353
  **Which clients are supported?** Claude Desktop, Claude Code, Cursor, Windsurf, and VS Code (Copilot agent mode), or any Model Context Protocol client.
347
354
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redditapis-mcp",
3
- "version": "0.10.3",
3
+ "version": "0.12.0",
4
4
  "mcpName": "io.github.redditapis/redditapis-mcp",
5
5
  "description": "Official MCP server for redditapis.com. Search Reddit posts, comments, communities, users and media; read subreddits, comment trees, top posts and profiles; create and manage monitors and webhooks. Native tools for Claude, Cursor and any MCP client.",
6
6
  "repository": {
@@ -30,8 +30,8 @@
30
30
  },
31
31
  "scripts": {
32
32
  "start": "node src/index.js",
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",
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",
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",
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",
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",
@@ -0,0 +1,103 @@
1
+ // Human-readable titles and MCP tool annotations (spec 2025-06-18,
2
+ // ToolAnnotations) for every tool in src/tools.js.
3
+ //
4
+ // A host uses these before it calls anything: `title` is the name it shows a
5
+ // person, and the four hints tell it which calls only read, which change
6
+ // state, which cannot be undone and which reach past this service. They are
7
+ // hints, never a security boundary; the API enforces what a key may do.
8
+ //
9
+ // The rules the table follows:
10
+ // - A read of Reddit data: readOnlyHint true, openWorldHint true (it reaches
11
+ // Reddit), idempotentHint true, destructiveHint false.
12
+ // - A read of this account's own state (balance, payments, monitors,
13
+ // webhooks, delivery history, feedback status, the local provenance
14
+ // ledger): readOnlyHint true, openWorldHint false.
15
+ // - A write: readOnlyHint false. destructiveHint true when it deletes,
16
+ // discards or overwrites (a monitor update REPLACES the whole filter;
17
+ // feedback_send's "discard" action drops drafts), false for an additive
18
+ // write. idempotentHint true only when repeating the same call has no
19
+ // further effect (an update to fixed values, a delete of one id).
20
+ // openWorldHint true when the call itself reaches an endpoint outside this
21
+ // service (a webhook test delivery, a watch that test-fires its target).
22
+ //
23
+ // readOnlyHint is not a second source of truth: it is derived from the
24
+ // catalog's own `write` flag, and test/annotations.test.mjs fails if the table
25
+ // and the catalog disagree in either direction (a tool with no row, or a row
26
+ // with no tool).
27
+
28
+ const READ_REDDIT = { readOnly: true, destructive: false, idempotent: true, openWorld: true };
29
+ const READ_OWN = { readOnly: true, destructive: false, idempotent: true, openWorld: false };
30
+
31
+ export const TOOL_ANNOTATIONS = {
32
+ // Reads of Reddit data.
33
+ reddit_subreddit_posts: { title: "List Subreddit Posts", ...READ_REDDIT },
34
+ reddit_verify_comments: { title: "Verify Comments Still Exist", ...READ_REDDIT },
35
+ reddit_home_feed: { title: "Home Feed", ...READ_REDDIT },
36
+ reddit_search: { title: "Search Posts", ...READ_REDDIT },
37
+ reddit_post_visibility: { title: "Post Visibility", ...READ_REDDIT },
38
+ reddit_post_comments: { title: "Get Post Comments", ...READ_REDDIT },
39
+ reddit_search_communities: { title: "Search Communities", ...READ_REDDIT },
40
+ reddit_search_comments: { title: "Search Posts by Comment", ...READ_REDDIT },
41
+ reddit_deep_comment_search: { title: "Deep Comment Search", ...READ_REDDIT },
42
+ reddit_search_media: { title: "Search Media Posts", ...READ_REDDIT },
43
+ reddit_search_users: { title: "Search Users", ...READ_REDDIT },
44
+ reddit_subreddit_top: { title: "Top Subreddit Posts", ...READ_REDDIT },
45
+ reddit_post: { title: "Get Post", ...READ_REDDIT },
46
+ reddit_user_profile: { title: "Get User Profile", ...READ_REDDIT },
47
+ reddit_user_achievements: { title: "Get User Achievements", ...READ_REDDIT },
48
+ reddit_user_comments: { title: "List User Comments", ...READ_REDDIT },
49
+ reddit_user_submitted: { title: "List User Posts", ...READ_REDDIT },
50
+ reddit_user_upvoted: { title: "List Upvoted Posts", ...READ_REDDIT },
51
+ reddit_user_saved: { title: "List Saved Items", ...READ_REDDIT },
52
+ reddit_user_hidden: { title: "List Hidden Posts", ...READ_REDDIT },
53
+ reddit_user_gilded: { title: "List Gilded Items", ...READ_REDDIT },
54
+ reddit_subreddit_comments: { title: "List Subreddit Comments", ...READ_REDDIT },
55
+ reddit_subreddit_about: { title: "Get Subreddit Info", ...READ_REDDIT },
56
+ reddit_subreddit_rules: { title: "Get Subreddit Rules", ...READ_REDDIT },
57
+ reddit_subreddit_moderators: { title: "List Subreddit Moderators", ...READ_REDDIT },
58
+ reddit_subreddit_wiki: { title: "Subreddit Wiki Page", ...READ_REDDIT },
59
+ reddit_by_id: { title: "Get Posts by ID", ...READ_REDDIT },
60
+ reddit_subreddits_popular: { title: "List Popular Subreddits", ...READ_REDDIT },
61
+ reddit_subreddits_new: { title: "List New Subreddits", ...READ_REDDIT },
62
+ reddit_subreddits_default: { title: "List Default Subreddits", ...READ_REDDIT },
63
+
64
+ // Reads of this account's own state.
65
+ reddit_monitor_list: { title: "List Monitors", ...READ_OWN },
66
+ reddit_monitor_health: { title: "Monitor Health", ...READ_OWN },
67
+ reddit_monitor_deliveries: { title: "List Monitor Deliveries", ...READ_OWN },
68
+ reddit_monitor_webhook_list: { title: "List Webhooks", ...READ_OWN },
69
+ reddit_feedback_list: { title: "List Feedback Reports", ...READ_OWN },
70
+ reddit_feedback_get: { title: "Get Feedback Report", ...READ_OWN },
71
+ reddit_account_me: { title: "Get Account Balance", ...READ_OWN },
72
+ reddit_account_payments: { title: "List Account Payments", ...READ_OWN },
73
+ reddit_explain: { title: "Explain Fetched Rows", ...READ_OWN },
74
+
75
+ // Writes.
76
+ reddit_monitor_add: { title: "Create Monitor", readOnly: false, destructive: false, idempotent: false, openWorld: false },
77
+ reddit_monitor_update: { title: "Update Monitor", readOnly: false, destructive: true, idempotent: true, openWorld: false },
78
+ reddit_monitor_remove: { title: "Delete Monitor", readOnly: false, destructive: true, idempotent: true, openWorld: false },
79
+ reddit_monitor_webhook_create: { title: "Create Webhook", readOnly: false, destructive: false, idempotent: false, openWorld: false },
80
+ reddit_monitor_webhook_test: { title: "Send Webhook Test", readOnly: false, destructive: false, idempotent: false, openWorld: true },
81
+ reddit_monitor_webhook_delete: { title: "Delete Webhook", readOnly: false, destructive: true, idempotent: true, openWorld: false },
82
+ reddit_feedback_send: { title: "Send Feedback Report", readOnly: false, destructive: true, idempotent: false, openWorld: false },
83
+ reddit_set_watch: { title: "Create Watch", readOnly: false, destructive: false, idempotent: false, openWorld: true },
84
+ };
85
+
86
+ /**
87
+ * The title and MCP annotations for one catalog tool. Throws for a tool with
88
+ * no row, so a new tool cannot register without its title and hints.
89
+ */
90
+ export function toolAnnotations(tool) {
91
+ const row = TOOL_ANNOTATIONS[tool.name];
92
+ if (!row) throw new Error(`[reddit-mcp] tool ${tool.name} has no row in src/annotations.js`);
93
+ return {
94
+ title: row.title,
95
+ annotations: {
96
+ title: row.title,
97
+ readOnlyHint: !tool.write,
98
+ destructiveHint: row.destructive,
99
+ idempotentHint: row.idempotent,
100
+ openWorldHint: row.openWorld,
101
+ },
102
+ };
103
+ }
package/src/server.js CHANGED
@@ -17,6 +17,7 @@ import { createFeedbackHandler, sameFailure } from "./feedback.js";
17
17
  import { createSetWatchHandler } from "./watch.js";
18
18
  import { createReadLedger, createExplainHandler } from "./provenance.js";
19
19
  import { registerPlaybooks } from "./playbooks.js";
20
+ import { toolAnnotations } from "./annotations.js";
20
21
 
21
22
  // Read from package.json rather than a hand-maintained literal -- this drifted
22
23
  // silently to "0.1.0" while the published package reached 0.1.12, so every
@@ -126,7 +127,7 @@ function paywallResult(kind, detail = "", overrides = {}) {
126
127
  };
127
128
  }
128
129
 
129
- export function hintFor(status, path) {
130
+ export function hintFor(status, path, error) {
130
131
  if (status === 401) return " (invalid or missing API key, verify REDDITAPIS_KEY at https://www.redditapis.com)";
131
132
  if (status === 402) return " (insufficient credits, top up at https://www.redditapis.com)";
132
133
  if (status === 403) return " (access forbidden. The subreddit/user may be private, banned, or quarantined)";
@@ -134,7 +135,10 @@ export function hintFor(status, path) {
134
135
  for (const [re, hint] of NOT_FOUND_HINTS) if (re.test(path || "")) return hint;
135
136
  return DEFAULT_NOT_FOUND_HINT;
136
137
  }
137
- if (status === 408) return " (the read did not complete in time; retry after the retry_after seconds)";
138
+ // A read that did not complete in time: the API answers it 408, and since the
139
+ // read-budget change a spent budget answers 503 with the same error value
140
+ // (0.11.0). Both get the "did not complete in time" hint, keyed on the error.
141
+ if (status === 408 || (status === 503 && error === "upstream_timeout")) return " (the read did not complete in time; retry after the retry_after seconds)";
138
142
  if (status === 429) return " (slow down: wait the retry_after seconds, keep this key's reads in flight under the limit the message names, then retry)";
139
143
  if (status >= 500) return " (upstream API error. Retry in a moment; if persistent, contact https://www.redditapis.com)";
140
144
  return "";
@@ -161,13 +165,28 @@ export function hintFor(status, path) {
161
165
  const SESSION_SENTENCE =
162
166
  "reddit_home_feed and reddit_user_upvoted/saved/hidden/gilded need the user's own Reddit cookies (reddit_session, loid) from POST /api/reddit/login on the REST API, not an MCP tool. ";
163
167
 
164
- export function buildInstructions({ inlineCredentials = true } = {}) {
165
- return INSTRUCTIONS_HEAD + (inlineCredentials ? SESSION_SENTENCE : "") + INSTRUCTIONS_TAIL;
168
+ // THE READ PRICE IS PASSED IN, NEVER WRITTEN HERE. The hosted server passes the
169
+ // rate its own billing charges (readRateUsd, from the API's pricing module), so
170
+ // the instructions can never name a price the API does not bill; a published
171
+ // figure in this file went stale the day read plans changed the read rate.
172
+ // Without a rate (the local stdio server) the sentence names no figure and
173
+ // points at the pricing page. A non-number or a non-positive rate is ignored.
174
+ export function readPriceSentence(readRateUsd) {
175
+ const r = Number(readRateUsd);
176
+ const priced = readRateUsd !== null && readRateUsd !== undefined && readRateUsd !== "" && Number.isFinite(r) && r > 0;
177
+ return priced
178
+ ? `Read tools bill per call (most $${r}); monitor, webhook and feedback tools are free. `
179
+ : "Read tools bill per call (prices: redditapis.com/pricing); monitor, webhook and feedback tools are free. ";
166
180
  }
167
181
 
182
+ export function buildInstructions({ inlineCredentials = true, readRateUsd = null } = {}) {
183
+ return INSTRUCTIONS_LEAD + readPriceSentence(readRateUsd) + INSTRUCTIONS_HEAD + (inlineCredentials ? SESSION_SENTENCE : "") + INSTRUCTIONS_TAIL;
184
+ }
185
+
186
+ const INSTRUCTIONS_LEAD = "redditapis.com MCP server. ";
187
+
168
188
  const INSTRUCTIONS_HEAD =
169
- "redditapis.com MCP server. Read tools cost credits per call (most $0.002); monitor, webhook and feedback tools are free. " +
170
- "reddit_account_me shows the balance for free before a large batch; on a 402, give the user the error's top-up URL. " +
189
+ "reddit_account_me shows the balance free before a big batch; on a 402, give the user the error's top-up URL. " +
171
190
  "reddit_search: sort='relevance' with a large `limit` for best matches; sort_type='score' re-orders that page; a quoted phrase or `subreddit` narrows it. " +
172
191
  "reddit_deep_comment_search returns matching comments; reddit_search_comments only their posts. " +
173
192
  "reddit_search_communities searches subreddits; reddit_subreddits_popular/new/default browse them. ";
@@ -203,6 +222,7 @@ export const INSTRUCTIONS = buildInstructions({ inlineCredentials: true });
203
222
  * OAuth token resolved to an account) and forwards calls over its own
204
223
  * trusted channel. When set, no API key is required or sent.
205
224
  * @param {(ms:number)=>Promise<void>} [opts.sleepImpl] injectable for tests
225
+ * @param {()=>number} [opts.nowImpl] clock, injectable for tests (default Date.now)
206
226
  * @param {number[]} [opts.retryDelaysMs] waits before each retry of a read that
207
227
  * hit a gateway failure (an API restart); default [3000, 8000]
208
228
  * @param {boolean} [opts.inlineCredentials] default true. false leaves every
@@ -210,6 +230,9 @@ export const INSTRUCTIONS = buildInstructions({ inlineCredentials: true });
210
230
  * proxy (takesInlineCredentials in tools.js) UNREGISTERED, and drops the
211
231
  * instructions sentence that names them. A remote host passes false so a
212
232
  * connected app is never asked to send a Reddit session through it.
233
+ * @param {number|null} [opts.readRateUsd] the read price the API bills right now.
234
+ * The hosted server passes it from its own pricing; omitted (the local
235
+ * server) the instructions name no figure (readPriceSentence).
213
236
  */
214
237
  export function createServer({
215
238
  apiKey,
@@ -219,8 +242,10 @@ export function createServer({
219
242
  fetchImpl = fetch,
220
243
  authHeaders = null,
221
244
  sleepImpl = (ms) => new Promise((r) => setTimeout(r, ms)),
245
+ nowImpl = () => Date.now(),
222
246
  retryDelaysMs = [3000, 8000],
223
247
  inlineCredentials = true,
248
+ readRateUsd = null,
224
249
  } = {}) {
225
250
  // A STRING "false" from an environment variable must not silently leave the
226
251
  // cookie tools exposed on a hosted server (review 2026-10-02): booleans only.
@@ -281,8 +306,8 @@ export function createServer({
281
306
  // connection for a short window. A READ is retried through it; timeouts and
282
307
  // writes never are, so a request the API may already have handled is never sent
283
308
  // twice (a gateway 504 is not retried for that reason). The API JSON errors
284
- // that ARE retried, once, are the read-side 503 upstream_unavailable (0.10.1)
285
- // and 408 upstream_timeout (0.10.2) below.
309
+ // that ARE retried, once, are the read-side 503 upstream_unavailable (0.10.1),
310
+ // 408 upstream_timeout (0.10.2) and 503 upstream_timeout (0.11.0) below.
286
311
  // Only a REFUSED connection is retried: the request never reached the API,
287
312
  // so it cannot have been handled or billed. A reset, a broken pipe or a
288
313
  // socket dropped mid-answer can all happen after the API did the work, and
@@ -300,14 +325,44 @@ export function createServer({
300
325
  // The TOP-LEVEL error value, parsed, never a substring match (review 2026-10-14:
301
326
  // a body nesting the string elsewhere must not be retried).
302
327
  const parsedBody = (text) => { try { const v = JSON.parse(text); return v && typeof v === "object" ? v : null; } catch { return null; } };
328
+ // 0.11.0: the API answers a read whose wall-clock budget ran out with 503 and
329
+ // the same upstream_timeout value (408 told the client its OWN request was
330
+ // slow). It is the same unbilled per-read refusal, so it gets the same retry.
303
331
  const apiTransientRead = (status, text) => {
304
332
  const err = parsedBody(text)?.error;
305
- return (status === 503 && err === "upstream_unavailable") || (status === 408 && err === "upstream_timeout");
333
+ return (status === 503 && (err === "upstream_unavailable" || err === "upstream_timeout")) ||
334
+ (status === 408 && err === "upstream_timeout");
306
335
  };
307
- const retryAfterMs = (text) => {
308
- const s = Number(parsedBody(text)?.retry_after);
336
+ // The wait comes from the body's retry_after, else the Retry-After header
337
+ // (delta-seconds), else 2 s; clamped 1..5 s either way (0.11.0: the header).
338
+ const retryAfterMs = (text, res) => {
339
+ let s = Number(parsedBody(text)?.retry_after);
340
+ if (!(Number.isFinite(s) && s > 0)) s = Number(res?.headers?.get?.("retry-after"));
309
341
  return Math.min(5, Math.max(1, Number.isFinite(s) && s > 0 ? s : 2)) * 1000;
310
342
  };
343
+ // THE RETRY STAYS INSIDE THE CLIENT TIMEOUT (0.11.0). A budget-spent read
344
+ // arrives after ~22 s; a 5 s wait and a fresh 30 s attempt would run the
345
+ // tool call to ~57 s, past the caller's own timeout, so it would be cut off
346
+ // with no answer at all. The retry is sent only when, after the wait, at
347
+ // least MIN_API_RETRY_MS of the call's REQUEST_TIMEOUT_MS is left, and that
348
+ // attempt is aborted at what is left, so the whole call ends inside it.
349
+ const MIN_API_RETRY_MS = 3000;
350
+ const callStartedAt = nowImpl();
351
+ let attemptTimeoutMs = REQUEST_TIMEOUT_MS;
352
+ // What is left of the client timeout right now. EVERY retry below (gateway page,
353
+ // refused connection, API transient read) sleeps and re-attempts only inside it
354
+ // (review of 0.11.0: the gateway and connection retries slept their fixed delays
355
+ // and re-attempted on a fresh timer, so a call could overshoot by up to ~11 s).
356
+ const leftMs = () => REQUEST_TIMEOUT_MS - (nowImpl() - callStartedAt);
357
+ // Sleep `delayMs` and shrink the next attempt to what is left, or return false
358
+ // when the retry could not finish inside the client timeout.
359
+ const retryWithin = async (delayMs) => {
360
+ const leftAfter = leftMs() - delayMs;
361
+ if (leftAfter < MIN_API_RETRY_MS) return false;
362
+ await sleepImpl(delayMs);
363
+ attemptTimeoutMs = Math.min(REQUEST_TIMEOUT_MS, leftAfter);
364
+ return true;
365
+ };
311
366
  const transientNetwork = (err) =>
312
367
  !gotResponse && err?.name !== "AbortError" && RETRYABLE_NET.has(err?.cause?.code ?? err?.code);
313
368
  let attempt = 0;
@@ -316,24 +371,25 @@ export function createServer({
316
371
  for (;;) {
317
372
  gotResponse = false;
318
373
  const ctrl = new AbortController();
319
- const timer = setTimeout(() => ctrl.abort(), REQUEST_TIMEOUT_MS);
374
+ const timer = setTimeout(() => ctrl.abort(), attemptTimeoutMs);
320
375
  try {
321
376
  const res = await fetchImpl(url, { method, headers, body: requestBody, signal: ctrl.signal });
322
377
  gotResponse = true;
323
378
  const body = await res.text();
324
379
  if (!isWrite && attempt < retryDelaysMs.length && gatewayFailure(res.status, body)) {
325
380
  clearTimeout(timer);
326
- await sleepImpl(retryDelaysMs[attempt++]);
327
- continue;
381
+ if (await retryWithin(retryDelaysMs[attempt++])) continue;
382
+ // No room inside the client timeout: the gateway page is answered below as the error.
328
383
  }
329
384
  if (!isWrite && !apiRetried && apiTransientRead(res.status, body)) {
330
385
  clearTimeout(timer);
331
386
  apiRetried = true;
332
- await sleepImpl(retryAfterMs(body));
333
- continue;
387
+ if (await retryWithin(retryAfterMs(body, res))) continue;
388
+ // No room for a retry inside the client timeout: answer the refusal now,
389
+ // with its hint, rather than be cut off waiting for a second read.
334
390
  }
335
391
  if (!res.ok) {
336
- const hint = hintFor(res.status, path);
392
+ const hint = hintFor(res.status, path, parsedBody(body)?.error);
337
393
  lastError = {
338
394
  path,
339
395
  method,
@@ -375,12 +431,13 @@ export function createServer({
375
431
  } catch (err) {
376
432
  if (!isWrite && attempt < retryDelaysMs.length && transientNetwork(err)) {
377
433
  clearTimeout(timer);
378
- await sleepImpl(retryDelaysMs[attempt++]);
379
- continue;
434
+ if (await retryWithin(retryDelaysMs[attempt++])) continue;
380
435
  }
381
436
  const code = err?.cause?.code ?? err?.code;
382
437
  const msg = err?.name === "AbortError"
383
- ? `timed out after ${REQUEST_TIMEOUT_MS}ms`
438
+ ? (attemptTimeoutMs < REQUEST_TIMEOUT_MS
439
+ ? `timed out after ${attemptTimeoutMs}ms (the retry had that much of the ${REQUEST_TIMEOUT_MS}ms client timeout left)`
440
+ : `timed out after ${attemptTimeoutMs}ms`)
384
441
  : `${err?.message || String(err)}${code ? ` (${code})` : ""}`;
385
442
  lastError = { path, method, status: null, error: msg.slice(0, 200), ts: Date.now() };
386
443
  return { isError: true, content: [{ type: "text", text: `Request failed: ${msg}` }] };
@@ -392,7 +449,7 @@ export function createServer({
392
449
 
393
450
  const server = new McpServer(
394
451
  { name: "redditapis", version: VERSION },
395
- { instructions: buildInstructions({ inlineCredentials: inlineCredentials !== false }) },
452
+ { instructions: buildInstructions({ inlineCredentials: inlineCredentials !== false, readRateUsd }) },
396
453
  );
397
454
 
398
455
  // Handlers for tools that carry local: "<name>" in the catalog. A name the
@@ -422,12 +479,9 @@ export function createServer({
422
479
  // a tools/call naming it fails as an unknown tool, never reaching the API.
423
480
  if (inlineCredentials === false && takesInlineCredentials(tool)) continue;
424
481
  const method = tool.method || "GET";
425
- const annotations = {
426
- title: tool.name,
427
- readOnlyHint: !tool.write,
428
- destructiveHint: Boolean(tool.destructive),
429
- openWorldHint: true,
430
- };
482
+ // Title and all four hints come from src/annotations.js, which throws for
483
+ // a tool with no row, so a new tool cannot register without them.
484
+ const { title, annotations } = toolAnnotations(tool);
431
485
  let handler;
432
486
  if (tool.local) {
433
487
  handler = LOCAL_HANDLERS[tool.local];
@@ -447,7 +501,7 @@ export function createServer({
447
501
  }
448
502
  server.registerTool(
449
503
  tool.name,
450
- { description: tool.description, inputSchema: tool.shape, annotations },
504
+ { title, description: tool.description, inputSchema: tool.shape, annotations },
451
505
  handler,
452
506
  );
453
507
  }
package/src/tools.js CHANGED
@@ -13,9 +13,10 @@
13
13
  // task #43) is a DIFFERENT kind of write: it configures the customer's OWN
14
14
  // redditapis.com account (an alerting subscription), the same risk class as
15
15
  // reading their own usage -- it never posts, votes, or DMs anywhere. Those tools
16
- // are marked `write: true` (and `destructive: true` for remove/delete), which
17
- // index.js turns into MCP's `readOnlyHint`/`destructiveHint` annotations so a
18
- // client can surface a confirmation before calling them.
16
+ // are marked `write: true` (and `destructive: true` for remove/delete). The
17
+ // title and all four MCP annotation hints each tool registers with live in
18
+ // src/annotations.js (readOnlyHint is derived from `write`), so a client can
19
+ // surface a confirmation before calling them.
19
20
  //
20
21
  // BODY-BEARING TOOLS: a POST tool's args become a JSON request body instead of
21
22
  // a query string (see buildBody below). `filterSpecFields` on a tool declares
@@ -811,6 +812,19 @@ export const TOOLS = [
811
812
  "Returns the remaining credit balance and usage totals of the account behind this API key. Free: not metered, and costs no credit. A 402 from a metered call means the balance is exhausted; that response carries a top-up URL.",
812
813
  shape: {},
813
814
  },
815
+ {
816
+ // THE SPEND SIDE OF THE BALANCE. reddit_account_me says how much credit is
817
+ // left; this says where it came from: every top-up with its amount, the
818
+ // credits it added, its status and when. GET /account/payments is mounted
819
+ // beside /account/me, outside /api, and costs nothing (endpoint-costs
820
+ // "account/payments": 0). Verified live: it answers 401 unauthenticated while
821
+ // /account/<nonsense> answers 404, so the route exists.
822
+ name: "reddit_account_payments",
823
+ path: "/account/payments",
824
+ description:
825
+ "Returns the payment history of the account behind this API key: each top-up's amount, the credits it added, its status and when it happened, newest first. Free: not metered, and costs no credit.",
826
+ shape: {},
827
+ },
814
828
  {
815
829
  // ONE CALL INSTEAD OF THREE. Standing up a watch today means composing a
816
830
  // webhook registration, a monitor creation and a test delivery, each with