redditapis-mcp 0.10.3 → 0.11.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,66 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.11.0 (2026-10-16)
4
+
5
+ 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).
6
+
7
+ ### A read the API answers 503 upstream_timeout is retried once
8
+
9
+ The API now answers a read whose wall-clock budget ran out with `503` and
10
+ `Retry-After`, keeping the `upstream_timeout` error value (it was `408`,
11
+ which told the client its own request was slow). The read retry knew only
12
+ `503 upstream_unavailable` and `408 upstream_timeout`, so this answer lost its
13
+ one retry and got the generic 5xx hint. `(503, upstream_timeout)` is now
14
+ retried once like the other two, and carries the "did not complete in time"
15
+ hint. The wait is the body's `retry_after`, else the `Retry-After` header,
16
+ clamped to 1 to 5 seconds. The retry is sent only when at least 3 seconds of
17
+ `REDDITAPIS_TIMEOUT_MS` are left after the wait, and that attempt is aborted
18
+ at what is left, so the whole tool call ends inside the client timeout; a
19
+ refusal that arrives too late is answered at once with its hint. Writes are
20
+ never retried. `test/remote-host.test.mjs` covers the retry, the hint, the
21
+ header, the write control and the timeout bound. The same bound now covers the
22
+ gateway-page and refused-connection retries too: each is sent only when at least
23
+ 3 s of `REDDITAPIS_TIMEOUT_MS` are left after its wait, so with a client timeout
24
+ under about 3 s plus the delay those retries are no longer sent at all.
25
+
26
+ ### README opening for the listings (README only)
27
+
28
+ The first paragraph is what Glama, mcpservers.org, the MCP Registry and npm
29
+ copy word for word. It now says in one paragraph what the server does and
30
+ costs, followed by the install line, the hosted sign-in line and the website.
31
+ Three FAQ answers replace the old developer-account and posting answers, and
32
+ the FAQ's "Of the other 15" is now "Of the other 17" (47 tools: 30 Reddit
33
+ reads plus 17 others). `server.json` `websiteUrl` is now
34
+ https://www.redditapis.com/mcp, and `package-lock.json`, which still said
35
+ 0.9.1, now carries the package version. `test/readme-opening.test.mjs` (in
36
+ `npm test`) checks the opening, the Website line against `websiteUrl`, every
37
+ tool count the README states against `src/tools.js`, and one version across
38
+ `package.json`, `server.json` and `package-lock.json`. No tool change.
39
+
40
+ ### Every tool has a title and all four annotation hints
41
+
42
+ Each of the 47 tools now registers a short, human-readable `title` (for
43
+ example "Search Posts", "Delete Webhook") and the four MCP tool annotation
44
+ hints: `readOnlyHint`, `destructiveHint`, `idempotentHint` and
45
+ `openWorldHint`. Reads of Reddit data are read-only and open-world; reads of
46
+ the account's own state (balance, payments, monitors, webhooks, deliveries,
47
+ feedback) are read-only and closed-world. Writes are marked destructive when
48
+ they delete, discard or overwrite (`reddit_monitor_remove`,
49
+ `reddit_monitor_webhook_delete`, `reddit_monitor_update`, whose filter
50
+ replaces the old one, and `reddit_feedback_send`, which can discard drafts),
51
+ and idempotent only where repeating the call changes nothing more. Before
52
+ this, every tool's title was its own name and only two hints were set. Tool
53
+ names, input schemas and behaviour are unchanged. A new test fails if any
54
+ registered tool lacks a title or a hint.
55
+
56
+ ### reddit_account_payments
57
+
58
+ The top-up history of the account behind this API key: each payment's amount,
59
+ the credits it added, its status and when it happened, newest first. Free and
60
+ never metered, like `reddit_account_me`, which gives the balance. Backed by
61
+ `GET /account/payments`, verified live (401 without a key, while an unknown
62
+ `/account/*` path is 404). 47 tools.
63
+
3
64
  ## 0.10.3 (2026-10-14)
4
65
 
5
66
  ### 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.002 per call, 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.002 per read, with $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.11.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",
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 "";
@@ -203,6 +207,7 @@ export const INSTRUCTIONS = buildInstructions({ inlineCredentials: true });
203
207
  * OAuth token resolved to an account) and forwards calls over its own
204
208
  * trusted channel. When set, no API key is required or sent.
205
209
  * @param {(ms:number)=>Promise<void>} [opts.sleepImpl] injectable for tests
210
+ * @param {()=>number} [opts.nowImpl] clock, injectable for tests (default Date.now)
206
211
  * @param {number[]} [opts.retryDelaysMs] waits before each retry of a read that
207
212
  * hit a gateway failure (an API restart); default [3000, 8000]
208
213
  * @param {boolean} [opts.inlineCredentials] default true. false leaves every
@@ -219,6 +224,7 @@ export function createServer({
219
224
  fetchImpl = fetch,
220
225
  authHeaders = null,
221
226
  sleepImpl = (ms) => new Promise((r) => setTimeout(r, ms)),
227
+ nowImpl = () => Date.now(),
222
228
  retryDelaysMs = [3000, 8000],
223
229
  inlineCredentials = true,
224
230
  } = {}) {
@@ -281,8 +287,8 @@ export function createServer({
281
287
  // connection for a short window. A READ is retried through it; timeouts and
282
288
  // writes never are, so a request the API may already have handled is never sent
283
289
  // 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.
290
+ // that ARE retried, once, are the read-side 503 upstream_unavailable (0.10.1),
291
+ // 408 upstream_timeout (0.10.2) and 503 upstream_timeout (0.11.0) below.
286
292
  // Only a REFUSED connection is retried: the request never reached the API,
287
293
  // so it cannot have been handled or billed. A reset, a broken pipe or a
288
294
  // socket dropped mid-answer can all happen after the API did the work, and
@@ -300,14 +306,44 @@ export function createServer({
300
306
  // The TOP-LEVEL error value, parsed, never a substring match (review 2026-10-14:
301
307
  // a body nesting the string elsewhere must not be retried).
302
308
  const parsedBody = (text) => { try { const v = JSON.parse(text); return v && typeof v === "object" ? v : null; } catch { return null; } };
309
+ // 0.11.0: the API answers a read whose wall-clock budget ran out with 503 and
310
+ // the same upstream_timeout value (408 told the client its OWN request was
311
+ // slow). It is the same unbilled per-read refusal, so it gets the same retry.
303
312
  const apiTransientRead = (status, text) => {
304
313
  const err = parsedBody(text)?.error;
305
- return (status === 503 && err === "upstream_unavailable") || (status === 408 && err === "upstream_timeout");
314
+ return (status === 503 && (err === "upstream_unavailable" || err === "upstream_timeout")) ||
315
+ (status === 408 && err === "upstream_timeout");
306
316
  };
307
- const retryAfterMs = (text) => {
308
- const s = Number(parsedBody(text)?.retry_after);
317
+ // The wait comes from the body's retry_after, else the Retry-After header
318
+ // (delta-seconds), else 2 s; clamped 1..5 s either way (0.11.0: the header).
319
+ const retryAfterMs = (text, res) => {
320
+ let s = Number(parsedBody(text)?.retry_after);
321
+ if (!(Number.isFinite(s) && s > 0)) s = Number(res?.headers?.get?.("retry-after"));
309
322
  return Math.min(5, Math.max(1, Number.isFinite(s) && s > 0 ? s : 2)) * 1000;
310
323
  };
324
+ // THE RETRY STAYS INSIDE THE CLIENT TIMEOUT (0.11.0). A budget-spent read
325
+ // arrives after ~22 s; a 5 s wait and a fresh 30 s attempt would run the
326
+ // tool call to ~57 s, past the caller's own timeout, so it would be cut off
327
+ // with no answer at all. The retry is sent only when, after the wait, at
328
+ // least MIN_API_RETRY_MS of the call's REQUEST_TIMEOUT_MS is left, and that
329
+ // attempt is aborted at what is left, so the whole call ends inside it.
330
+ const MIN_API_RETRY_MS = 3000;
331
+ const callStartedAt = nowImpl();
332
+ let attemptTimeoutMs = REQUEST_TIMEOUT_MS;
333
+ // What is left of the client timeout right now. EVERY retry below (gateway page,
334
+ // refused connection, API transient read) sleeps and re-attempts only inside it
335
+ // (review of 0.11.0: the gateway and connection retries slept their fixed delays
336
+ // and re-attempted on a fresh timer, so a call could overshoot by up to ~11 s).
337
+ const leftMs = () => REQUEST_TIMEOUT_MS - (nowImpl() - callStartedAt);
338
+ // Sleep `delayMs` and shrink the next attempt to what is left, or return false
339
+ // when the retry could not finish inside the client timeout.
340
+ const retryWithin = async (delayMs) => {
341
+ const leftAfter = leftMs() - delayMs;
342
+ if (leftAfter < MIN_API_RETRY_MS) return false;
343
+ await sleepImpl(delayMs);
344
+ attemptTimeoutMs = Math.min(REQUEST_TIMEOUT_MS, leftAfter);
345
+ return true;
346
+ };
311
347
  const transientNetwork = (err) =>
312
348
  !gotResponse && err?.name !== "AbortError" && RETRYABLE_NET.has(err?.cause?.code ?? err?.code);
313
349
  let attempt = 0;
@@ -316,24 +352,25 @@ export function createServer({
316
352
  for (;;) {
317
353
  gotResponse = false;
318
354
  const ctrl = new AbortController();
319
- const timer = setTimeout(() => ctrl.abort(), REQUEST_TIMEOUT_MS);
355
+ const timer = setTimeout(() => ctrl.abort(), attemptTimeoutMs);
320
356
  try {
321
357
  const res = await fetchImpl(url, { method, headers, body: requestBody, signal: ctrl.signal });
322
358
  gotResponse = true;
323
359
  const body = await res.text();
324
360
  if (!isWrite && attempt < retryDelaysMs.length && gatewayFailure(res.status, body)) {
325
361
  clearTimeout(timer);
326
- await sleepImpl(retryDelaysMs[attempt++]);
327
- continue;
362
+ if (await retryWithin(retryDelaysMs[attempt++])) continue;
363
+ // No room inside the client timeout: the gateway page is answered below as the error.
328
364
  }
329
365
  if (!isWrite && !apiRetried && apiTransientRead(res.status, body)) {
330
366
  clearTimeout(timer);
331
367
  apiRetried = true;
332
- await sleepImpl(retryAfterMs(body));
333
- continue;
368
+ if (await retryWithin(retryAfterMs(body, res))) continue;
369
+ // No room for a retry inside the client timeout: answer the refusal now,
370
+ // with its hint, rather than be cut off waiting for a second read.
334
371
  }
335
372
  if (!res.ok) {
336
- const hint = hintFor(res.status, path);
373
+ const hint = hintFor(res.status, path, parsedBody(body)?.error);
337
374
  lastError = {
338
375
  path,
339
376
  method,
@@ -375,12 +412,13 @@ export function createServer({
375
412
  } catch (err) {
376
413
  if (!isWrite && attempt < retryDelaysMs.length && transientNetwork(err)) {
377
414
  clearTimeout(timer);
378
- await sleepImpl(retryDelaysMs[attempt++]);
379
- continue;
415
+ if (await retryWithin(retryDelaysMs[attempt++])) continue;
380
416
  }
381
417
  const code = err?.cause?.code ?? err?.code;
382
418
  const msg = err?.name === "AbortError"
383
- ? `timed out after ${REQUEST_TIMEOUT_MS}ms`
419
+ ? (attemptTimeoutMs < REQUEST_TIMEOUT_MS
420
+ ? `timed out after ${attemptTimeoutMs}ms (the retry had that much of the ${REQUEST_TIMEOUT_MS}ms client timeout left)`
421
+ : `timed out after ${attemptTimeoutMs}ms`)
384
422
  : `${err?.message || String(err)}${code ? ` (${code})` : ""}`;
385
423
  lastError = { path, method, status: null, error: msg.slice(0, 200), ts: Date.now() };
386
424
  return { isError: true, content: [{ type: "text", text: `Request failed: ${msg}` }] };
@@ -422,12 +460,9 @@ export function createServer({
422
460
  // a tools/call naming it fails as an unknown tool, never reaching the API.
423
461
  if (inlineCredentials === false && takesInlineCredentials(tool)) continue;
424
462
  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
- };
463
+ // Title and all four hints come from src/annotations.js, which throws for
464
+ // a tool with no row, so a new tool cannot register without them.
465
+ const { title, annotations } = toolAnnotations(tool);
431
466
  let handler;
432
467
  if (tool.local) {
433
468
  handler = LOCAL_HANDLERS[tool.local];
@@ -447,7 +482,7 @@ export function createServer({
447
482
  }
448
483
  server.registerTool(
449
484
  tool.name,
450
- { description: tool.description, inputSchema: tool.shape, annotations },
485
+ { title, description: tool.description, inputSchema: tool.shape, annotations },
451
486
  handler,
452
487
  );
453
488
  }
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