@xiedada/nodemw-mcp-server 0.0.8 → 0.0.11

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.
Files changed (2) hide show
  1. package/dist/index.js +70 -25
  2. 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.8",
40
+ version: "0.0.11",
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) {
@@ -885,9 +930,9 @@ function whoamiTool(server) {
885
930
  rights: z15.array(z15.string()),
886
931
  ratelimits: z15.union([z15.record(z15.unknown()), z15.array(z15.unknown())]),
887
932
  editcount: z15.number(),
888
- realname: z15.string(),
889
- email: z15.string(),
890
- emailauthenticated: z15.string()
933
+ realname: z15.string().optional(),
934
+ email: z15.string().optional(),
935
+ emailauthenticated: z15.string().optional()
891
936
  }) } });
892
937
  return tool;
893
938
  }
@@ -924,12 +969,12 @@ function whoisTool(server) {
924
969
  userid: z16.number(),
925
970
  name: z16.string(),
926
971
  groups: z16.array(z16.string()),
927
- implicitgroups: z16.array(z16.string()),
972
+ implicitgroups: z16.array(z16.string()).optional(),
928
973
  rights: z16.array(z16.string()),
929
974
  editcount: z16.number(),
930
- registration: z16.string(),
931
- emailable: z16.string(),
932
- gender: z16.string(),
975
+ registration: z16.string().optional(),
976
+ emailable: z16.string().optional(),
977
+ gender: z16.string().optional(),
933
978
  blockinfo: z16.record(z16.unknown()).optional()
934
979
  }) } });
935
980
  return tool;
@@ -971,12 +1016,12 @@ function whoareTool(server) {
971
1016
  userid: z17.number(),
972
1017
  name: z17.string(),
973
1018
  groups: z17.array(z17.string()),
974
- implicitgroups: z17.array(z17.string()),
1019
+ implicitgroups: z17.array(z17.string()).optional(),
975
1020
  rights: z17.array(z17.string()),
976
1021
  editcount: z17.number(),
977
- registration: z17.string(),
978
- emailable: z17.string(),
979
- gender: z17.string(),
1022
+ registration: z17.string().optional(),
1023
+ emailable: z17.string().optional(),
1024
+ gender: z17.string().optional(),
980
1025
  blockinfo: z17.record(z17.unknown()).optional()
981
1026
  })), count: z17.number() } });
982
1027
  return tool;
@@ -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) {
@@ -1390,9 +1435,9 @@ function getSiteStatsTool(server) {
1390
1435
  edits: z27.number(),
1391
1436
  images: z27.number(),
1392
1437
  users: z27.number(),
1393
- activeusers: z27.number(),
1394
- admins: z27.number(),
1395
- jobs: z27.number()
1438
+ activeusers: z27.number().optional(),
1439
+ admins: z27.number().optional(),
1440
+ jobs: z27.number().optional()
1396
1441
  }) } });
1397
1442
  return tool;
1398
1443
  }
@@ -1572,7 +1617,7 @@ function editTool(server) {
1572
1617
  },
1573
1618
  async (params) => handleEditTool(params)
1574
1619
  );
1575
- tool.update({ outputSchema: { result: z32.string(), pageid: z32.number(), title: z32.string(), contentmodel: z32.string(), newrevid: z32.number(), newtimestamp: z32.string(), oldrevid: z32.number().optional() } });
1620
+ tool.update({ outputSchema: { result: z32.string(), pageid: z32.number(), title: z32.string(), contentmodel: z32.string().optional(), newrevid: z32.number(), newtimestamp: z32.string().optional(), oldrevid: z32.number().optional() } });
1576
1621
  return tool;
1577
1622
  }
1578
1623
  async function handleEditTool(params) {
@@ -1682,7 +1727,7 @@ function prependTool(server) {
1682
1727
  },
1683
1728
  async (params) => handlePrependTool(params)
1684
1729
  );
1685
- tool.update({ outputSchema: { result: z34.string(), pageid: z34.number(), title: z34.string(), contentmodel: z34.string(), newrevid: z34.number(), newtimestamp: z34.string(), oldrevid: z34.number().optional() } });
1730
+ tool.update({ outputSchema: { result: z34.string(), pageid: z34.number(), title: z34.string(), contentmodel: z34.string().optional(), newrevid: z34.number(), newtimestamp: z34.string().optional(), oldrevid: z34.number().optional() } });
1686
1731
  return tool;
1687
1732
  }
1688
1733
  async function handlePrependTool(params) {
@@ -1759,7 +1804,7 @@ function deleteTool(server) {
1759
1804
  },
1760
1805
  async (params) => handleDeleteTool(params)
1761
1806
  );
1762
- tool.update({ outputSchema: { title: z36.string(), reason: z36.string(), logid: z36.number() } });
1807
+ tool.update({ outputSchema: { title: z36.string(), reason: z36.string(), logid: z36.number().optional() } });
1763
1808
  return tool;
1764
1809
  }
1765
1810
  async function handleDeleteTool(params) {
@@ -1806,7 +1851,7 @@ function protectTool(server) {
1806
1851
  },
1807
1852
  async (params) => handleProtectTool(params)
1808
1853
  );
1809
- tool.update({ outputSchema: { title: z37.string(), reason: z37.string().optional(), protections: z37.array(z37.record(z37.unknown())), cascade: z37.boolean() } });
1854
+ tool.update({ outputSchema: { title: z37.string(), reason: z37.string().optional(), protections: z37.array(z37.record(z37.unknown())), cascade: z37.boolean().optional() } });
1810
1855
  return tool;
1811
1856
  }
1812
1857
  async function handleProtectTool(params) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiedada/nodemw-mcp-server",
3
- "version": "0.0.8",
3
+ "version": "0.0.11",
4
4
  "description": "MCP server for nodemw - MediaWiki API client",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",