Documentation
¶
Overview ¶
Package core provides the canonical types for MCP server configuration that can be converted to/from various AI assistant formats.
Index ¶
- Constants
- Variables
- func Convert(data []byte, from, to string) ([]byte, error)
- func Register(adapter Adapter)
- type Adapter
- type AdapterRegistry
- type Config
- func (c *Config) AddInput(input InputVariable)
- func (c *Config) AddServer(name string, server Server)
- func (c *Config) EnabledServers() map[string]Server
- func (c *Config) GetInput(id string) (InputVariable, bool)
- func (c *Config) GetServer(name string) (Server, bool)
- func (c *Config) MarshalJSON() ([]byte, error)
- func (c *Config) Merge(other *Config)
- func (c *Config) RemoteServers() map[string]Server
- func (c *Config) RemoveServer(name string)
- func (c *Config) ServerNames() []string
- func (c *Config) StdioServers() map[string]Server
- func (c *Config) UnmarshalJSON(data []byte) error
- func (c *Config) Validate() error
- func (c *Config) WriteFile(path string) error
- func (c *Config) WriteFileWithMode(path string, mode fs.FileMode) error
- type InputVariable
- type ParseError
- type Server
- type ServerValidationError
- type TransportType
- type WriteError
Constants ¶
const DefaultFileMode fs.FileMode = 0600
DefaultFileMode is the default permission mode for configuration files. This can be used by adapters or overridden with WriteFileWithMode.
Variables ¶
var ( // ErrNoCommandOrURL is returned when a server has neither command nor URL. ErrNoCommandOrURL = errors.New("server must have either command (stdio) or url (http/sse)") // ErrBothCommandAndURL is returned when a server has both command and URL. ErrBothCommandAndURL = errors.New("server cannot have both command and url") // ErrInvalidTransport is returned when a transport type is invalid. ErrInvalidTransport = errors.New("invalid transport type") // ErrServerNotFound is returned when a server is not found. ErrServerNotFound = errors.New("server not found") // ErrEmptyConfig is returned when configuration is empty. ErrEmptyConfig = errors.New("configuration is empty") )
Common errors for MCP configuration.
var DefaultRegistry = NewAdapterRegistry()
DefaultRegistry is the global adapter registry.
Functions ¶
Types ¶
type Adapter ¶
type Adapter interface {
// Name returns the name of the tool/format (e.g., "claude", "vscode").
Name() string
// DefaultPaths returns the default configuration file paths for this tool.
DefaultPaths() []string
// Parse parses tool-specific data into the canonical Config format.
Parse(data []byte) (*Config, error)
// Marshal converts the canonical Config to tool-specific format.
Marshal(cfg *Config) ([]byte, error)
// ReadFile reads a tool-specific config file and returns canonical Config.
ReadFile(path string) (*Config, error)
// WriteFile writes the canonical Config to a tool-specific file.
WriteFile(cfg *Config, path string) error
}
Adapter defines the interface for converting between the canonical Config format and tool-specific formats.
func GetAdapter ¶
GetAdapter returns an adapter from the default registry.
type AdapterRegistry ¶
type AdapterRegistry struct {
// contains filtered or unexported fields
}
AdapterRegistry holds registered adapters for different tools.
func NewAdapterRegistry ¶
func NewAdapterRegistry() *AdapterRegistry
NewAdapterRegistry creates a new adapter registry.
func (*AdapterRegistry) Convert ¶
func (r *AdapterRegistry) Convert(data []byte, from, to string) ([]byte, error)
Convert converts a config from one format to another.
func (*AdapterRegistry) Get ¶
func (r *AdapterRegistry) Get(name string) (Adapter, bool)
Get returns an adapter by name.
func (*AdapterRegistry) Names ¶
func (r *AdapterRegistry) Names() []string
Names returns the names of all registered adapters.
func (*AdapterRegistry) Register ¶
func (r *AdapterRegistry) Register(adapter Adapter)
Register adds an adapter to the registry.
type Config ¶
type Config struct {
// Servers is a map of server names to their configurations.
Servers map[string]Server `json:"servers"`
// Inputs defines input variables for sensitive data like API keys (VS Code feature).
Inputs []InputVariable `json:"inputs,omitempty"`
}
Config represents the canonical MCP configuration that can be converted to/from various AI assistant formats.
func (*Config) AddInput ¶
func (c *Config) AddInput(input InputVariable)
AddInput adds an input variable to the configuration.
func (*Config) EnabledServers ¶
EnabledServers returns only the servers that are enabled.
func (*Config) GetInput ¶
func (c *Config) GetInput(id string) (InputVariable, bool)
GetInput returns an input variable by ID and whether it exists.
func (*Config) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Config) Merge ¶
Merge combines another config into this one. Servers and inputs from the other config override those in this config with the same name/ID.
func (*Config) RemoteServers ¶
RemoteServers returns only the servers configured for HTTP/SSE transport.
func (*Config) RemoveServer ¶
RemoveServer removes a server from the configuration.
func (*Config) ServerNames ¶
ServerNames returns a slice of all server names.
func (*Config) StdioServers ¶
StdioServers returns only the servers configured for stdio transport.
func (*Config) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type InputVariable ¶
type InputVariable struct {
// Type is the input type, typically "promptString".
Type string `json:"type"`
// ID is the unique identifier referenced in server config as ${input:id}.
ID string `json:"id"`
// Description is the user-friendly prompt text.
Description string `json:"description"`
// Password hides typed input when true (for API keys and passwords).
Password bool `json:"password,omitempty"`
}
InputVariable represents a placeholder for sensitive configuration values. When referenced using ${input:variable-id}, the user is prompted for the value.
type ParseError ¶
ParseError represents an error parsing a configuration file.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
func (*ParseError) Unwrap ¶
func (e *ParseError) Unwrap() error
type Server ¶
type Server struct {
// Transport specifies the communication protocol (stdio, http, sse).
// If empty, it will be inferred from Command (stdio) or URL (http).
Transport TransportType `json:"transport,omitempty"`
// Command is the executable to launch for stdio servers.
Command string `json:"command,omitempty"`
// Args are the command-line arguments passed to the command.
Args []string `json:"args,omitempty"`
// Env contains environment variables for the server process.
Env map[string]string `json:"env,omitempty"`
// EnvFile is the path to an environment file to load (VS Code feature).
EnvFile string `json:"envFile,omitempty"`
// Cwd is the working directory for the server process (Codex feature).
Cwd string `json:"cwd,omitempty"`
// URL is the endpoint for HTTP/SSE servers.
URL string `json:"url,omitempty"`
// Headers contains HTTP headers for authentication or configuration.
Headers map[string]string `json:"headers,omitempty"`
// BearerTokenEnvVar is the name of an env var containing a bearer token (Codex feature).
BearerTokenEnvVar string `json:"bearerTokenEnvVar,omitempty"`
// EnabledTools is an allow-list of tools to expose (Codex/Cline feature).
EnabledTools []string `json:"enabledTools,omitempty"`
// DisabledTools is a deny-list of tools to hide (Codex/Cline feature).
DisabledTools []string `json:"disabledTools,omitempty"`
// AlwaysAllow lists tools that don't require user approval (Cline feature).
AlwaysAllow []string `json:"alwaysAllow,omitempty"`
// Enabled indicates whether the server is active. Defaults to true.
Enabled *bool `json:"enabled,omitempty"`
// StartupTimeoutSec is the timeout for server startup in seconds (Codex feature).
StartupTimeoutSec int `json:"startupTimeoutSec,omitempty"`
// ToolTimeoutSec is the timeout for tool execution in seconds (Codex feature).
ToolTimeoutSec int `json:"toolTimeoutSec,omitempty"`
// NetworkTimeoutSec is the timeout for network operations (Cline feature).
NetworkTimeoutSec int `json:"networkTimeoutSec,omitempty"`
}
Server represents a canonical MCP server configuration that can be converted to/from various AI assistant formats (Claude, Cursor, VS Code, etc.).
func (*Server) InferTransport ¶
func (s *Server) InferTransport() TransportType
InferTransport returns the inferred transport type based on configuration.
func (*Server) IsEnabled ¶
IsEnabled returns whether the server is enabled. Defaults to true if not set.
func (*Server) SetEnabled ¶
SetEnabled sets the enabled state of the server.
type ServerValidationError ¶
ServerValidationError wraps a validation error with the server name.
func (*ServerValidationError) Error ¶
func (e *ServerValidationError) Error() string
func (*ServerValidationError) Unwrap ¶
func (e *ServerValidationError) Unwrap() error
type TransportType ¶
type TransportType string
TransportType represents the communication protocol for an MCP server.
const ( // TransportStdio represents local servers using standard input/output streams. TransportStdio TransportType = "stdio" // TransportHTTP represents remote servers using HTTP/Streamable HTTP transport. TransportHTTP TransportType = "http" // TransportSSE represents remote servers using Server-Sent Events (legacy). TransportSSE TransportType = "sse" )
func (TransportType) IsLocal ¶
func (t TransportType) IsLocal() bool
IsLocal returns true if the transport type runs locally (stdio).
func (TransportType) IsRemote ¶
func (t TransportType) IsRemote() bool
IsRemote returns true if the transport type is network-based.
func (TransportType) String ¶
func (t TransportType) String() string
String returns the string representation of the transport type.
func (TransportType) Valid ¶
func (t TransportType) Valid() bool
Valid returns true if the transport type is a known valid type.
type WriteError ¶
WriteError represents an error writing a configuration file.
func (*WriteError) Error ¶
func (e *WriteError) Error() string
func (*WriteError) Unwrap ¶
func (e *WriteError) Unwrap() error