Documentation
¶
Overview ¶
Package upstream contains domain types for MCP upstream server configuration.
Package upstream contains domain types for MCP upstream server configuration.
Index ¶
- Constants
- Variables
- type ConnectionStatus
- type DiscoveredTool
- type ToolCache
- func (c *ToolCache) ClearConflicts()
- func (c *ToolCache) Count() int
- func (c *ToolCache) GetAllTools() []*DiscoveredTool
- func (c *ToolCache) GetConflicts() []ToolConflict
- func (c *ToolCache) GetTool(name string) (*DiscoveredTool, bool)
- func (c *ToolCache) GetToolsByUpstream(upstreamID string) []*DiscoveredTool
- func (c *ToolCache) HasConflict(name string, excludeUpstreamID string) (bool, string)
- func (c *ToolCache) RecordConflict(conflict ToolConflict)
- func (c *ToolCache) RemoveUpstream(upstreamID string)
- func (c *ToolCache) SetToolsForUpstream(upstreamID string, tools []*DiscoveredTool)
- type ToolConflict
- type Upstream
- type UpstreamStore
- type UpstreamType
Constants ¶
const ( // MaxToolsPerUpstream is the maximum number of tools a single upstream can register. // Prevents memory DoS from a malicious upstream advertising excessive tool counts. MaxToolsPerUpstream = 1000 // MaxTotalTools is the maximum total tools across all upstreams. MaxTotalTools = 10000 )
Variables ¶
var ( // ErrUpstreamNotFound is returned when an upstream with the given ID does not exist. ErrUpstreamNotFound = errors.New("upstream not found") // ErrDuplicateUpstreamName is returned when an upstream name already exists. ErrDuplicateUpstreamName = errors.New("duplicate upstream name") )
Sentinel errors for upstream store operations.
Functions ¶
This section is empty.
Types ¶
type ConnectionStatus ¶
type ConnectionStatus string
ConnectionStatus represents the runtime connection state of an upstream.
const ( // StatusConnected indicates the upstream is connected and operational. StatusConnected ConnectionStatus = "connected" // StatusDisconnected indicates the upstream is not connected. StatusDisconnected ConnectionStatus = "disconnected" // StatusConnecting indicates a connection attempt is in progress. StatusConnecting ConnectionStatus = "connecting" // StatusError indicates the upstream encountered a connection error. StatusError ConnectionStatus = "error" )
type DiscoveredTool ¶
type DiscoveredTool struct {
// Name is the tool's unique identifier.
Name string
// Description is the human-readable tool description.
Description string
// InputSchema is the JSON Schema for the tool's parameters.
InputSchema json.RawMessage
// UpstreamID identifies which upstream this tool was discovered from.
UpstreamID string
// UpstreamName is the human-readable name of the upstream.
UpstreamName string
// DiscoveredAt records when this tool was discovered.
DiscoveredAt time.Time
}
DiscoveredTool represents a tool discovered from an upstream MCP server.
type ToolCache ¶
type ToolCache struct {
// contains filtered or unexported fields
}
ToolCache provides thread-safe storage for discovered tools. It maintains two indexes: by tool name (for routing) and by upstream ID (for refresh/removal).
func (*ToolCache) ClearConflicts ¶
func (c *ToolCache) ClearConflicts()
ClearConflicts removes all recorded conflicts.
func (*ToolCache) GetAllTools ¶
func (c *ToolCache) GetAllTools() []*DiscoveredTool
GetAllTools returns all cached tools.
func (*ToolCache) GetConflicts ¶
func (c *ToolCache) GetConflicts() []ToolConflict
GetConflicts returns all recorded tool name conflicts.
func (*ToolCache) GetTool ¶
func (c *ToolCache) GetTool(name string) (*DiscoveredTool, bool)
GetTool looks up a tool by name.
func (*ToolCache) GetToolsByUpstream ¶
func (c *ToolCache) GetToolsByUpstream(upstreamID string) []*DiscoveredTool
GetToolsByUpstream returns all tools for a specific upstream.
func (*ToolCache) HasConflict ¶
HasConflict checks if a tool name exists from a different upstream. Returns (conflict exists, existing upstream ID).
func (*ToolCache) RecordConflict ¶
func (c *ToolCache) RecordConflict(conflict ToolConflict)
RecordConflict records a tool name conflict.
func (*ToolCache) RemoveUpstream ¶
RemoveUpstream removes all tools for an upstream from the cache.
func (*ToolCache) SetToolsForUpstream ¶
func (c *ToolCache) SetToolsForUpstream(upstreamID string, tools []*DiscoveredTool)
SetToolsForUpstream replaces all tools for the given upstream. It first removes old entries from the tools map for this upstream, then adds the new tools to both maps. Tools are truncated to MaxToolsPerUpstream per upstream and MaxTotalTools globally.
type ToolConflict ¶
type ToolConflict struct {
// ToolName is the conflicting tool name.
ToolName string
// SkippedUpstreamID is the ID of the upstream whose tool was skipped.
SkippedUpstreamID string
// SkippedUpstreamName is the human-readable name of the skipped upstream.
SkippedUpstreamName string
// WinnerUpstreamID is the ID of the upstream that owns the winning tool.
WinnerUpstreamID string
// WinnerUpstreamName is the human-readable name of the winning upstream.
WinnerUpstreamName string
}
ToolConflict records a tool name conflict where a tool was skipped because another upstream already registered a tool with the same name.
type Upstream ¶
type Upstream struct {
// ID is the unique identifier (UUID).
ID string
// Name is the human-readable display name (unique).
Name string
// Type is the transport type: stdio or http.
Type UpstreamType
// Enabled indicates whether this upstream is active.
Enabled bool
// Command is the executable path (stdio only).
Command string
// Args are the command-line arguments (stdio only).
Args []string
// URL is the endpoint (HTTP only).
URL string
// Env holds environment variables passed to stdio upstreams.
Env map[string]string
// Status is the runtime connection state (not persisted).
Status ConnectionStatus
// LastError is the most recent error message (not persisted).
LastError string
// ToolCount is the number of tools discovered (not persisted).
ToolCount int
// CreatedAt is when this upstream was added.
CreatedAt time.Time
// UpdatedAt is when this upstream was last modified.
UpdatedAt time.Time
}
Upstream represents a configured MCP upstream server.
type UpstreamStore ¶
type UpstreamStore interface {
// List returns all configured upstreams.
List(ctx context.Context) ([]Upstream, error)
// Get returns a single upstream by ID.
// Returns ErrUpstreamNotFound if the upstream does not exist.
Get(ctx context.Context, id string) (*Upstream, error)
// Add stores a new upstream.
Add(ctx context.Context, upstream *Upstream) error
// Update replaces an existing upstream.
// Returns ErrUpstreamNotFound if the upstream does not exist.
Update(ctx context.Context, upstream *Upstream) error
// Delete removes an upstream by ID.
// Returns ErrUpstreamNotFound if the upstream does not exist.
Delete(ctx context.Context, id string) error
}
UpstreamStore provides CRUD operations for upstream configuration. This is a port (interface) in the hexagonal architecture. Implementations: in-memory (memory package).
type UpstreamType ¶
type UpstreamType string
UpstreamType identifies the transport protocol for an upstream server.
const ( // UpstreamTypeStdio represents an upstream that communicates via stdin/stdout. UpstreamTypeStdio UpstreamType = "stdio" // UpstreamTypeHTTP represents an upstream that communicates via HTTP/SSE. UpstreamTypeHTTP UpstreamType = "http" )