shared

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package shared provides common infrastructure for protocol code generation shared between MCP implementations.

Package shared provides common utilities for code generation across protocols.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildHTTPServiceBase

func BuildHTTPServiceBase(service *expr.ServiceExpr, config ProtocolConfig) *expr.HTTPServiceExpr

BuildHTTPServiceBase creates the HTTP/JSON-RPC service expression with common configuration for routes and SSE endpoints. It uses the provided ProtocolConfig to determine the JSON-RPC path.

func GatherAttributeImports

func GatherAttributeImports(genpkg string, att *expr.AttributeExpr) []*codegen.ImportSpec

GatherAttributeImports collects import specifications for external user types and meta-type imports referenced by the given attribute expression.

func JoinImportPath

func JoinImportPath(genpkg, rel string) string

JoinImportPath constructs a full import path by joining the generation package base path with a relative path. It handles trailing "/gen" suffixes correctly.

func ToJSONSchema

func ToJSONSchema(attr *expr.AttributeExpr) (string, error)

ToJSONSchema returns a compact JSON Schema for the given Goa attribute. It generates inline schemas without $ref references, which is required for MCP protocols that expect fully resolved schemas.

Types

type ProtocolConfig

type ProtocolConfig interface {
	// JSONRPCPath returns the path for JSON-RPC endpoints.
	JSONRPCPath() string
}

ProtocolConfig supplies the JSON-RPC route path needed to build transport expressions. Shared transport helpers deliberately depend on this minimal contract so protocol-specific metadata stays in the owning generator package.

type ProtocolExprBuilderBase

type ProtocolExprBuilderBase struct {
	// contains filtered or unexported fields
}

ProtocolExprBuilderBase provides common expression building functionality shared between MCP protocol implementations.

func NewProtocolExprBuilderBase

func NewProtocolExprBuilderBase() *ProtocolExprBuilderBase

NewProtocolExprBuilderBase creates a new base expression builder.

func (*ProtocolExprBuilderBase) CollectUserTypes

func (b *ProtocolExprBuilderBase) CollectUserTypes() []expr.UserType

CollectUserTypes returns all user types referenced by the protocol service in a deterministic order for stable code generation. The order is based on insertion order, then sorted alphabetically using insertion sort.

func (*ProtocolExprBuilderBase) GetOrCreateType

func (b *ProtocolExprBuilderBase) GetOrCreateType(name string, builder func() *expr.AttributeExpr) *expr.UserTypeExpr

GetOrCreateType retrieves or creates a named user type used by the protocol model.

func (*ProtocolExprBuilderBase) PrepareAndValidate

func (b *ProtocolExprBuilderBase) PrepareAndValidate(root *expr.RootExpr) error

PrepareAndValidate runs Prepare, Validate, and Finalize on the provided root without mutating the global Goa expr.Root to keep generation reentrant.

func (*ProtocolExprBuilderBase) RecordValidationError

func (b *ProtocolExprBuilderBase) RecordValidationError(err error)

RecordValidationError registers a generation-time validation failure that must be returned by PrepareAndValidate even when it is discovered before Goa's eval.Context snapshot begins.

func (*ProtocolExprBuilderBase) Types

Types returns the internal types map for direct access when needed.

func (*ProtocolExprBuilderBase) UserTypeAttr

func (b *ProtocolExprBuilderBase) UserTypeAttr(name string, builder func() *expr.AttributeExpr) *expr.AttributeExpr

UserTypeAttr returns an attribute that references the user type with the given name. This ensures downstream codegen treats the payload/result as a user type instead of inlining the underlying object.

Jump to

Keyboard shortcuts

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