mcp

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConfigPath

func DefaultConfigPath() (string, error)

DefaultConfigPath returns the default path for mcp.json.

func GetBundledServersByCategory

func GetBundledServersByCategory() map[string][]BundledServer

GetBundledServersByCategory returns servers grouped by category.

func GetMCPToolSpecs

func GetMCPToolSpecs(manager *Manager) []llm.ToolSpec

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) CallTool

func (c *Client) CallTool(ctx context.Context, name string, args json.RawMessage) (string, error)

CallTool invokes a tool on the MCP server.

func (*Client) IsRunning

func (c *Client) IsRunning() bool

IsRunning returns whether the client is connected.

func (*Client) Name

func (c *Client) Name() string

Name returns the server name.

func (*Client) Start

func (c *Client) Start(ctx context.Context) error

Start connects to the MCP server and initializes the session.

func (*Client) Stop

func (c *Client) Stop() error

Stop closes the MCP server connection.

func (*Client) Tools

func (c *Client) Tools() []ToolSpec

Tools returns the available tools from this server.

type Config

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

Config represents the mcp.json configuration file.

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig loads the MCP configuration from the default path.

func LoadConfigFromPath

func LoadConfigFromPath(path string) (*Config, error)

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

func (c *Config) RemoveServer(name string) bool

RemoveServer removes a server configuration.

func (*Config) Save

func (c *Config) Save() error

Save saves the configuration to the default path.

func (*Config) SaveToPath

func (c *Config) SaveToPath(path string) error

SaveToPath saves the configuration to a specific path.

func (*Config) ServerNames

func (c *Config) ServerNames() []string

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

func NewMCPTool(manager *Manager, spec ToolSpec) *MCPTool

NewMCPTool creates a new MCP tool wrapper.

func (*MCPTool) Execute

func (t *MCPTool) Execute(ctx context.Context, args json.RawMessage) (string, error)

Execute invokes the tool on the MCP server.

func (*MCPTool) Spec

func (t *MCPTool) Spec() llm.ToolSpec

Spec returns the tool specification for the LLM.

type Manager

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

Manager handles MCP server lifecycle and provides tools to LLM.

func NewManager

func NewManager() *Manager

NewManager creates a new MCP manager.

func (*Manager) AllTools

func (m *Manager) AllTools() []ToolSpec

AllTools returns all tools from all running MCP servers. Tool names are prefixed with server name to avoid collisions.

func (*Manager) AvailableServers

func (m *Manager) AvailableServers() []string

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) Config

func (m *Manager) Config() *Config

Config returns the current configuration.

func (*Manager) Disable

func (m *Manager) Disable(name string) error

Disable stops an MCP server.

func (*Manager) Enable

func (m *Manager) Enable(ctx context.Context, name string) error

Enable starts an MCP server in the background (non-blocking).

func (*Manager) EnabledServers

func (m *Manager) EnabledServers() []string

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) LoadConfig

func (m *Manager) LoadConfig() error

LoadConfig loads the MCP configuration.

func (*Manager) Restart

func (m *Manager) Restart(ctx context.Context, name string) error

Restart stops and restarts an MCP server.

func (*Manager) ServerStatus

func (m *Manager) ServerStatus(name string) (ServerStatus, error)

ServerStatus returns the current status of a server.

func (*Manager) SetStatusChannel

func (m *Manager) SetStatusChannel(ch chan StatusUpdate)

SetStatusChannel sets a channel to receive status updates.

func (*Manager) StopAll

func (m *Manager) StopAll()

StopAll stops all running MCP servers.

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 SearchMetadata

type SearchMetadata struct {
	Count      int    `json:"count"`
	NextCursor string `json:"nextCursor,omitempty"`
}

SearchMetadata contains pagination info.

type SearchOptions

type SearchOptions struct {
	Query  string
	Limit  int
	Cursor string
}

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 {
	Command string            `json:"command"`
	Args    []string          `json:"args"`
	Env     map[string]string `json:"env,omitempty"`
}

ServerConfig represents a configured MCP server.

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

type ToolSpec struct {
	Name        string
	Description string
	Schema      map[string]any
}

ToolSpec describes a tool available from an MCP server.

type TransportInfo

type TransportInfo struct {
	Type string `json:"type"` // stdio, sse, streamable-http
	URL  string `json:"url,omitempty"`
}

TransportInfo describes the transport type.

Jump to

Keyboard shortcuts

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