Skip to main content
Glama

Documentation Generator MCP Server

by srwlli
error_responses.py•5.02 kB
""" Centralized error response factory for consistent error formatting (ARCH-001). Provides static methods for creating standardized error responses across all MCP tools. """ from mcp.types import TextContent import jsonschema __all__ = ['ErrorResponse'] class ErrorResponse: """Factory class for creating consistent error responses.""" @staticmethod def invalid_input(detail: str, hint: str = None) -> list[TextContent]: """ Create error response for invalid input (ValueError). Args: detail: Error detail message hint: Optional hint for fixing the error Returns: List containing TextContent with formatted error message """ text = f"āŒ Invalid input: {detail}" if hint: text += f"\n\nšŸ’” {hint}" return [TextContent(type="text", text=text)] @staticmethod def not_found(resource: str, hint: str = None) -> list[TextContent]: """ Create error response for resource not found (FileNotFoundError). Args: resource: Description of what was not found hint: Optional hint for fixing the error Returns: List containing TextContent with formatted error message """ text = f"āŒ {resource} not found" if hint: text += f"\n\nšŸ’” {hint}" return [TextContent(type="text", text=text)] @staticmethod def permission_denied(detail: str, hint: str = None) -> list[TextContent]: """ Create error response for permission denied (PermissionError). Args: detail: Error detail message hint: Optional hint for fixing the error Returns: List containing TextContent with formatted error message """ text = f"āŒ Permission denied: {detail}" if hint: text += f"\n\nšŸ’” {hint}" return [TextContent(type="text", text=text)] @staticmethod def validation_failed(error: jsonschema.ValidationError) -> list[TextContent]: """ Create error response for schema validation failure. Args: error: jsonschema ValidationError object Returns: List containing TextContent with formatted error message including path """ text = f"āŒ Changelog validation failed\n\nError: {error.message}" if error.path: path_str = " → ".join(str(p) for p in error.path) text += f"\nPath: {path_str}" else: text += "\nPath: (root)" text += "\n\nšŸ’” Check CHANGELOG.json against schema at coderef/changelog/schema.json" return [TextContent(type="text", text=text)] @staticmethod def malformed_json(detail: str, hint: str = None) -> list[TextContent]: """ Create error response for malformed JSON (json.JSONDecodeError). Args: detail: Error detail message hint: Optional hint for fixing the error Returns: List containing TextContent with formatted error message """ text = f"āŒ Malformed JSON: {detail}" if hint: text += f"\n\nšŸ’” {hint}" else: text += "\n\nšŸ’” Validate JSON syntax" return [TextContent(type="text", text=text)] @staticmethod def encoding_error(detail: str, hint: str = None) -> list[TextContent]: """ Create error response for encoding errors (UnicodeDecodeError). Args: detail: Error detail message hint: Optional hint for fixing the error Returns: List containing TextContent with formatted error message """ text = f"āŒ Encoding error: {detail}" if hint: text += f"\n\nšŸ’” {hint}" else: text += "\n\nšŸ’” File may be corrupted or not UTF-8 encoded" return [TextContent(type="text", text=text)] @staticmethod def io_error(detail: str, hint: str = None) -> list[TextContent]: """ Create error response for I/O errors (IOError). Args: detail: Error detail message hint: Optional hint for fixing the error Returns: List containing TextContent with formatted error message """ text = f"āŒ File operation failed: {detail}" if hint: text += f"\n\nšŸ’” {hint}" return [TextContent(type="text", text=text)] @staticmethod def generic_error(detail: str, hint: str = None) -> list[TextContent]: """ Create generic error response (Exception). Args: detail: Error detail message hint: Optional hint for fixing the error Returns: List containing TextContent with formatted error message """ text = f"āŒ Error: {detail}" if hint: text += f"\n\nšŸ’” {hint}" return [TextContent(type="text", text=text)]

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/srwlli/docs-mcp'

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