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 ¶
- Variables
- func CleanComment(comment string) string
- func DeriveToolName(fullName string) string
- func Generate(gen *protogen.Plugin, file *protogen.File, cfg Config)
- func MethodToSnakeCase(name string) string
- func PrefixWithNamespace(namespace, name string) string
- func ValidateAutoName(name string) error
- func ValidateToolName(name string) error
- type Config
Constants ¶
This section is empty.
Variables ¶
var DefaultVariants = map[string]bool{"inprocess": true, "grpc": true}
DefaultVariants are emitted when no explicit variants are configured.
Functions ¶
func CleanComment ¶
CleanComment strips leading/trailing whitespace and comment markers from proto comments. Also removes linter directives (buf:lint, @ignore-comment, etc.).
func DeriveToolName ¶
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 MethodToSnakeCase ¶
MethodToSnakeCase converts a PascalCase method name to snake_case. "GetUserProfile" → "get_user_profile"
func PrefixWithNamespace ¶
PrefixWithNamespace prepends a namespace to a tool name. Returns the name unchanged if namespace is empty.
func ValidateAutoName ¶
ValidateAutoName validates an auto-generated tool/prompt name. Auto names allow mixed case (from fully qualified proto names).
func ValidateToolName ¶
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
HasVariant reports whether a variant should be generated.