Documentation
¶
Index ¶
- func CacheTools(serverName string, tools []ToolSpec)
- func DefaultConfigPath() (string, error)
- func GetBundledServersByCategory() map[string][]BundledServer
- func GetMCPToolSpecs(manager *Manager) []llm.ToolSpec
- func RegisterMCPTools(manager *Manager, registry *llm.ToolRegistry)
- type ArgumentInfo
- type BundledServer
- type Client
- func (c *Client) CallTool(ctx context.Context, name string, args json.RawMessage) (string, error)
- func (c *Client) IsRunning() bool
- func (c *Client) Name() string
- func (c *Client) SetSamplingHandler(handler *SamplingHandler)
- func (c *Client) Start(ctx context.Context) error
- func (c *Client) Stop() error
- func (c *Client) Tools() []ToolSpec
- type Config
- type MCPTool
- type Manager
- func (m *Manager) AllTools() []ToolSpec
- func (m *Manager) AvailableServers() []string
- func (m *Manager) CallTool(ctx context.Context, fullName string, args json.RawMessage) (string, error)
- func (m *Manager) Config() *Config
- func (m *Manager) Disable(name string) error
- func (m *Manager) Enable(ctx context.Context, name string) error
- func (m *Manager) EnabledServers() []string
- func (m *Manager) GetAllStates() []ServerState
- func (m *Manager) GetSamplingHandler() *SamplingHandler
- func (m *Manager) LoadConfig() error
- func (m *Manager) Restart(ctx context.Context, name string) error
- func (m *Manager) ServerStatus(name string) (ServerStatus, error)
- func (m *Manager) SetSamplingProvider(provider llm.Provider, model string, yoloMode bool)
- func (m *Manager) SetStatusChannel(ch chan StatusUpdate)
- func (m *Manager) StopAll()
- type OfficialMeta
- type PackageInfo
- type RegistryClient
- type RegistryMeta
- type RegistryServer
- type RegistryServerWrapper
- type RepositoryInfo
- type SamplingApprovalChoice
- type SamplingConfig
- type SamplingHandler
- type SearchMetadata
- type SearchOptions
- type SearchResult
- type ServerConfig
- type ServerState
- type ServerStatus
- type StatusUpdate
- type ToolSpec
- type TransportInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CacheTools ¶ added in v0.0.64
CacheTools writes the tool list for a server to the cache file.
func DefaultConfigPath ¶
DefaultConfigPath returns the default path for mcp.json.
func GetBundledServersByCategory ¶
func GetBundledServersByCategory() map[string][]BundledServer
GetBundledServersByCategory returns servers grouped by category.
func GetMCPToolSpecs ¶
GetMCPToolSpecs returns LLM tool specs for all running MCP tools.
func RegisterMCPTools ¶
func RegisterMCPTools(manager *Manager, registry *llm.ToolRegistry)
RegisterMCPTools registers all MCP tools from the manager into the tool registry.
Types ¶
type ArgumentInfo ¶
type ArgumentInfo struct {
Name string `json:"name"`
Description string `json:"description"`
Type string `json:"type"` // positional, named
Format string `json:"format"` // string, number
IsRequired bool `json:"isRequired"`
Default string `json:"default,omitempty"`
}
ArgumentInfo describes a command-line argument.
type BundledServer ¶
type BundledServer struct {
Name string
Description string
Package string // npm package name
PackageType string // "npm" or "pypi"
Category string
Official bool // true if official/reference implementation
URL string // repository or homepage URL
}
BundledServer represents a curated MCP server included in the binary. These are popular servers that may not always appear in registry searches.
func GetBundledServers ¶
func GetBundledServers() []BundledServer
GetBundledServers returns all bundled servers.
func (*BundledServer) ToRegistryServer ¶
func (b *BundledServer) ToRegistryServer() RegistryServer
ToRegistryServer converts a BundledServer to a RegistryServer for UI consistency.
func (*BundledServer) ToServerConfig ¶
func (b *BundledServer) ToServerConfig() ServerConfig
ToServerConfig converts a BundledServer to a local ServerConfig.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps an MCP server connection.
func NewClient ¶
func NewClient(name string, config ServerConfig) *Client
NewClient creates a new MCP client for the given server configuration.
func (*Client) SetSamplingHandler ¶ added in v0.0.39
func (c *Client) SetSamplingHandler(handler *SamplingHandler)
SetSamplingHandler sets the sampling handler for this client.
type Config ¶
type Config struct {
Servers map[string]ServerConfig `json:"servers"`
}
Config represents the mcp.json configuration file.
func LoadConfig ¶
LoadConfig loads the MCP configuration from the default path.
func LoadConfigFromPath ¶
LoadConfigFromPath loads the MCP configuration from a specific path.
func (*Config) AddServer ¶
func (c *Config) AddServer(name string, cfg ServerConfig)
AddServer adds or updates a server configuration.
func (*Config) RemoveServer ¶
RemoveServer removes a server configuration.
func (*Config) SaveToPath ¶
SaveToPath saves the configuration to a specific path.
func (*Config) ServerNames ¶
ServerNames returns a sorted list of configured server names.
type MCPTool ¶
type MCPTool struct {
// contains filtered or unexported fields
}
MCPTool wraps an MCP server tool as an llm.Tool.
func NewMCPTool ¶
NewMCPTool creates a new MCP tool wrapper.
func (*MCPTool) Execute ¶
func (t *MCPTool) Execute(ctx context.Context, args json.RawMessage) (llm.ToolOutput, error)
Execute invokes the tool on the MCP server.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles MCP server lifecycle and provides tools to LLM.
func (*Manager) AllTools ¶
AllTools returns all tools from all running MCP servers. Tool names are prefixed with server name to avoid collisions.
func (*Manager) AvailableServers ¶
AvailableServers returns the names of all configured servers.
func (*Manager) CallTool ¶
func (m *Manager) CallTool(ctx context.Context, fullName string, args json.RawMessage) (string, error)
CallTool routes a tool call to the appropriate MCP server. Tool names should be prefixed with "servername__".
func (*Manager) EnabledServers ¶
EnabledServers returns the names of currently enabled (running or starting) servers.
func (*Manager) GetAllStates ¶
func (m *Manager) GetAllStates() []ServerState
GetAllStates returns the current state of all servers (for UI display).
func (*Manager) GetSamplingHandler ¶ added in v0.0.39
func (m *Manager) GetSamplingHandler() *SamplingHandler
GetSamplingHandler returns the current sampling handler.
func (*Manager) LoadConfig ¶
LoadConfig loads the MCP configuration.
func (*Manager) ServerStatus ¶
func (m *Manager) ServerStatus(name string) (ServerStatus, error)
ServerStatus returns the current status of a server.
func (*Manager) SetSamplingProvider ¶ added in v0.0.39
SetSamplingProvider configures the provider and model for MCP sampling requests. If yoloMode is true, sampling requests are auto-approved without prompting.
func (*Manager) SetStatusChannel ¶
func (m *Manager) SetStatusChannel(ch chan StatusUpdate)
SetStatusChannel sets a channel to receive status updates.
type OfficialMeta ¶
type OfficialMeta struct {
Status string `json:"status"` // active, deleted
PublishedAt string `json:"publishedAt"`
UpdatedAt string `json:"updatedAt"`
IsLatest bool `json:"isLatest"`
}
OfficialMeta contains official registry metadata.
type PackageInfo ¶
type PackageInfo struct {
RegistryType string `json:"registryType"` // npm, pypi, oci
RegistryBaseURL string `json:"registryBaseUrl,omitempty"`
Identifier string `json:"identifier"`
Version string `json:"version"`
Transport *TransportInfo `json:"transport,omitempty"`
Arguments []ArgumentInfo `json:"packageArguments,omitempty"`
RuntimeArgs []ArgumentInfo `json:"runtimeArguments,omitempty"`
}
PackageInfo describes how to install/run a server.
type RegistryClient ¶
type RegistryClient struct {
// contains filtered or unexported fields
}
RegistryClient queries the official MCP registry.
func NewRegistryClient ¶
func NewRegistryClient() *RegistryClient
NewRegistryClient creates a new registry client.
func (*RegistryClient) GetServer ¶
func (r *RegistryClient) GetServer(ctx context.Context, name string) (*RegistryServer, error)
GetServer fetches a specific server by name.
func (*RegistryClient) Search ¶
func (r *RegistryClient) Search(ctx context.Context, opts SearchOptions) (*SearchResult, error)
Search queries the registry for MCP servers.
type RegistryMeta ¶
type RegistryMeta struct {
Official *OfficialMeta `json:"io.modelcontextprotocol.registry/official,omitempty"`
}
RegistryMeta contains registry-specific metadata.
type RegistryServer ¶
type RegistryServer struct {
Name string `json:"name"`
Description string `json:"description"`
Version string `json:"version"`
Repository *RepositoryInfo `json:"repository,omitempty"`
Packages []PackageInfo `json:"packages,omitempty"`
Meta *RegistryMeta `json:"_meta,omitempty"`
}
RegistryServer represents a server from the registry.
func (*RegistryServer) DisplayName ¶
func (s *RegistryServer) DisplayName() string
DisplayName returns a user-friendly display name for the server.
func (*RegistryServer) ToServerConfig ¶
func (s *RegistryServer) ToServerConfig() (ServerConfig, bool)
ToServerConfig converts a registry server to a local configuration. Returns the config and a flag indicating if user input is needed.
type RegistryServerWrapper ¶
type RegistryServerWrapper struct {
Server RegistryServer `json:"server"`
Meta *RegistryMeta `json:"_meta,omitempty"`
}
RegistryServerWrapper wraps server with metadata.
func GetBundledAsRegistryWrappers ¶
func GetBundledAsRegistryWrappers() []RegistryServerWrapper
GetBundledAsRegistryWrappers returns bundled servers as RegistryServerWrappers for UI.
type RepositoryInfo ¶
type RepositoryInfo struct {
URL string `json:"url"`
Source string `json:"source"`
Subfolder string `json:"subfolder,omitempty"`
}
RepositoryInfo contains source repository information.
type SamplingApprovalChoice ¶ added in v0.0.39
type SamplingApprovalChoice int
SamplingApprovalChoice represents a user's approval selection for sampling.
const ( SamplingChoiceDeny SamplingApprovalChoice = iota // Deny the request SamplingChoiceAllow // Allow for this session SamplingChoiceCancelled // User cancelled )
type SamplingConfig ¶ added in v0.0.39
type SamplingConfig struct {
// Enabled controls whether sampling is allowed for this server (default: true)
Enabled *bool `json:"enabled,omitempty"`
// AutoApprove skips the approval prompt for this server
AutoApprove bool `json:"auto_approve,omitempty"`
// Provider overrides the provider used for sampling (e.g., "zen", "anthropic")
Provider string `json:"provider,omitempty"`
// Model overrides the model used for sampling
Model string `json:"model,omitempty"`
// MaxTokens limits the maximum tokens per sampling request
MaxTokens int `json:"max_tokens,omitempty"`
}
SamplingConfig configures MCP sampling behavior for a server.
func (*SamplingConfig) IsSamplingEnabled ¶ added in v0.0.39
func (c *SamplingConfig) IsSamplingEnabled() bool
IsSamplingEnabled returns whether sampling is enabled for this server.
type SamplingHandler ¶ added in v0.0.39
type SamplingHandler struct {
// contains filtered or unexported fields
}
SamplingHandler handles sampling/createMessage requests from MCP servers.
func NewSamplingHandler ¶ added in v0.0.39
func NewSamplingHandler(provider llm.Provider, model string) *SamplingHandler
NewSamplingHandler creates a new sampling handler.
func (*SamplingHandler) Handle ¶ added in v0.0.39
func (h *SamplingHandler) Handle(ctx context.Context, serverName string, req *mcp.CreateMessageRequest) (*mcp.CreateMessageResult, error)
Handle processes a sampling/createMessage request from an MCP server.
func (*SamplingHandler) SetServerConfig ¶ added in v0.0.39
func (h *SamplingHandler) SetServerConfig(name string, config ServerConfig)
SetServerConfig sets the configuration for a specific server.
func (*SamplingHandler) SetYoloMode ¶ added in v0.0.39
func (h *SamplingHandler) SetYoloMode(enabled bool)
SetYoloMode enables or disables yolo mode (auto-approve all sampling requests).
type SearchMetadata ¶
type SearchMetadata struct {
Count int `json:"count"`
NextCursor string `json:"nextCursor,omitempty"`
}
SearchMetadata contains pagination info.
type SearchOptions ¶
SearchOptions configures a registry search.
type SearchResult ¶
type SearchResult struct {
Servers []RegistryServerWrapper `json:"servers"`
Metadata SearchMetadata `json:"metadata"`
}
SearchResult contains the response from a registry search.
type ServerConfig ¶
type ServerConfig struct {
// Type discriminator: "stdio" (default if command present) or "http"
Type string `json:"type,omitempty"`
// Stdio transport fields
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
// HTTP transport fields
URL string `json:"url,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
// Shared fields
Env map[string]string `json:"env,omitempty"`
// Sampling configuration
Sampling *SamplingConfig `json:"sampling,omitempty"`
}
ServerConfig represents a configured MCP server. Supports both stdio transport (Command/Args) and HTTP transport (URL).
func (*ServerConfig) TransportType ¶ added in v0.0.23
func (c *ServerConfig) TransportType() string
TransportType returns the effective transport type for this server.
func (*ServerConfig) Validate ¶ added in v0.0.23
func (c *ServerConfig) Validate() error
Validate checks that the server configuration is valid.
type ServerState ¶
type ServerState struct {
Name string
Status ServerStatus
Error error
Client *Client
}
ServerState holds the state of a managed MCP server.
type ServerStatus ¶
type ServerStatus string
ServerStatus represents the current state of an MCP server.
const ( StatusStopped ServerStatus = "stopped" StatusStarting ServerStatus = "starting" StatusReady ServerStatus = "ready" StatusFailed ServerStatus = "failed" )
type StatusUpdate ¶
type StatusUpdate struct {
Name string
Status ServerStatus
Error error
}
StatusUpdate is sent when a server's status changes.
type ToolSpec ¶
ToolSpec describes a tool available from an MCP server.
func LoadCachedTools ¶ added in v0.0.64
LoadCachedTools returns the cached tool list for a server, or nil if not cached.
type TransportInfo ¶
type TransportInfo struct {
Type string `json:"type"` // stdio, sse, streamable-http
URL string `json:"url,omitempty"`
}
TransportInfo describes the transport type.