Documentation
¶
Overview ¶
Package codegen contains the MCP generator built on top of Goa evaluation and Goa's JSON-RPC codegen.
Codegen Philosophy ¶
MCP code generation is intentionally fail-fast and transport-closed: MCP-enabled services either generate a pure MCP surface or generation fails. The package derives all per-run state from the evaluated Goa roots, then builds a synthetic MCP service expression and lets Goa generate the JSON-RPC transport/client code that MCP needs.
Where MCP needs behavior beyond Goa's standard JSON-RPC generator (tool/resource/prompt adapters, MCP-specific clients, helper packages), this package emits dedicated files around Goa's output. The generator still rewrites a narrow set of example/CLI sections because Goa does not yet expose smaller hooks for that scaffolding; the docs should stay honest about that coupling until the underlying hook surface improves.
Index ¶
- func FormatTagList(tags []string) string
- func Generate(genpkg string, roots []eval.Root, files []*codegen.File) ([]*codegen.File, error)
- func ModifyExampleFiles(_ string, roots []eval.Root, files []*codegen.File) ([]*codegen.File, error)
- func PrepareExample(genpkg string, roots []eval.Root) error
- func PrepareServices(_ string, roots []eval.Root) error
- type AdapterData
- type AnnotationMetaEntry
- type ClientCallerData
- type DefaultField
- type DynamicPromptAdapter
- type EnumField
- type IconData
- type NotificationAdapter
- type OAuthData
- type OAuthScopeData
- type ProjectedToolAdapter
- type PromptArg
- type PromptMessageAdapter
- type RegisterData
- type RegisterTool
- type ResourceAdapter
- type ResourceQueryField
- type RuntimePromptAdapter
- type ServiceMethodMapping
- type SkillDirectoryAdapter
- type StaticPromptAdapter
- type SubscriptionAdapter
- type ToolAdapter
- type ToolSearchData
- type UnionEnvelopeMeta
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatTagList ¶ added in v1.1.6
FormatTagList renders the declared tag set as a quoted, comma-separated list suitable for embedding in a recovery hint message.
func Generate ¶
Generate orchestrates MCP code generation for services that declare MCP configuration in the DSL. It composes Goa service and JSON-RPC generators and adds adapter/client helpers.
func ModifyExampleFiles ¶
func ModifyExampleFiles(_ string, roots []eval.Root, files []*codegen.File) ([]*codegen.File, error)
ModifyExampleFiles patches example CLI wiring to target the MCP adapter client and replaces the default MCP stub factory to return the adapter-wrapped service. It avoids touching HTTP server signatures or example mains.
func PrepareExample ¶
PrepareExample augments the original roots so the Goa example generator includes the MCP JSON-RPC server without manual cmd edits. It runs the same pure-MCP contract validation as Generate so example scaffolding cannot mask invalid MCP mappings.
func PrepareServices ¶
PrepareServices validates the full pure-MCP generation contract before filtering HTTP transport generation for MCP-enabled services. Callers may use Generate directly, but when PrepareServices is part of the pipeline it guarantees invalid MCP designs fail before any transport pruning happens.
Types ¶
type AdapterData ¶
type AdapterData struct {
ServiceName string
ServiceGoName string
MCPServiceName string
MCPName string
MCPVersion string
MCPDescription string
WebsiteURL string
Icons []*IconData
ProtocolVersion string
Package string
MCPPackage string
ServiceJSONRPCAlias string
ImportPath string
Tools []*ToolAdapter
Resources []*ResourceAdapter
SkillDirectories []*SkillDirectoryAdapter
StaticPrompts []*StaticPromptAdapter
DynamicPrompts []*DynamicPromptAdapter
Notifications []*NotificationAdapter
Subscriptions []*SubscriptionAdapter
// Streaming flags derived from original service DSL
ToolsCallStreaming bool
// Derived flags
HasWatchableResources bool
NeedsMCPClient bool
NeedsOriginalClient bool
NeedsQueryFormatting bool
Register *RegisterData
ClientCaller *ClientCallerData
OAuth *OAuthData
ToolSearch *ToolSearchData
}
AdapterData holds the data for generating the adapter
type AnnotationMetaEntry ¶
AnnotationMetaEntry stores one generated tool annotation entry.
type ClientCallerData ¶
type ClientCallerData struct {
MCPImportPath string
}
type DefaultField ¶
DefaultField describes a top-level payload field default assignment.
type DynamicPromptAdapter ¶
type DynamicPromptAdapter struct {
Name string
Description string
Icons []*IconData
OriginalMethodName string
HasPayload bool
PayloadType string
ResultType string
// Arguments describes prompt arguments derived from the payload (dynamic prompts)
Arguments []PromptArg
// ExampleArguments contains a minimal valid JSON for prompt arguments
ExampleArguments string
}
DynamicPromptAdapter represents a dynamic prompt adapter
type EnumField ¶ added in v1.2.2
EnumField describes a top-level payload enum validation in declaration order.
type NotificationAdapter ¶
type NotificationAdapter struct {
Name string
Description string
OriginalMethodName string
HasMessage bool
MessagePointer bool
HasData bool
}
NotificationAdapter represents a notification mapping
type OAuthData ¶ added in v1.1.0
type OAuthData struct {
AuthorizationServers []string
Scopes []OAuthScopeData
ResourceIdentifier string
BearerMethodsSupported []string
ResourceDocumentationURL string
// TrustProxyHeaders controls whether generated code honors
// X-Forwarded-* and RFC 7239 Forwarded headers when deriving
// the canonical resource URL and the WWW-Authenticate
// challenge origin. Default is false: a server reachable
// directly by clients must not trust forwarded headers because
// an attacker could otherwise control the PRM `resource` field.
TrustProxyHeaders bool
}
OAuthData carries the OAuth protected-resource configuration into generation. Nil when the DSL does not declare OAuth.
type OAuthScopeData ¶ added in v1.1.0
OAuthScopeData describes one scope advertised by the protected resource.
type ProjectedToolAdapter ¶ added in v1.2.2
type ProjectedToolAdapter struct {
SourceToolset string
SourceTool string
Description string
Title string
PlacementService string
PlacementMCPServer string
SpecsPackageName string
SpecsImportPath string
SpecName string
BoundService string
BoundMethod string
MethodPayloadType string
RuntimeToolName string
DispatcherFuncName string
DispatchOptionsName string
QualifiedSourceTool string
HasPayload bool
HasResult bool
InputSchema string
OutputSchema string
ExampleArguments string
}
ProjectedToolAdapter carries ownership data for method-backed toolset tools projected into MCP.
func ProjectedToolInventory ¶ added in v1.2.2
func ProjectedToolInventory(genpkg string, roots []eval.Root, serviceName string, mcpServer string) ([]*ProjectedToolAdapter, error)
ProjectedToolInventory returns method-backed toolset tools placed into a generated MCP server.
type PromptMessageAdapter ¶
PromptMessageAdapter represents a prompt message
type RegisterData ¶
type RegisterData struct {
Package string
HelperName string
ServiceName string
SuiteName string
SuiteQualifiedName string
Description string
Tools []RegisterTool
}
RegisterData drives generation of runtime registration helpers.
type RegisterTool ¶
type RegisterTool struct {
ID string
QualifiedName string
Description string
Meta []AnnotationMetaEntry
PayloadType string
ResultType string
InputSchema string
ExampleArgs string
}
RegisterTool represents a single tool entry in the helper file.
type ResourceAdapter ¶
type ResourceAdapter struct {
Name string
Description string
URI string
MimeType string
Icons []*IconData
OriginalMethodName string
HasPayload bool
HasResult bool
PayloadType string
ResultType string
QueryFields []*ResourceQueryField
Watchable bool
}
ResourceAdapter represents a resource adapter
type ResourceQueryField ¶
type ResourceQueryField struct {
QueryKey string
GuardExpr string
ValueExpr string
CollectionExpr string
FormatKind string
Repeated bool
}
ResourceQueryField describes one statically known query parameter binding for a resource payload field.
type RuntimePromptAdapter ¶ added in v1.2.2
RuntimePromptAdapter represents a runtime prompt spec generated from a static MCP prompt.
type ServiceMethodMapping ¶
type ServiceMethodMapping struct {
ToolMethods map[string]string
ResourceMethods map[string]string
DynamicPromptMethods map[string]string
}
ServiceMethodMapping maps MCP operations to original service methods.
type SkillDirectoryAdapter ¶ added in v1.2.2
type SkillDirectoryAdapter struct {
Root string
}
SkillDirectoryAdapter represents one skill root exposed as MCP resources.
type StaticPromptAdapter ¶
type StaticPromptAdapter struct {
Name string
Description string
Icons []*IconData
Messages []*PromptMessageAdapter
RuntimePrompt *RuntimePromptAdapter
}
StaticPromptAdapter represents a static prompt
type SubscriptionAdapter ¶
type SubscriptionAdapter struct {
ResourceName string
ResourceURI string
OriginalMethodName string
}
SubscriptionAdapter represents a subscription mapping
type ToolAdapter ¶
type ToolAdapter struct {
Name string
Description string
Title string
DiscoveryCategory string
DiscoveryTags []string
DiscoveryKeywords []string
Icons []*IconData
OriginalMethodName string
Meta []AnnotationMetaEntry
MetaJSON string
AnnotationsJSON string
HasPayload bool
HasResult bool
PayloadType string
ResultType string
InputSchema string
OutputSchema string
IsStreaming bool
StreamInterface string
StreamEventType string
// Simple validations (top-level only)
RequiredFields []string
EnumFields []EnumField
DefaultFields []DefaultField
// ExampleArguments contains a minimal valid JSON for tool arguments
ExampleArguments string
// CanonicalExampleJSON is a deterministic, always-valid JSON example of
// the payload, synthesized from the IR. Used by the per-tool input
// recovery function emitted into the adapter.
CanonicalExampleJSON string
// UnionEnvelopes lists, for each top-level payload field whose type is
// a discriminated union, the metadata the recovery hint needs to
// describe valid discriminator values and the configured branch key.
UnionEnvelopes []UnionEnvelopeMeta
// Projected is non-nil when this adapter comes from an agent toolset
// projected into MCP instead of a method-level MCP Tool declaration.
Projected *ProjectedToolAdapter
}
ToolAdapter represents a tool adapter
type ToolSearchData ¶ added in v1.2.2
type ToolSearchData struct {
DefaultMaxResults int
MinScore int
ExactMatchMode string
FuzzyNameMatching bool
BroadFallback bool
NameWeight int
TitleWeight int
MetadataWeight int
DescriptionWeight int
ParameterWeight int
FuzzyNameWeight int
}
ToolSearchData carries generated progressive discovery ranking defaults.
type UnionEnvelopeMeta ¶ added in v1.1.6
type UnionEnvelopeMeta struct {
// FieldName is the outer payload field that holds the union envelope
// (e.g. "request" when the payload declares Attribute("request", OneOf(...))).
FieldName string
// TypeKey is the discriminator field name inside the envelope (defaults to "type").
TypeKey string
// ValueKey is the inner branch payload key inside the envelope (defaults to "value").
ValueKey string
// Tags lists the declared discriminator values in DSL source order.
Tags []string
// FirstTag is the deterministic substitution tag used when the caller
// supplied an invalid discriminator. Equal to Tags[0] when Tags is non-empty.
FirstTag string
// TagExamples maps each declared tag to the canonical full-payload JSON
// example that uses that tag for this envelope. When the caller supplies a
// valid tag but some other field is malformed, the recovery hint reuses the
// caller's tag by looking it up here.
TagExamples map[string]string
}
UnionEnvelopeMeta captures, for one top-level payload field whose type is a discriminated union, the data the per-tool recovery hint needs to build a DSL-faithful example.
Source Files
¶
- adapter_core_jennifer.go
- adapter_generator.go
- adapter_jennifer_sections.go
- adapter_tools_jennifer.go
- cli_templates.go
- client_adapter_file.go
- client_caller_file.go
- doc.go
- example.go
- generate.go
- init.go
- mcp_contract.go
- mcp_expr_builder.go
- mcp_methods.go
- mcp_types.go
- oauth_discovery_file.go
- plugin.go
- prompt_adapter_helpers.go
- register_file.go
- resource_query_helpers.go
- sdk_server_file.go
- source_snapshot.go
- templates.go
- tool_recovery_meta.go
- tool_validation_helpers.go