@xiedada/nodemw-mcp-server 0.0.8 → 0.0.9
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/dist/index.js +52 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
37
37
|
// package.json
|
|
38
38
|
var package_default = {
|
|
39
39
|
name: "@xiedada/nodemw-mcp-server",
|
|
40
|
-
version: "0.0.
|
|
40
|
+
version: "0.0.9",
|
|
41
41
|
description: "MCP server for nodemw - MediaWiki API client",
|
|
42
42
|
type: "module",
|
|
43
43
|
main: "dist/index.js",
|
|
@@ -255,6 +255,13 @@ async function recordReadState(title) {
|
|
|
255
255
|
} catch {
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
|
+
function getFirstItem(obj) {
|
|
259
|
+
if (!obj) return null;
|
|
260
|
+
for (const key in obj) {
|
|
261
|
+
return obj[key];
|
|
262
|
+
}
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
258
265
|
function getArticleTool(server) {
|
|
259
266
|
return server.tool(
|
|
260
267
|
"get-article",
|
|
@@ -262,19 +269,57 @@ function getArticleTool(server) {
|
|
|
262
269
|
{
|
|
263
270
|
title: z.string().describe("Article title"),
|
|
264
271
|
followRedirect: z.boolean().optional().default(true).describe("Follow redirects"),
|
|
265
|
-
redirectInfo: z.boolean().optional().default(false).describe("Include information about redirects")
|
|
272
|
+
redirectInfo: z.boolean().optional().default(false).describe("Include information about redirects"),
|
|
273
|
+
revision: z.number().optional().describe("Specific revision ID to fetch. If omitted, returns the latest version.")
|
|
266
274
|
},
|
|
267
275
|
{
|
|
268
276
|
title: "Get article",
|
|
269
277
|
readOnlyHint: true,
|
|
270
278
|
destructiveHint: false
|
|
271
279
|
},
|
|
272
|
-
async ({ title, followRedirect, redirectInfo }) => handleGetArticleTool(title, followRedirect, redirectInfo)
|
|
280
|
+
async ({ title, followRedirect, redirectInfo, revision }) => handleGetArticleTool(title, followRedirect, redirectInfo, revision)
|
|
273
281
|
);
|
|
274
282
|
}
|
|
275
|
-
async function handleGetArticleTool(title, followRedirect, redirectInfo) {
|
|
283
|
+
async function handleGetArticleTool(title, followRedirect, redirectInfo, revision) {
|
|
276
284
|
try {
|
|
277
285
|
const bot = await getBot();
|
|
286
|
+
if (revision !== void 0) {
|
|
287
|
+
const params = {
|
|
288
|
+
action: "query",
|
|
289
|
+
prop: "revisions",
|
|
290
|
+
rvprop: "content",
|
|
291
|
+
rvstartid: revision,
|
|
292
|
+
rvlimit: 1,
|
|
293
|
+
titles: title,
|
|
294
|
+
...followRedirect && { redirects: "" }
|
|
295
|
+
};
|
|
296
|
+
const info = await new Promise((resolve, reject) => {
|
|
297
|
+
bot.api.call(params, (err, info2) => {
|
|
298
|
+
if (err) reject(err);
|
|
299
|
+
else resolve(info2);
|
|
300
|
+
}, "GET");
|
|
301
|
+
});
|
|
302
|
+
const pages = info.pages;
|
|
303
|
+
const page = getFirstItem(pages);
|
|
304
|
+
if (!page || page.missing) {
|
|
305
|
+
return {
|
|
306
|
+
content: [{ type: "text", text: `Page "${title}" not found.` }],
|
|
307
|
+
isError: true
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
const revisions = page.revisions;
|
|
311
|
+
const rev = revisions?.[0];
|
|
312
|
+
if (!rev || rev["*"] == null) {
|
|
313
|
+
return {
|
|
314
|
+
content: [{ type: "text", text: `Revision ${revision} not found for page "${title}".` }],
|
|
315
|
+
isError: true
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
await recordReadState(title);
|
|
319
|
+
return {
|
|
320
|
+
content: [{ type: "text", text: rev["*"] }]
|
|
321
|
+
};
|
|
322
|
+
}
|
|
278
323
|
if (redirectInfo) {
|
|
279
324
|
const result = await new Promise((resolve, reject) => {
|
|
280
325
|
const callback = (err, content2, redirectInfo2) => {
|
|
@@ -687,7 +732,7 @@ async function handleGetArticleRevisionsTool(title) {
|
|
|
687
732
|
"getArticleRevisions",
|
|
688
733
|
title
|
|
689
734
|
);
|
|
690
|
-
const revisions = allRevisions.flat();
|
|
735
|
+
const revisions = allRevisions.flat().filter((rev) => rev != null);
|
|
691
736
|
return jsonResult({
|
|
692
737
|
title,
|
|
693
738
|
revisions,
|
|
@@ -834,7 +879,7 @@ function getUserContribsTool(server) {
|
|
|
834
879
|
},
|
|
835
880
|
async ({ username, namespace, limit }) => handleGetUserContribsTool(username, namespace, limit)
|
|
836
881
|
);
|
|
837
|
-
tool.update({ outputSchema: { username: z14.string(), namespace: z14.number(), limit: z14.number(), total: z14.number(), displayed: z14.number(), contributions: z14.array(z14.record(z14.unknown())) } });
|
|
882
|
+
tool.update({ outputSchema: { username: z14.string(), namespace: z14.number().optional(), limit: z14.number(), total: z14.number(), displayed: z14.number(), contributions: z14.array(z14.record(z14.unknown())) } });
|
|
838
883
|
return tool;
|
|
839
884
|
}
|
|
840
885
|
async function handleGetUserContribsTool(username, namespace, limit = 50) {
|
|
@@ -1309,7 +1354,7 @@ function getRecentChangesTool(server) {
|
|
|
1309
1354
|
},
|
|
1310
1355
|
async ({ start, limit }) => handleGetRecentChangesTool(start, limit)
|
|
1311
1356
|
);
|
|
1312
|
-
tool.update({ outputSchema: { total: z25.number(), limit: z25.number(), start: z25.string(), changes: z25.array(z25.record(z25.unknown())) } });
|
|
1357
|
+
tool.update({ outputSchema: { total: z25.number(), limit: z25.number(), start: z25.string().optional(), changes: z25.array(z25.record(z25.unknown())) } });
|
|
1313
1358
|
return tool;
|
|
1314
1359
|
}
|
|
1315
1360
|
async function handleGetRecentChangesTool(start, limit = 50) {
|