protoschema

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package protoschema builds the JSON Schema of the proto3 JSON form of 1 message, for the input and output schema of a generated MCP tool.

A tool's arguments are what an agent sends, so the schema is the draft 2020-12 mapping of docs/specs/mcp-tools.md: an object whose properties are the message's JSON names, 1 schema for each field, and no property that the message does not declare. A recursive message is a definition under $defs with a $ref, so that the schema ends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForMessage

func ForMessage(md protoreflect.MessageDescriptor) ([]byte, error)

ForMessage returns the JSON Schema of the proto3 JSON form of 1 message, as canonical JSON: the object keys sorted, 2 spaces of indent, and no trailing newline. The result is deterministic: the same message gives the same bytes.

The message must have a JSON object form, because a tool's arguments and result are JSON objects: a well-known type that protojson writes as a string, a number, an array or a JSON null (Timestamp, Duration, FieldMask, Value, ListValue, every wrapper type) has no such schema, and ForMessage refuses it.

A root message that is a well-known type with an object form uses that type's JSON mapping, and not its descriptor's fields: a Struct is any JSON object, so its schema is 1 object with no fixed property, and 1 built from its `fields` map would refuse the object that protojson writes. The same rule holds for a Struct and an Empty field of another message.

func HasObjectForm

func HasObjectForm(md protoreflect.MessageDescriptor) bool

HasObjectForm reports whether 1 message's proto3 JSON form is 1 JSON object, which is what a tool's arguments and result must be. A message that is not a well-known type is an object, whatever its name: an ordinary message named "Timestamp" in a proto file with no package is no well-known type. Of the well-known types, Struct, Empty and Any are objects, and every other 1 is not.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL