get_a_joke
Retrieve a funny joke about a specified animal. Use for testing or quick humor.
Instructions
Get a really funny joke! For testing :)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| animal | Yes |
Implementation Reference
- mcpunk/tools.py:214-224 (handler)The handler function for the 'get_a_joke' tool. It takes an 'animal' string (max 20 chars) and returns a joke about that animal crossing the road.
@mcp.tool() @log_inputs_outputs() def get_a_joke(animal: Annotated[str, Field(max_length=20)]) -> ToolResponse: """Get a really funny joke! For testing :)""" return MCPToolOutput( text=( f"Why did the {animal} cross the road?\n" f"To get to the other side!\n" f"Because it was a {animal}." ), ).render() - mcpunk/tools.py:214-214 (registration)The @mcp.tool() decorator registers 'get_a_joke' as an MCP tool with the FastMCP server.
@mcp.tool() - mcpunk/util.py:17-64 (helper)The log_inputs_outputs decorator, used on get_a_joke, wraps the function to log inputs and outputs for debugging.
def log_inputs_outputs( log_level: int | str = logging.INFO, ) -> Callable[[Callable[P, R]], Callable[P, R]]: """Decorator to wrap a tool function and log its inputs and outputs. mcp = FastMCP() @mcp.tool() @log_inputs() def get_a_joke(): ... Args: log_level: The log level to use for the log messages, like `logging.INFO` or "INFO", matching those in the `logging` module. """ if isinstance(log_level, str): level = logging.getLevelNamesMapping()[log_level] else: level = log_level def decorator(func: Callable[P, R]) -> Callable[P, R]: @wraps(func) def wrapper(*args: P.args, **kwargs: P.kwargs) -> R: lines = [ "", " " * 2 + "./" + "-" * 116 + "\\.", " " * 1 + "./" + " " * 118 + "\\.", " " * 0 + "./" + " " * 120 + "\\.", f"Calling tool {func.__name__} with inputs:", ] for i, v in enumerate(args): lines.append(f" Arg_{i}={v!r}") for k, v in kwargs.items(): lines.append(f" {k}={v!r}") logger.log(level, "\n".join(lines)) resp = func(*args, **kwargs) lines = [ "", f" resp={resp!r}", " " * 0 + ".\\" + " " * 120 + "/.", " " * 1 + ".\\" + " " * 118 + "/.", " " * 2 + ".\\" + "-" * 116 + "/.", ] logger.log(level, "\n".join(lines)) return resp return wrapper return decorator