test_wikipedia_connectivity
Check whether the Wikipedia API is reachable and responsive. Returns the base URL, language, site info, and response time, or reports failure with error details.
Instructions
Provide diagnostics for Wikipedia API connectivity.
Returns the base API URL, language, site information, and response time in milliseconds. If connectivity fails, status will be 'failed' with error details.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| status | Yes | ||
| url | Yes | ||
| language | Yes | ||
| site_name | No | ||
| server | No | ||
| response_time_ms | No | ||
| error | No | ||
| error_type | No |
Implementation Reference
- wikipedia_mcp/server.py:228-246 (handler)The handler function for the 'test_wikipedia_connectivity' tool. It calls wikipedia_client.test_connectivity() and rounds the response_time_ms if present.
@register_tool("test_wikipedia_connectivity", model_output_schema(ConnectivityResponse)) def test_wikipedia_connectivity(): """ Provide diagnostics for Wikipedia API connectivity. Returns the base API URL, language, site information, and response time in milliseconds. If connectivity fails, status will be 'failed' with error details. """ logger.info("Tool: Testing Wikipedia connectivity") diagnostics = wikipedia_client.test_connectivity() if ( diagnostics.get("status") == "success" and "response_time_ms" in diagnostics and isinstance(diagnostics["response_time_ms"], (int, float)) ): diagnostics["response_time_ms"] = round(float(diagnostics["response_time_ms"]), 3) return diagnostics - wikipedia_mcp/schemas.py:31-39 (schema)The output schema/model for the connectivity test tool response.
class ConnectivityResponse(MCPBaseModel): status: str url: str language: str site_name: Optional[str] = None server: Optional[str] = None response_time_ms: Optional[float] = None error: Optional[str] = None error_type: Optional[str] = None - wikipedia_mcp/server.py:160-176 (registration)The registration decorator that registers the tool under both the canonical name and the 'wikipedia_' alias.
def register_tool(name: str, output_schema: dict[str, Any]): def decorator(func): server.tool( func, name=name, annotations=_READ_ONLY_TOOL_ANNOTATIONS, output_schema=output_schema, ) server.tool( func, name=f"wikipedia_{name}", annotations=_READ_ONLY_TOOL_ANNOTATIONS, output_schema=output_schema, ) return func return decorator - The helper method on WikipediaClient that actually performs the HTTP request to the Wikipedia API and returns connectivity diagnostics.
def test_connectivity(self) -> Dict[str, Any]: """ Test connectivity to the Wikipedia API and return diagnostics. Returns: A dictionary with status, URL, language, site information, and response time. On failure, returns status 'failed' with error details. """ test_url = f"https://{self.base_language}.wikipedia.org/w/api.php" test_params = { "action": "query", "format": "json", "meta": "siteinfo", "siprop": "general", } try: logger.info(f"Testing connectivity to {test_url}") data, error = self._request_json( url=test_url, params=test_params, timeout=10, retries=1, ) if error: return { "status": "failed", "url": test_url, "language": self.base_language, "error": error.get("message", "Connectivity test failed"), "error_type": error.get("error_type", "RequestError"), } site_info = (data or {}).get("query", {}).get("general", {}) return { "status": "success", "url": test_url, "language": self.base_language, "site_name": site_info.get("sitename", "Unknown"), "server": site_info.get("server", "Unknown"), "response_time_ms": None, } except Exception as exc: # pragma: no cover - safeguarded logger.error("Connectivity test failed: %s", exc) return { "status": "failed", "url": test_url, "language": self.base_language, "error": str(exc), "error_type": type(exc).__name__, }