88from mcp import Client , types
99from mcp .client .session import ClientSession , ElicitationFnT
1010from mcp .server .mcpserver import Context , MCPServer
11- from mcp .server .session import ServerSession
1211from mcp .shared ._context import RequestContext
1312from mcp .types import ElicitRequestParams , ElicitResult , TextContent
1413
@@ -22,7 +21,7 @@ def create_ask_user_tool(mcp: MCPServer):
2221 """Create a standard ask_user tool that handles all elicitation responses."""
2322
2423 @mcp .tool (description = "A tool that uses elicitation" )
25- async def ask_user (prompt : str , ctx : Context [ ServerSession , None ] ) -> str :
24+ async def ask_user (prompt : str , ctx : Context ) -> str :
2625 result = await ctx .elicit (message = f"Tool wants to ask: { prompt } " , schema = AnswerSchema )
2726
2827 if result .action == "accept" and result .data :
@@ -97,7 +96,7 @@ async def test_elicitation_schema_validation():
9796
9897 def create_validation_tool (name : str , schema_class : type [BaseModel ]):
9998 @mcp .tool (name = name , description = f"Tool testing { name } " )
100- async def tool (ctx : Context [ ServerSession , None ] ) -> str :
99+ async def tool (ctx : Context ) -> str :
101100 try :
102101 await ctx .elicit (message = "This should fail validation" , schema = schema_class )
103102 return "Should not reach here" # pragma: no cover
@@ -147,7 +146,7 @@ class OptionalSchema(BaseModel):
147146 subscribe : bool | None = Field (default = False , description = "Subscribe to newsletter?" )
148147
149148 @mcp .tool (description = "Tool with optional fields" )
150- async def optional_tool (ctx : Context [ ServerSession , None ] ) -> str :
149+ async def optional_tool (ctx : Context ) -> str :
151150 result = await ctx .elicit (message = "Please provide your information" , schema = OptionalSchema )
152151
153152 if result .action == "accept" and result .data :
@@ -188,7 +187,7 @@ class InvalidOptionalSchema(BaseModel):
188187 optional_list : list [int ] | None = Field (default = None , description = "Invalid optional list" )
189188
190189 @mcp .tool (description = "Tool with invalid optional field" )
191- async def invalid_optional_tool (ctx : Context [ ServerSession , None ] ) -> str :
190+ async def invalid_optional_tool (ctx : Context ) -> str :
192191 try :
193192 await ctx .elicit (message = "This should fail" , schema = InvalidOptionalSchema )
194193 return "Should not reach here" # pragma: no cover
@@ -214,7 +213,7 @@ class ValidMultiSelectSchema(BaseModel):
214213 tags : list [str ] = Field (description = "Tags" )
215214
216215 @mcp .tool (description = "Tool with valid list[str] field" )
217- async def valid_multiselect_tool (ctx : Context [ ServerSession , None ] ) -> str :
216+ async def valid_multiselect_tool (ctx : Context ) -> str :
218217 result = await ctx .elicit (message = "Please provide tags" , schema = ValidMultiSelectSchema )
219218 if result .action == "accept" and result .data :
220219 return f"Name: { result .data .name } , Tags: { ', ' .join (result .data .tags )} "
@@ -233,7 +232,7 @@ class OptionalMultiSelectSchema(BaseModel):
233232 tags : list [str ] | None = Field (default = None , description = "Optional tags" )
234233
235234 @mcp .tool (description = "Tool with optional list[str] field" )
236- async def optional_multiselect_tool (ctx : Context [ ServerSession , None ] ) -> str :
235+ async def optional_multiselect_tool (ctx : Context ) -> str :
237236 result = await ctx .elicit (message = "Please provide optional tags" , schema = OptionalMultiSelectSchema )
238237 if result .action == "accept" and result .data :
239238 tags_str = ", " .join (result .data .tags ) if result .data .tags else "none"
@@ -262,7 +261,7 @@ class DefaultsSchema(BaseModel):
262261 email : str = Field (description = "Email address (required)" )
263262
264263 @mcp .tool (description = "Tool with default values" )
265- async def defaults_tool (ctx : Context [ ServerSession , None ] ) -> str :
264+ async def defaults_tool (ctx : Context ) -> str :
266265 result = await ctx .elicit (message = "Please provide your information" , schema = DefaultsSchema )
267266
268267 if result .action == "accept" and result .data :
@@ -327,7 +326,7 @@ class FavoriteColorSchema(BaseModel):
327326 )
328327
329328 @mcp .tool (description = "Single color selection" )
330- async def select_favorite_color (ctx : Context [ ServerSession , None ] ) -> str :
329+ async def select_favorite_color (ctx : Context ) -> str :
331330 result = await ctx .elicit (message = "Select your favorite color" , schema = FavoriteColorSchema )
332331 if result .action == "accept" and result .data :
333332 return f"User: { result .data .user_name } , Favorite: { result .data .favorite_color } "
@@ -351,7 +350,7 @@ class FavoriteColorsSchema(BaseModel):
351350 )
352351
353352 @mcp .tool (description = "Multiple color selection" )
354- async def select_favorite_colors (ctx : Context [ ServerSession , None ] ) -> str :
353+ async def select_favorite_colors (ctx : Context ) -> str :
355354 result = await ctx .elicit (message = "Select your favorite colors" , schema = FavoriteColorsSchema )
356355 if result .action == "accept" and result .data :
357356 return f"User: { result .data .user_name } , Colors: { ', ' .join (result .data .favorite_colors )} "
@@ -366,7 +365,7 @@ class LegacyColorSchema(BaseModel):
366365 )
367366
368367 @mcp .tool (description = "Legacy enum format" )
369- async def select_color_legacy (ctx : Context [ ServerSession , None ] ) -> str :
368+ async def select_color_legacy (ctx : Context ) -> str :
370369 result = await ctx .elicit (message = "Select a color (legacy format)" , schema = LegacyColorSchema )
371370 if result .action == "accept" and result .data :
372371 return f"User: { result .data .user_name } , Color: { result .data .color } "
0 commit comments