runtime

package
v1.261029.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MPL-2.0 Imports: 34 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const AdvisorBehaviorPrompt = `` /* 1974-byte string literal not displayed */

AdvisorBehaviorPrompt is the behavioral contract that tingly-box appends to the worker's system prompt whenever the advisor tool is injected. Behavior instructions are weighted more heavily in system prompts than in tool descriptions, so models follow them more reliably.

View Source
const AdvisorToolDescription = "" /* 209-byte string literal not displayed */

AdvisorToolDescription is the short, concise tool description shown alongside other tools. The full behavioral contract lives in AdvisorBehaviorPrompt and is appended to the worker's system prompt by the MCP injection transform.

Variables

This section is empty.

Functions

func EffectiveToolPolicy added in v1.261026.0

func EffectiveToolPolicy(source typ.MCPSourceConfig, name string) (bool, typ.MCPToolUsage)

EffectiveToolPolicy applies source enablement, its allow list, and a per-tool override. A tool policy cannot grant a tool excluded by the source allow list.

func IsBuiltinSourceID added in v0.260514.1

func IsBuiltinSourceID(sourceID string) bool

func IsClientVisibleSource added in v0.260514.1

func IsClientVisibleSource(source typ.MCPSourceConfig) bool

func IsClientVisibleVirtualTool added in v0.260514.1

func IsClientVisibleVirtualTool(tool coretool.VirtualTool) bool

func IsMCPToolName

func IsMCPToolName(name string) bool

IsMCPToolName checks whether a tool name is a normalized MCP tool.

func IsServerToolSource added in v1.261026.1

func IsServerToolSource(source typ.MCPSourceConfig) bool

IsServerToolSource is independent of implementation: built-in web tools use stdio MCP internally but have gateway-only Server Tool semantics.

func IsServerVisibleSource added in v0.260514.1

func IsServerVisibleSource(source typ.MCPSourceConfig) bool

func IsServerVisibleVirtualTool added in v0.260514.1

func IsServerVisibleVirtualTool(tool coretool.VirtualTool) bool

func NewAdvisorVirtualTool added in v0.260507.1

func NewAdvisorVirtualTool(cfg typ.AdvisorConfig, cp *client.ClientPool, store *SessionStore) coretool.VirtualTool

func NormalizeToolName

func NormalizeToolName(sourceID, toolName string) string

NormalizeToolName converts source/tool pair to normalized tool name.

func ParseNormalizedToolName

func ParseNormalizedToolName(name string) (string, string, bool)

ParseNormalizedToolName parses normalized name and returns sourceID/toolName.

func Profiles added in v1.261026.0

func Profiles(cfg *typ.MCPRuntimeConfig) []typ.MCPProfile

Profiles returns the saved profiles with Default always first.

func RegisterBuiltinTools

func RegisterBuiltinTools(getConfig func() *typ.MCPRuntimeConfig, setConfig func(toolType string, config interface{}) error) error

RegisterBuiltinTools ensures built-in tools are registered in the MCP configuration. If webtools already exists, it updates the command path to use the current binary's absolute path.

func SourceImplementation added in v0.260514.1

func SourceImplementation(source typ.MCPSourceConfig) typ.ToolImplementation

func SourceProvider added in v0.260514.1

func SourceProvider(source typ.MCPSourceConfig) typ.ToolProvider

func SourceToolDescriptor added in v0.260514.1

func SourceToolDescriptor(source typ.MCPSourceConfig, tool SourceTool) typ.ToolDescriptor

func SourceUsage added in v1.261026.0

func SourceUsage(source typ.MCPSourceConfig) typ.MCPToolUsage

SourceUsage reports where a source's tools may run. Client availability is not a setting: ordinary MCP tools can be offered through a profile, and profiles plus switches decide which. Server Tools are always gateway-only.

func SourceVisibility added in v0.260514.1

func SourceVisibility(source typ.MCPSourceConfig) typ.ToolVisibility

func VirtualToolDescriptor added in v0.260514.1

func VirtualToolDescriptor(sourceID string, tool coretool.VirtualTool) typ.ToolDescriptor

Types

type AdvisorResponse added in v0.260507.1

type AdvisorResponse struct {
	Assessment          string `json:"assessment"`
	Recommendation      string `json:"recommendation"`
	UnsolicitedFindings string `json:"unsolicited_findings,omitempty"`
}

type BaseToolSource

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

BaseToolSource provides common functionality for all tool source implementations.

func NewBaseToolSource

func NewBaseToolSource(sourceID string, transport TransportType) *BaseToolSource

NewBaseToolSource creates a new base tool source.

func (*BaseToolSource) DisableHealthCheck

func (b *BaseToolSource) DisableHealthCheck(ctx context.Context)

DisableHealthCheck provides a default no-op implementation for on-demand connections.

func (*BaseToolSource) EnableHealthCheck

func (b *BaseToolSource) EnableHealthCheck(ctx context.Context, interval time.Duration)

EnableHealthCheck provides a default no-op implementation for on-demand connections.

func (*BaseToolSource) GetConnectionState

func (b *BaseToolSource) GetConnectionState() ConnectionState

GetConnectionState returns the current connection state.

func (*BaseToolSource) GetConnectionStatus

func (b *BaseToolSource) GetConnectionStatus() ConnectionStatus

GetConnectionStatus returns the current connection status.

func (*BaseToolSource) GetSourceID

func (b *BaseToolSource) GetSourceID() string

GetSourceID returns the source ID.

func (*BaseToolSource) GetType

func (b *BaseToolSource) GetType() TransportType

GetType returns the transport type.

func (*BaseToolSource) HealthCheck

func (b *BaseToolSource) HealthCheck(ctx context.Context) error

HealthCheck provides a default no-op health check for on-demand connections.

func (*BaseToolSource) IsRetired added in v1.261026.0

func (b *BaseToolSource) IsRetired() bool

func (*BaseToolSource) Retire added in v1.261026.0

func (b *BaseToolSource) Retire()

Retire prevents an old source reference from reconnecting after replacement.

type CatalogTool added in v1.261026.0

type CatalogTool struct {
	SourceID       string                 `json:"source_id"`
	Name           string                 `json:"name"`
	NormalizedName string                 `json:"normalized_name"`
	Description    string                 `json:"description,omitempty"`
	InputSchema    json.RawMessage        `json:"input_schema,omitempty"`
	OutputSchema   json.RawMessage        `json:"output_schema,omitempty"`
	Annotations    json.RawMessage        `json:"annotations,omitempty"`
	Enabled        bool                   `json:"enabled"`
	Usage          typ.MCPToolUsage       `json:"usage"`
	Implementation typ.ToolImplementation `json:"implementation"`
}

type ConnectionError

type ConnectionError struct {
	Source string
	Reason string
	Err    error
}

ConnectionError represents a connection-related error.

func (*ConnectionError) Error

func (e *ConnectionError) Error() string

type ConnectionState

type ConnectionState string

ConnectionState represents the current state of a tool source connection.

const (
	StateDisconnected ConnectionState = "disconnected"
	StateConnecting   ConnectionState = "connecting"
	StateConnected    ConnectionState = "connected"
	StateError        ConnectionState = "error"
)

type ConnectionStatus

type ConnectionStatus struct {
	State         ConnectionState `json:"state"`
	LastConnected time.Time       `json:"last_connected,omitempty"`
	LastError     error           `json:"last_error,omitempty"`
	RetryCount    int             `json:"retry_count,omitempty"`
}

ConnectionStatus represents the current status of a tool source connection.

type DefaultErrorClassifier

type DefaultErrorClassifier struct{}

DefaultErrorClassifier provides default error classification.

func (*DefaultErrorClassifier) IsPermanent

func (c *DefaultErrorClassifier) IsPermanent(err error) bool

IsPermanent checks if an error is permanent (auth failures, not found, etc.).

func (*DefaultErrorClassifier) IsTransient

func (c *DefaultErrorClassifier) IsTransient(err error) bool

IsTransient checks if an error is transient (temporary network issues, timeouts, etc.).

type EnvRefIssue added in v0.260507.1

type EnvRefIssue struct {
	SourceID  string
	FieldPath string
	VarName   string
}

EnvRefIssue describes a missing environment reference in MCP runtime config.

func ExpandMCPRuntimeEnvRefs added in v0.260507.1

func ExpandMCPRuntimeEnvRefs(cfg *typ.MCPRuntimeConfig) []EnvRefIssue

ExpandMCPRuntimeEnvRefs expands ${VAR} references in all string fields of MCP runtime config. Missing variables are left as-is and returned as issues.

func ValidateEnabledMCPSourceEnvRefs added in v0.260507.1

func ValidateEnabledMCPSourceEnvRefs(sources []typ.MCPSourceConfig) []EnvRefIssue

ValidateEnabledMCPSourceEnvRefs checks ${VAR} references for enabled sources only. Missing variables are returned as issues. In-process transports (e.g. "advisor") are skipped — they never spawn a subprocess and do not consume the env map.

type ErrorClassifier

type ErrorClassifier interface {
	IsTransient(err error) bool
	IsPermanent(err error) bool
}

ErrorClassifier classifies errors as transient or permanent.

type ExponentialBackoffStrategy

type ExponentialBackoffStrategy struct {
	InitialInterval time.Duration
	MaxInterval     time.Duration
	Multiplier      float64
	MaxRetries      int
}

ExponentialBackoffStrategy implements exponential backoff with jitter.

func NewExponentialBackoffStrategy

func NewExponentialBackoffStrategy() *ExponentialBackoffStrategy

NewExponentialBackoffStrategy creates a new exponential backoff strategy.

func (*ExponentialBackoffStrategy) NextRetry

func (s *ExponentialBackoffStrategy) NextRetry(retryCount int) time.Duration

NextRetry returns the duration to wait before the next retry.

func (*ExponentialBackoffStrategy) ShouldRetry

func (s *ExponentialBackoffStrategy) ShouldRetry(retryCount int) bool

ShouldRetry determines if another retry should be attempted.

type HTTPError

type HTTPError struct {
	StatusCode int
	Message    string
}

HTTPError represents an HTTP error with status code.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type HTTPToolSource

type HTTPToolSource struct {
	*BaseToolSource
	// contains filtered or unexported fields
}

HTTPToolSource implements ToolSource for HTTP-based MCP servers. This is a persistent connection type with health monitoring.

func NewHTTPToolSource

func NewHTTPToolSource(sourceConfig typ.MCPSourceConfig, sc *sessionCache) (*HTTPToolSource, error)

NewHTTPToolSource creates a new HTTP tool source.

func (*HTTPToolSource) CallTool

func (s *HTTPToolSource) CallTool(ctx context.Context, toolName string, arguments string) (coretool.ToolResult, error)

CallTool executes a tool from the HTTP MCP server.

func (*HTTPToolSource) Connect

func (s *HTTPToolSource) Connect(ctx context.Context) error

Connect establishes an HTTP connection to the MCP server.

func (*HTTPToolSource) DisableHealthCheck

func (s *HTTPToolSource) DisableHealthCheck(ctx context.Context)

DisableHealthCheck stops health monitoring.

func (*HTTPToolSource) Disconnect

func (s *HTTPToolSource) Disconnect(ctx context.Context) error

Disconnect closes the HTTP connection.

func (*HTTPToolSource) EnableHealthCheck

func (s *HTTPToolSource) EnableHealthCheck(ctx context.Context, interval time.Duration)

EnableHealthCheck starts periodic health monitoring.

func (*HTTPToolSource) GetSourceConfig

func (s *HTTPToolSource) GetSourceConfig() interface{}

GetSourceConfig returns the source configuration.

func (*HTTPToolSource) HealthCheck

func (s *HTTPToolSource) HealthCheck(ctx context.Context) error

HealthCheck verifies the HTTP connection is still active.

func (*HTTPToolSource) IsConfigured added in v0.260514.1

func (s *HTTPToolSource) IsConfigured() bool

IsConfigured returns whether this source has sufficient configuration to connect.

func (*HTTPToolSource) IsConnected

func (s *HTTPToolSource) IsConnected() bool

IsConnected returns whether the HTTP connection is active.

func (*HTTPToolSource) ListTools

func (s *HTTPToolSource) ListTools(ctx context.Context) ([]ToolDefinition, error)

ListTools returns all tools from the HTTP MCP server.

func (*HTTPToolSource) Reconnect

func (s *HTTPToolSource) Reconnect(ctx context.Context) error

Reconnect implements ReconnectableSource interface.

type HealthMonitor

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

HealthMonitor provides health monitoring for persistent connections.

func NewHealthMonitor

func NewHealthMonitor(source ToolSource, errorClassifier ErrorClassifier) *HealthMonitor

NewHealthMonitor creates a new health monitor.

func (*HealthMonitor) Start

func (h *HealthMonitor) Start(ctx context.Context, interval time.Duration)

Start begins health monitoring with the specified interval.

func (*HealthMonitor) Stop

func (h *HealthMonitor) Stop(ctx context.Context)

Stop stops health monitoring.

type InvalidToolNameError

type InvalidToolNameError struct {
	Name string
}

InvalidToolNameError indicates an invalid tool name.

func (*InvalidToolNameError) Error

func (e *InvalidToolNameError) Error() string

type ProfileRoute added in v1.261026.0

type ProfileRoute struct {
	ID       string        `json:"id"`
	Name     string        `json:"name"`
	Endpoint string        `json:"endpoint"`
	Enabled  bool          `json:"enabled"`
	Default  bool          `json:"default"`
	Sources  []RouteSource `json:"sources"`
}

type ReconnectableSource

type ReconnectableSource interface {
	ToolSource
	Reconnect(ctx context.Context) error
}

ReconnectableSource extends ToolSource with reconnection capability.

type RouteAdvisor added in v1.261026.0

type RouteAdvisor struct {
	ProviderUUID string `json:"provider_uuid"`
	ProviderName string `json:"provider_name,omitempty"`
	Model        string `json:"model"`
}

type RouteSource added in v1.261026.0

type RouteSource struct {
	ID         string        `json:"id"`
	Name       string        `json:"name"`
	Origin     string        `json:"origin"`
	Transport  string        `json:"transport"`
	Address    string        `json:"address"`
	State      string        `json:"state"`
	Error      string        `json:"error,omitempty"`
	Processing string        `json:"processing"`
	Advisor    *RouteAdvisor `json:"advisor,omitempty"`
	Tools      []CatalogTool `json:"tools"`
}

RouteSource is a safe display projection, never a connection configuration. Credentials, environment values, URL query strings and command args are omitted.

type RoutingSnapshot added in v1.261026.0

type RoutingSnapshot struct {
	Sources     []RouteSource  `json:"sources"`
	Profiles    []ProfileRoute `json:"profiles"`
	ServerTools []RouteSource  `json:"server_tools"`
}

type Runtime

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

Runtime handles MCP tool source discovery and tool execution.

func NewRuntime

func NewRuntime(getConfig configProvider) *Runtime

NewRuntime creates a new MCP runtime.

func (*Runtime) CallTool

func (r *Runtime) CallTool(ctx context.Context, normalizedName string, arguments string) (coretool.ToolResult, error)

CallTool executes a normalized MCP tool call and returns a structured ToolResult. Dispatches virtual tools first (kernel mode), then remote tools (user mode).

func (*Runtime) Catalog added in v1.261026.0

func (r *Runtime) Catalog(ctx context.Context, usage string) []SourceStatus

Catalog discovers each source independently with bounded concurrency. Errors stay attached to the source; one failed server never turns the catalog empty.

func (*Runtime) CheckToolScope added in v1.261029.0

func (r *Runtime) CheckToolScope(profileID, normalizedName string, args map[string]any) error

CheckToolScope refuses a GitHub call that leaves the profile's repository scope. It runs on the call path, not only when listing tools, so guessed arguments cannot widen access. Other sources and unscoped profiles pass.

func (*Runtime) Close

func (r *Runtime) Close()

Close releases all MCP sessions and tool source connections.

Each stdio source's Disconnect can itself take a few seconds (the underlying SDK closes stdin, waits, then escalates through SIGTERM and SIGKILL before giving up — see the CommandTransport.TerminateDuration set in session.go) and does not honor ctx. Disconnecting sources one at a time under a single 5s budget — the previous behavior — meant that budget was only ever enforced for the first source; every source after it added its own wait on top, so a handful of slow MCP servers turned every `restart`/`stop` into a multi-second-to-multi-minute hang depending on source count. Disconnecting them concurrently keeps the wall-clock cost bounded to the single shared timeout no matter how many sources are configured; any source still hung past the deadline is force-killed directly (see ForceKill) rather than left to finish in a background goroutine that the exiting process would likely outlive.

func (*Runtime) DiscoverSource added in v1.261026.0

func (r *Runtime) DiscoverSource(ctx context.Context, id string) (SourceStatus, error)

func (*Runtime) GetAdvisorMaxUses added in v0.260507.1

func (r *Runtime) GetAdvisorMaxUses() int

GetAdvisorMaxUses returns the MaxUsesPerRequest from the advisor source config. Returns 0 if no advisor is configured or the value is not positive.

func (*Runtime) GetConfig

func (r *Runtime) GetConfig() *typ.MCPRuntimeConfig

GetConfig returns the current MCP runtime configuration.

func (*Runtime) HasBuiltinServerTools added in v1.261026.0

func (r *Runtime) HasBuiltinServerTools() bool

HasBuiltinServerTools reports whether any Tingly Box Server Tool would be offered to a model right now. It lets the request path serve Server Tools without the experimental MCP flag, which only governs connected MCP tools.

func (*Runtime) HasServerTools

func (r *Runtime) HasServerTools() bool

HasServerTools returns true if there are any server tools configured

func (*Runtime) IsBuiltinServerToolAvailable added in v1.261026.1

func (r *Runtime) IsBuiltinServerToolAvailable(sourceID, toolName string) bool

IsBuiltinServerToolAvailable checks policy and per-tool readiness without connecting a stdio process. A missing search key never disables Fetch.

func (*Runtime) IsClientToolAvailable added in v0.260514.1

func (r *Runtime) IsClientToolAvailable(sourceID string, toolName string) bool

IsClientToolAvailable reports whether a client-visible tool on the given source is enabled and configured to handle requests.

The check is two-layered:

  1. Source-level: enabled + IsConfigured() on the ToolSource implementation. Custom MCP servers (stdio/http/sse) use their transport-specific check (command non-empty / endpoint non-empty / env refs resolved).
  2. Tool-level: for builtin sources, a per-tool ToolReadinessChecker may impose additional requirements (e.g. mcp_web_search requires SERPER_API_KEY).

func (*Runtime) IsGatewayToolName added in v1.261026.0

func (r *Runtime) IsGatewayToolName(name string) bool

func (*Runtime) ListBuiltinServerToolsForInjection added in v1.261026.0

func (r *Runtime) ListBuiltinServerToolsForInjection(ctx context.Context) []openai.ChatCompletionToolUnionParam

ListBuiltinServerToolsForInjection returns only Tingly Box's own Server Tools (Advisor, Search and Fetch), which need no user-connected MCP.

func (*Runtime) ListCallableServerToolNames added in v0.260514.1

func (r *Runtime) ListCallableServerToolNames(ctx context.Context) map[string]struct{}

func (*Runtime) ListClientSourceToolsForMCP added in v0.260507.1

func (r *Runtime) ListClientSourceToolsForMCP(ctx context.Context) (map[string][]SourceTool, error)

ListClientSourceToolsForMCP returns source tools that are eligible for MCP client exposure. Rules:

  • source must be enabled
  • source must be client-visible
  • tool must come from non-virtual source (ListSourceTools contract)

func (*Runtime) ListClientVisibleMCPToolNames added in v0.260514.1

func (r *Runtime) ListClientVisibleMCPToolNames(ctx context.Context) map[string]struct{}

func (*Runtime) ListEnabledServerToolNames

func (r *Runtime) ListEnabledServerToolNames(ctx context.Context) map[string]struct{}

ListEnabledServerToolNames returns normalized MCP tool names that are callable by server-side MCP execution paths. This includes:

  • injected server-side virtual tools (via ListServerToolsForInjection)
  • backward-compatible aliases for server-only virtual tools (e.g. advisor source id)

Results are cached with a short TTL to avoid repeated full source enumeration.

func (*Runtime) ListInjectableServerToolNames added in v0.260514.1

func (r *Runtime) ListInjectableServerToolNames(ctx context.Context) map[string]struct{}

func (*Runtime) ListServerToolsForInjection added in v0.260507.1

func (r *Runtime) ListServerToolsForInjection(ctx context.Context) []openai.ChatCompletionToolUnionParam

ListServerToolsForInjection returns MCP tools that should be injected into upstream model requests. Injection includes gateway-only Server Tools and connected MCP tools opted in for gateway usage. The request path gates the latter with the MCP flag.

func (*Runtime) ListSourceTools

func (r *Runtime) ListSourceTools(ctx context.Context) (map[string][]SourceTool, error)

ListSourceTools returns all MCP tools grouped by source with their original names. This is used by local mode to expose tools to external MCP clients.

func (*Runtime) ProfileAllows added in v1.261026.0

func (r *Runtime) ProfileAllows(profileID, normalizedName string) bool

ProfileAllows reports whether a profile exposes a tool: the profile is on, the tool is in it, and the tool is on in it. Global enablement is checked by the caller against the effective tool policy.

func (*Runtime) ProfileExists added in v1.261026.0

func (r *Runtime) ProfileExists(profileID string) bool

func (*Runtime) Reconcile added in v1.261026.0

func (r *Runtime) Reconcile(ctx context.Context)

Reconcile closes removed/changed sources and invalidates tool-name caches. Sources reconnect lazily; a policy-only edit keeps the current connection.

func (*Runtime) ReconnectSource added in v1.261026.0

func (r *Runtime) ReconnectSource(ctx context.Context, id string) (SourceStatus, error)

func (*Runtime) RegisterAdviser added in v0.260507.1

func (r *Runtime) RegisterAdviser(cfg typ.AdvisorConfig, cp *client.ClientPool)

RegisterAdviser registers the adviser as a virtual tool in the runtime.

func (*Runtime) Routing added in v1.261026.0

func (r *Runtime) Routing(ctx context.Context) RoutingSnapshot

Routing derives reachability from the same effective policies used by both the MCP bridge and model tool injection. Ordinary tools and server tools are independent uses; a source can appear in both without becoming two configs.

func (*Runtime) SessionStore added in v0.260514.1

func (r *Runtime) SessionStore() *SessionStore

SessionStore returns the runtime's session store.

func (*Runtime) SetClientPool added in v0.260507.1

func (r *Runtime) SetClientPool(cp *client.ClientPool)

SetClientPool injects the client pool into the runtime's tool source factory.

func (*Runtime) VirtualRegistry added in v0.260507.1

func (r *Runtime) VirtualRegistry() *coretool.VirtualToolRegistry

VirtualRegistry returns the runtime's virtual tool registry, or nil if the runtime is nil.

type SSEToolSource

type SSEToolSource struct {
	*BaseToolSource
	// contains filtered or unexported fields
}

SSEToolSource implements ToolSource for SSE-based MCP servers. This is a persistent connection type with health monitoring.

func NewSSEToolSource

func NewSSEToolSource(sourceConfig typ.MCPSourceConfig, sc *sessionCache) (*SSEToolSource, error)

NewSSEToolSource creates a new SSE tool source.

func (*SSEToolSource) CallTool

func (s *SSEToolSource) CallTool(ctx context.Context, toolName string, arguments string) (coretool.ToolResult, error)

CallTool executes a tool from the SSE MCP server.

func (*SSEToolSource) Connect

func (s *SSEToolSource) Connect(ctx context.Context) error

Connect establishes an SSE connection to the MCP server.

func (*SSEToolSource) DisableHealthCheck

func (s *SSEToolSource) DisableHealthCheck(ctx context.Context)

DisableHealthCheck stops health monitoring.

func (*SSEToolSource) Disconnect

func (s *SSEToolSource) Disconnect(ctx context.Context) error

Disconnect closes the SSE connection.

func (*SSEToolSource) EnableHealthCheck

func (s *SSEToolSource) EnableHealthCheck(ctx context.Context, interval time.Duration)

EnableHealthCheck starts periodic health monitoring.

func (*SSEToolSource) GetSourceConfig

func (s *SSEToolSource) GetSourceConfig() interface{}

GetSourceConfig returns the source configuration.

func (*SSEToolSource) HealthCheck

func (s *SSEToolSource) HealthCheck(ctx context.Context) error

HealthCheck verifies the SSE connection is still active.

func (*SSEToolSource) IsConfigured added in v0.260514.1

func (s *SSEToolSource) IsConfigured() bool

IsConfigured returns whether this source has sufficient configuration to connect.

func (*SSEToolSource) IsConnected

func (s *SSEToolSource) IsConnected() bool

IsConnected returns whether the SSE connection is active.

func (*SSEToolSource) ListTools

func (s *SSEToolSource) ListTools(ctx context.Context) ([]ToolDefinition, error)

ListTools returns all tools from the SSE MCP server.

func (*SSEToolSource) Reconnect

func (s *SSEToolSource) Reconnect(ctx context.Context) error

Reconnect implements ReconnectableSource interface.

type SessionContext added in v0.260507.1

type SessionContext struct {
	SessionID      string
	BuildLogs      []string
	LastWorkerResp string
	CreatedAt      time.Time
}

SessionContext holds session-persistent heavy data.

type SessionStore added in v0.260507.1

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

SessionStore is an in-memory KV with TTL sweeper.

func NewSessionStore added in v0.260507.1

func NewSessionStore(ttl time.Duration) *SessionStore

func (*SessionStore) Destroy added in v0.260507.1

func (s *SessionStore) Destroy(sessionID string)

func (*SessionStore) Get added in v0.260507.1

func (s *SessionStore) Get(sessionID string) (*SessionContext, bool)

func (*SessionStore) Put added in v0.260507.1

func (s *SessionStore) Put(ctx *SessionContext)

func (*SessionStore) StartSweeper added in v0.260507.1

func (s *SessionStore) StartSweeper(interval time.Duration) *time.Ticker

func (*SessionStore) Sweep added in v0.260507.1

func (s *SessionStore) Sweep()

type SourceNotFoundError

type SourceNotFoundError struct {
	ID string
}

SourceNotFoundError indicates that a source was not found.

func (*SourceNotFoundError) Error

func (e *SourceNotFoundError) Error() string

type SourceStatus added in v1.261026.0

type SourceStatus struct {
	SourceID string        `json:"source_id"`
	State    string        `json:"state"`
	Error    string        `json:"error,omitempty"`
	Tools    []CatalogTool `json:"tools"`
}

type SourceTool

type SourceTool struct {
	NormalizedName string
	OutputSchema   json.RawMessage
	Annotations    json.RawMessage
	SourceID       string
	SourceName     string
	Name           string
	Description    string
	InputSchema    json.RawMessage
}

SourceTool represents a tool from a specific MCP source with its original name.

type StdioToolSource

type StdioToolSource struct {
	*BaseToolSource
	// contains filtered or unexported fields
}

StdioToolSource implements ToolSource for stdio-based MCP servers. This is an on-demand connection type - the subprocess is started when needed.

func NewStdioToolSource

func NewStdioToolSource(sourceConfig typ.MCPSourceConfig, sc *sessionCache) (*StdioToolSource, error)

NewStdioToolSource creates a new stdio tool source.

func (*StdioToolSource) CallTool

func (s *StdioToolSource) CallTool(ctx context.Context, toolName string, arguments string) (coretool.ToolResult, error)

CallTool executes a tool from the stdio MCP server.

func (*StdioToolSource) Connect

func (s *StdioToolSource) Connect(ctx context.Context) error

Connect establishes a stdio connection to the MCP server.

func (*StdioToolSource) DisableHealthCheck

func (s *StdioToolSource) DisableHealthCheck(ctx context.Context)

DisableHealthCheck is a no-op for on-demand connections.

func (*StdioToolSource) Disconnect

func (s *StdioToolSource) Disconnect(ctx context.Context) error

Disconnect closes the stdio connection. For stdio, this terminates the subprocess.

func (*StdioToolSource) EnableHealthCheck

func (s *StdioToolSource) EnableHealthCheck(ctx context.Context, interval time.Duration)

EnableHealthCheck is a no-op for on-demand connections.

func (*StdioToolSource) ForceKill added in v0.260924.1

func (s *StdioToolSource) ForceKill()

ForceKill immediately kills the underlying subprocess, bypassing the SDK's own close handshake (stdin-close wait -> SIGTERM -> wait -> SIGKILL). Deliberately lock-free (see killCmd) so it can run concurrently with, and without waiting behind, an in-flight Disconnect: it exists precisely to backstop a Disconnect that hasn't finished within the caller's budget.

func (*StdioToolSource) GetSourceConfig

func (s *StdioToolSource) GetSourceConfig() interface{}

GetSourceConfig returns the source configuration.

func (*StdioToolSource) HealthCheck

func (s *StdioToolSource) HealthCheck(ctx context.Context) error

HealthCheck verifies the stdio connection is still active.

func (*StdioToolSource) IsConfigured added in v0.260514.1

func (s *StdioToolSource) IsConfigured() bool

IsConfigured returns whether this source has sufficient configuration to connect. For stdio, this means the command field is non-empty and all required env vars are resolved.

func (*StdioToolSource) IsConnected

func (s *StdioToolSource) IsConnected() bool

IsConnected returns whether the stdio connection is active.

func (*StdioToolSource) ListTools

func (s *StdioToolSource) ListTools(ctx context.Context) ([]ToolDefinition, error)

ListTools returns all tools from the stdio MCP server.

type ToolDefinition

type ToolDefinition struct {
	Name         string          `json:"name"`
	Description  string          `json:"description,omitempty"`
	InputSchema  json.RawMessage `json:"input_schema,omitempty"`
	OutputSchema json.RawMessage `json:"output_schema,omitempty"`
	Annotations  json.RawMessage `json:"annotations,omitempty"`
}

ToolDefinition represents a tool's metadata and schema.

type ToolExecutionError

type ToolExecutionError struct {
	ToolName string
	Message  string
}

ToolExecutionError represents an error during tool execution.

func (*ToolExecutionError) Error

func (e *ToolExecutionError) Error() string

type ToolSource

type ToolSource interface {
	// Connection management
	Connect(ctx context.Context) error
	Disconnect(ctx context.Context) error
	IsConnected() bool
	IsConfigured() bool
	GetConnectionState() ConnectionState
	GetConnectionStatus() ConnectionStatus

	// Tool operations
	ListTools(ctx context.Context) ([]ToolDefinition, error)
	CallTool(ctx context.Context, toolName string, arguments string) (coretool.ToolResult, error)

	// Health monitoring (for persistent connections)
	HealthCheck(ctx context.Context) error
	EnableHealthCheck(ctx context.Context, interval time.Duration)
	DisableHealthCheck(ctx context.Context)

	// Metadata
	GetType() TransportType
	GetSourceID() string
	GetSourceConfig() interface{} // Returns source-specific config
}

ToolSource is the unified interface for all MCP tool sources. All transport types (stdio, http, sse, builtin) implement this interface.

type ToolSourceFactory

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

ToolSourceFactory creates tool sources based on configuration.

func NewToolSourceFactory

func NewToolSourceFactory(sc *sessionCache, cp *client.ClientPool) *ToolSourceFactory

NewToolSourceFactory creates a new tool source factory.

func (*ToolSourceFactory) CreateToolSource

func (f *ToolSourceFactory) CreateToolSource(sourceConfig typ.MCPSourceConfig) (ToolSource, error)

CreateToolSource creates a tool source based on the transport type.

func (*ToolSourceFactory) SetClientPool added in v0.260507.1

func (f *ToolSourceFactory) SetClientPool(cp *client.ClientPool)

SetClientPool sets the client pool on the factory.

type TransportType

type TransportType string

TransportType represents the type of transport for a tool source.

const (
	TransportStdio TransportType = "stdio"
	TransportHTTP  TransportType = "http"
	TransportSSE   TransportType = "sse"
)

type UnsupportedTransportError

type UnsupportedTransportError struct {
	Transport string
}

UnsupportedTransportError indicates an unsupported transport type.

func (*UnsupportedTransportError) Error

func (e *UnsupportedTransportError) Error() string

Jump to

Keyboard shortcuts

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