Help us shape the future of Go! Take the 2026 Go Developer Survey

protobufparser

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package protobufparser provides a parser for Protocol Buffers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseProtoByReflection

func ParseProtoByReflection(ctx context.Context, target string) (*descriptorpb.FileDescriptorSet, error)

ParseProtoByReflection connects to a gRPC service that has server reflection enabled, discovers its entire set of protobuf definitions, including all dependencies, and returns them as a complete FileDescriptorSet.

ctx is the context for the reflection process, including timeouts. target is the address of the gRPC service to connect to.

func ParseProtoFromDefs

func ParseProtoFromDefs(
	_ context.Context,
	protoDefinitions []*configv1.ProtoDefinition,
	protoCollections []*configv1.ProtoCollection,
) (*descriptorpb.FileDescriptorSet, error)

ParseProtoFromDefs parses a set of protobuf definitions from a slice of ProtoDefinition and a ProtoCollection. It writes the proto files to a temporary directory, invokes protoc to generate a FileDescriptorSet, and then returns the parsed FileDescriptorSet.

Types

type McpField

type McpField struct {
	Name        string
	Description string
	Type        string
	IsRepeated  bool
}

McpField represents a field within a protobuf message, including its name, description, type, and whether it is repeated.

func (*McpField) GetDescription

func (f *McpField) GetDescription() string

GetDescription returns the description of the McpField.

func (*McpField) GetName

func (f *McpField) GetName() string

GetName returns the name of the McpField.

func (*McpField) GetType

func (f *McpField) GetType() string

GetType returns the type of the McpField.

type McpPrompt

type McpPrompt struct {
	Name           string
	Description    string
	Template       string
	ServiceName    string
	MethodName     string
	FullMethodName string
	RequestType    string
	ResponseType   string
}

McpPrompt represents the information extracted from a gRPC method that has been annotated as an MCP prompt.

type McpResource

type McpResource struct {
	Name        string
	Description string
	MessageType string
}

McpResource represents a protobuf message that has been annotated as an MCP resource.

type McpTool

type McpTool struct {
	Name            string
	Description     string
	ServiceName     string
	MethodName      string
	FullMethodName  string // e.g., /package.ServiceName/MethodName
	RequestType     string // Fully qualified name
	ResponseType    string // Fully qualified name
	RequestFields   []McpField
	ResponseFields  []McpField
	ReadOnlyHint    bool
	DestructiveHint bool
	IdempotentHint  bool
	OpenWorldHint   bool
}

McpTool represents the information extracted from a gRPC method that has been annotated as an MCP tool.

type ParsedMcpAnnotations

type ParsedMcpAnnotations struct {
	Tools     []McpTool
	Prompts   []McpPrompt
	Resources []McpResource
}

ParsedMcpAnnotations holds the structured data extracted from MCP (Model Context Protocol) annotations within a set of protobuf files.

func ExtractMcpDefinitions

func ExtractMcpDefinitions(fds *descriptorpb.FileDescriptorSet) (*ParsedMcpAnnotations, error)

ExtractMcpDefinitions iterates through a FileDescriptorSet, parsing any MCP (Model Context Protocol) options found in service methods and messages. It extracts definitions for tools, prompts, and resources.

fds is the FileDescriptorSet to be parsed. It returns a ParsedMcpAnnotations struct containing the extracted information or an error if the parsing fails.

Jump to

Keyboard shortcuts

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