mcp

package
v0.0.0-...-35c3f38 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(ctx context.Context, configs []config.MCPServerConfig, logger core.Logger) ([]core.Action, error)

Load is a convenience function for backward compatibility or bulk loading. Deprecated: Use NewLoader(cfg).WithLogger(logger).Load(ctx) instead for better error handling.

func LoadWithFactory

func LoadWithFactory(ctx context.Context, configs []config.MCPServerConfig, factory ClientFactory, logger core.Logger) ([]core.Action, error)

LoadWithFactory allows injection of a custom ClientFactory for testing. Deprecated: Use NewLoader(cfg).WithFactory(f).Load(ctx) instead.

Types

type Client

type Client interface {
	GetActiveTools(ctx context.Context, g *genkit.Genkit) ([]ai.Tool, error)
}

Client defines the interface for an MCP client wrapper. This allows us to mock the client in tests.

type ClientFactory

type ClientFactory interface {
	CreateClient(ctx context.Context, cfg config.MCPServerConfig) (Client, error)
}

ClientFactory is an interface for creating MCP clients.

type DefaultFactory

type DefaultFactory struct{}

DefaultFactory implements ClientFactory using the real Genkit MCP plugin.

func (*DefaultFactory) CreateClient

func (f *DefaultFactory) CreateClient(ctx context.Context, cfg config.MCPServerConfig) (Client, error)

CreateClient creates a new GenkitMCPClient.

type Loader

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

Loader handles the initialization of an MCP server.

func NewLoader

func NewLoader(cfg config.MCPServerConfig) *Loader

NewLoader creates a new Loader for the given configuration.

func (*Loader) Load

func (l *Loader) Load(ctx context.Context) ([]core.Action, error)

Load connects to the MCP server and returns the discovered actions. It implements the Driver Resilience (Health Check) pattern. If FailOnStartup is true, it returns connection errors. If FailOnStartup is false (default), it logs a warning and returns "Unhealthy" actions for expected tools defined in the config.

func (*Loader) WithFactory

func (l *Loader) WithFactory(f ClientFactory) *Loader

WithFactory allows overriding the default ClientFactory (useful for testing).

func (*Loader) WithLogger

func (l *Loader) WithLogger(logger core.Logger) *Loader

WithLogger allows injecting a logger.

type MCPAction

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

MCPAction wraps a Genkit AI Tool discovered from an MCP server.

func NewAction

func NewAction(serverName string, tool ai.Tool, name string, initError error) *MCPAction

NewAction creates a new MCPAction. If tool is nil (e.g. startup failure), name must be provided.

func (*MCPAction) Execute

func (a *MCPAction) Execute(ctx context.Context, input core.Envelope) (core.Envelope, error)

Execute invokes the underlying MCP tool via Genkit.

func (*MCPAction) Metadata

func (a *MCPAction) Metadata() core.ActionMetadata

Metadata returns the action metadata.