get_crawl_stats
Retrieve crawl statistics for a specific website from Bing Webmaster Tools to monitor search engine indexing performance and identify crawl issues.
Instructions
Retrieve crawl statistics for a specific site.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site_url | Yes |
Implementation Reference
- mcp_server_bwt/main.py:260-278 (handler)The complete implementation of the 'get_crawl_stats' tool, including registration decorator and handler function. It takes a site_url, makes an API request to Bing Webmaster Tools' GetCrawlStats endpoint, processes the response, and returns crawl statistics with MCP-compatible typing.@mcp.tool( name="get_crawl_stats", description="Retrieve crawl statistics for a specific site." ) async def get_crawl_stats( site_url: Annotated[str, "The URL of the site"] ) -> List[Dict[str, Any]]: """ Retrieve crawl statistics for a specific site. Args: site_url: The URL of the site Returns: List of daily crawl statistics """ async with api: stats = await api._make_request(f"GetCrawlStats?siteUrl={site_url}") return api._ensure_type_field(stats, "CrawlStats")
- mcp_server_bwt/main.py:260-262 (registration)Registration of the 'get_crawl_stats' tool using the @mcp.tool decorator with name and description.@mcp.tool( name="get_crawl_stats", description="Retrieve crawl statistics for a specific site." )
- mcp_server_bwt/main.py:59-111 (helper)The _make_request helper method in BingWebmasterAPI class used by get_crawl_stats to perform the HTTP request to the Bing API.async def _make_request( self, endpoint: str, method: str = "GET", json_data: Optional[Dict[str, Any]] = None, params: Optional[Dict[str, Any]] = None, ) -> Any: """Make a request to the Bing API and handle OData responses.""" if not self.client: raise RuntimeError( "API client not initialized. Use 'async with api:' context manager." ) headers = {"Content-Type": "application/json; charset=utf-8"} # Build URL with API key if "?" in endpoint: url = f"{self.base_url}/{endpoint}&apikey={self.api_key}" else: url = f"{self.base_url}/{endpoint}?apikey={self.api_key}" # Add additional parameters if provided if params: for key, value in params.items(): url += f"&{key}={value}" try: if method == "GET": response = await self.client.get(url, headers=headers) else: response = await self.client.request( method, url, headers=headers, json=json_data ) if response.status_code != 200: error_text = response.text logger.error(f"API error {response.status_code}: {error_text}") raise Exception(f"API error {response.status_code}: {error_text}") data = response.json() # Handle OData response format if "d" in data: return data["d"] return data except httpx.TimeoutException: logger.error(f"Request timeout for {endpoint}") raise Exception("Request timed out") except Exception as e: logger.error(f"Request failed: {str(e)}") raise
- mcp_server_bwt/main.py:112-121 (helper)The _ensure_type_field helper method used to add MCP-compatible __type fields to the API response data.def _ensure_type_field(self, data: Any, type_name: str) -> Any: """Ensure __type field is present for MCP compatibility.""" if isinstance(data, list): for item in data: if isinstance(item, dict) and "__type" not in item: item["__type"] = f"{type_name}:#Microsoft.Bing.Webmaster.Api" elif isinstance(data, dict) and "__type" not in data: data["__type"] = f"{type_name}:#Microsoft.Bing.Webmaster.Api" return data