Documentation
¶
Index ¶
- func ValidateConfig(config *Config) error
- type Auth
- type Client
- type Config
- type HTTPClient
- func (h *HTTPClient) CallTool(ctx context.Context, toolName string, args map[string]interface{}) (interface{}, error)
- func (h *HTTPClient) Close() error
- func (h *HTTPClient) Config() *Config
- func (h *HTTPClient) Connect(ctx context.Context) error
- func (h *HTTPClient) ListTools(ctx context.Context) ([]Tool, error)
- func (h *HTTPClient) Ping(ctx context.Context) error
- type MCPClient
- type MCPError
- type MCPRequest
- type MCPResponse
- type StdioClient
- func (s *StdioClient) CallTool(ctx context.Context, toolName string, args map[string]interface{}) (interface{}, error)
- func (s *StdioClient) Close() error
- func (s *StdioClient) Config() *Config
- func (s *StdioClient) Connect(ctx context.Context) error
- func (s *StdioClient) ListTools(ctx context.Context) ([]Tool, error)
- func (s *StdioClient) Ping(ctx context.Context) error
- type Tool
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateConfig ¶ added in v0.8.4
ValidateConfig validates MCP configuration
Types ¶
type Auth ¶ added in v0.8.4
type Auth struct {
Type string `yaml:"type" json:"type"` // bearer, basic, api-key
Token string `yaml:"token" json:"token"` // Bearer token
Username string `yaml:"username" json:"username"` // Basic auth username
Password string `yaml:"password" json:"password"` // Basic auth password
APIKey string `yaml:"api_key" json:"api_key"` // API key
Headers map[string]string `yaml:"headers" json:"headers"` // Custom auth headers
}
Auth contains authentication credentials
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an MCP client that communicates with weave-mcp via stdio
type Config ¶ added in v0.8.4
type Config struct {
Name string `yaml:"name" json:"name"` // Server name
ServerURL string `yaml:"url" json:"url"` // HTTP URL or stdio command
Transport Transport `yaml:"transport" json:"transport"` // http or stdio
Auth *Auth `yaml:"auth,omitempty" json:"auth,omitempty"` // Authentication config
Timeout time.Duration `yaml:"timeout" json:"timeout"` // Request timeout
MaxRetries int `yaml:"max_retries" json:"max_retries"` // Retry attempts
Headers map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"` // Custom headers (HTTP only)
Enabled bool `yaml:"enabled" json:"enabled"` // Whether server is enabled
Tools []string `yaml:"tools,omitempty" json:"tools,omitempty"` // Available tools (optional)
Description string `yaml:"description,omitempty" json:"description,omitempty"` // Server description
}
Config configures MCP client connection
type HTTPClient ¶ added in v0.8.4
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient implements MCPClient for HTTP transport
func (*HTTPClient) CallTool ¶ added in v0.8.4
func (h *HTTPClient) CallTool(ctx context.Context, toolName string, args map[string]interface{}) (interface{}, error)
CallTool calls an MCP tool
func (*HTTPClient) Close ¶ added in v0.8.4
func (h *HTTPClient) Close() error
Close closes the HTTP client
func (*HTTPClient) Config ¶ added in v0.8.4
func (h *HTTPClient) Config() *Config
Config returns the client configuration
func (*HTTPClient) Connect ¶ added in v0.8.4
func (h *HTTPClient) Connect(ctx context.Context) error
Connect establishes HTTP connection and performs handshake
type MCPClient ¶ added in v0.8.4
type MCPClient interface {
// Connection management
Connect(ctx context.Context) error
Close() error
Ping(ctx context.Context) error
// Tool discovery
ListTools(ctx context.Context) ([]Tool, error)
// Tool invocation
CallTool(ctx context.Context, toolName string, args map[string]interface{}) (interface{}, error)
// Configuration
Config() *Config
}
MCPClient provides a unified interface for MCP protocol clients Supports both HTTP and stdio transport protocols
func NewHTTPClient ¶ added in v0.8.4
NewHTTPClient creates a new HTTP MCP client
func NewMCPClient ¶ added in v0.8.4
NewMCPClient creates a new MCP client based on transport type
func NewStdioClient ¶ added in v0.8.4
NewStdioClient creates a new stdio MCP client
type MCPError ¶
type MCPError struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
MCPError represents an error from the MCP server
type MCPRequest ¶
type MCPRequest struct {
JSONRPC string `json:"jsonrpc"`
ID *int `json:"id,omitempty"` // Optional for notifications
Method string `json:"method"`
Params map[string]interface{} `json:"params,omitempty"`
}
MCPRequest represents a request to the MCP server
type MCPResponse ¶
type MCPResponse struct {
JSONRPC string `json:"jsonrpc"`
ID int `json:"id"`
Result map[string]interface{} `json:"result,omitempty"`
Error *MCPError `json:"-"` // Handled via UnmarshalJSON
RawError json.RawMessage `json:"error,omitempty"`
}
MCPResponse represents a response from the MCP server
func (*MCPResponse) UnmarshalJSON ¶ added in v0.3.13
func (r *MCPResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom unmarshaling for MCPResponse to handle both error formats
type StdioClient ¶ added in v0.8.4
type StdioClient struct {
// contains filtered or unexported fields
}
StdioClient wraps the existing Client to implement MCPClient interface
func (*StdioClient) CallTool ¶ added in v0.8.4
func (s *StdioClient) CallTool(ctx context.Context, toolName string, args map[string]interface{}) (interface{}, error)
CallTool calls an MCP tool
func (*StdioClient) Close ¶ added in v0.8.4
func (s *StdioClient) Close() error
Close closes the connection
func (*StdioClient) Config ¶ added in v0.8.4
func (s *StdioClient) Config() *Config
Config returns the client configuration
func (*StdioClient) Connect ¶ added in v0.8.4
func (s *StdioClient) Connect(ctx context.Context) error
Connect establishes connection (already done in NewClient)