errors.py•1.04 kB
"""Custom exception classes for the MCP server."""
class MCPAuthenticationError(Exception):
"""Raised when authentication fails or is missing."""
def __init__(self, message: str = "Authentication required. Please provide a valid token."):
self.message = message
super().__init__(self.message)
class MCPAuthorizationError(Exception):
"""Raised when user lacks permission to access a resource."""
def __init__(
self,
message: str = "You do not have permission to access this resource.",
):
self.message = message
super().__init__(self.message)
class MCPValidationError(Exception):
"""Raised when input validation fails."""
def __init__(self, message: str, field: str | None = None):
self.message = message
self.field = field
super().__init__(self.message)
def __str__(self) -> str:
if self.field:
return f"Validation error for '{self.field}': {self.message}"
return f"Validation error: {self.message}"