get_joke
Retrieve a random joke from the Python MCP Server Template to add humor to applications or conversations.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_joke"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp_server.py:11-15 (handler)The handler function for the 'get_joke' tool. It is decorated with @mcp.tool() for registration and fetches a random joke from an API, returning the setup followed by the punchline.
@mcp.tool() async def get_joke() -> str: response = httpx.get("https://official-joke-api.appspot.com/random_joke") joke_data = response.json() return joke_data["setup"] + "\n" + joke_data["punchline"] - mcp_server.py:11-11 (registration)The @mcp.tool() decorator registers the get_joke function as a tool in the FastMCP server.
@mcp.tool()