Skip to content

Commit 93d8496

Browse files
Remove redundant inline parsing examples
The original author's inline parsing examples are now redundant since we have a dedicated 'Parsing Tool Results' section under Advanced Usage. This commit removes all the duplicated content, keeping the documentation clean and focused.
1 parent 92e082b commit 93d8496

File tree

1 file changed

+7
-48
lines changed

1 file changed

+7
-48
lines changed

README.md

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,28 +1411,11 @@ async def run():
14111411

14121412
# Call a tool (add tool from fastmcp_quickstart)
14131413
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}")
14361419

14371420

14381421
def main():
@@ -1458,7 +1441,7 @@ Run from the repository root:
14581441

14591442
import asyncio
14601443

1461-
from mcp import ClientSession, types
1444+
from mcp import ClientSession
14621445
from mcp.client.streamable_http import streamablehttp_client
14631446

14641447

@@ -1477,31 +1460,6 @@ async def main():
14771460
tools = await session.list_tools()
14781461
print(f"Available tools: {[tool.name for tool in tools.tools]}")
14791462

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-
15051463

15061464
if __name__ == "__main__":
15071465
asyncio.run(main())
@@ -1716,6 +1674,7 @@ async def main():
17161674
if __name__ == "__main__":
17171675
asyncio.run(main())
17181676
```
1677+
17191678
### MCP Primitives
17201679

17211680
The MCP protocol defines three core primitives that servers can implement:

0 commit comments

Comments
 (0)