fix: add StatelessModeNotSupported exception and improve tests (#1828)

This commit is contained in:
Max Isbey 2026-01-06 11:26:26 +00:00 • committed by GitHub
commit 37de50144f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,6 +18,24 @@ class McpError(Exception):
self.error = error
class StatelessModeNotSupported(RuntimeError):
"""
Raised when attempting to use a method that is not supported in stateless mode.
Server-to-client requests (sampling, elicitation, list_roots) are not
supported in stateless HTTP mode because there is no persistent connection
for bidirectional communication.
"""
def __init__(self, method: str):
super().__init__(
f"Cannot use {method} in stateless HTTP mode. "
"Stateless mode does not support server-to-client requests. "
"Use stateful mode (stateless_http=False) to enable this feature."
)
self.method = method
class UrlElicitationRequiredError(McpError):
"""
Specialized error for when a tool requires URL mode elicitation(s) before proceeding.