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
+61Lines changed: 61 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -829,6 +829,67 @@ if __name__ == "__main__":
829
829
830
830
Caution: The `mcp run` and `mcp dev` tool doesn't support low-level server.
831
831
832
+
#### Structured Output Support
833
+
834
+
The low-level server supports structured output for tools, allowing you to return both human-readable content and machine-readable structured data. Tools can define an `outputSchema` to validate their structured output:
# low-level server will validate structured output against the tool's
879
+
# output schema, and automatically serialize it into a TextContent block
880
+
# for backwards compatibility with pre-2025-06-18 clients.
881
+
return structured
882
+
exceptExceptionas e:
883
+
raiseValueError(f"Calculation error: {str(e)}")
884
+
```
885
+
886
+
Tools can return data in three ways:
887
+
1.**Content only**: Return a list of content blocks (default behavior before spec revision 2025-06-18)
888
+
2.**Structured data only**: Return a dictionary that will be serialized to JSON (Introduced in spec revision 2025-06-18)
889
+
3.**Both**: Return a tuple of (content, structured_data) preferred option to use for backwards compatibility
890
+
891
+
When an `outputSchema` is defined, the server automatically validates the structured output against the schema. This ensures type safety and helps catch errors early.
892
+
832
893
### Writing MCP Clients
833
894
834
895
The SDK provides a high-level client interface for connecting to MCP servers using various [transports](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports):
0 commit comments