Documentation
¶
Overview ¶
Package server implements a Model Context Protocol (MCP) server. It provides a JSON-RPC dispatcher, method handlers, and provider interfaces that allow exposing tools and resources to MCP clients.
Index ¶
- Constants
- type BridgeOption
- type LoomBridge
- func (b *LoomBridge) CallTool(ctx context.Context, name string, args map[string]interface{}) (*protocol.CallToolResult, error)
- func (b *LoomBridge) Close() error
- func (b *LoomBridge) ListResources(ctx context.Context) ([]protocol.Resource, error)
- func (b *LoomBridge) ListTools(_ context.Context) ([]protocol.Tool, error)
- func (b *LoomBridge) ReadResource(ctx context.Context, uri string) (*protocol.ReadResourceResult, error)
- func (b *LoomBridge) SetMCPServer(s *MCPServer)
- type MCPServer
- func (s *MCPServer) ClientCapabilities() *protocol.ClientCapabilities
- func (s *MCPServer) ClientInfo() *protocol.Implementation
- func (s *MCPServer) HandleMessage(ctx context.Context, msg []byte) ([]byte, error)
- func (s *MCPServer) NotifyResourceListChanged()
- func (s *MCPServer) RegisterHandler(method string, handler MethodHandler)
- func (s *MCPServer) Serve(ctx context.Context, t transport.Transport) error
- type MethodHandler
- type Option
- type ResourceProvider
- type ToolProvider
Constants ¶
const DefaultRequestTimeout = 30 * time.Second
DefaultRequestTimeout is the per-RPC timeout applied to every gRPC call made through the bridge. Callers can override this with BridgeOption.
const WeaveRequestTimeout = 5 * time.Minute
WeaveRequestTimeout is a longer timeout for Weave/StreamWeave RPCs, which involve multi-step agent execution (LLM calls + tool use).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BridgeOption ¶
type BridgeOption func(*LoomBridge)
BridgeOption configures a LoomBridge.
func WithMCPServer ¶
func WithMCPServer(s *MCPServer) BridgeOption
WithMCPServer sets the MCPServer reference so the bridge can send resource list change notifications after app mutations (create/update/delete).
func WithRequestTimeout ¶
func WithRequestTimeout(d time.Duration) BridgeOption
WithRequestTimeout sets the per-RPC timeout for gRPC calls.
func WithSkillOrchestrator ¶
func WithSkillOrchestrator(o *skills.Orchestrator) BridgeOption
WithSkillOrchestrator sets the skill orchestrator for local skill management tools. When set, the bridge exposes loom_list_skills, loom_get_skill, loom_create_skill, loom_activate_skill, and loom_deactivate_skill tools.
func WithTLS ¶
func WithTLS(certFile string, skipVerify bool) BridgeOption
WithTLS configures TLS for the gRPC connection to the looms server. certFile is the path to a PEM-encoded CA certificate. If empty, the system certificate pool is used. Set skipVerify to true to skip server certificate verification -- this is NOT recommended for production deployments.
type LoomBridge ¶
type LoomBridge struct {
// contains filtered or unexported fields
}
LoomBridge maps Loom's gRPC API to MCP tool and resource providers. It connects to a running looms server and exposes its capabilities as MCP tools for clients like Claude Desktop.
func NewLoomBridge ¶
func NewLoomBridge(grpcAddr string, uiRegistry *apps.UIResourceRegistry, logger *zap.Logger, opts ...BridgeOption) (*LoomBridge, error)
NewLoomBridge creates a bridge to a running looms server.
func NewLoomBridgeFromClient ¶
func NewLoomBridgeFromClient(client loomv1.LoomServiceClient, uiRegistry *apps.UIResourceRegistry, logger *zap.Logger, opts ...BridgeOption) *LoomBridge
NewLoomBridgeFromClient creates a bridge from an existing gRPC client. Useful for testing with mock clients.
func (*LoomBridge) CallTool ¶
func (b *LoomBridge) CallTool(ctx context.Context, name string, args map[string]interface{}) (*protocol.CallToolResult, error)
CallTool implements ToolProvider.
func (*LoomBridge) ListResources ¶
ListResources implements ResourceProvider. Returns embedded apps from the local registry merged with dynamic apps from the gRPC server. The server is authoritative for dynamic apps; the local registry is authoritative for embedded apps.
func (*LoomBridge) ReadResource ¶
func (b *LoomBridge) ReadResource(ctx context.Context, uri string) (*protocol.ReadResourceResult, error)
ReadResource implements ResourceProvider. Reads from the local registry first (embedded apps). If not found locally, proxies the request to the gRPC server (dynamic apps).
func (*LoomBridge) SetMCPServer ¶
func (b *LoomBridge) SetMCPServer(s *MCPServer)
SetMCPServer sets the MCPServer reference after construction. This is useful when the MCPServer is created after the bridge (common in main.go wiring).
type MCPServer ¶
type MCPServer struct {
// contains filtered or unexported fields
}
MCPServer is a JSON-RPC based MCP server that dispatches method calls to registered handlers.
func NewMCPServer ¶
NewMCPServer creates a new MCP server with the given identity and options.
func (*MCPServer) ClientCapabilities ¶
func (s *MCPServer) ClientCapabilities() *protocol.ClientCapabilities
ClientCapabilities returns the connected client's capabilities, or nil if not yet initialized.
func (*MCPServer) ClientInfo ¶
func (s *MCPServer) ClientInfo() *protocol.Implementation
ClientInfo returns the connected client's information, or nil if not yet initialized.
func (*MCPServer) HandleMessage ¶
HandleMessage processes a single JSON-RPC message and returns the response bytes. For notifications (no id), returns nil.
func (*MCPServer) NotifyResourceListChanged ¶
func (s *MCPServer) NotifyResourceListChanged()
NotifyResourceListChanged enqueues a resources/list_changed notification. The notification is sent asynchronously via the Serve() select loop. If the channel is full the notification is dropped with a warning log.
func (*MCPServer) RegisterHandler ¶
func (s *MCPServer) RegisterHandler(method string, handler MethodHandler)
RegisterHandler registers a handler for a JSON-RPC method.
type MethodHandler ¶
type MethodHandler func(ctx context.Context, id json.RawMessage, params json.RawMessage) (interface{}, error)
MethodHandler processes a JSON-RPC method call. id is the request ID (nil for notifications). params is the raw JSON params from the request.
type Option ¶
type Option func(*MCPServer)
Option configures an MCPServer.
func WithExtensions ¶
WithExtensions sets the server's extensions (e.g., MCP Apps).
func WithResourceProvider ¶
func WithResourceProvider(p ResourceProvider) Option
WithResourceProvider registers a ResourceProvider and enables the resources capability. Sets ListChanged: true to indicate the server may send resource list change notifications.
func WithToolProvider ¶
func WithToolProvider(p ToolProvider) Option
WithToolProvider registers a ToolProvider and enables the tools capability.
type ResourceProvider ¶
type ResourceProvider interface {
// ListResources returns all available resources.
ListResources(ctx context.Context) ([]protocol.Resource, error)
// ReadResource reads a resource by its URI.
ReadResource(ctx context.Context, uri string) (*protocol.ReadResourceResult, error)
}
ResourceProvider supplies resources to the MCP server. Implementations expose domain-specific data and UI resources.
type ToolProvider ¶
type ToolProvider interface {
// ListTools returns all available tools.
ListTools(ctx context.Context) ([]protocol.Tool, error)
// CallTool invokes a tool by name with the given arguments.
CallTool(ctx context.Context, name string, args map[string]interface{}) (*protocol.CallToolResult, error)
}
ToolProvider supplies tools to the MCP server. Implementations map domain-specific capabilities to MCP tool definitions.