search_wikipedia
Find Wikipedia articles by entering search terms to retrieve relevant information and metadata for research or reference purposes.
Instructions
Search Wikipedia for articles matching a query.
Parameters: query: The search term to look up on Wikipedia. limit: Maximum number of results to return (1-500).
Returns a dictionary with the search query, results, status, and additional metadata. If the query is empty or invalid, the status will be 'error' and an explanatory message is included.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| limit | No |
Implementation Reference
- wikipedia_mcp/server.py:42-92 (handler)The search_wikipedia tool handler, registered via @server.tool() decorator. Validates query and limit parameters, performs search using WikipediaClient, and returns formatted results with status.@server.tool() def search_wikipedia(query: str, limit: int = 10) -> Dict[str, Any]: """ Search Wikipedia for articles matching a query. Parameters: query: The search term to look up on Wikipedia. limit: Maximum number of results to return (1-500). Returns a dictionary with the search query, results, status, and additional metadata. If the query is empty or invalid, the status will be 'error' and an explanatory message is included. """ logger.info("Tool: Searching Wikipedia for '%s' (limit=%d)", query, limit) # Validate query if not query or not query.strip(): logger.warning("Search tool called with empty query") return { "query": query, "results": [], "status": "error", "message": "Empty search query provided", } # Sanitize and validate limit validated_limit = limit if limit <= 0: validated_limit = 10 logger.warning("Invalid limit %d; using default %d", limit, validated_limit) elif limit > 500: validated_limit = 500 logger.warning("Limit %d capped to %d", limit, validated_limit) results = wikipedia_client.search(query, limit=validated_limit) status = "success" if results else "no_results" response: Dict[str, Any] = { "query": query, "results": results, "status": status, "count": len(results), "language": wikipedia_client.base_language, } if not results: response["message"] = ( "No search results found. This could indicate connectivity issues, " "API errors, or simply no matching articles." ) return response