search
Find relevant wiki pages by entering a search query and specifying the number of results. Supports MediaWiki sites like Wikipedia, Fandom, and Wiki.GG.
Instructions
Search for a wiki page. The shorter the request, the better, preferably containing only the main term to be searched. Args: query: The query to search for limit: The number of results to return Returns: A list of pages that match the query
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| query | Yes |
Input Schema (JSON Schema)
{
"properties": {
"limit": {
"default": 5,
"title": "Limit",
"type": "integer"
},
"query": {
"title": "Query",
"type": "string"
}
},
"required": [
"query"
],
"title": "searchArguments",
"type": "object"
}
Implementation Reference
- src/mediawiki_mcp_server/main.py:54-71 (handler)The handler function for the 'search' tool. It is decorated with @mcp.tool() for registration and includes type hints and docstring serving as schema. Makes an API request to search MediaWiki pages.@mcp.tool() async def search(query: str, limit: int = 5): """ Search for a wiki page. The shorter the request, the better, preferably containing only the main term to be searched. Args: query: The query to search for limit: The number of results to return Returns: A list of pages that match the query """ path = "search/page" params = { "q": query, "limit": limit, } response = await make_request(path, params) return response
- Helper utility function used by the 'search' tool to make HTTP requests to the MediaWiki API, handling proxies and redirects.async def make_request(path: str, params: dict) -> httpx.Response: headers = { "User-Agent": USER_AGENT, } url = config.base_url + config.path_prefix + path proxies = get_proxy_settings() async with httpx.AsyncClient(proxies=proxies, follow_redirects=True) as client: try: response = await client.get(url, headers=headers, params=params) if response.status_code in (301, 302, 303, 307, 308): final_response = await client.get( response.headers["Location"], headers=headers ) return final_response.json() return response.json() except httpx.HTTPStatusError as e: logger.error(e) return {"error": e}
- Helper function to retrieve proxy settings from environment, used by make_request.def get_proxy_settings(): """Get proxy settings from environment variables""" http_proxy = os.environ.get("HTTP_PROXY") return http_proxy