1313from pydantic_core import core_schema
1414from typing_extensions import TypeAliasType
1515
16+ from mcp .server .mcpserver .exceptions import ToolError
1617from mcp .server .session import ServerSession
1718
1819ElicitSchemaModelT = TypeVar ("ElicitSchemaModelT" , bound = BaseModel )
@@ -116,7 +117,7 @@ async def elicit_with_validation(
116117 For sensitive data like credentials or OAuth flows, use elicit_url() instead.
117118
118119 Raises:
119- ValueError : If the client accepted the elicitation without supplying
120+ ToolError : If the client accepted the elicitation without supplying
120121 content, or with content that does not match the requested schema.
121122 """
122123 json_schema = render_elicitation_schema (schema )
@@ -129,13 +130,11 @@ async def elicit_with_validation(
129130
130131 if result .action == "accept" :
131132 if result .content is None :
132- raise ValueError ("Received an accepted elicitation with no content" )
133+ raise ToolError ("Received an accepted elicitation with no content" )
133134 try :
134135 validated_data = schema .model_validate (result .content )
135136 except ValidationError as e :
136- raise ValueError (
137- "Received an accepted elicitation whose content does not match the requested schema"
138- ) from e
137+ raise ToolError ("Received an accepted elicitation whose content does not match the requested schema" ) from e
139138 return AcceptedElicitation (data = validated_data )
140139 if result .action == "decline" :
141140 return DeclinedElicitation ()
0 commit comments