|
| 1 | +from datetime import date |
| 2 | +from typing import TypedDict |
| 3 | + |
| 4 | +import requests |
| 5 | +from fastmcp import FastMCP |
| 6 | + |
| 7 | +mcp = FastMCP("WordleMCP") |
| 8 | + |
| 9 | +class WordleAPIData(TypedDict): |
| 10 | + id: int |
| 11 | + solution: str |
| 12 | + print_date: str |
| 13 | + days_since_launch: int |
| 14 | + editor: str |
| 15 | + |
| 16 | + |
| 17 | +@mcp.tool( |
| 18 | + name="get_wordle_solution", |
| 19 | + description="Fetches the Wordle of a particular date provided between 2021-05-19 to 23 days future", |
| 20 | + annotations={"readOnlyHint": True} |
| 21 | +) |
| 22 | +async def get_wordle_data(date: str = date.today().isoformat()) -> WordleAPIData: |
| 23 | + """ |
| 24 | + Retrieves Wordle puzzle data for a specified date. |
| 25 | + |
| 26 | + This function fetches the complete Wordle solution and associated metadata |
| 27 | + for any given date within the supported range. |
| 28 | + |
| 29 | + Args: |
| 30 | + date (str, optional): Target date in YYYY-MM-DD format. If not provided, |
| 31 | + defaults to the current date. |
| 32 | + |
| 33 | + Returns: |
| 34 | + dict: JSON response containing: |
| 35 | + - solution: The 5-letter Wordle answer |
| 36 | + - puzzle_id: Sequential puzzle number |
| 37 | + - metadata: Additional puzzle information (editor, days since launch, etc.) |
| 38 | + |
| 39 | + Note: |
| 40 | + - Date format must be YYYY-MM-DD (ISO 8601) |
| 41 | + - Available date range: 2021-05-19 (Wordle launch) to 23 days future |
| 42 | + - Returns error for dates outside supported range |
| 43 | + """ |
| 44 | + |
| 45 | + url: str = f"https://www.nytimes.com/svc/wordle/v2/{date}.json" |
| 46 | + |
| 47 | + # Make the GET request to the Wordle API |
| 48 | + return requests.get(url, timeout=300).json() |
| 49 | + |
| 50 | + |
| 51 | +if __name__ == "__main__": |
| 52 | + mcp.run() |
0 commit comments