nico-martin's picture
nico-martin HF Staff
done
db78b1a
raw
history blame
2.2 kB
import type { WebMCPTool } from "@utils/webMcp.ts";
const getCurrentTimeTool: WebMCPTool = {
name: "get_current_time",
description: "Returns the current date and time.",
inputSchema: {
type: "object",
properties: {},
required: [],
},
execute: async () => {
const date = new Date();
return `ISO 8601: ${date.toISOString()}\ndd.mm.yyyy: ${date.toLocaleDateString()}\nhh:mm:ss: ${date.toLocaleTimeString()}`;
},
};
const getJokeTool: WebMCPTool = {
name: "get_joke",
description:
"Fetches a joke from the jokes API. Can filter by category, type, or search text.",
inputSchema: {
type: "object",
properties: {
category: {
type: "string",
description:
"Joke category: Any, Programming, Misc, Pun, Spooky, Christmas",
default: "Any",
},
type: {
type: "string",
description:
"Joke format: single (one-liner) or twopart (setup/delivery)",
default: "Any",
},
contains: {
type: "string",
description: "Search for jokes containing this text",
},
},
required: [],
},
execute: async (args) => {
const params = new URLSearchParams({ amount: "1" });
if (args.category && args.category !== "Any") {
params.append("category", args.category);
}
if (args.type && args.type !== "Any") {
params.append("type", args.type);
}
if (args.contains) {
params.append("contains", args.contains);
}
try {
const response = await fetch(
`https://jokes.nico.dev/joke?${params.toString()}`
);
if (!response.ok) {
return `Error fetching joke: ${response.statusText}`;
}
const data = await response.json();
if (data.error) {
return `Error: ${data.error}`;
}
if (data.joke) {
return data.joke;
}
if (data.jokes && data.jokes.length > 0) {
return data.jokes[0].text;
}
return "No joke found";
} catch (error) {
return `Error fetching joke: ${error instanceof Error ? error.message : "Unknown error"}`;
}
},
};
export const TOOLS = [getCurrentTimeTool, getJokeTool];