@@ -12,8 +12,8 @@ import (
1212// Note: The jsonschema_description tag is added to the JSON schema as description
1313// Ideally use better descriptions, this is just an example
1414type WeatherRequest struct {
15- Location string `json:"location" jsonschema_description:"City or location"`
16- Units string `json:"units,omitempty" jsonschema_description:"celsius or fahrenheit"`
15+ Location string `json:"location,required " jsonschema_description:"City or location"`
16+ Units string `json:"units,omitempty" jsonschema_description:"celsius or fahrenheit" jsonschema:"enum=celsius,enum=fahrenheit" `
1717}
1818
1919type WeatherResponse struct {
@@ -32,7 +32,7 @@ type UserProfile struct {
3232}
3333
3434type UserRequest struct {
35- UserID string `json:"userId" jsonschema_description:"User ID"`
35+ UserID string `json:"userId,required " jsonschema_description:"User ID"`
3636}
3737
3838type Asset struct {
@@ -43,46 +43,45 @@ type Asset struct {
4343}
4444
4545type AssetListRequest struct {
46- Limit int `json:"limit,omitempty" jsonschema_description:"Number of assets to return"`
46+ Limit int `json:"limit,omitempty" jsonschema_description:"Number of assets to return" jsonschema:"minimum=1,maximum=100,default=10" `
4747}
4848
4949func main () {
5050 s := server .NewMCPServer (
51- "Structured Output Example" ,
51+ "Structured Input/ Output Example" ,
5252 "1.0.0" ,
5353 server .WithToolCapabilities (false ),
5454 )
5555
5656 // Example 1: Auto-generated schema from struct
5757 weatherTool := mcp .NewTool ("get_weather" ,
5858 mcp .WithDescription ("Get weather with structured output" ),
59+ mcp .WithInputSchema [WeatherRequest ](),
5960 mcp .WithOutputSchema [WeatherResponse ](),
60- mcp .WithString ("location" , mcp .Required ()),
61- mcp .WithString ("units" , mcp .Enum ("celsius" , "fahrenheit" ), mcp .DefaultString ("celsius" )),
6261 )
6362 s .AddTool (weatherTool , mcp .NewStructuredToolHandler (getWeatherHandler ))
6463
6564 // Example 2: Nested struct schema
6665 userTool := mcp .NewTool ("get_user_profile" ,
6766 mcp .WithDescription ("Get user profile" ),
67+ mcp .WithInputSchema [UserRequest ](),
6868 mcp .WithOutputSchema [UserProfile ](),
69- mcp .WithString ("userId" , mcp .Required ()),
7069 )
7170 s .AddTool (userTool , mcp .NewStructuredToolHandler (getUserProfileHandler ))
7271
7372 // Example 3: Array output - direct array of objects
7473 assetsTool := mcp .NewTool ("get_assets" ,
7574 mcp .WithDescription ("Get list of assets as array" ),
75+ mcp .WithInputSchema [AssetListRequest ](),
7676 mcp .WithOutputSchema [[]Asset ](),
77- mcp .WithNumber ("limit" , mcp .Min (1 ), mcp .Max (100 ), mcp .DefaultNumber (10 )),
7877 )
7978 s .AddTool (assetsTool , mcp .NewStructuredToolHandler (getAssetsHandler ))
8079
8180 // Example 4: Manual result creation
8281 manualTool := mcp .NewTool ("manual_structured" ,
8382 mcp .WithDescription ("Manual structured result" ),
83+ mcp .WithInputSchema [WeatherRequest ](),
8484 mcp .WithOutputSchema [WeatherResponse ](),
85- mcp .WithString ("location" , mcp .Required ()),
8685 )
8786 s .AddTool (manualTool , mcp .NewTypedToolHandler (manualWeatherHandler ))
8887
0 commit comments