redditapis-mcp 0.10.2 → 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 +84 -0
- package/README.md +13 -6
- package/package.json +6 -5
- package/src/annotations.js +103 -0
- package/src/server.js +58 -23
- package/src/tools.js +29 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,89 @@
|
|
|
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
|
+
|
|
64
|
+
## 0.10.3 (2026-10-14)
|
|
65
|
+
|
|
66
|
+
### reddit_post_comments takes limit, depth and sort
|
|
67
|
+
|
|
68
|
+
A thread read had no knobs, so a 33-comment thread came back as 75k chars in one
|
|
69
|
+
line and a 2,700-comment thread was unreadable from any MCP client. The tool now
|
|
70
|
+
accepts `limit` (top-level comments, 1 to 500, default 100), `depth` (reply depth,
|
|
71
|
+
1 to 10; `depth=1` is top-level only; absent is the full tree) and `sort`
|
|
72
|
+
(confidence, top, new, controversial, old, qa). The API echoes what it applied in
|
|
73
|
+
`meta` (`limit_used`, `depth_used`, `sort_used`). Reported through feedback
|
|
74
|
+
cbf0156d.
|
|
75
|
+
|
|
76
|
+
### Fan-out tools say when an answer is partial
|
|
77
|
+
|
|
78
|
+
`reddit_deep_comment_search` reports `meta.partial`, `meta.trees_failed` and
|
|
79
|
+
`meta.trees_fetched` when one of its comment-tree reads failed while the others
|
|
80
|
+
succeeded, and fails only when every tree failed and at least one was refused
|
|
81
|
+
upstream. `reddit_post_visibility` answers `undecidable` with
|
|
82
|
+
`checked.listing_error` when the post resolved but the author listing read did
|
|
83
|
+
not (`upstream_unavailable` and `upstream_timeout` are not billed;
|
|
84
|
+
`listing_unavailable` means Reddit answered the listing with 403 or 404 and is
|
|
85
|
+
billed). The descriptions carry both contracts.
|
|
86
|
+
|
|
3
87
|
## 0.10.2 (2026-10-14)
|
|
4
88
|
|
|
5
89
|
### The 408 upstream_timeout read gets the same one retry
|
package/README.md
CHANGED
|
@@ -4,9 +4,13 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/redditapis-mcp)
|
|
5
5
|
[](./LICENSE)
|
|
6
6
|
|
|
7
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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,11 +30,12 @@
|
|
|
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",
|
|
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
|
-
"postpublish": "node scripts/
|
|
37
|
-
"check:registry-drift": "node scripts/registry-drift.mjs"
|
|
36
|
+
"postpublish": "node scripts/postpublish.mjs",
|
|
37
|
+
"check:registry-drift": "node scripts/registry-drift.mjs",
|
|
38
|
+
"check:hub-parity": "node scripts/hosted-hub-parity.mjs"
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
41
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
@@ -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
|
-
|
|
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
|
-
//
|
|
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"
|
|
314
|
+
return (status === 503 && (err === "upstream_unavailable" || err === "upstream_timeout")) ||
|
|
315
|
+
(status === 408 && err === "upstream_timeout");
|
|
306
316
|
};
|
|
307
|
-
|
|
308
|
-
|
|
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(),
|
|
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
|
|
327
|
-
|
|
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
|
|
333
|
-
|
|
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
|
|
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
|
-
?
|
|
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
|
-
|
|
426
|
-
|
|
427
|
-
|
|
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)
|
|
17
|
-
//
|
|
18
|
-
//
|
|
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
|
|
@@ -294,7 +295,7 @@ export const TOOLS = [
|
|
|
294
295
|
name: "reddit_post_visibility",
|
|
295
296
|
path: "/api/reddit/post/{id}/visibility",
|
|
296
297
|
description:
|
|
297
|
-
"Is a post still publicly visible, or did it quietly stop being so? A removed Reddit post still returns when fetched by id, so the post alone does not answer this. This fetches the post and then one page of its author's submitted listing and compares them. Returns a verdict of live, not_visible or undecidable, a plain-language reason, and a confident flag. By design it does not say WHY a post is not visible: a moderator removal, an admin removal, a spam filter and an author who has hidden their history are indistinguishable from outside. undecidable is a real answer, not a failure. Two upstream calls, billed as one $0.004 dual read.",
|
|
298
|
+
"Is a post still publicly visible, or did it quietly stop being so? A removed Reddit post still returns when fetched by id, so the post alone does not answer this. This fetches the post and then one page of its author's submitted listing and compares them. Returns a verdict of live, not_visible or undecidable, a plain-language reason, and a confident flag. By design it does not say WHY a post is not visible: a moderator removal, an admin removal, a spam filter and an author who has hidden their history are indistinguishable from outside. undecidable is a real answer, not a failure. When the post resolves but the author listing read fails, the answer is still returned as undecidable with checked.author_listing false and checked.listing_error naming why (upstream_unavailable or upstream_timeout: our read was refused, not billed; listing_unavailable: Reddit answered the listing with 403 or 404, billed). Two upstream calls, billed as one $0.004 dual read.",
|
|
298
299
|
shape: {
|
|
299
300
|
id: z.string().min(1).describe("Reddit post id, base36, with or without the t3_ prefix"),
|
|
300
301
|
},
|
|
@@ -303,11 +304,20 @@ export const TOOLS = [
|
|
|
303
304
|
name: "reddit_post_comments",
|
|
304
305
|
path: "/api/reddit/comments",
|
|
305
306
|
description:
|
|
306
|
-
"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.",
|
|
307
|
+
"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.",
|
|
307
308
|
shape: {
|
|
308
309
|
permalink: z.string().min(1).describe(
|
|
309
310
|
"The post permalink path from a prior post result, e.g. '/r/programming/comments/abc123/some_title/'. Required.",
|
|
310
311
|
),
|
|
312
|
+
limit: z.number().int().min(1).max(500).optional().describe(
|
|
313
|
+
"Maximum top-level comments, 1-500 (default 100). A small value with depth=1 gives a readable summary of a large thread.",
|
|
314
|
+
),
|
|
315
|
+
depth: z.number().int().min(1).max(10).optional().describe(
|
|
316
|
+
"Maximum reply depth, 1-10. depth=1 returns top-level comments only. Absent, Reddit's full tree is returned.",
|
|
317
|
+
),
|
|
318
|
+
sort: z.enum(["confidence", "top", "new", "controversial", "old", "qa"]).optional().describe(
|
|
319
|
+
"Comment ordering: confidence (Reddit's best), top, new, controversial, old or qa. Absent, Reddit's default for the thread.",
|
|
320
|
+
),
|
|
311
321
|
},
|
|
312
322
|
},
|
|
313
323
|
{
|
|
@@ -328,7 +338,7 @@ export const TOOLS = [
|
|
|
328
338
|
name: "reddit_deep_comment_search",
|
|
329
339
|
path: "/api/reddit/search/comments/deep",
|
|
330
340
|
description:
|
|
331
|
-
"Comment search that returns the ACTUAL comments whose body matches the keyword, sorted by score (highest first), with body, score, author, a comment-deep permalink, and the parent post. It fetches each matching post's comment tree and filters the comment bodies, so the results are first-hand opinions and answers rather than parent posts. Premium call (it fans out into several reads): `limit` sets how many parent POSTS to expand, 1-25 (default 5), not how many comments come back. The response's `after` cursor expands the NEXT batch of parent posts. `max_comments` optionally caps how many comments come back (the top-scored are kept). Matching is on the visible comment text at word boundaries (link URLs are ignored), so every result mentions the query where a reader can see it. Best-effort: a deleted or deeply-nested comment may be missed (meta.truncated flags when a tree was too deep). group_by='author' switches to a research mode that returns WHO is talking about the query (distinct people ranked by matching-comment count) in place of a flat comment list, capped by max_authors. Example: q='best mechanical keyboard' sort='relevance' t='year'.",
|
|
341
|
+
"Comment search that returns the ACTUAL comments whose body matches the keyword, sorted by score (highest first), with body, score, author, a comment-deep permalink, and the parent post. It fetches each matching post's comment tree and filters the comment bodies, so the results are first-hand opinions and answers rather than parent posts. Premium call (it fans out into several reads): `limit` sets how many parent POSTS to expand, 1-25 (default 5), not how many comments come back. The response's `after` cursor expands the NEXT batch of parent posts. `max_comments` optionally caps how many comments come back (the top-scored are kept). Matching is on the visible comment text at word boundaries (link URLs are ignored), so every result mentions the query where a reader can see it. Best-effort: a deleted or deeply-nested comment may be missed (meta.truncated flags when a tree was too deep). Each parent post is its own comment-tree read and one can fail while the others succeed: meta.partial is true with meta.trees_failed and meta.trees_fetched when that happened, so the result covers fewer parent posts than it scanned; the call fails only when every tree failed and at least one was refused upstream. group_by='author' switches to a research mode that returns WHO is talking about the query (distinct people ranked by matching-comment count) in place of a flat comment list, capped by max_authors. Example: q='best mechanical keyboard' sort='relevance' t='year'.",
|
|
332
342
|
shape: {
|
|
333
343
|
...QUERY,
|
|
334
344
|
...SORT_SEARCH,
|
|
@@ -802,6 +812,19 @@ export const TOOLS = [
|
|
|
802
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.",
|
|
803
813
|
shape: {},
|
|
804
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
|
+
},
|
|
805
828
|
{
|
|
806
829
|
// ONE CALL INSTEAD OF THREE. Standing up a watch today means composing a
|
|
807
830
|
// webhook registration, a monitor creation and a test delivery, each with
|