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
@@ -383,6 +383,61 @@ causes the tool to be classified as structured _and this is undesirable_,
383
383
the classification can be suppressed by passing `structured_output=False`
384
384
to the `@tool` decorator.
385
385
386
+
##### Advanced: Direct CallToolResult
387
+
388
+
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)
1822
1877
2.**Structured data only**: Return a dictionary that will be serialized to JSON (Introduced in spec revision 2025-06-18)
1823
1878
3.**Both**: Return a tuple of (content, structured_data) preferred option to use for backwards compatibility
1879
+
4.**Direct CallToolResult**: Return `CallToolResult` directly for full control (including `_meta` field)
1824
1880
1825
1881
When an `outputSchema` is defined, the server automatically validates the structured output against the schema. This ensures type safety and helps catch errors early.
1826
1882
1883
+
##### Returning CallToolResult Directly
1884
+
1885
+
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.
1960
+
1827
1961
### Pagination (Advanced)
1828
1962
1829
1963
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