Documentation
¶
Overview ¶
Package test provides utilities for testing the MCP implementation.
Index ¶
- func NewServer(name string) server.Server
- func WithLogger(logger *slog.Logger) server.Option
- type ClientInfo
- type ClientSession
- type Context
- type MockTransport
- func (m *MockTransport) ClearMessages()
- func (m *MockTransport) ClearRequestHistory()
- func (m *MockTransport) Connect() error
- func (m *MockTransport) ConnectWithContext(ctx context.Context) error
- func (m *MockTransport) Disconnect() error
- func (m *MockTransport) GetLogger() *slog.Logger
- func (m *MockTransport) GetMessages() [][]byte
- func (m *MockTransport) GetProtocolVersion() string
- func (m *MockTransport) GetRequestHistory() [][]byte
- func (m *MockTransport) GetSendHandler() func([]byte)
- func (m *MockTransport) Initialize() error
- func (m *MockTransport) Receive() ([]byte, error)
- func (m *MockTransport) RegisterNotificationHandler(handler func(method string, params []byte))
- func (m *MockTransport) Send(message []byte) error
- func (m *MockTransport) SendAsync(ctx context.Context, message []byte) error
- func (m *MockTransport) SendWithContext(ctx context.Context, message []byte) ([]byte, error)
- func (m *MockTransport) SetConnectionTimeout(timeout time.Duration)
- func (m *MockTransport) SetDebugHandler(handler transport.DebugHandler)
- func (m *MockTransport) SetHandler(handler func([]byte))
- func (m *MockTransport) SetLogger(logger *slog.Logger)
- func (m *MockTransport) SetMessageHandler(handler transport.MessageHandler)
- func (m *MockTransport) SetProtocolVersion(version string)
- func (m *MockTransport) SetRequestTimeout(timeout time.Duration)
- func (m *MockTransport) SetResponseDelay(delay time.Duration)
- func (m *MockTransport) SetSendCallback(callback func(message []byte) ([]byte, error))
- func (m *MockTransport) SetSendFunc(sendFunc func(data []byte) error)
- func (m *MockTransport) SimulateMessage(message []byte)
- func (m *MockTransport) Start() error
- func (m *MockTransport) Stop() error
- type Request
- type RequestSamplingOptions
- type Response
- type SamplingCapabilities
- type SamplingMessage
- type SamplingMessageContent
- type SamplingModelHint
- type SamplingModelPreferences
- type SamplingResponse
- type SessionID
- type SessionManager
- func (sm *SessionManager) CloseSession(id SessionID) bool
- func (sm *SessionManager) CreateSession(clientInfo ClientInfo, protocolVersion string) *ClientSession
- func (sm *SessionManager) GetSession(id SessionID) (*ClientSession, bool)
- func (sm *SessionManager) UpdateClientCapabilities(id SessionID, caps SamplingCapabilities) bool
- func (sm *SessionManager) UpdateSession(id SessionID, updateFn func(*ClientSession)) bool
- type ToolHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClientInfo ¶
type ClientInfo struct {
SamplingSupported bool
SamplingCaps SamplingCapabilities
ProtocolVersion string
}
ClientInfo represents information about a client
type ClientSession ¶
type ClientSession struct {
ID SessionID
ClientInfo ClientInfo
Metadata map[string]interface{}
}
ClientSession represents a client session
type Context ¶
type Context struct {
Request *Request
Response *Response
Version string
Metadata map[string]interface{}
}
Context represents the context for a request/response cycle
type MockTransport ¶
type MockTransport struct {
// contains filtered or unexported fields
}
MockTransport is a simple mock transport for testing
func NewMockTransport ¶
func NewMockTransport() *MockTransport
NewMockTransport creates a new MockTransport
func (*MockTransport) ClearMessages ¶
func (m *MockTransport) ClearMessages()
ClearMessages clears the messages
func (*MockTransport) ClearRequestHistory ¶
func (m *MockTransport) ClearRequestHistory()
ClearRequestHistory clears the request history
func (*MockTransport) Connect ¶
func (m *MockTransport) Connect() error
Connect simulates connecting the transport
func (*MockTransport) ConnectWithContext ¶
func (m *MockTransport) ConnectWithContext(ctx context.Context) error
ConnectWithContext simulates connecting the transport with context
func (*MockTransport) Disconnect ¶
func (m *MockTransport) Disconnect() error
Disconnect simulates disconnecting the transport
func (*MockTransport) GetLogger ¶ added in v1.5.5
func (m *MockTransport) GetLogger() *slog.Logger
GetLogger implements the Transport interface by returning a default logger
func (*MockTransport) GetMessages ¶
func (m *MockTransport) GetMessages() [][]byte
GetMessages returns the messages sent to the transport
func (*MockTransport) GetProtocolVersion ¶ added in v1.5.5
func (m *MockTransport) GetProtocolVersion() string
func (*MockTransport) GetRequestHistory ¶
func (m *MockTransport) GetRequestHistory() [][]byte
GetRequestHistory returns the request history
func (*MockTransport) GetSendHandler ¶
func (m *MockTransport) GetSendHandler() func([]byte)
GetSendHandler returns a function to call HandleJSONRPCResponse
func (*MockTransport) Initialize ¶ added in v1.5.5
func (m *MockTransport) Initialize() error
Transport interface implementations that were missing
func (*MockTransport) Receive ¶ added in v1.5.5
func (m *MockTransport) Receive() ([]byte, error)
func (*MockTransport) RegisterNotificationHandler ¶
func (m *MockTransport) RegisterNotificationHandler(handler func(method string, params []byte))
RegisterNotificationHandler registers a handler for notifications
func (*MockTransport) Send ¶
func (m *MockTransport) Send(message []byte) error
Send implements the Transport interface
func (*MockTransport) SendAsync ¶
func (m *MockTransport) SendAsync(ctx context.Context, message []byte) error
SendAsync implements the server.Transport interface
func (*MockTransport) SendWithContext ¶
SendWithContext sends a message with context
func (*MockTransport) SetConnectionTimeout ¶
func (m *MockTransport) SetConnectionTimeout(timeout time.Duration)
SetConnectionTimeout sets the timeout for connection
func (*MockTransport) SetDebugHandler ¶ added in v1.5.5
func (m *MockTransport) SetDebugHandler(handler transport.DebugHandler)
func (*MockTransport) SetHandler ¶
func (m *MockTransport) SetHandler(handler func([]byte))
SetHandler implements the server.Transport interface
func (*MockTransport) SetLogger ¶ added in v1.5.5
func (m *MockTransport) SetLogger(logger *slog.Logger)
func (*MockTransport) SetMessageHandler ¶ added in v1.5.5
func (m *MockTransport) SetMessageHandler(handler transport.MessageHandler)
func (*MockTransport) SetProtocolVersion ¶ added in v1.5.5
func (m *MockTransport) SetProtocolVersion(version string)
func (*MockTransport) SetRequestTimeout ¶
func (m *MockTransport) SetRequestTimeout(timeout time.Duration)
SetRequestTimeout sets the timeout for requests
func (*MockTransport) SetResponseDelay ¶
func (m *MockTransport) SetResponseDelay(delay time.Duration)
SetResponseDelay sets the delay for responses
func (*MockTransport) SetSendCallback ¶
func (m *MockTransport) SetSendCallback(callback func(message []byte) ([]byte, error))
SetSendCallback sets the callback for Send
func (*MockTransport) SetSendFunc ¶
func (m *MockTransport) SetSendFunc(sendFunc func(data []byte) error)
SetSendFunc sets the function for Send
func (*MockTransport) SimulateMessage ¶
func (m *MockTransport) SimulateMessage(message []byte)
SimulateMessage simulates receiving a message from the client
func (*MockTransport) Start ¶ added in v1.5.5
func (m *MockTransport) Start() error
func (*MockTransport) Stop ¶ added in v1.5.5
func (m *MockTransport) Stop() error
type Request ¶
type Request struct {
JSONRPC string `json:"jsonrpc"`
ID interface{} `json:"id,omitempty"`
Method string `json:"method"`
Params map[string]interface{} `json:"params,omitempty"`
ToolName string `json:"name,omitempty"`
ToolArgs map[string]interface{} `json:"arguments,omitempty"`
}
Request represents a JSON-RPC request
type RequestSamplingOptions ¶
type RequestSamplingOptions struct {
Timeout time.Duration
MaxRetries int
RetryInterval time.Duration
IgnoreCapability bool
ForceSession bool
}
RequestSamplingOptions defines options for sampling requests
func DefaultSamplingOptions ¶
func DefaultSamplingOptions() RequestSamplingOptions
DefaultSamplingOptions returns the default options for sampling requests
type Response ¶
type Response struct {
JSONRPC string `json:"jsonrpc"`
ID interface{} `json:"id,omitempty"`
Result interface{} `json:"result,omitempty"`
Error interface{} `json:"error,omitempty"`
}
Response represents a JSON-RPC response
type SamplingCapabilities ¶
type SamplingCapabilities struct {
Supported bool
TextSupport bool
ImageSupport bool
AudioSupport bool
}
SamplingCapabilities represents client capabilities for sampling
func DetectClientCapabilities ¶
func DetectClientCapabilities(protocolVersion string) SamplingCapabilities
DetectClientCapabilities detects client capabilities based on protocol version
type SamplingMessage ¶
type SamplingMessage struct {
Role string `json:"role"`
Content SamplingMessageContent `json:"content"`
}
SamplingMessage represents a message in a sampling conversation
func CreateAudioSamplingMessage ¶
func CreateAudioSamplingMessage(role, audioData, mimeType string) SamplingMessage
CreateAudioSamplingMessage creates an audio sampling message
func CreateImageSamplingMessage ¶
func CreateImageSamplingMessage(role, imageData, mimeType string) SamplingMessage
CreateImageSamplingMessage creates an image sampling message
func CreateTextSamplingMessage ¶
func CreateTextSamplingMessage(role, text string) SamplingMessage
CreateTextSamplingMessage creates a text sampling message
type SamplingMessageContent ¶
type SamplingMessageContent struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
Data string `json:"data,omitempty"`
MimeType string `json:"mimeType,omitempty"`
}
SamplingMessageContent represents the content of a sampling message
func (SamplingMessageContent) IsValidForVersion ¶
func (c SamplingMessageContent) IsValidForVersion(version string) bool
IsValidForVersion checks if the content type is valid for the given protocol version
type SamplingModelHint ¶
type SamplingModelHint struct {
Name string `json:"name"`
}
SamplingModelHint represents a hint for model selection in sampling requests
type SamplingModelPreferences ¶
type SamplingModelPreferences struct {
Hints []SamplingModelHint `json:"hints,omitempty"`
CostPriority *float64 `json:"costPriority,omitempty"`
SpeedPriority *float64 `json:"speedPriority,omitempty"`
IntelligencePriority *float64 `json:"intelligencePriority,omitempty"`
}
SamplingModelPreferences represents the model preferences for a sampling request
type SamplingResponse ¶
type SamplingResponse struct {
Role string `json:"role"`
Content SamplingMessageContent `json:"content"`
Model string `json:"model,omitempty"`
StopReason string `json:"stopReason,omitempty"`
}
SamplingResponse represents the response to a sampling/createMessage request
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager manages client sessions
func NewSessionManager ¶
func NewSessionManager() *SessionManager
NewSessionManager creates a new session manager
func (*SessionManager) CloseSession ¶
func (sm *SessionManager) CloseSession(id SessionID) bool
CloseSession closes a client session
func (*SessionManager) CreateSession ¶
func (sm *SessionManager) CreateSession(clientInfo ClientInfo, protocolVersion string) *ClientSession
CreateSession creates a new client session
func (*SessionManager) GetSession ¶
func (sm *SessionManager) GetSession(id SessionID) (*ClientSession, bool)
GetSession gets a client session by ID
func (*SessionManager) UpdateClientCapabilities ¶
func (sm *SessionManager) UpdateClientCapabilities(id SessionID, caps SamplingCapabilities) bool
UpdateClientCapabilities updates client capabilities
func (*SessionManager) UpdateSession ¶
func (sm *SessionManager) UpdateSession(id SessionID, updateFn func(*ClientSession)) bool
UpdateSession updates a client session
type ToolHandler ¶
ToolHandler is the type of function that handles tool calls