broker

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: Apache-2.0 Imports: 41 Imported by: 0

README

Tracks upstream MCP servers

Documentation

Overview

Package broker tracks upstream MCP servers and manages the relationship from clients to upstream

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBrokerTool added in v0.7.0

func IsBrokerTool(tool mcp.Tool) bool

IsBrokerTool returns true if the given tool is a broker-internal meta-tool, either by name (static tools) or by meta annotation (dynamic tools like tags).

Types

type CapabilitiesValidation

type CapabilitiesValidation struct {
	IsValid             bool     `json:"isValid"`
	HasToolCapabilities bool     `json:"hasToolCapabilities"`
	ToolCount           int      `json:"toolCount"`
	MissingCapabilities []string `json:"missingCapabilities"`
}

CapabilitiesValidation represents the capabilities validation results

type ConnectionStatus

type ConnectionStatus struct {
	IsReachable    bool   `json:"isReachable"`
	Error          string `json:"error,omitempty"`
	HTTPStatusCode int    `json:"httpStatusCode,omitempty"`
}

ConnectionStatus represents the connection health of an MCP server

type ElicitationHandler added in v0.7.0

type ElicitationHandler struct {
	ElicitationMap elicitationLookup
	Config         serverConfigLookup
}

ElicitationHandler handles requests routed by the ext-proc router when a tool call requires URL-based token elicitation. It looks up the elicitation entry, builds the token page URL from server config, and returns the -32042 SSE error response per the MCP spec (2025-11-25).

func (*ElicitationHandler) ServeHTTP added in v0.7.0

func (h *ElicitationHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type MCPBroker

type MCPBroker interface {

	// Returns tool annotations for a given tool name
	ToolAnnotations(serverID config.UpstreamMCPID, tool string) (mcp.ToolAnnotation, bool)

	// Returns server info for a given tool name
	GetServerInfo(tool string) (*config.MCPServer, error)

	// Returns server info for a given prompt name
	GetServerInfoByPrompt(prompt string) (*config.MCPServer, error)

	// MCPServer gets an MCP server that federates the upstreams known to this MCPBroker
	MCPServer() *server.MCPServer

	//RegisteredServers returns the map of registered servers
	RegisteredMCPServers() map[config.UpstreamMCPID]upstream.ActiveMCPServer

	// GetVirtualSeverByHeader returns a virtual server definition based on a header where the header is the namespaced/name of the virtual server resource
	GetVirtualSeverByHeader(namespaceName string) (config.VirtualServer, error)

	// ValidateAllServers performs comprehensive validation of all registered servers and returns status
	ValidateAllServers() StatusResponse

	// IsReady reports whether the broker can serve traffic.
	// Returns true when no upstream servers are configured (empty tool list is valid),
	// or when at least one configured upstream is healthy.
	// Returns false only when servers are configured but none have connected yet.
	IsReady() bool

	// HandleStatusRequest handles HTTP status endpoint requests
	HandleStatusRequest(w http.ResponseWriter, r *http.Request)

	// IsBrokerToolName returns true if the given tool name is a broker-internal meta-tool
	IsBrokerToolName(name string) bool

	// Shutdown closes any resources associated with this Broker
	Shutdown(ctx context.Context) error

	config.Observer
}

MCPBroker manages a set of MCP servers and their sessions

func NewBroker

func NewBroker(logger *slog.Logger, opts ...Option) MCPBroker

NewBroker creates a new MCPBroker accepts optional config functions such as WithEnforceCapabilityFilter

type OAuthProtectedResource

type OAuthProtectedResource struct {
	ResourceName           string   `json:"resource_name"`
	Resource               string   `json:"resource"`
	AuthorizationServers   []string `json:"authorization_servers"`
	BearerMethodsSupported []string `json:"bearer_methods_supported"`
	ScopesSupported        []string `json:"scopes_supported"`
}

OAuthProtectedResource represents the OAuth protected resource response

type Option added in v0.6.0

type Option func(mb *mcpBrokerImpl)

Option configures a broker instance

func WithDiscoveryToolThreshold added in v0.7.0

func WithDiscoveryToolThreshold(threshold int) Option

WithDiscoveryToolThreshold sets the tool count above which only meta-tools are shown

func WithDiscoveryToolsEnabled added in v0.7.0

func WithDiscoveryToolsEnabled(enabled bool) Option

WithDiscoveryToolsEnabled enables or disables the discover_tools and select_tools meta-tools

func WithElicitationEnabled added in v0.7.0

func WithElicitationEnabled(enabled bool) Option

WithElicitationEnabled enables URL elicitation credential collection

func WithEnforceCapabilityFilter added in v0.7.0

func WithEnforceCapabilityFilter(enforce bool) Option

WithEnforceCapabilityFilter defines enforceCapabilityFilter setting and is intended for use with the NewBroker function

func WithInvalidToolPolicy added in v0.6.0

func WithInvalidToolPolicy(policy mcpv1alpha1.InvalidToolPolicy) Option

WithInvalidToolPolicy sets the policy for handling upstream tools with invalid schemas

func WithManagerTickerInterval

func WithManagerTickerInterval(interval time.Duration) Option

WithManagerTickerInterval sets the interval for MCP manager backend health checks

func WithSessionCache added in v0.7.0

func WithSessionCache(cache *session.Cache) Option

WithSessionCache sets the session cache used for user-specific tool fetches

func WithTrustedHeadersPublicKey

func WithTrustedHeadersPublicKey(key string) Option

WithTrustedHeadersPublicKey defines the public key used to verify signed headers and is intended for use with the NewBroker function

func WithUserSpecificFetchTimeout added in v0.7.0

func WithUserSpecificFetchTimeout(timeout time.Duration) Option

WithUserSpecificFetchTimeout sets the per-server timeout for user-specific tool fetches

type ProtectedResourceHandler

type ProtectedResourceHandler struct {
	Logger *slog.Logger
}

ProtectedResourceHandler is the HTTP handler for the oauth protected resource config

func (*ProtectedResourceHandler) Handle

Handle handles the /.well-known/oauth-protected-resource endpoint

type ProtocolValidation

type ProtocolValidation struct {
	IsValid          bool   `json:"isValid"`
	SupportedVersion string `json:"supportedVersion"`
	ExpectedVersion  string `json:"expectedVersion"`
}

ProtocolValidation represents the MCP protocol version validation results

type ServerValidationStatus

type ServerValidationStatus struct {
	ID                     string                 `json:"id"`
	Name                   string                 `json:"name"`
	Prefix                 string                 `json:"prefix"`
	ConnectionStatus       ConnectionStatus       `json:"connectionStatus"`
	ProtocolValidation     ProtocolValidation     `json:"protocolValidation"`
	CapabilitiesValidation CapabilitiesValidation `json:"capabilitiesValidation"`
	ToolConflicts          []ToolConflict         `json:"toolConflicts"`
	LastValidated          time.Time              `json:"lastValidated"`
}

ServerValidationStatus contains the validation status of a single MCP server

type StatusHandler

type StatusHandler struct {
	// contains filtered or unexported fields
}

StatusHandler handles HTTP requests to the status endpoint

func NewStatusHandler

func NewStatusHandler(broker MCPBroker, logger slog.Logger) *StatusHandler

NewStatusHandler creates a new status handler for HTTP status endpoints

func (*StatusHandler) ServeHTTP

func (h *StatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler interface

type StatusResponse

type StatusResponse struct {
	Servers          []upstream.ServerValidationStatus `json:"servers"`
	OverallValid     bool                              `json:"overallValid"`
	TotalServers     int                               `json:"totalServers"`
	HealthyServers   int                               `json:"healthyServers"`
	UnHealthyServers int                               `json:"unHealthyServers"`
	ToolConflicts    int                               `json:"toolConflicts"`
	Timestamp        time.Time                         `json:"timestamp"`
	ScopedSessions   int                               `json:"scopedSessions"`
}

StatusResponse contains the overall validation status of all servers

type TokenHandler added in v0.7.0

type TokenHandler struct {
	// contains filtered or unexported fields
}

TokenHandler handles HTTP requests to the /tokens endpoint for per-user token collection via URL elicitation.

func NewTokenHandler added in v0.7.0

func NewTokenHandler(tokenCache tokenStore, elicitationMap elicitation.Map, logger slog.Logger) *TokenHandler

NewTokenHandler creates a handler for the /tokens endpoint.

func (*TokenHandler) ServeHTTP added in v0.7.0

func (h *TokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ToolConflict

type ToolConflict struct {
	ToolName      string   `json:"toolName"`
	PrefixedName  string   `json:"prefixedName"`
	ConflictsWith []string `json:"conflictsWith"`
}

ToolConflict represents a tool name conflict between servers

Directories

Path Synopsis
Package upstream is a package for managing upstream MCP servers
Package upstream is a package for managing upstream MCP servers

Jump to

Keyboard shortcuts

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