component

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package component defines the downstream MCP boundary used by the catalog and composite server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithRequestHeaders

func ContextWithRequestHeaders(ctx context.Context, headers http.Header) context.Context

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

func DownstreamMeta(meta mcp.Meta) mcp.Meta

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

func RequestHeadersFromContext(ctx context.Context) http.Header

RequestHeadersFromContext returns a copy of the frontend request headers.

func WithoutValues

func WithoutValues(ctx context.Context) context.Context

WithoutValues preserves cancellation and deadlines while preventing private values owned by an upstream SDK session from leaking into a downstream one.

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

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) Close

func (p *Pool) Close() error

Close closes every pooled runtime and prevents future acquisitions.

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) Discover

func (f *RoutingFactory) Discover(ctx context.Context, server config.Server) (*Features, error)

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

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.

type RuntimeOptions

type RuntimeOptions struct {
	IdleTimeout      time.Duration
	FrontendActivity int
	Callbacks        Callbacks
	OnOpen           func()
	OnClose          func()
}

RuntimeOptions controls the lifecycle of a stateful component runtime.

Directories

Path Synopsis
Package http implements Streamable HTTP component clients.
Package http implements Streamable HTTP component clients.
Package stdio implements isolated command-backed MCP components.
Package stdio implements isolated command-backed MCP components.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL