Documentation
¶
Index ¶
- Constants
- func ExpandHome(path string) string
- func FormatInputSchema(schema any) []string
- func GetConfigSearchPaths() []string
- func GetRequiredParams(schema any) []string
- func InferTransportType(cfg ServerConfig) string
- func IsMCPError(err error) bool
- func IsPipedInput() bool
- func ParseKVArgs(args []string) (map[string]any, error)
- func ParseYAML(yamlStr string) (map[string]any, error)
- func ReadStdinYAML() (map[string]any, error)
- func ReadYAMLFile(path string) (map[string]any, error)
- func SaveConfig(config *MCPConfig, path string) error
- type AuthConfig
- type Client
- func (c *Client) CallTool(ctx context.Context, name string, params map[string]any) (*mcp.CallToolResult, error)
- func (c *Client) Close()
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) GetConfig() ServerConfig
- func (c *Client) GetTransport() string
- func (c *Client) ListTools(ctx context.Context) ([]*mcp.Tool, error)
- type Dispatcher
- func (d *Dispatcher) CallTool(ctx context.Context, toolName, serverName string, params map[string]any) (string, any, error)
- func (d *Dispatcher) Close()
- func (d *Dispatcher) ConfigPaths() []string
- func (d *Dispatcher) FindTool(ctx context.Context, toolName string) ([]ToolMatch, error)
- func (d *Dispatcher) GetClient(serverName string) (*Client, error)
- func (d *Dispatcher) GetConfig() *MCPConfig
- func (d *Dispatcher) GetServerInfo(ctx context.Context, serverName string) (*ServerInfo, error)
- func (d *Dispatcher) GetToolInfo(ctx context.Context, serverName, toolName string) (*ToolMatch, error)
- func (d *Dispatcher) ListAllServers(ctx context.Context) []ServerInfo
- func (d *Dispatcher) ListServersConfig() []ServerInfo
- func (d *Dispatcher) SearchTools(ctx context.Context, query string) []ToolMatch
- func (d *Dispatcher) SuggestTools(ctx context.Context, task string) []SuggestMatch
- type MCPConfig
- type MCPError
- func CallErrors(toolName, serverName string, err error) *MCPError
- func ConfigErrors(message string) *MCPError
- func ConnectErrors(serverName, message string) *MCPError
- func GetMCPError(err error) *MCPError
- func MethodNotFoundErrors(toolName, serverName string) *MCPError
- func NewMCPError(code, message string) *MCPError
- func NewMCPErrorWithDetails(code, message string, details map[string]any) *MCPError
- func ParamErrors(message string) *MCPError
- func ServerNotFoundErrors(serverName string) *MCPError
- type OAuthConfig
- type ParamInfo
- type ServerConfig
- type ServerInfo
- type SuggestMatch
- type ToolInfo
- type ToolMatch
Constants ¶
const ( TransportSSE = "sse" TransportStreamable = "streamable" TransportStdio = "stdio" )
Transport type constants
const ( ErrCodeConfigNotFound = "MCP_CONFIG_NOT_FOUND" ErrCodeConnectFailed = "MCP_CONNECT_FAILED" ErrCodeServerNotFound = "MCP_SERVER_NOT_FOUND" ErrCodeMethodNotFound = "MCP_METHOD_NOT_FOUND" ErrCodeMethodAmbiguous = "MCP_METHOD_AMBIGUOUS" ErrCodeCallFailed = "MCP_CALL_FAILED" ErrCodeParamInvalid = "MCP_PARAM_INVALID" )
Error codes
Variables ¶
This section is empty.
Functions ¶
func ExpandHome ¶
ExpandHome expands ~ in paths to user's home directory
func FormatInputSchema ¶
FormatInputSchema converts JSON Schema to human-readable format Returns: ["key:type={value} // description", ...]
func GetConfigSearchPaths ¶
func GetConfigSearchPaths() []string
GetConfigSearchPaths returns platform-specific config file search paths
func GetRequiredParams ¶
GetRequiredParams extracts required parameter names
func InferTransportType ¶
func InferTransportType(cfg ServerConfig) string
InferTransportType infers transport type from server config
func IsPipedInput ¶ added in v0.4.0
func IsPipedInput() bool
IsPipedInput checks if stdin is a pipe (piped input)
func ParseKVArgs ¶
ParseKVArgs parses "key=value" or "key:type=value" format arguments
func ReadStdinYAML ¶ added in v0.4.0
ReadStdinYAML reads YAML from stdin and returns a map
func ReadYAMLFile ¶ added in v0.4.0
ReadYAMLFile reads and parses a YAML file
func SaveConfig ¶ added in v0.3.0
SaveConfig saves the config to a specific path
Types ¶
type AuthConfig ¶ added in v0.2.8
type AuthConfig struct {
// OAuth 2.1 + PKCE configuration
OAuth *OAuthConfig `json:"oauth,omitempty"`
}
AuthConfig represents authentication configuration for MCP servers
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an MCP server client
func NewClient ¶
func NewClient(name string, config ServerConfig) *Client
NewClient creates a new MCP client for a server
func (*Client) CallTool ¶
func (c *Client) CallTool(ctx context.Context, name string, params map[string]any) (*mcp.CallToolResult, error)
CallTool calls a tool with the given name and parameters
func (*Client) GetConfig ¶
func (c *Client) GetConfig() ServerConfig
GetConfig returns the server config
func (*Client) GetTransport ¶
GetTransport returns the transport type
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher manages multiple MCP server clients
func NewDispatcher ¶
func NewDispatcher(config *MCPConfig, loadedPaths []string) *Dispatcher
NewDispatcher creates a new Dispatcher
func (*Dispatcher) CallTool ¶
func (d *Dispatcher) CallTool(ctx context.Context, toolName, serverName string, params map[string]any) (string, any, error)
CallTool calls a tool on a server with retry on network failures
func (*Dispatcher) Close ¶ added in v0.3.0
func (d *Dispatcher) Close()
Close closes all client connections
func (*Dispatcher) ConfigPaths ¶
func (d *Dispatcher) ConfigPaths() []string
ConfigPaths returns the loaded config file paths
func (*Dispatcher) GetClient ¶ added in v0.3.0
func (d *Dispatcher) GetClient(serverName string) (*Client, error)
GetClient returns a client for the given server name, creating one if needed
func (*Dispatcher) GetConfig ¶
func (d *Dispatcher) GetConfig() *MCPConfig
GetConfig returns the underlying config
func (*Dispatcher) GetServerInfo ¶
func (d *Dispatcher) GetServerInfo(ctx context.Context, serverName string) (*ServerInfo, error)
GetServerInfo returns info for a specific server
func (*Dispatcher) GetToolInfo ¶
func (d *Dispatcher) GetToolInfo(ctx context.Context, serverName, toolName string) (*ToolMatch, error)
GetToolInfo returns info for a specific tool on a server
func (*Dispatcher) ListAllServers ¶
func (d *Dispatcher) ListAllServers(ctx context.Context) []ServerInfo
ListAllServers returns server info with tools from all servers
func (*Dispatcher) ListServersConfig ¶
func (d *Dispatcher) ListServersConfig() []ServerInfo
ListServersConfig returns server info from config without connecting
func (*Dispatcher) SearchTools ¶ added in v0.3.0
func (d *Dispatcher) SearchTools(ctx context.Context, query string) []ToolMatch
SearchTools searches for tools across all servers by name or description
func (*Dispatcher) SuggestTools ¶ added in v0.3.0
func (d *Dispatcher) SuggestTools(ctx context.Context, task string) []SuggestMatch
SuggestTools suggests tools based on a task description using keyword matching
type MCPConfig ¶
type MCPConfig struct {
MCPServers map[string]ServerConfig `json:"mcpServers"`
}
MCPConfig represents the full MCP configuration
func LoadConfig ¶
LoadConfig loads and merges all config files from search paths
func LoadConfigFromPaths ¶
LoadConfigFromPaths loads and merges config files from specified paths
func (*MCPConfig) GetServerConfig ¶
func (c *MCPConfig) GetServerConfig(name string) (ServerConfig, bool)
GetServerConfig returns config for a specific server
type MCPError ¶
MCPError represents an MCP-specific error
func CallErrors ¶
CallErrors returns a CallFailed error
func ConfigErrors ¶
ConfigErrors returns a ConfigNotFound error
func ConnectErrors ¶
ConnectErrors returns a ConnectFailed error
func GetMCPError ¶
GetMCPError extracts MCPError from an error
func MethodNotFoundErrors ¶
MethodNotFoundErrors returns a MethodNotFound error
func NewMCPError ¶
NewMCPError creates a new MCPError
func NewMCPErrorWithDetails ¶
NewMCPErrorWithDetails creates a new MCPError with details
func ParamErrors ¶
ParamErrors returns a ParamInvalid error
func ServerNotFoundErrors ¶
ServerNotFoundErrors returns a ServerNotFound error
type OAuthConfig ¶ added in v0.2.8
type OAuthConfig struct {
// AccessToken is a static access token to use for authentication.
// If provided, it will be used directly as a Bearer token.
AccessToken string `json:"accessToken,omitempty"`
// ClientID is the OAuth client ID (for full OAuth flow).
ClientID string `json:"clientId,omitempty"`
// ClientSecret is the OAuth client secret (for confidential clients).
ClientSecret string `json:"clientSecret,omitempty"`
// AuthorizationURL is the authorization server's authorization endpoint.
AuthorizationURL string `json:"authorizationURL,omitempty"`
// TokenURL is the authorization server's token endpoint.
TokenURL string `json:"tokenURL,omitempty"`
// Scopes are the OAuth scopes to request.
Scopes string `json:"scopes,omitempty"`
// RedirectURL is the callback URL for OAuth (defaults to http://localhost:7777/callback).
RedirectURL string `json:"redirectURL,omitempty"`
// ClientIDMetadataURL is the URL for Client ID Metadata Document (MCP spec).
ClientIDMetadataURL string `json:"clientIdMetadataUrl,omitempty"`
}
OAuthConfig holds OAuth 2.1 authentication parameters
type ParamInfo ¶
type ParamInfo struct {
Name string `json:"name"`
Type string `json:"type"`
Required bool `json:"required"`
Description string `json:"description,omitempty"`
}
ParamInfo represents structured parameter information
func GetParamInfoList ¶
GetParamInfoList extracts structured parameter information
type ServerConfig ¶
type ServerConfig struct {
Transport string `json:"transport,omitempty"`
Type string `json:"type,omitempty"`
URL string `json:"url,omitempty"`
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env map[string]string `json:"env,omitempty"`
Timeout int `json:"timeout,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Auth AuthConfig `json:"auth,omitempty"`
}
ServerConfig represents a server configuration
type ServerInfo ¶
type ServerInfo struct {
Name string `json:"name"`
Transport string `json:"transport"`
URL string `json:"url,omitempty"`
Command string `json:"command,omitempty"`
Tools []string `json:"tools,omitempty"`
Error string `json:"error,omitempty"`
}
ServerInfo represents information about an MCP server
type SuggestMatch ¶ added in v0.3.0
SuggestMatch represents a suggested tool with reasoning