Skip to content

Add comprehensive documentation to GenerateOutputSchema#7072

Merged
pelikhan merged 3 commits intomainfrom
copilot/add-documentation-for-generate-output-schema
Dec 20, 2025
Merged

Add comprehensive documentation to GenerateOutputSchema#7072
pelikhan merged 3 commits intomainfrom
copilot/add-documentation-for-generate-output-schema

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 20, 2025

The GenerateOutputSchema function lacked detail on schema generation rules and MCP requirements, making it difficult for users to understand how to properly define tool output schemas.

Changes

  • Schema generation rules: Documents how json tags define property names, jsonschema tags provide descriptions, omitempty/omitzero mark optional fields, pointer types include null, and v0.4.0+ features (nullable slices, PropertyOrder)
  • MCP requirements: Clarifies that tool outputs must be objects with descriptions on all properties and correct required/optional field specification
  • Example: Simplified usage example with correct tag format
// GenerateOutputSchema generates a JSON schema from a Go struct type for MCP tool outputs.
// The schema conforms to JSON Schema draft 2020-12 and draft-07.
//
// Schema generation rules:
//   - json tags define property names
//   - jsonschema tags define descriptions
//   - omitempty/omitzero mark optional fields
//   - Pointer types include null in their type array
//   - Slices allow null values (jsonschema-go v0.4.0+)
//   - PropertyOrder maintains deterministic field ordering (v0.4.0+)
//
// MCP Requirements:
//   - Tool output schemas must be objects (not arrays or primitives)
//   - All properties should have descriptions for better LLM understanding
//   - Required vs optional fields must be correctly specified
//
// Example:
//
//	type Output struct {
//	    Name string `json:"name" jsonschema:"Name of the user"`
//	    Age  int    `json:"age,omitempty" jsonschema:"Age in years"`
//	}
//	schema, err := GenerateOutputSchema[Output]()
Original prompt

This section details on the original issue you should resolve

<issue_title>[plan] Add comprehensive documentation to GenerateOutputSchema</issue_title>
<issue_description>## Objective

Add detailed documentation to GenerateOutputSchema explaining schema generation rules and MCP requirements.

Context

The function currently has minimal documentation. Users need to understand how schema generation works and what MCP tool outputs require.

Implementation

Add comprehensive godoc comment to GenerateOutputSchema function:

// GenerateOutputSchema generates a JSON schema from a Go struct type for MCP tool outputs.
// The schema conforms to JSON Schema draft 2020-12 and draft-07.
//
// Schema generation rules:
//   - json tags define property names
//   - jsonschema tags define descriptions
//   - omitempty/omitzero mark optional fields
//   - Pointer types include null in their type array
//   - Slices allow null values (jsonschema-go v0.4.0+)
//   - PropertyOrder maintains deterministic field ordering (v0.4.0+)
//
// MCP Requirements:
//   - Tool output schemas must be objects (not arrays or primitives)
//   - All properties should have descriptions for better LLM understanding
//   - Required vs optional fields must be correctly specified
//
// Example:
//
//     type Output struct {
//         Name string `json:"name" jsonschema:"Name of the user"`
//         Age  int    `json:"age,omitempty" jsonschema:"Age in years"`
//     }
//     schema, err := GenerateOutputSchema[Output]()
func GenerateOutputSchema[T any]() (*jsonschema.Schema, error) {
    return jsonschema.For[T](nil)
}

Files to Modify

  • pkg/cli/mcp_schema.go - Add documentation to GenerateOutputSchema

Acceptance Criteria

AI generated by Plan Command for discussion #6818

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- 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>
Copilot AI changed the title [WIP] Add comprehensive documentation for GenerateOutputSchema Add comprehensive documentation to GenerateOutputSchema Dec 20, 2025
Copilot AI requested a review from mnkiefer December 20, 2025 18:01
@pelikhan pelikhan marked this pull request as ready for review December 20, 2025 18:08
@pelikhan pelikhan merged commit 204c79b into main Dec 20, 2025
5 checks passed
@pelikhan pelikhan deleted the copilot/add-documentation-for-generate-output-schema branch December 20, 2025 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[plan] Add comprehensive documentation to GenerateOutputSchema

3 participants