4141 GetPromptResult ,
4242 ImageContent ,
4343 TextContent ,
44- DataContent ,
4544 ToolAnnotations ,
4645)
4746from mcp .types import Prompt as MCPPrompt
@@ -170,7 +169,6 @@ def _setup_handlers(self) -> None:
170169 self ._mcp_server .get_prompt ()(self .get_prompt )
171170 self ._mcp_server .list_resource_templates ()(self .list_resource_templates )
172171
173-
174172 async def list_tools (self ) -> list [MCPTool ]:
175173 """List all available tools."""
176174 tools = self ._tool_manager .list_tools ()
@@ -198,7 +196,7 @@ def get_context(self) -> Context[ServerSession, object]:
198196
199197 async def call_tool (
200198 self , name : str , arguments : dict [str , Any ]
201- ) -> Sequence [TextContent | ImageContent | DataContent | EmbeddedResource ]:
199+ ) -> Sequence [TextContent | ImageContent | EmbeddedResource ]:
202200 """Call a tool by name with arguments."""
203201 context = self .get_context ()
204202 result = await self ._tool_manager .call_tool (name , arguments , context = context )
@@ -556,13 +554,13 @@ async def get_prompt(
556554
557555def _convert_to_content (
558556 result : Any ,
559- ) -> Sequence [TextContent | ImageContent | EmbeddedResource | DataContent ]:
557+ ) -> Sequence [TextContent | ImageContent | EmbeddedResource ]:
560558 """Convert a result to a sequence of content objects."""
561559 if result is None :
562560 return []
563561
564562 # Handle existing content types
565- if isinstance (result , TextContent | ImageContent | EmbeddedResource | DataContent ):
563+ if isinstance (result , TextContent | ImageContent | EmbeddedResource ):
566564 return [result ]
567565
568566 if isinstance (result , Image ):
@@ -573,19 +571,8 @@ def _convert_to_content(
573571
574572 # For non-string objects, convert to DataContent
575573 if not isinstance (result , str ):
576- # Try to convert to a JSON-serializable structure
577- try :
578- # Get the data as a dict/list structure
579- data = pydantic_core .to_jsonable_python (result )
580- # Create DataContent with the data
581- return [DataContent (type = "data" , data = data )]
582- except Exception as e :
583- logger .warning (f"Failed to convert result to DataContent: { e } " )
584- # Fall back to string representation
585- result_str = pydantic_core .to_json (result , fallback = str , indent = 2 ).decode ()
586- return [TextContent (type = "text" , text = result_str )]
574+ result = pydantic_core .to_json (result , fallback = str , indent = 2 ).decode ()
587575
588- # For strings, use TextContent
589576 return [TextContent (type = "text" , text = result )]
590577
591578
0 commit comments