generator

package
v0.2.40 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package generator implements the protoc-gen-go-mcp code generation logic. It reads proto service definitions with mcp_tool, mcp_resource, and mcp_prompt annotations, and emits Go registration functions that wire them into an mcpkit MCP server.

The generator supports three forwarding variants (in-process, gRPC, ConnectRPC), configurable via Config.Variants. Templates are loaded from embedded .tmpl files via go:embed.

Tool annotations support custom names, descriptions, timeouts, structured output with result summary templates, and namespace prefixing. Resource annotations support both static URIs and RFC 6570 URI templates. Prompt arguments are auto-derived from request message fields.

See ext/protogen/docs/DESIGN.md for the full design document.

Index

Constants

This section is empty.

Variables

View Source
var DefaultVariants = map[string]bool{"inprocess": true, "grpc": true}

DefaultVariants are emitted when no explicit variants are configured.

Functions

func CleanComment

func CleanComment(comment string) string

CleanComment strips leading/trailing whitespace and comment markers from proto comments. Also removes linter directives (buf:lint, @ignore-comment, etc.).

func DeriveToolName

func DeriveToolName(fullName string) string

DeriveToolName generates a tool name from a proto method's fully qualified name. If the name exceeds maxToolNameLen, it is mangled with a hash prefix.

func Generate

func Generate(gen *protogen.Plugin, file *protogen.File, cfg Config)

Generate processes a proto file and emits mcpkit registration code.

func MethodToSnakeCase

func MethodToSnakeCase(name string) string

MethodToSnakeCase converts a PascalCase method name to snake_case. "GetUserProfile" → "get_user_profile"

func PrefixWithNamespace

func PrefixWithNamespace(namespace, name string) string

PrefixWithNamespace prepends a namespace to a tool name. Returns the name unchanged if namespace is empty.

func ValidateAutoName

func ValidateAutoName(name string) error

ValidateAutoName validates an auto-generated tool/prompt name. Auto names allow mixed case (from fully qualified proto names).

func ValidateToolName

func ValidateToolName(name string) error

ValidateToolName validates a custom (user-provided) tool name. Custom names must be strict snake_case.

Types

type Config

type Config struct {
	// PackageSuffix is appended to the Go package name. Default: "mcp".
	PackageSuffix string

	// Variants controls which registration flavors to generate.
	// Valid values: "inprocess", "grpc", "connect".
	// Default (nil or empty): all three.
	Variants map[string]bool
}

Config holds generation options.

func (Config) HasVariant added in v0.2.11

func (c Config) HasVariant(name string) bool

HasVariant reports whether a variant should be generated.

Jump to

Keyboard shortcuts

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