@@ -779,6 +779,22 @@ async def run():
779779
780780 # Call a tool
781781 result = await session.call_tool(" tool-name" , arguments = {" arg1" : " value" })
782+ # Parse the result (type: CallToolResult)
783+ for item in result.content:
784+ if isinstance (item, types.TextContent):
785+ # Extract text directly from TextContent
786+ print (f " Tool output (TextContent): { item.text} " )
787+ elif isinstance (item, types.EmbeddedResource):
788+ # Check if the embedded resource contains text
789+ if isinstance (item.resource, types.TextResourceContents):
790+ print (f " Tool output (EmbeddedResource - Text): { item.resource.text} " )
791+ elif isinstance (item.resource, types.BlobResourceContents):
792+ print (f " Tool output (EmbeddedResource - Blob): URI { item.resource.uri} , MIME Type { item.resource.mimeType} " )
793+ elif isinstance (item, types.ImageContent):
794+ # Showing only a snippet of image data
795+ print (f " Tool output (ImageContent): MIME Type { item.mimeType} , Data (base64): { item.data[:30 ]} ... " )
796+ else :
797+ print (f " Tool output (Unknown Content Type): { type (item)} " )
782798
783799
784800if __name__ == " __main__" :
@@ -807,6 +823,22 @@ async def main():
807823 await session.initialize()
808824 # Call a tool
809825 tool_result = await session.call_tool(" echo" , {" message" : " hello" })
826+ # Parse the result (type: CallToolResult)
827+ for item in tool_result.content:
828+ if isinstance (item, types.TextContent):
829+ # Extract text directly from TextContent
830+ print (f " Tool output (TextContent): { item.text} " )
831+ elif isinstance (item, types.EmbeddedResource):
832+ # Check if the embedded resource contains text
833+ if isinstance (item.resource, types.TextResourceContents):
834+ print (f " Tool output (EmbeddedResource - Text): { item.resource.text} " )
835+ elif isinstance (item.resource, types.BlobResourceContents):
836+ print (f " Tool output (EmbeddedResource - Blob): URI { item.resource.uri} , MIME Type { item.resource.mimeType} " )
837+ elif isinstance (item, types.ImageContent):
838+ # Showing only a snippet of image data
839+ print (f " Tool output (ImageContent): MIME Type { item.mimeType} , Data (base64): { item.data[:30 ]} ... " )
840+ else :
841+ print (f " Tool output (Unknown Content Type): { type (item)} " )
810842```
811843
812844### OAuth Authentication for Clients
0 commit comments