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)
1775
1830
2.**Structured data only**: Return a dictionary that will be serialized to JSON (Introduced in spec revision 2025-06-18)
1776
1831
3.**Both**: Return a tuple of (content, structured_data) preferred option to use for backwards compatibility
1832
+
4.**Direct CallToolResult**: Return `CallToolResult` directly for full control (including `_meta` field)
1777
1833
1778
1834
When an `outputSchema` is defined, the server automatically validates the structured output against the schema. This ensures type safety and helps catch errors early.
1779
1835
1836
+
##### Returning CallToolResult Directly
1837
+
1838
+
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.
1913
+
1780
1914
### Pagination (Advanced)
1781
1915
1782
1916
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