package lazymcp ¶
import "golazy.dev/lazymcp"
Constants ¶
const VisibilityModel, VisibilityApp ¶
const (
VisibilityModel = "model"
VisibilityApp = "app"
)
Types ¶
type AppCSP ¶
AppCSP describes MCP Apps content security policy metadata.
type AppCSP struct {
ConnectDomains []string `json:"connect_domains,omitempty"`
ResourceDomains []string `json:"resource_domains,omitempty"`
FrameDomains []string `json:"frame_domains,omitempty"`
}
type AppPermissions ¶
AppPermissions describes optional MCP Apps permission metadata.
type AppPermissions struct {
Tools []string `json:"tools,omitempty"`
}
type AppSpec ¶
AppSpec describes one MCP Apps UI resource owned by an MCP module.
type AppSpec struct {
URI string
Name string
Desc string
HTML string
View string
Variables func(context.Context) (map[string]any, error)
Layout string
UseLayout bool
CSP AppCSP
Permissions AppPermissions
Domain string
PrefersBorder bool
}
type Base ¶
Base is embedded by application MCP module types.
type Base struct {
// contains filtered or unexported fields
}
func NewBase ¶
NewBase creates an MCP base value.
func NewBase(ctx context.Context) Base
func (base Base) Context ¶
Context returns the application context captured by NewBase.
func (base Base) Context() context.Context
func (base Base) Name ¶
Name returns the explicit module name. Empty means infer from type/package.
func (base Base) Name() string
type Message ¶
Message is an MCP prompt message.
type Message struct {
Role string `json:"role"`
Text string `json:"text"`
}
func UserMessages ¶
UserMessages creates user-role prompt messages.
func UserMessages(messages ...string) []Message
type Options ¶
Options configures a Scope.
type Options struct {
Views Views
Authorizer func(context.Context, string) bool
}
type PromptSpec ¶
PromptSpec describes one MCP prompt.
type PromptSpec struct {
Name string
Desc string
Messages []Message
Fn any
}
type ResourceContent ¶
ResourceContent is returned by ResourceSpec readers.
type ResourceContent struct {
Text string
Blob []byte
MIMEType string
}
type ResourceSpec ¶
ResourceSpec describes one MCP resource.
type ResourceSpec struct {
URI string
Name string
Desc string
MIMEType string
Read func(context.Context) (ResourceContent, error)
}
type ResultMetadata ¶
ResultMetadata lets a typed tool result attach widget-only MCP result metadata. The result itself remains the model-visible structuredContent.
type ResultMetadata interface {
MCPResultMeta() map[string]any
}
type Scope ¶
Scope owns registered MCP modules and serves the MCP HTTP endpoint.
type Scope struct {
// contains filtered or unexported fields
}
func NewScope ¶
NewScope creates an empty MCP scope.
func NewScope(options Options) *Scope
func (scope *Scope) Empty ¶
Empty reports whether the scope has no registered modules.
func (scope *Scope) Empty() bool
func (scope *Scope) Handler ¶
Handler serves MCP requests at /mcp and falls through to next for other paths.
func (scope *Scope) Handler(next http.Handler) http.Handler
func (scope *Scope) MiddlewareName ¶
MiddlewareName returns the dispatcher-visible middleware name.
func (scope *Scope) MiddlewareName() string
func (scope *Scope) Register ¶
Register registers one MCP module component.
func (scope *Scope) Register(component any) error
func (scope *Scope) ServeHTTP ¶
ServeHTTP serves MCP JSON-RPC requests.
func (scope *Scope) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (scope *Scope) ServeStdio ¶
ServeStdio serves newline-delimited MCP JSON-RPC on input and output. Register modules before serving. Responses may arrive out of order; writes are serialized, and notifications never receive responses. No logs are written to output. Incoming messages are limited to 64 MiB; outgoing messages have no transport size limit.
On EOF, ServeStdio finishes pending requests. Cancellation cancels requests and closes streams implementing io.Closer to unblock reads and writes. For other streams, the caller must unblock I/O before cancellation can finish. Streams stay open on normal EOF. ServeStdio returns ctx.Err() on cancellation.
func (scope *Scope) ServeStdio(ctx context.Context, input io.Reader, output io.Writer) error
type SkillSpec ¶
SkillSpec describes an Agent Skill directory served through MCP resources.
type SkillSpec struct {
Path string
FS fs.FS
}
type ToolSpec ¶
ToolSpec describes one MCP tool.
type ToolSpec struct {
Name string
Desc string
Fn any
OutputSchema map[string]any
UI UIRef
Visibility []string
}
type UIRef ¶
UIRef links a tool to an MCP Apps UI resource.
type UIRef struct {
ResourceURI string
}
func UI ¶
UI returns a UIRef for uri.
func UI(uri string) UIRef
type ViewOptions ¶
ViewOptions configures rendering for one MCP App view.
type ViewOptions struct {
View string
Variables map[string]any
Layout string
UseLayout bool
}
type Views ¶
Views renders MCP App views. lazyapp adapts lazyview.Views to this interface.
type Views interface {
RenderString(context.Context, ViewOptions) (string, error)
}
func NewViewRenderer ¶
NewViewRenderer adapts an initialized lazyview renderer for MCP App resources. It can be used with a standalone Scope without starting a lazyapp server.
func NewViewRenderer(views *lazyview.Views) Views
Package lazymcp exposes GoLazy application capabilities through the Model Context Protocol.
Applications normally configure MCP through lazyapp.Config.MCP. The package can also be used directly by constructing a Scope, registering MCP modules, and mounting the scope as an HTTP handler or calling Scope.ServeStdio for a local subprocess. NewViewRenderer adapts standalone lazyview rendering for MCP Apps. Keep stdout exclusively for protocol messages and logs on stderr. Authentication and authorization are intentionally supplied by outer layers; lazymcp reads validated JWT claims from context when they are present and filters module access from the "mcps" claim by default.