Skip to content

Commit 50261cb

Browse files
Copilotmnkiefer
andcommitted
Add comprehensive documentation to GenerateOutputSchema
- Added detailed schema generation rules - Documented v0.4.0+ features (PropertyOrder, nullable slices) - Added MCP requirements section - Updated usage example to match convention - All tests pass successfully Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
1 parent 7027128 commit 50261cb

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

pkg/cli/mcp_schema.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,28 @@ import (
55
)
66

77
// GenerateOutputSchema generates a JSON schema from a Go struct type for MCP tool outputs.
8-
// This helper uses the github.com/google/jsonschema-go package to automatically generate
9-
// schemas from Go types, leveraging struct tags for descriptions and constraints.
8+
// The schema conforms to JSON Schema draft 2020-12 and draft-07.
109
//
11-
// The schema is generated with default options which respect:
12-
// - json tags for field names
13-
// - jsonschema tags for descriptions and constraints
14-
// - omitempty to mark optional fields
10+
// Schema generation rules:
11+
// - json tags define property names
12+
// - jsonschema tags define descriptions
13+
// - omitempty/omitzero mark optional fields
14+
// - Pointer types include null in their type array
15+
// - Slices allow null values (jsonschema-go v0.4.0+)
16+
// - PropertyOrder maintains deterministic field ordering (v0.4.0+)
1517
//
16-
// Example usage:
18+
// MCP Requirements:
19+
// - Tool output schemas must be objects (not arrays or primitives)
20+
// - All properties should have descriptions for better LLM understanding
21+
// - Required vs optional fields must be correctly specified
1722
//
18-
// type MyOutput struct {
19-
// Name string `json:"name" jsonschema:"description=Name of the item"`
20-
// Count int `json:"count,omitempty" jsonschema:"description=Number of items"`
21-
// }
23+
// Example:
2224
//
23-
// schema, err := GenerateOutputSchema[MyOutput]()
24-
// tool := &mcp.Tool{
25-
// Name: "my-tool",
26-
// Description: "My tool description",
27-
// OutputSchema: schema,
25+
// type Output struct {
26+
// Name string `json:"name" jsonschema:"Name of the user"`
27+
// Age int `json:"age,omitempty" jsonschema:"Age in years"`
2828
// }
29+
// schema, err := GenerateOutputSchema[Output]()
2930
func GenerateOutputSchema[T any]() (*jsonschema.Schema, error) {
3031
return jsonschema.For[T](nil)
3132
}

0 commit comments

Comments
 (0)