Skip to main content
Glama

scan_file

Scan files for viruses using the ClamAV engine by providing base64-encoded data and filename to detect malware and security threats.

Instructions

Scan a base64-encoded file using ClamAV. Args: base64_data (str): Base64 encoded string representing a file filename (str): Name of the file to use in the scan Returns: dict: Scan results including the raw clamscan output

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
base64_dataYes
filenameYes

Implementation Reference

  • main.py:15-63 (handler)
    The implementation of the 'scan_file' tool. This is the handler function decorated with @mcp.tool() for registration. It handles base64-encoded file input, decodes it to a temporary file, scans it using ClamAV's clamscan, and returns the scan results or error information.
    @mcp.tool() def scan_file(base64_data: str, filename: str) -> dict: """ Scan a base64-encoded file using ClamAV. Args: base64_data (str): Base64 encoded string representing a file filename (str): Name of the file to use in the scan Returns: dict: Scan results including the raw clamscan output """ logger.info(f"Received scan request for file: {filename}") temp_file_path = None try: # Decode the base64 string file_content = base64.b64decode(base64_data) # Create a temporary file to store the decoded content with tempfile.NamedTemporaryFile(delete=False, mode='wb', suffix=f"_{filename}") as temp_file: temp_file.write(file_content) temp_file_path = temp_file.name # Set permissions to allow ClamAV to read the file os.chmod(temp_file_path, 0o644) logger.info(f"Created temporary file: {temp_file_path}") # Run clamscan command result = subprocess.run(['clamscan', temp_file_path], capture_output=True, text=True) logger.info("Scan completed successfully") return { "success": True, "result": result.stdout + result.stderr } except Exception as e: logger.error(f"Error during scan: {str(e)}") return { "success": False, "error": str(e) } finally: # Clean up the temporary file if temp_file_path and os.path.exists(temp_file_path): os.unlink(temp_file_path) logger.info(f"Cleaned up temporary file: {temp_file_path}")
  • main.py:15-15 (registration)
    The @mcp.tool() decorator registers the scan_file function as an MCP tool.
    @mcp.tool()
  • main.py:16-26 (schema)
    Input schema defined by type hints (base64_data: str, filename: str) and output as dict, with detailed docstring.
    def scan_file(base64_data: str, filename: str) -> dict: """ Scan a base64-encoded file using ClamAV. Args: base64_data (str): Base64 encoded string representing a file filename (str): Name of the file to use in the scan Returns: dict: Scan results including the raw clamscan output """

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/a2amarket/mcp-clamav'

If you have feedback or need assistance with the MCP directory API, please join our Discord server