You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+135-1Lines changed: 135 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -497,6 +497,61 @@ causes the tool to be classified as structured _and this is undesirable_,
497
497
the classification can be suppressed by passing `structured_output=False`
498
498
to the `@tool` decorator.
499
499
500
+
##### Advanced: Direct CallToolResult
501
+
502
+
For full control over tool responses including the `_meta` field (for passing data to client applications without exposing it to the model), you can return `CallToolResult` directly:
**Important:**`CallToolResult` must always be returned (no `Optional` or `Union`). For empty results, use `CallToolResult(content=[])`. For optional simple types, use `str | None` without `CallToolResult`.
1.**Content only**: Return a list of content blocks (default behavior before spec revision 2025-06-18)
1889
1944
2.**Structured data only**: Return a dictionary that will be serialized to JSON (Introduced in spec revision 2025-06-18)
1890
1945
3.**Both**: Return a tuple of (content, structured_data) preferred option to use for backwards compatibility
1946
+
4.**Direct CallToolResult**: Return `CallToolResult` directly for full control (including `_meta` field)
1891
1947
1892
1948
When an `outputSchema` is defined, the server automatically validates the structured output against the schema. This ensures type safety and helps catch errors early.
1893
1949
1950
+
##### Returning CallToolResult Directly
1951
+
1952
+
For full control over the response including the `_meta` field (for passing data to client applications without exposing it to the model), return `CallToolResult` directly:
**Note:** When returning `CallToolResult`, you bypass the automatic content/structured conversion. You must construct the complete response yourself.
2027
+
1894
2028
### Pagination (Advanced)
1895
2029
1896
2030
For servers that need to handle large datasets, the low-level server provides paginated versions of list operations. This is an optional optimization - most servers won't need pagination unless they're dealing with hundreds or thousands of items.
0 commit comments