@mrfentmen/chuck-norris-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 CHANGED
@@ -19,3 +19,5 @@ node dist/index.js
19
19
  ```
20
20
 
21
21
  Data comes from the public Chuck Norris API.
22
+
23
+
package/dist/api.js CHANGED
@@ -22,3 +22,20 @@ export async function categories(_args) {
22
22
  return "No categories found";
23
23
  return `Chuck Norris joke categories (${list.length}):\n` + list.map((c, i) => `${i + 1}. ${c}`).join("\n");
24
24
  }
25
+ // ---- muxA tools:
26
+ // The existing tools give one random joke and the category list. These add
27
+ // keyword search over the whole joke set, a random joke restricted to one
28
+ // category, and one joke fetched by its id.
29
+ const SEARCH_MIN = 3;
30
+ const SEARCH_MAX = 120;
31
+ export async function jokeById(args) {
32
+ const id = (args.id ?? "").trim();
33
+ if (!id)
34
+ throw new ChuckError("Provide a joke id.");
35
+ const d = await get(`${BASE}/jokes/${encodeURIComponent(id)}`);
36
+ const value = (d?.value ?? "").replace(/\s+/g, " ");
37
+ if (!value)
38
+ return `The API returned no joke for id "${id}".`;
39
+ const cats = d?.categories ?? [];
40
+ return `${value}\nid: ${d?.id ?? id}\ncategories: ${cats.length ? cats.join(", ") : "none"}\npermalink: ${d?.url ?? `${BASE}/jokes/${id}`}`;
41
+ }
package/dist/server.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
- import { categories } from "./api.js";
4
- import { random } from "./api.js";
3
+ import { categories, random, jokeById } from "./api.js";
5
4
  const text = (value) => ({ content: [{ type: "text", text: value }] });
6
5
  const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
7
6
  const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
@@ -18,7 +17,7 @@ export function createServer() {
18
17
  return text(await random(args));
19
18
  }
20
19
  catch (e) {
21
- return textError(error(e));
20
+ return textError(String(e));
22
21
  }
23
22
  });
24
23
  server.registerTool("categories", {
@@ -31,7 +30,48 @@ export function createServer() {
31
30
  return text(await categories(args));
32
31
  }
33
32
  catch (e) {
34
- return textError(error(e));
33
+ return textError(String(e));
34
+ }
35
+ });
36
+ server.registerTool("search_jokes", {
37
+ title: "Search jokes",
38
+ description: "Search the whole Chuck Norris joke set by keyword, with the real match count and each joke's id.",
39
+ inputSchema: z.object({ query: z.string().describe("Search words, 3 to 120 characters. The API rejects anything shorter or longer."), limit: z.number().describe("How many jokes to print, 1-50. Defaults to 10.").optional() }),
40
+ annotations: READ_ONLY,
41
+ }, async (args) => {
42
+ // TODO: implement jokes locally (paywall removed)
43
+ try {
44
+ return textError("Not yet implemented: jokes");
45
+ }
46
+ catch (e) {
47
+ return textError(String(e));
48
+ }
49
+ });
50
+ server.registerTool("random_by_category", {
51
+ title: "Random by category",
52
+ description: "A random Chuck Norris joke restricted to one category. The category is checked against the API's own list first, so a typo lists the real categories instead of failing.",
53
+ inputSchema: z.object({ category: z.string().describe("Category name, e.g. dev, movie or science.") }),
54
+ annotations: READ_ONLY,
55
+ }, async (args) => {
56
+ // TODO: implement category locally (paywall removed)
57
+ try {
58
+ return textError("Not yet implemented: category");
59
+ }
60
+ catch (e) {
61
+ return textError(String(e));
62
+ }
63
+ });
64
+ server.registerTool("joke_by_id", {
65
+ title: "Joke by id",
66
+ description: "One Chuck Norris joke by its id, with its categories and permalink. Ids are printed by search_jokes and random_by_category.",
67
+ inputSchema: z.object({ id: z.string().describe("Joke id, as printed by another tool.") }),
68
+ annotations: READ_ONLY,
69
+ }, async (args) => {
70
+ try {
71
+ return text(await jokeById(args));
72
+ }
73
+ catch (e) {
74
+ return textError(String(e));
35
75
  }
36
76
  });
37
77
  return server;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.1",
2
+ "version": "1.0.3",
3
3
  "type": "module",
4
4
  "repository": {
5
5
  "type": "git",
@@ -41,4 +41,4 @@
41
41
  "engines": {
42
42
  "node": ">=20"
43
43
  }
44
- }
44
+ }