mcp

package
v0.16.7 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PluginName = "mcp"
	PluginID   = "tool/mcp"

	TransportStdio          = "stdio"
	TransportSSE            = "sse"
	TransportStreamableHTTP = "streamable_http"
	TransportHTTP           = "http"

	DefaultTimeoutSeconds = 30
)
View Source
const (
	RuntimeName = "manager"
)

Variables

This section is empty.

Functions

func BaseToolID

func BaseToolID(serverName, toolName string) string

func LookupRuntime

func LookupRuntime(lookup pkgplugins.RuntimeLookup) (runtimeAccessor, bool)

func SanitizeName

func SanitizeName(name string) string

func SetDefaultManager

func SetDefaultManager(manager *Manager)

Types

type CanonicalRegistry

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

CanonicalRegistry maintains a stable mapping from canonical Anna MCP tool IDs to the original MCP server/tool names.

func NewCanonicalRegistry

func NewCanonicalRegistry() *CanonicalRegistry

func (*CanonicalRegistry) Add

func (r *CanonicalRegistry) Add(serverName, toolName string) string

func (*CanonicalRegistry) Reset

func (r *CanonicalRegistry) Reset()

func (*CanonicalRegistry) Resolve

func (r *CanonicalRegistry) Resolve(id string) (Target, bool)

func (*CanonicalRegistry) Snapshot

func (r *CanonicalRegistry) Snapshot() map[string]Target

type Config

type Config struct {
	Servers []ServerConfig `json:"servers"`
}

Config is the persisted MCP plugin config.

func DecodeConfig

func DecodeConfig(raw map[string]any) (Config, error)

func (Config) EnabledServers

func (c Config) EnabledServers() []ServerConfig

func (Config) HasEnabledServers

func (c Config) HasEnabledServers() bool

func (Config) Validate

func (c Config) Validate() error

type DialFunc

type DialFunc func(ctx context.Context, server ServerConfig, runtime sandbox.Session) (Session, error)

DialFunc establishes one MCP client session for the provided server config.

type ErrRuntimeRequired added in v0.10.0

type ErrRuntimeRequired struct {
	Transport string
}

func (ErrRuntimeRequired) Error added in v0.10.0

func (e ErrRuntimeRequired) Error() string

type ErrUnsupportedTransport

type ErrUnsupportedTransport struct {
	Transport string
}

func (ErrUnsupportedTransport) Error

func (e ErrUnsupportedTransport) Error() string

type ExecResult

type ExecResult struct {
	OK         bool           `json:"ok"`
	ID         string         `json:"id"`
	ServerName string         `json:"server_name"`
	ToolName   string         `json:"tool_name"`
	Content    any            `json:"content,omitempty"`
	Structured map[string]any `json:"structured,omitempty"`
	IsError    bool           `json:"is_error"`
	Meta       map[string]any `json:"meta,omitempty"`
}

ExecResult is the normalized result shape returned by the mcp tool.

type Manager

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

Manager is the shared process-wide runtime for MCP state.

func DefaultManager

func DefaultManager() *Manager

func NewManager

func NewManager() *Manager

func (*Manager) AddTool

func (m *Manager) AddTool(serverName, toolName, displayName, description string, inputSchema, outputSchema, annotations map[string]any) ToolInfo

func (*Manager) Config

func (m *Manager) Config() Config

func (*Manager) Configure

func (m *Manager) Configure(cfg Config, enabled bool)

func (*Manager) Enabled

func (m *Manager) Enabled() bool

func (*Manager) Exec

func (m *Manager) Exec(ctx context.Context, id string, args map[string]any) (ExecResult, error)

func (*Manager) GetTool

func (m *Manager) GetTool(id string) (ToolInfo, bool)

func (*Manager) ListTools

func (m *Manager) ListTools() []ToolInfo

func (*Manager) Reconcile

func (m *Manager) Reconcile(parent context.Context, cfg Config, enabled bool)

func (*Manager) Resolve

func (m *Manager) Resolve(id string) (Target, bool)

func (*Manager) SetDial

func (m *Manager) SetDial(dial DialFunc)

func (*Manager) SetRuntime added in v0.10.0

func (m *Manager) SetRuntime(runtime sandbox.Session)

func (*Manager) SetSupervisorConfig

func (m *Manager) SetSupervisorConfig(cfg SupervisorConfig)

func (*Manager) Statuses

func (m *Manager) Statuses() []ServerStatus

func (*Manager) ValidTools

func (m *Manager) ValidTools() []ToolInfo

type ServerConfig

type ServerConfig struct {
	Name           string            `json:"name"`
	Enabled        bool              `json:"enabled"`
	Transport      string            `json:"transport"`
	Command        string            `json:"command"`
	Args           []string          `json:"args"`
	Env            map[string]string `json:"env"`
	URL            string            `json:"url"`
	Headers        map[string]string `json:"headers"`
	TimeoutSeconds int               `json:"timeout_seconds"`
}

ServerConfig describes one managed MCP server.

func (ServerConfig) Validate

func (s ServerConfig) Validate() error

func (ServerConfig) WithDefaults

func (s ServerConfig) WithDefaults() ServerConfig

type ServerStatus

type ServerStatus struct {
	Name                string    `json:"name"`
	Transport           string    `json:"transport"`
	State               string    `json:"state"`
	Failures            int       `json:"failures"`
	Suppressed          bool      `json:"suppressed"`
	LastError           string    `json:"last_error,omitempty"`
	LastConnectedAt     time.Time `json:"last_connected_at"`
	LastDiscoveredAt    time.Time `json:"last_discovered_at"`
	DiscoveredToolCount int       `json:"discovered_tool_count"`
}

ServerStatus describes the current runtime state of one managed MCP server.

type Session

type Session interface {
	Close() error
	Wait() error
	ListTools(ctx context.Context, params *officialmcp.ListToolsParams) (*officialmcp.ListToolsResult, error)
	CallTool(ctx context.Context, params *officialmcp.CallToolParams) (*officialmcp.CallToolResult, error)
}

Session is the subset of MCP client session behavior used by Anna's runtime.

type SupervisorConfig

type SupervisorConfig struct {
	FailureThreshold int
	BackoffBase      time.Duration
	BackoffMax       time.Duration
}

type Target

type Target struct {
	ServerName string
	ToolName   string
}

Target identifies one original MCP tool on one MCP server.

func ParseToolID

func ParseToolID(id string) (Target, error)

type Tool

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

func New

func New(manager *Manager) *Tool

func (*Tool) Definition

func (t *Tool) Definition() tools.Definition

func (*Tool) Execute

func (t *Tool) Execute(ctx context.Context, args map[string]any) (string, error)

type ToolInfo

type ToolInfo struct {
	ID           string         `json:"id"`
	ServerName   string         `json:"server_name"`
	ToolName     string         `json:"tool_name"`
	Name         string         `json:"name"`
	Description  string         `json:"description"`
	InputSchema  map[string]any `json:"input_schema,omitempty"`
	OutputSchema map[string]any `json:"output_schema,omitempty"`
	Annotations  map[string]any `json:"annotations,omitempty"`
	Valid        bool           `json:"valid"`
}

ToolInfo is Anna's cached normalized view of one MCP tool.

Jump to

Keyboard shortcuts

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