@@ -1411,28 +1411,11 @@ async def run():
1411
1411
1412
1412
# Call a tool (add tool from fastmcp_quickstart)
1413
1413
result = await session.call_tool(" add" , arguments = {" a" : 5 , " b" : 3 })
1414
- # Parse the result (type: CallToolResult)
1415
- for item in result.content:
1416
- if isinstance (item, types.TextContent):
1417
- # Extract text directly from TextContent
1418
- print (f " Tool output (TextContent): { item.text} " )
1419
- elif isinstance (item, types.EmbeddedResource):
1420
- # Check if the embedded resource contains text
1421
- if isinstance (item.resource, types.TextResourceContents):
1422
- print (
1423
- f " Tool output (EmbeddedResource - Text): { item.resource.text} "
1424
- )
1425
- elif isinstance (item.resource, types.BlobResourceContents):
1426
- print (
1427
- f " Tool output (EmbeddedResource - Blob): URI { item.resource.uri} , MIME Type { item.resource.mimeType} "
1428
- )
1429
- elif isinstance (item, types.ImageContent):
1430
- # Showing only a snippet of image data
1431
- print (
1432
- f " Tool output (ImageContent): MIME Type { item.mimeType} , Data (base64): { item.data[:30 ]} ... "
1433
- )
1434
- else :
1435
- print (f " Tool output (Unknown Content Type): { type (item)} " )
1414
+ result_unstructured = result.content[0 ]
1415
+ if isinstance (result_unstructured, types.TextContent):
1416
+ print (f " Tool result: { result_unstructured.text} " )
1417
+ result_structured = result.structuredContent
1418
+ print (f " Structured tool result: { result_structured} " )
1436
1419
1437
1420
1438
1421
def main ():
@@ -1458,7 +1441,7 @@ Run from the repository root:
1458
1441
1459
1442
import asyncio
1460
1443
1461
- from mcp import ClientSession, types
1444
+ from mcp import ClientSession
1462
1445
from mcp.client.streamable_http import streamablehttp_client
1463
1446
1464
1447
@@ -1477,31 +1460,6 @@ async def main():
1477
1460
tools = await session.list_tools()
1478
1461
print (f " Available tools: { [tool.name for tool in tools.tools]} " )
1479
1462
1480
- # Call a tool
1481
- tool_result = await session.call_tool(" echo" , {" message" : " hello" })
1482
- # Parse the result (type: CallToolResult)
1483
- for item in tool_result.content:
1484
- if isinstance (item, types.TextContent):
1485
- # Extract text directly from TextContent
1486
- print (f " Tool output (TextContent): { item.text} " )
1487
- elif isinstance (item, types.EmbeddedResource):
1488
- # Check if the embedded resource contains text
1489
- if isinstance (item.resource, types.TextResourceContents):
1490
- print (
1491
- f " Tool output (EmbeddedResource - Text): { item.resource.text} "
1492
- )
1493
- elif isinstance (item.resource, types.BlobResourceContents):
1494
- print (
1495
- f " Tool output (EmbeddedResource - Blob): URI { item.resource.uri} , MIME Type { item.resource.mimeType} "
1496
- )
1497
- elif isinstance (item, types.ImageContent):
1498
- # Showing only a snippet of image data
1499
- print (
1500
- f " Tool output (ImageContent): MIME Type { item.mimeType} , Data (base64): { item.data[:30 ]} ... "
1501
- )
1502
- else :
1503
- print (f " Tool output (Unknown Content Type): { type (item)} " )
1504
-
1505
1463
1506
1464
if __name__ == " __main__" :
1507
1465
asyncio.run(main())
@@ -1716,6 +1674,7 @@ async def main():
1716
1674
if __name__ == " __main__" :
1717
1675
asyncio.run(main())
1718
1676
```
1677
+
1719
1678
### MCP Primitives
1720
1679
1721
1680
The MCP protocol defines three core primitives that servers can implement:
0 commit comments