manager

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthRTProvider

type AuthRTProvider func(ctx context.Context) *authtransport.RoundTripper

AuthRTProvider returns a per-request auth RoundTripper (e.g., per-user) chosen from context. When provided, it takes precedence over the static authRT set via WithAuthRoundTripper.

type JarProvider

type JarProvider func(ctx context.Context) (http.CookieJar, error)

JarProvider returns a per-request CookieJar (e.g., per-user) chosen from context. When provided, it takes precedence over the static cookieJar set via WithCookieJar.

type Manager

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

Manager caches MCP clients per (userID:conversationID, serverName) and handles idle reaping.

func New

func New(prov Provider, opts ...Option) (*Manager, error)

New creates a Manager with the given Provider and options.

func (*Manager) CloseConversation

func (m *Manager) CloseConversation(convID string)

CloseConversation drops all clients for a conversation (across all users). Note: underlying transports may keep connections if the library doesn't expose Close.

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, convID, serverName string) (mcpclient.Interface, error)

Get returns an MCP client for (user+convID, serverName), creating it if needed. When a UserIDExtractor is configured, the pool key includes the user ID to prevent shared conversations from leaking MCP auth/tokens across users.

func (*Manager) Options

func (m *Manager) Options(ctx context.Context, serverName string) (*mcpcfg.MCPClient, error)

Options exposes the underlying provider client options (authoring metadata, timeouts, etc.) for a given server name.

func (*Manager) Reap

func (m *Manager) Reap()

Reap closes idle clients beyond TTL by dropping references.

func (*Manager) Reconnect

func (m *Manager) Reconnect(ctx context.Context, convID, serverName string) (mcpclient.Interface, error)

Reconnect drops the cached client for (convID, serverName) and creates a new one. It returns the fresh client or an error if recreation fails.

func (*Manager) StartReaper

func (m *Manager) StartReaper(ctx context.Context, interval time.Duration) (stop func())

StartReaper launches a background goroutine that periodically invokes Reap until the provided context is cancelled or the returned stop function is called. If interval is non-positive, ttl/2 is used with a minimum of 1 minute.

func (*Manager) Touch

func (m *Manager) Touch(convID, serverName string)

Touch updates last-used time for (convID, serverName).

func (*Manager) UseIDToken

func (m *Manager) UseIDToken(ctx context.Context, serverName string) bool

UseIDToken reports whether the MCP server config prefers using an ID token when authenticating outbound calls to this server.

func (*Manager) WithAuthTokenContext

func (m *Manager) WithAuthTokenContext(ctx context.Context, serverName string) context.Context

WithAuthTokenContext injects the selected auth token into context under the MCP auth transport key so HTTP transports can emit the appropriate Bearer header. This is a best-effort helper; when no token is available it returns ctx as-is.

type Option

type Option func(*Manager) error

Option configures Manager. It can return an error which will be bubbled up by New.

func WithAuthRoundTripper

func WithAuthRoundTripper(rt *authtransport.RoundTripper) Option

WithAuthRoundTripper enables auth integration by attaching the provided RoundTripper as an Authorizer interceptor to created MCP clients.

func WithAuthRoundTripperProvider

func WithAuthRoundTripperProvider(p AuthRTProvider) Option

WithAuthRoundTripperProvider injects a provider that selects an auth RoundTripper per request.

func WithCookieJar

func WithCookieJar(jar http.CookieJar) Option

WithCookieJar injects a host-controlled CookieJar that will be applied to newly created MCP clients via ClientOptions, overriding any per-provider jar.

func WithCookieJarProvider

func WithCookieJarProvider(p JarProvider) Option

WithCookieJarProvider injects a provider that selects a CookieJar per request (e.g., per user).

func WithHandlerFactory

func WithHandlerFactory(newHandler func() protoclient.Handler) Option

WithHandlerFactory sets a factory for per-connection client handlers (for elicitation, etc.).

func WithTTL

func WithTTL(ttl time.Duration) Option

WithTTL sets idle TTL before reaping a client.

func WithTokenProvider added in v0.1.8

func WithTokenProvider(tp token.Provider) Option

WithTokenProvider injects the shared token lifecycle manager so MCP requests can refresh tokens just before outbound auth is attached.

func WithUserIDExtractor

func WithUserIDExtractor(fn UserIDExtractor) Option

WithUserIDExtractor sets the function used to derive a user-scoped pool key.

type Provider

type Provider interface {
	Options(ctx context.Context, serverName string) (*mcpcfg.MCPClient, error)
}

Provider returns client options for a given MCP server name.

type RepoProvider

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

RepoProvider loads MCP client options from the Agently workspace repo ($AGENTLY_WORKSPACE/mcp).

func NewRepoProvider

func NewRepoProvider(opts ...RepoProviderOption) *RepoProvider

func (*RepoProvider) Options

func (p *RepoProvider) Options(ctx context.Context, name string) (*mcpcfg.MCPClient, error)

type RepoProviderOption

type RepoProviderOption func(*RepoProvider)

RepoProviderOption configures RepoProvider.

func WithRepoStateStore

func WithRepoStateStore(ss workspace.StateStore) RepoProviderOption

WithRepoStateStore injects a StateStore for resolving state directories.

type UserIDExtractor

type UserIDExtractor func(ctx context.Context) string

UserIDExtractor returns a user identifier from context for pool isolation. When set, the pool key becomes "userID:convID" instead of just "convID" to prevent shared conversations from leaking MCP auth across users.

Jump to

Keyboard shortcuts

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