Documentation
¶
Overview ¶
Package component defines the downstream MCP boundary used by the catalog and composite server.
Index ¶
- func ContextWithRequestHeaders(ctx context.Context, headers http.Header) context.Context
- func DownstreamMeta(meta mcp.Meta) mcp.Meta
- func NewClient(implementation *mcp.Implementation, callbacks Callbacks) *mcp.Client
- func RequestHeadersFromContext(ctx context.Context) http.Header
- func WithoutValues(ctx context.Context) context.Context
- type AuthorizationError
- type Callbacks
- type Discoverer
- type Factory
- type FeatureFamily
- type Features
- type FrontendActivityRuntime
- type Invoker
- type Pool
- type RoutingFactory
- func (f *RoutingFactory) CallTool(ctx context.Context, server config.Server, params *mcp.CallToolParams) (*mcp.CallToolResult, error)
- func (f *RoutingFactory) Close() error
- func (f *RoutingFactory) Discover(ctx context.Context, server config.Server) (*Features, error)
- func (f *RoutingFactory) GetPrompt(ctx context.Context, server config.Server, params *mcp.GetPromptParams) (*mcp.GetPromptResult, error)
- func (f *RoutingFactory) OpenRuntime(ctx context.Context, server config.Server, opts RuntimeOptions) (Runtime, error)
- func (f *RoutingFactory) ReadResource(ctx context.Context, server config.Server, params *mcp.ReadResourceParams) (*mcp.ReadResourceResult, error)
- func (f *RoutingFactory) Subscribe(ctx context.Context, server config.Server, params *mcp.SubscribeParams) error
- func (f *RoutingFactory) Unsubscribe(ctx context.Context, server config.Server, params *mcp.UnsubscribeParams) error
- type Runtime
- type RuntimeFactory
- type RuntimeOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithRequestHeaders ¶
ContextWithRequestHeaders attaches an immutable snapshot of the headers from the frontend HTTP request. The snapshot is the only context value preserved by WithoutValues for downstream HTTP forwarding.
func DownstreamMeta ¶
DownstreamMeta removes transport-owned frontend metadata while preserving application metadata forwarded to a downstream component. The downstream client session injects values appropriate for its negotiated protocol.
func NewClient ¶
func NewClient(implementation *mcp.Implementation, callbacks Callbacks) *mcp.Client
NewClient creates a downstream client whose callbacks are bound to one frontend session. Multi-round-trip handling is deliberately disabled so continuation results can cross the composite boundary unchanged.
func RequestHeadersFromContext ¶
RequestHeadersFromContext returns a copy of the frontend request headers.
Types ¶
type AuthorizationError ¶
type AuthorizationError struct {
StatusCode int
ResourceMetadata string
Scope string
Scopes []string
ErrorCode string
ErrorDescription string
}
AuthorizationError reports an authorization challenge returned by an HTTP component. The challenge fields are the Bearer parameters used by MCP authorization flows.
func (*AuthorizationError) Error ¶
func (e *AuthorizationError) Error() string
type Callbacks ¶
type Callbacks struct {
Frontend *mcp.ServerSession
Component string
Progress func(context.Context, *mcp.ProgressNotificationParams)
Logging func(context.Context, *mcp.LoggingMessageParams) //nolint:staticcheck // Required to proxy logging for legacy MCP versions.
ListChanged func(context.Context, FeatureFamily)
ResourceUpdate func(context.Context, string)
}
Callbacks binds one downstream session to its exact frontend session and configuration. A zero Frontend marks a stateless runtime, where direct server-to-client requests are rejected.
type Discoverer ¶
type Discoverer interface {
// Discover may be called concurrently and must be safe for concurrent use.
Discover(context.Context, config.Server) (*Features, error)
}
Discoverer discovers every supported feature exposed by a component.
type Factory ¶
type Factory interface {
Discoverer
Invoker
RuntimeFactory
Close() error
}
Factory provides discovery and invocation operations.
type FeatureFamily ¶
type FeatureFamily string
FeatureFamily identifies a composite catalog family changed by a component.
const ( FeatureTools FeatureFamily = "tools" FeaturePrompts FeatureFamily = "prompts" FeatureResources FeatureFamily = "resources" )
type Features ¶
type Features struct {
ServerInfo *mcp.Implementation
Tools []*mcp.Tool
Prompts []*mcp.Prompt
Resources []*mcp.Resource
ResourceTemplates []*mcp.ResourceTemplate
}
Features is a complete component discovery snapshot.
type FrontendActivityRuntime ¶
type FrontendActivityRuntime interface {
SetFrontendActivity(int)
}
FrontendActivityRuntime receives the number of active frontend HTTP requests associated with its stateful session.
type Invoker ¶
type Invoker interface {
CallTool(context.Context, config.Server, *mcp.CallToolParams) (*mcp.CallToolResult, error)
GetPrompt(context.Context, config.Server, *mcp.GetPromptParams) (*mcp.GetPromptResult, error)
ReadResource(context.Context, config.Server, *mcp.ReadResourceParams) (*mcp.ReadResourceResult, error)
Subscribe(context.Context, config.Server, *mcp.SubscribeParams) error
Unsubscribe(context.Context, config.Server, *mcp.UnsubscribeParams) error
}
Invoker invokes component operations in request-scoped runtimes.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool owns component runtimes scoped to an exact frontend session and config.
func NewPool ¶
func NewPool(factory RuntimeFactory) *Pool
NewPool creates a stateful component runtime pool.
func (*Pool) Acquire ¶
func (p *Pool) Acquire(ctx context.Context, frontend *mcp.ServerSession, fingerprint string, server config.Server, opts RuntimeOptions) (Runtime, func(), error)
Acquire returns the runtime bound to frontend, fingerprint, and server. The returned release function must be called after the operation finishes.
func (*Pool) SetFrontendActivity ¶
func (p *Pool) SetFrontendActivity(frontend *mcp.ServerSession, active int)
SetFrontendActivity updates the number of active HTTP requests for all runtimes bound to frontend.
type RoutingFactory ¶
type RoutingFactory struct {
// contains filtered or unexported fields
}
RoutingFactory selects a transport-specific factory for each component.
func NewRoutingFactory ¶
func NewRoutingFactory(httpFactory, stdioFactory Factory) *RoutingFactory
NewRoutingFactory creates a factory for HTTP and command components.
func (*RoutingFactory) CallTool ¶
func (f *RoutingFactory) CallTool(ctx context.Context, server config.Server, params *mcp.CallToolParams) (*mcp.CallToolResult, error)
func (*RoutingFactory) Close ¶
func (f *RoutingFactory) Close() error
Close closes both transport-specific factories.
func (*RoutingFactory) GetPrompt ¶
func (f *RoutingFactory) GetPrompt(ctx context.Context, server config.Server, params *mcp.GetPromptParams) (*mcp.GetPromptResult, error)
func (*RoutingFactory) OpenRuntime ¶
func (f *RoutingFactory) OpenRuntime(ctx context.Context, server config.Server, opts RuntimeOptions) (Runtime, error)
func (*RoutingFactory) ReadResource ¶
func (f *RoutingFactory) ReadResource(ctx context.Context, server config.Server, params *mcp.ReadResourceParams) (*mcp.ReadResourceResult, error)
func (*RoutingFactory) Subscribe ¶
func (f *RoutingFactory) Subscribe(ctx context.Context, server config.Server, params *mcp.SubscribeParams) error
func (*RoutingFactory) Unsubscribe ¶
func (f *RoutingFactory) Unsubscribe(ctx context.Context, server config.Server, params *mcp.UnsubscribeParams) error
type Runtime ¶
type Runtime interface {
CallTool(context.Context, *mcp.CallToolParams) (*mcp.CallToolResult, error)
GetPrompt(context.Context, *mcp.GetPromptParams) (*mcp.GetPromptResult, error)
ReadResource(context.Context, *mcp.ReadResourceParams) (*mcp.ReadResourceResult, error)
Subscribe(context.Context, *mcp.SubscribeParams) error
Unsubscribe(context.Context, *mcp.UnsubscribeParams) error
Close() error
}
Runtime is one connected component session used for multiple operations.
type RuntimeFactory ¶
type RuntimeFactory interface {
OpenRuntime(context.Context, config.Server, RuntimeOptions) (Runtime, error)
}
RuntimeFactory opens connected component sessions for stateful frontends.