mcp

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateConfig added in v0.8.4

func ValidateConfig(config *Config) error

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

func NewClient

func NewClient(stdioPath string) (*Client, error)

NewClient creates a new MCP client

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, tool string, args map[string]interface{}) (interface{}, error)

CallTool calls an MCP tool with the given arguments

func (*Client) Close

func (c *Client) Close() error

Close closes the MCP client connection

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context) ([]Tool, error)

ListTools lists all available tools from the MCP server

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

func (*HTTPClient) ListTools added in v0.8.4

func (h *HTTPClient) ListTools(ctx context.Context) ([]Tool, error)

ListTools lists available tools

func (*HTTPClient) Ping added in v0.8.4

func (h *HTTPClient) Ping(ctx context.Context) error

Ping tests the connection

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

func NewHTTPClient(config *Config) (MCPClient, error)

NewHTTPClient creates a new HTTP MCP client

func NewMCPClient added in v0.8.4

func NewMCPClient(config *Config) (MCPClient, error)

NewMCPClient creates a new MCP client based on transport type

func NewStdioClient added in v0.8.4

func NewStdioClient(config *Config) (MCPClient, error)

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)

func (*StdioClient) ListTools added in v0.8.4

func (s *StdioClient) ListTools(ctx context.Context) ([]Tool, error)

ListTools lists available tools

func (*StdioClient) Ping added in v0.8.4

func (s *StdioClient) Ping(ctx context.Context) error

Ping tests the connection

type Tool

type Tool struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	InputSchema map[string]interface{} `json:"inputSchema"`
}

Tool represents an MCP tool

type Transport added in v0.8.4

type Transport string

Transport represents the transport protocol

const (
	TransportHTTP  Transport = "http"
	TransportStdio Transport = "stdio"
)

Jump to

Keyboard shortcuts

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