MCPcopy Index your code
hub / github.com/modelcontextprotocol/python-sdk / UrlElicitationRequiredError

Class UrlElicitationRequiredError

src/mcp/shared/exceptions.py:74–119  ·  view source on GitHub ↗

Specialized error for when a tool requires URL mode elicitation(s) before proceeding. Servers can raise this error from tool handlers to indicate that the client must complete one or more URL elicitations before the request can be processed. Example: ```python raise Url

Source from the content-addressed store, hash-verified

72
73
74class UrlElicitationRequiredError(MCPError):
75 """Specialized error for when a tool requires URL mode elicitation(s) before proceeding.
76
77 Servers can raise this error from tool handlers to indicate that the client
78 must complete one or more URL elicitations before the request can be processed.
79
80 Example:
81 ```python
82 raise UrlElicitationRequiredError([
83 ElicitRequestURLParams(
84 message="Authorization required for your files",
85 url="https://example.com/oauth/authorize",
86 elicitation_id="auth-001"
87 )
88 ])
89 ```
90 """
91
92 def __init__(self, elicitations: list[ElicitRequestURLParams], message: str | None = None):
93 """Initialize UrlElicitationRequiredError."""
94 if message is None:
95 message = f"URL elicitation{'s' if len(elicitations) > 1 else ''} required"
96
97 self._elicitations = elicitations
98
99 super().__init__(
100 code=URL_ELICITATION_REQUIRED,
101 message=message,
102 data={"elicitations": [e.model_dump(by_alias=True, exclude_none=True) for e in elicitations]},
103 )
104
105 @property
106 def elicitations(self) -> list[ElicitRequestURLParams]:
107 """The list of URL elicitations required before the request can proceed."""
108 return self._elicitations
109
110 @classmethod
111 def from_error(cls, error: ErrorData) -> UrlElicitationRequiredError:
112 """Reconstruct from an ErrorData received over the wire."""
113 if error.code != URL_ELICITATION_REQUIRED:
114 raise ValueError(f"Expected error code {URL_ELICITATION_REQUIRED}, got {error.code}")
115
116 data = cast(dict[str, Any], error.data or {})
117 raw_elicitations = cast(list[dict[str, Any]], data.get("elicitations", []))
118 elicitations = [ElicitRequestURLParams.model_validate(e) for e in raw_elicitations]
119 return cls(elicitations, error.message)

Calls

no outgoing calls