@@ -767,6 +767,22 @@ async def run():
767
767
768
768
# Call a tool
769
769
result = await session.call_tool(" tool-name" , arguments = {" arg1" : " value" })
770
+ # Parse the result (type: CallToolResult)
771
+ for item in result.content:
772
+ if isinstance (item, types.TextContent):
773
+ # Extract text directly from TextContent
774
+ print (f " Tool output (TextContent): { item.text} " )
775
+ elif isinstance (item, types.EmbeddedResource):
776
+ # Check if the embedded resource contains text
777
+ if isinstance (item.resource, types.TextResourceContents):
778
+ print (f " Tool output (EmbeddedResource - Text): { item.resource.text} " )
779
+ elif isinstance (item.resource, types.BlobResourceContents):
780
+ print (f " Tool output (EmbeddedResource - Blob): URI { item.resource.uri} , MIME Type { item.resource.mimeType} " )
781
+ elif isinstance (item, types.ImageContent):
782
+ # Showing only a snippet of image data
783
+ print (f " Tool output (ImageContent): MIME Type { item.mimeType} , Data (base64): { item.data[:30 ]} ... " )
784
+ else :
785
+ print (f " Tool output (Unknown Content Type): { type (item)} " )
770
786
771
787
772
788
if __name__ == " __main__" :
@@ -795,6 +811,22 @@ async def main():
795
811
await session.initialize()
796
812
# Call a tool
797
813
tool_result = await session.call_tool(" echo" , {" message" : " hello" })
814
+ # Parse the result (type: CallToolResult)
815
+ for item in tool_result.content:
816
+ if isinstance (item, types.TextContent):
817
+ # Extract text directly from TextContent
818
+ print (f " Tool output (TextContent): { item.text} " )
819
+ elif isinstance (item, types.EmbeddedResource):
820
+ # Check if the embedded resource contains text
821
+ if isinstance (item.resource, types.TextResourceContents):
822
+ print (f " Tool output (EmbeddedResource - Text): { item.resource.text} " )
823
+ elif isinstance (item.resource, types.BlobResourceContents):
824
+ print (f " Tool output (EmbeddedResource - Blob): URI { item.resource.uri} , MIME Type { item.resource.mimeType} " )
825
+ elif isinstance (item, types.ImageContent):
826
+ # Showing only a snippet of image data
827
+ print (f " Tool output (ImageContent): MIME Type { item.mimeType} , Data (base64): { item.data[:30 ]} ... " )
828
+ else :
829
+ print (f " Tool output (Unknown Content Type): { type (item)} " )
798
830
```
799
831
800
832
### OAuth Authentication for Clients
0 commit comments