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 Loom's standard JSON-RPC generator (tool/resource/prompt adapters, MCP-specific clients, helper packages), this package emits dedicated files or replaces stable named sections using evaluated generator data. Mount, handler, endpoint initialization, SSE, and client-constructor ownership all enforce exact upstream cardinality. The generator never inspects or rewrites rendered Go source.
Index ¶
- func FormatTagList(tags []string) string
- func Generate(genpkg string, roots []eval.Root, files []*codegen.File) ([]*codegen.File, error)
- func ModifyExampleFiles(_ string, _ []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 DefaultField
- type DynamicPromptAdapter
- type EnumField
- type IconData
- type OAuthData
- type OAuthScopeData
- type ProjectedToolAdapter
- type PromptArg
- type PromptMessageAdapter
- type RegisterData
- type RegisterTool
- type RequiredField
- type ResourceAdapter
- type ResourceQueryField
- type RuntimePromptAdapter
- type ServiceMethodMapping
- type SkillDirectoryAdapter
- type StaticPromptAdapter
- type ToolAdapter
- type ToolSearchData
- type UnionEnvelopeMeta
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatTagList ¶
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 generates the internal adapter contract and an official-SDK server without synthesizing a native MCP wire transport.
func ModifyExampleFiles ¶
ModifyExampleFiles leaves Loom-owned application examples unchanged. MCP applications explicitly mount the generated SDKServer.
func PrepareExample ¶
PrepareExample validates MCP mappings without injecting a native transport into Loom's example generator. Applications mount the generated SDKServer at their chosen Streamable HTTP path.
func PrepareServices ¶
PrepareServices validates MCP-enabled services before generation. MCP no longer mutates Goa transport expressions: the official SDK owns the MCP wire transport, while explicitly designed HTTP and JSON-RPC transports remain independent application surfaces.
Types ¶
type AdapterData ¶
type AdapterData struct {
ServiceName string
ServiceGoName string
MCPServiceName string
MCPName string
MCPVersion string
MCPDescription string
WebsiteURL string
Icons []*IconData
Package string
MCPPackage string
ImportPath string
Tools []*ToolAdapter
Resources []*ResourceAdapter
SkillDirectories []*SkillDirectoryAdapter
StaticPrompts []*StaticPromptAdapter
DynamicPrompts []*DynamicPromptAdapter
HasWatchableResources bool
Register *RegisterData
OAuth *OAuthData
ToolSearch *ToolSearchData
}
AdapterData holds the data for generating the adapter
type AnnotationMetaEntry ¶
AnnotationMetaEntry stores one generated tool annotation entry.
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 OAuthData ¶
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 ¶
OAuthScopeData describes one scope advertised by the protected resource.
type ProjectedToolAdapter ¶
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
InjectedFields []string
HasBounds bool
InputSchema string
OutputSchema string
ExampleArguments string
}
ProjectedToolAdapter carries ownership data for method-backed toolset tools projected into MCP.
func ProjectedToolInventory ¶
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 RequiredField ¶
RequiredField describes one top-level required payload field.
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
QuerySchema string
Watchable bool
IsStreaming bool
StreamInterface string
StreamEventType string
}
ResourceAdapter represents a resource adapter
type ResourceQueryField ¶
type ResourceQueryField struct {
QueryKey string
GuardExpr string
ValueExpr string
CollectionExpr string
FormatKind string
Repeated bool
Bits int
DefaultValues []string
}
ResourceQueryField describes one statically known query parameter binding for a resource payload field.
type RuntimePromptAdapter ¶
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 ¶
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 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 []RequiredField
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 ¶
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 ¶
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
- doc.go
- example.go
- generate.go
- init.go
- jennifer_helpers.go
- local_provider_file.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