Skip to main content
Glama

scan_file

Scan base64-encoded files for viruses using ClamAV. Provides detailed scan results, including raw clamscan output, to ensure file safety and security.

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 complete implementation of the 'scan_file' tool, registered via @mcp.tool() decorator. It decodes base64-encoded file data, writes to a temporary file, scans it using ClamAV's clamscan command, captures the output, and returns success/error results along with the scan output. Includes proper cleanup and logging.
    @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}")

Other Tools

Related Tools

  • @abdessamad-elamrani/MalwareAnalyzerMCP
  • @abdessamad-elamrani/MalwareAnalyzerMCP
  • @abdessamad-elamrani/MalwareAnalyzerMCP
  • @abdessamad-elamrani/MalwareAnalyzerMCP
  • @brettbergin/adversary-mcp-server
  • @A-Niranjan/mcp-filesystem

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