get_url_report
Analyze a URL to receive a comprehensive threat intelligence report covering reputation and security insights.
Instructions
Get a comprehensive URL analysis report from Google Threat Intelligence.
Args: url (required): URL to analyse. Returns: Report with insights about the URL.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | ||
| api_key | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- gti_mcp/tools/urls.py:72-90 (handler)The main handler function for the 'get_url_report' tool. It base64-encodes the URL, fetches a comprehensive report from the Google Threat Intelligence API using the VirusTotal client (with 'associations' relationship), and sanitizes the response.
@server.tool() async def get_url_report(url: str, ctx: Context, api_key: str = None) -> typing.Dict[str, typing.Any]: """Get a comprehensive URL analysis report from Google Threat Intelligence. Args: url (required): URL to analyse. Returns: Report with insights about the URL. """ url_id = url_to_base64(url) async with vt_client(ctx, api_key=api_key) as client: res = await utils.fetch_object( client, "urls", "url", url_id, relationships=["associations"], params={"exclude_attributes": "last_analysis_results"}) return utils.sanitize_response(res) - gti_mcp/tools/urls.py:63-69 (helper)Helper function that converts a URL to its base64 representation (without padding) as required by the Google Threat Intelligence API.
def url_to_base64(url: str) -> str: """Converts the URL into base64. Without padding, as required by the Google Threat Intelligence API. """ b = base64.b64encode(url.encode('utf-8')) return b.decode('utf-8').rstrip("=") - gti_mcp/utils.py:29-84 (helper)Core utility function called by get_url_report. Fetches an object from the VirusTotal API, handling errors and sanitizing the response by removing 'aggregations' from attributes.
async def fetch_object( vt_client: vt.Client, resource_collection_type: str, resource_type: str, resource_id: str, attributes: list[str] | None = None, relationships: list[str] | None = None, params: dict[str, typing.Any] | None = None): """Fetches objects from Google Threat Intelligence API.""" logging.info( f"Fetching comprehensive {resource_collection_type} " f"report for id: {resource_id}") params = {k: v for k, v in params.items()} if params else {} # Retrieve a selection of object attributes and/or relationships. if attributes: params["attributes"] = ",".join(attributes) if relationships: params["relationships"] = ",".join(relationships) try: obj = await vt_client.get_object_async( f"/{resource_collection_type}/{resource_id}", params=params) if obj.error: logging.error( f"Error fetching main {resource_type} report for {resource_id}: {obj.error}" ) return { "error": f"Failed to get main {resource_type} report: {obj.error}", # "details": report.get("details"), } except vt.error.APIError as e: logging.warning( f"VirusTotal API Error fetching {resource_type} {resource_id}: {e.code} - {e.message}" ) return { "error": f"VirusTotal API Error: {e.code} - {e.message}", "details": f"The requested {resource_type} '{resource_id}' could not be found or there was an issue with the API request." } except Exception as e: logging.exception( f"Unexpected error fetching {resource_type} {resource_id}: {e}" ) return {"error": "An unexpected internal error occurred."} # Build response. obj_dict = obj.to_dict() obj_dict['id'] = obj.id if 'aggregations' in obj_dict['attributes']: del obj_dict['attributes']['aggregations'] logging.info( f"Successfully generated concise threat summary for id: {resource_id}") return obj_dict - gti_mcp/utils.py:119-138 (helper)Utility function that recursively removes empty dictionaries and lists from the API response before returning it.
def sanitize_response(data: typing.Any) -> typing.Any: """Removes empty dictionaries and lists recursively from a response.""" if isinstance(data, dict): sanitized_dict = {} for key, value in data.items(): sanitized_value = sanitize_response(value) if sanitized_value is not None: sanitized_dict[key] = sanitized_value return sanitized_dict elif isinstance(data, list): sanitized_list = [] for item in data: sanitized_item = sanitize_response(item) if sanitized_item is not None: sanitized_list.append(sanitized_item) return sanitized_list elif isinstance(data, str): return data if data else None else: return data - gti_mcp/tools/urls.py:72-73 (registration)The @server.tool() decorator registers this function as an MCP tool named 'get_url_report' with the server.
@server.tool() async def get_url_report(url: str, ctx: Context, api_key: str = None) -> typing.Dict[str, typing.Any]: