Skip to main content
Glama
helpers.py1.35 kB
""" Contains various helper functions for common tasks. """ import uuid import logging logger = logging.getLogger(__name__) def generate_unique_id() -> str: """ Generates a universally unique identifier (UUID). """ unique_id = str(uuid.uuid4()) logger.debug(f"Generated unique ID: {unique_id}") return unique_id def sanitize_input_string(input_str: str) -> str: """ A placeholder for input sanitization. In a real application, this would involve more robust cleaning to prevent injection attacks or unexpected data. [15, 33] """ if not isinstance(input_str, str): logger.warning(f"Non-string input provided for sanitization: {type(input_str)}") return str(input_str) # Convert to string defensively sanitized_str = input_str.strip() # Example: Remove potentially harmful characters or sequences # sanitized_str = sanitized_str.replace("<script>", "") logger.debug(f"Sanitized input: '{input_str}' -> '{sanitized_str}'") return sanitized_str # Example usage (for testing within this module) if __name__ == "__main__": print("Generated ID:", generate_unique_id()) print( "Sanitized string:", sanitize_input_string(" Hello World! <script>alert('xss')</script> "), ) print("Sanitized non-string:", sanitize_input_string(123))

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/jairosoft-com/mcp-server-python-template'

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