mcp

package
v2026.909.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TransportStdio          = "stdio"
	TransportSSE            = "sse"
	TransportStreamableHTTP = "streamable-http"
)

Variables

View Source
var ErrManagerClosed = errors.New("MCP manager closed")

ErrManagerClosed indicates that the MCP manager has already been shut down.

View Source
var ErrServerUnavailable = errors.New("MCP server unavailable")

ErrServerUnavailable indicates that a server could not be connected or reconnected. The original cause is wrapped for diagnostics.

View Source
var ErrToolCallOutcomeUnknown = errors.New("MCP tool call outcome unknown")

ErrToolCallOutcomeUnknown indicates that an MCP tool call may have reached the remote server, but its response was lost. Such calls must not be replayed automatically unless the host explicitly opts into that policy.

Functions

func ConfiguredServerCount

func ConfiguredServerCount() (int, error)

func ExposedToolName

func ExposedToolName(serverName, toolName string) string

func UniqueToolName

func UniqueToolName(base string, used map[string]bool) string

Types

type CatalogEntry added in v2026.617.0

type CatalogEntry struct {
	Name        string         `json:"name"`
	Server      string         `json:"server"`
	Tool        string         `json:"tool"`
	Description string         `json:"description"`
	Schema      map[string]any `json:"schema,omitempty"`
}

type Config

type Config struct {
	Servers []ServerConfig
	Path    string
}

func LoadConfig

func LoadConfig() (*Config, error)

func ParseConfig

func ParseConfig(raw []byte) (*Config, error)

type InternalAdapterInfo added in v2026.909.0

type InternalAdapterInfo struct {
	ServerName string
	Adapter    string
}

InternalAdapterInfo is the non-sensitive part of an internal MCP server configuration needed by a host adapter factory.

type Manager

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

func NewManager

func NewManager(ctx context.Context, cfg *Config, stderr io.Writer) *Manager

func NewManagerWithOptions added in v2026.909.0

func NewManagerWithOptions(ctx context.Context, cfg *Config, stderr io.Writer, options *ManagerOptions) *Manager

func NewManagerWithRemoteTools

func NewManagerWithRemoteTools(tools []RemoteTool) *Manager

func Start

func Start(ctx context.Context, stderr io.Writer) (*Manager, error)

func StartLazy

func StartLazy(stderr io.Writer) (*Manager, error)

func StartLazyWithOptions added in v2026.909.0

func StartLazyWithOptions(stderr io.Writer, options *ManagerOptions) (*Manager, error)

func StartWithOptions added in v2026.909.0

func StartWithOptions(ctx context.Context, stderr io.Writer, options *ManagerOptions) (*Manager, error)

func (*Manager) AddRoots added in v2026.909.0

func (m *Manager) AddRoots(roots ...*sdkmcp.Root)

func (*Manager) CallInternalTool added in v2026.909.0

func (m *Manager) CallInternalTool(ctx context.Context, serverName, toolName, intent string, args map[string]any) (any, error)

CallInternalTool invokes a host-managed MCP tool by its stable server and remote tool names. Internal adapter calls deliberately bypass the model-facing MCP catalog, but still use the Manager's session lifecycle, retry policy, and logging.

func (*Manager) CallTool

func (m *Manager) CallTool(ctx context.Context, name string, raw json.RawMessage) (any, error)

func (*Manager) Catalog added in v2026.617.0

func (m *Manager) Catalog() []CatalogEntry

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) Complete added in v2026.909.0

func (m *Manager) Complete(ctx context.Context, serverName string, params *sdkmcp.CompleteParams) (*sdkmcp.CompleteResult, error)

Complete asks one MCP server for argument completions.

func (*Manager) Connect

func (m *Manager) Connect(ctx context.Context) (servers int, tools int, err error)

func (*Manager) GetPrompt added in v2026.909.0

func (m *Manager) GetPrompt(ctx context.Context, serverName, name string, arguments map[string]string) (*sdkmcp.GetPromptResult, error)

GetPrompt gets a rendered prompt from one connected MCP server.

func (*Manager) HasTool

func (m *Manager) HasTool(name string) bool

func (*Manager) InternalAdapters added in v2026.909.0

func (m *Manager) InternalAdapters() []InternalAdapterInfo

InternalAdapters returns configured host-managed adapters, including ones that are not currently connected. The latter still need to be represented so the router can report a backend failure and try its fallback.

func (*Manager) IsReady

func (m *Manager) IsReady() bool

func (*Manager) ListPrompts added in v2026.909.0

func (m *Manager) ListPrompts(ctx context.Context, serverName string) ([]*sdkmcp.Prompt, error)

ListPrompts refreshes and returns prompts for one connected server.

func (*Manager) ListResourceTemplates added in v2026.909.0

func (m *Manager) ListResourceTemplates(ctx context.Context, serverName string) ([]*sdkmcp.ResourceTemplate, error)

ListResourceTemplates refreshes and returns resource URI templates for one connected server.

func (*Manager) ListResources added in v2026.909.0

func (m *Manager) ListResources(ctx context.Context, serverName string) ([]*sdkmcp.Resource, error)

ListResources refreshes and returns resources for one connected server.

func (*Manager) OpenAITools

func (m *Manager) OpenAITools() []openai.ChatCompletionToolUnionParam

func (*Manager) Ping added in v2026.909.0

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

Ping checks the connection to one MCP server.

func (*Manager) Prompts added in v2026.909.0

func (m *Manager) Prompts() []RemotePrompt

Prompts returns a snapshot of all prompts currently advertised by connected servers.

func (*Manager) ReadResource added in v2026.909.0

func (m *Manager) ReadResource(ctx context.Context, serverName, uri string) (*sdkmcp.ReadResourceResult, error)

ReadResource reads a resource from one connected MCP server.

func (*Manager) RemoveRoots added in v2026.909.0

func (m *Manager) RemoveRoots(uris ...string)

func (*Manager) ResourceTemplates added in v2026.909.0

func (m *Manager) ResourceTemplates() []RemoteResourceTemplate

ResourceTemplates returns a snapshot of all resource templates currently advertised by connected servers.

func (*Manager) Resources added in v2026.909.0

func (m *Manager) Resources() []RemoteResource

Resources returns a snapshot of all resources currently advertised by connected servers.

func (*Manager) Servers added in v2026.909.0

func (m *Manager) Servers() []ServerInfo

func (*Manager) SetLoggingLevel added in v2026.909.0

func (m *Manager) SetLoggingLevel(ctx context.Context, serverName string, level sdkmcp.LoggingLevel) error

SetLoggingLevel requests a minimum log level from one MCP server. Logging is deprecated by MCP July but remains part of the compatibility surface.

func (*Manager) Subscribe added in v2026.909.0

func (m *Manager) Subscribe(ctx context.Context, serverName, uri string) error

Subscribe subscribes to updates for a resource. For MCP July servers the SDK maps this to subscriptions/listen; for legacy servers it uses the resources/subscribe request.

func (*Manager) ToolDump

func (m *Manager) ToolDump() string

func (*Manager) Tools added in v2026.909.0

func (m *Manager) Tools() []RemoteTool

Tools returns a snapshot of the complete MCP tool descriptors currently advertised by connected servers. The OpenAI projection is available through OpenAITools; this view retains MCP-specific metadata and output schemas.

func (*Manager) Unsubscribe added in v2026.909.0

func (m *Manager) Unsubscribe(ctx context.Context, serverName, uri string) error

Unsubscribe stops a resource subscription.

func (*Manager) WaitReady

func (m *Manager) WaitReady(ctx context.Context) error

type ManagerOptions added in v2026.909.0

type ManagerOptions struct {
	ClientOptions sdkmcp.ClientOptions

	// Roots are advertised to MCP servers that request roots/list. They can be
	// changed later with AddRoots and RemoveRoots.
	Roots []*sdkmcp.Root

	// OAuthHandler creates the OAuth handler for a configured HTTP server. The
	// factory is intentionally injectable: interactive authorization and token
	// persistence belong to the host application, not to mcp.json.
	OAuthHandler func(context.Context, ServerConfig) (auth.OAuthHandler, error)

	// AuthorizationCodeFetcher starts an interactive OAuth authorization-code
	// flow when a server config declares OAuth but no custom OAuthHandler
	// factory is supplied.
	AuthorizationCodeFetcher auth.AuthorizationCodeFetcher
	OAuthHTTPClient          *http.Client

	// DisableCatalogSubscriptions disables the modern subscriptions/listen
	// stream used only for catalog-change notifications. Catalogs are still
	// refreshed after reconnect and explicit list operations; this is useful
	// for stateless/internal adapters that only need request-response calls.
	DisableCatalogSubscriptions bool

	// RetryToolCall may explicitly authorize replaying a tool call after a
	// connection failure. By default the manager only retries calls rejected
	// with ErrSessionMissing, because MCP tool annotations are advisory and a
	// lost response can otherwise duplicate side effects.
	RetryToolCall func(serverName, toolName string, definition *sdkmcp.Tool, cause error) bool
}

ManagerOptions configures the MCP host capabilities exposed by Solomon.

ClientOptions is passed to every MCP client. It can provide handlers for elicitation, sampling, progress, logging, list changes, and resource updates. The manager wraps the list-change handlers so its own catalogs are refreshed asynchronously without blocking the SDK's notification reader.

type OAuthConfig added in v2026.909.0

type OAuthConfig struct {
	ClientID            string   `json:"clientId,omitempty"`
	ClientSecret        string   `json:"clientSecret,omitempty"`
	ClientIDMetadataURL string   `json:"clientIdMetadataUrl,omitempty"`
	RedirectURL         string   `json:"redirectUrl,omitempty"`
	RedirectURIs        []string `json:"redirectUris,omitempty"`
	ClientName          string   `json:"clientName,omitempty"`
	ClientURI           string   `json:"clientUri,omitempty"`
	Scope               string   `json:"scope,omitempty"`
	RequestRefresh      bool     `json:"requestRefreshToken,omitempty"`
}

OAuthConfig configures the MCP OAuth client registration. Interactive authorization and token persistence are deliberately supplied by the host through ManagerOptions; secrets should normally be expanded from the environment in mcp.json rather than committed to a build.

type RemotePrompt added in v2026.909.0

type RemotePrompt struct {
	ServerName string
	Definition *sdkmcp.Prompt
}

RemotePrompt is a prompt advertised by a connected MCP server.

type RemoteResource added in v2026.909.0

type RemoteResource struct {
	ServerName string
	Definition *sdkmcp.Resource
}

RemoteResource is a resource advertised by a connected MCP server.

type RemoteResourceTemplate added in v2026.909.0

type RemoteResourceTemplate struct {
	ServerName string
	Definition *sdkmcp.ResourceTemplate
}

RemoteResourceTemplate is a resource URI template advertised by a connected MCP server.

type RemoteTool

type RemoteTool struct {
	OpenAIName  string
	ServerName  string
	ToolName    string
	Description string
	Schema      map[string]any
	// Definition retains the complete MCP tool descriptor, including title,
	// icons, annotations, and outputSchema that are not representable in an
	// OpenAI function definition.
	Definition *sdkmcp.Tool
}

func AdaptTool

func AdaptTool(serverName string, tool *sdkmcp.Tool) (RemoteTool, error)

type ServerConfig

type ServerConfig struct {
	Name      string            `json:"-"`
	Type      string            `json:"type"`
	Internal  bool              `json:"internal"`
	Adapter   string            `json:"adapter"`
	Command   string            `json:"command"`
	Args      []string          `json:"args"`
	Env       map[string]string `json:"env"`
	CWD       string            `json:"cwd"`
	URL       string            `json:"url"`
	Headers   map[string]string `json:"headers"`
	OAuth     *OAuthConfig      `json:"oauth,omitempty"`
	Timeout   int               `json:"timeout"`
	Allow     []string          `json:"allow"`
	Deny      []string          `json:"deny"`
	Fallback  bool              `json:"-"`
	SortIndex int               `json:"-"`
}

func (ServerConfig) NeedsInternet added in v2026.609.3

func (sc ServerConfig) NeedsInternet() bool

func (ServerConfig) ToolAllowed

func (sc ServerConfig) ToolAllowed(name string) bool

type ServerInfo added in v2026.909.0

type ServerInfo struct {
	Name            string
	Type            string
	URL             string
	ProtocolVersion string
	Implementation  *sdkmcp.Implementation
	Capabilities    *sdkmcp.ServerCapabilities
	Instructions    string
}

ServerInfo is a snapshot of a connected MCP server's negotiated session.

Jump to

Keyboard shortcuts

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