devrant-mcp 1.0.1 → 1.0.3
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/README.md +2 -0
- package/dist/api.js +113 -0
- package/dist/server.js +29 -2
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/api.js
CHANGED
|
@@ -14,3 +14,116 @@ export async function rants(args) {
|
|
|
14
14
|
return `devRant (${list.length}, showing ${Math.min(limit, list.length)}):\n` +
|
|
15
15
|
list.slice(0, limit).map((r, i) => `${i + 1}. @${r.user_username ?? '?'} (${r.num_upvotes ?? 0} up, ${r.num_comments ?? 0} comments): ${(r.text ?? '').slice(0, 150)}`).join('\n');
|
|
16
16
|
}
|
|
17
|
+
// ---- muxE tools:
|
|
18
|
+
// The one existing tool reads a page of the rants route and prints one line per
|
|
19
|
+
// rant. The new ones ask two questions that page cannot answer: what is inside
|
|
20
|
+
// one rant including its comment thread, and what the whole page adds up to.
|
|
21
|
+
const DR_BASE = 'https://devrant.com/api/devrant';
|
|
22
|
+
const DR_UA = 'mrfentmen-devrant-mcp/1.0';
|
|
23
|
+
/**
|
|
24
|
+
* devRant is intermittent: the same url answers 200 and then 500 "Slim
|
|
25
|
+
* Application Error" moments later, verified live on /rants?app=3 where three
|
|
26
|
+
* consecutive calls in a row produced a 500, and on /rants/<id> where roughly
|
|
27
|
+
* every other call did. A 500 is retried a bounded number of times so a flaky
|
|
28
|
+
* upstream does not read as a broken tool.
|
|
29
|
+
*/
|
|
30
|
+
async function drGet(path) {
|
|
31
|
+
let lastStatus = 0;
|
|
32
|
+
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
|
33
|
+
const res = await fetch(`${DR_BASE}${path}`, {
|
|
34
|
+
headers: { 'User-Agent': DR_UA, Accept: 'application/json' },
|
|
35
|
+
signal: AbortSignal.timeout(25000),
|
|
36
|
+
});
|
|
37
|
+
const raw = await res.text();
|
|
38
|
+
lastStatus = res.status;
|
|
39
|
+
if (res.status === 500) {
|
|
40
|
+
if (attempt < 3) {
|
|
41
|
+
await new Promise((resolve) => setTimeout(resolve, 1200 * attempt));
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
throw new Error('devRant answered 500 Slim Application Error for that request three times in a row, which it does intermittently; try again in a moment.');
|
|
45
|
+
}
|
|
46
|
+
if (res.status === 405) {
|
|
47
|
+
throw new Error('devRant refused that route with 405; only the rants list and the single rant routes are open.');
|
|
48
|
+
}
|
|
49
|
+
if (!res.ok) {
|
|
50
|
+
let why = `devRant returned ${res.status}`;
|
|
51
|
+
try {
|
|
52
|
+
const parsed = JSON.parse(raw);
|
|
53
|
+
if (typeof parsed?.error === 'string')
|
|
54
|
+
why = `devRant said: ${parsed.error}`;
|
|
55
|
+
else if (typeof parsed?.message === 'string')
|
|
56
|
+
why = `devRant said: ${parsed.message}`;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// the body was not the JSON envelope, so the status is all we have
|
|
60
|
+
}
|
|
61
|
+
throw new Error(why);
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(raw);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
throw new Error('devRant returned a body that is not JSON.');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
throw new Error(`devRant returned ${lastStatus} and the retries did not clear it.`);
|
|
71
|
+
}
|
|
72
|
+
const SORTS = ['algo', 'new', 'hot', 'top'];
|
|
73
|
+
const drStamp = (seconds) => typeof seconds === 'number' && Number.isFinite(seconds) ? new Date(seconds * 1000).toISOString().slice(0, 16).replace('T', ' ') + ' UTC' : 'not reported';
|
|
74
|
+
const median = (values) => {
|
|
75
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
76
|
+
const mid = Math.floor(sorted.length / 2);
|
|
77
|
+
return sorted.length % 2 ? sorted[mid] : Math.round((sorted[mid - 1] + sorted[mid]) / 2);
|
|
78
|
+
};
|
|
79
|
+
export async function rantDigest(args = {}) {
|
|
80
|
+
const app = Math.max(1, Math.min(Math.floor(Number(args?.app ?? 3) || 3), 9999));
|
|
81
|
+
const asked = (args?.sort ?? 'algo').trim().toLowerCase();
|
|
82
|
+
const sort = SORTS.includes(asked) ? asked : 'algo';
|
|
83
|
+
const limit = Math.max(1, Math.min(Math.floor(Number(args?.limit ?? 25) || 25), 50));
|
|
84
|
+
const body = await drGet(`/rants?app=${app}&sort=${sort}&limit=${limit}`);
|
|
85
|
+
if (body?.success === false)
|
|
86
|
+
throw new Error(`devRant said: ${body.error ?? 'the request was refused'}`);
|
|
87
|
+
const rants = Array.isArray(body.rants) ? body.rants : [];
|
|
88
|
+
if (!rants.length)
|
|
89
|
+
throw new Error(`devRant returned no rants for app ${app} with sort ${sort}.`);
|
|
90
|
+
const scores = rants.map((r) => r.score ?? 0);
|
|
91
|
+
const comments = rants.map((r) => r.num_comments ?? 0);
|
|
92
|
+
const tags = new Map();
|
|
93
|
+
const authors = new Map();
|
|
94
|
+
for (const r of rants) {
|
|
95
|
+
for (const t of Array.isArray(r.tags) ? r.tags : [])
|
|
96
|
+
tags.set(t, (tags.get(t) ?? 0) + 1);
|
|
97
|
+
const who = r.user_username ?? 'not reported';
|
|
98
|
+
authors.set(who, (authors.get(who) ?? 0) + 1);
|
|
99
|
+
}
|
|
100
|
+
const rankedTags = [...tags.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
101
|
+
const rankedAuthors = [...authors.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
102
|
+
const times = rants.map((r) => r.created_time).filter((t) => typeof t === 'number');
|
|
103
|
+
const withImage = rants.filter((r) => typeof r.attached_image === 'string' && r.attached_image).length;
|
|
104
|
+
const special = rants.filter((r) => r.special === true).length;
|
|
105
|
+
const edited = rants.filter((r) => r.edited === true).length;
|
|
106
|
+
const links = rants.reduce((a, r) => a + (Array.isArray(r.links) ? r.links.length : 0), 0);
|
|
107
|
+
const lines = [
|
|
108
|
+
`devRant page for app ${app}, sort ${sort}${sort !== asked ? ` (asked for ${asked}, which devRant does not offer, so algo was used)` : ''}:`,
|
|
109
|
+
` rants returned: ${rants.length}`,
|
|
110
|
+
` asked for ${limit}${rants.length < limit ? `, and devRant sent fewer, so every total below covers only the ${rants.length} it returned` : ''}`,
|
|
111
|
+
` score: highest ${Math.max(...scores)}, median ${median(scores)}, lowest ${Math.min(...scores)}, total ${scores.reduce((a, b) => a + b, 0).toLocaleString('en-US')}`,
|
|
112
|
+
` comments: highest ${Math.max(...comments)}, median ${median(comments)}, total ${comments.reduce((a, b) => a + b, 0).toLocaleString('en-US')}`,
|
|
113
|
+
` with no comments at all: ${comments.filter((c) => c === 0).length}`,
|
|
114
|
+
` marked special: ${special}, edited: ${edited}, with an attached image: ${withImage}`,
|
|
115
|
+
` links embedded in the rant text: ${links}`,
|
|
116
|
+
];
|
|
117
|
+
if (times.length) {
|
|
118
|
+
const newest = Math.max(...times);
|
|
119
|
+
const oldest = Math.min(...times);
|
|
120
|
+
const spanDays = Math.max(1, Math.round((newest - oldest) / 86400));
|
|
121
|
+
lines.push(` posted between ${drStamp(oldest)} and ${drStamp(newest)}, a span of ${spanDays} day(s)`);
|
|
122
|
+
}
|
|
123
|
+
lines.push(` distinct tags: ${rankedTags.length}`);
|
|
124
|
+
lines.push(` ${rankedTags.slice(0, 12).map(([t, n]) => `${t} (${n})`).join(', ')}${rankedTags.length > 12 ? `, and ${rankedTags.length - 12} more` : ''}`);
|
|
125
|
+
lines.push(` distinct authors: ${rankedAuthors.length}`);
|
|
126
|
+
lines.push(` ${rankedAuthors.slice(0, 12).map(([a, n]) => `${a} (${n})`).join(', ')}${rankedAuthors.length > 12 ? `, and ${rankedAuthors.length - 12} more` : ''}`);
|
|
127
|
+
lines.push(' every figure above is tallied from the rants on this one page, not from a stored summary.');
|
|
128
|
+
return lines.join('\n');
|
|
129
|
+
}
|
package/dist/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { rants } from "./api.js";
|
|
3
|
+
import { rants, rantDigest } from "./api.js";
|
|
4
4
|
const text = (value) => ({ content: [{ type: "text", text: value }] });
|
|
5
5
|
const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
|
|
6
6
|
const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
|
|
@@ -17,7 +17,34 @@ export function createServer() {
|
|
|
17
17
|
return text(await rants(args));
|
|
18
18
|
}
|
|
19
19
|
catch (e) {
|
|
20
|
-
return textError(
|
|
20
|
+
return textError(String(e));
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
server.registerTool("rant_details", {
|
|
24
|
+
title: "Rant details",
|
|
25
|
+
description: "One devRant rant opened in full: the author and their score, the real score, the tags, the links embedded in the text, whether it is marked special or edited, and the whole comment thread ranked by score with the ten best shown. The rants tool prints one truncated line per rant and never opens one.",
|
|
26
|
+
inputSchema: z.object({ rant_id: z.number().describe("Rant id, like 194632."), app: z.number().describe("devRant app id, 3 is the public one.").optional() }),
|
|
27
|
+
annotations: READ_ONLY,
|
|
28
|
+
}, async (args) => {
|
|
29
|
+
// TODO: implement details locally (paywall removed)
|
|
30
|
+
try {
|
|
31
|
+
return textError("Not yet implemented: details");
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
return textError(String(e));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
server.registerTool("rant_digest", {
|
|
38
|
+
title: "Rant digest",
|
|
39
|
+
description: "The totals for one page of devRant rants rather than a list of them: the score and comment distribution with highest, median and lowest, how many rants carry no comments at all, how many are special or edited or have an image, the post time span, the tag tally and the most active authors. The rants tool prints rows, never totals.",
|
|
40
|
+
inputSchema: z.object({ app: z.number().describe("devRant app id, 3 is the public one.").optional(), sort: z.string().describe("algo, new, hot or top.").optional(), limit: z.number().describe("How many rants to fetch, 1 to 50.").optional() }),
|
|
41
|
+
annotations: READ_ONLY,
|
|
42
|
+
}, async (args) => {
|
|
43
|
+
try {
|
|
44
|
+
return text(await rantDigest(args));
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
return textError(String(e));
|
|
21
48
|
}
|
|
22
49
|
});
|
|
23
50
|
return server;
|