Documentation
¶
Index ¶
- func DefaultTestImplementation() *mcp.Implementation
- type ExampleTestSuite
- func (s *ExampleTestSuite) BinaryPath() string
- func (s *ExampleTestSuite) BuildBinary() string
- func (s *ExampleTestSuite) CallTool(ctx context.Context, session *mcp.ClientSession, name string, ...) ([]mcp.Content, bool, error)
- func (s *ExampleTestSuite) GetPrompt(ctx context.Context, session *mcp.ClientSession, name string, ...) ([]*mcp.PromptMessage, error)
- func (s *ExampleTestSuite) ListPrompts(ctx context.Context, session *mcp.ClientSession) ([]*mcp.Prompt, error)
- func (s *ExampleTestSuite) ListResources(ctx context.Context, session *mcp.ClientSession) ([]*mcp.Resource, error)
- func (s *ExampleTestSuite) ListTools(ctx context.Context, session *mcp.ClientSession) ([]*mcp.Tool, error)
- func (s *ExampleTestSuite) ReadResource(ctx context.Context, session *mcp.ClientSession, uri string) (*mcp.ReadResourceResult, error)
- func (s *ExampleTestSuite) SendMCPRequest(req MCPRequest) (*MCPResponse, error)
- func (s *ExampleTestSuite) SetHandler(handler http.Handler)
- func (s *ExampleTestSuite) SetupSuite()
- func (s *ExampleTestSuite) SetupTest()
- func (s *ExampleTestSuite) TearDownTest()
- func (s *ExampleTestSuite) TestHealth()
- func (s *ExampleTestSuite) URL() string
- func (s *ExampleTestSuite) WithMCPSession(handler *mcpio.Handler, testFunc func(*mcp.ClientSession))
- type IntegrationSuite
- type MCPError
- type MCPRequest
- type MCPResponse
- type MCPSession
- type MockRequestContext
- func (m *MockRequestContext) GetHeaders() http.Header
- func (m *MockRequestContext) GetIdentifier() string
- func (m *MockRequestContext) GetMeta() map[string]any
- func (m *MockRequestContext) GetProgressToken() any
- func (m *MockRequestContext) GetSession() *capabilities.Session
- func (m *MockRequestContext) GetTokenInfo() *auth.TokenInfo
- type MockServerSession
- func (m *MockServerSession) Close() error
- func (m *MockServerSession) CreateMessage(ctx context.Context, params *mcp.CreateMessageParams) (*mcp.CreateMessageResult, error)
- func (m *MockServerSession) Elicit(ctx context.Context, params *mcp.ElicitParams) (*mcp.ElicitResult, error)
- func (m *MockServerSession) ID() string
- func (m *MockServerSession) InitializeParams() *mcp.InitializeParams
- func (m *MockServerSession) ListRoots(ctx context.Context, params *mcp.ListRootsParams) (*mcp.ListRootsResult, error)
- func (m *MockServerSession) Log(ctx context.Context, params *mcp.LoggingMessageParams) error
- func (m *MockServerSession) NotifyProgress(ctx context.Context, params *mcp.ProgressNotificationParams) error
- func (m *MockServerSession) Wait() error
- type MockSession
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultTestImplementation ¶
func DefaultTestImplementation() *mcp.Implementation
DefaultTestImplementation returns the standard test client implementation
Types ¶
type ExampleTestSuite ¶
type ExampleTestSuite struct {
suite.Suite
ProjectRoot string
ExampleName string
// contains filtered or unexported fields
}
ExampleTestSuite provides utilities for testing MCP examples using testify suites
func (*ExampleTestSuite) BinaryPath ¶
func (s *ExampleTestSuite) BinaryPath() string
BinaryPath returns the path to the built example binary
func (*ExampleTestSuite) BuildBinary ¶
func (s *ExampleTestSuite) BuildBinary() string
BuildBinary builds the example binary in a temp directory
func (*ExampleTestSuite) CallTool ¶
func (s *ExampleTestSuite) CallTool(ctx context.Context, session *mcp.ClientSession, name string, args map[string]any) ([]mcp.Content, bool, error)
CallTool calls an MCP tool and returns the result
func (*ExampleTestSuite) GetPrompt ¶
func (s *ExampleTestSuite) GetPrompt(ctx context.Context, session *mcp.ClientSession, name string, args map[string]string) ([]*mcp.PromptMessage, error)
GetPrompt gets an MCP prompt and returns the messages
func (*ExampleTestSuite) ListPrompts ¶
func (s *ExampleTestSuite) ListPrompts(ctx context.Context, session *mcp.ClientSession) ([]*mcp.Prompt, error)
ListPrompts lists available prompts from a session
func (*ExampleTestSuite) ListResources ¶
func (s *ExampleTestSuite) ListResources(ctx context.Context, session *mcp.ClientSession) ([]*mcp.Resource, error)
ListResources lists available resources from a session
func (*ExampleTestSuite) ListTools ¶
func (s *ExampleTestSuite) ListTools(ctx context.Context, session *mcp.ClientSession) ([]*mcp.Tool, error)
ListTools lists available tools from a session
func (*ExampleTestSuite) ReadResource ¶
func (s *ExampleTestSuite) ReadResource(ctx context.Context, session *mcp.ClientSession, uri string) (*mcp.ReadResourceResult, error)
ReadResource reads an MCP resource
func (*ExampleTestSuite) SendMCPRequest ¶
func (s *ExampleTestSuite) SendMCPRequest(req MCPRequest) (*MCPResponse, error)
SendMCPRequest sends a JSON-RPC request to the MCP endpoint (for HTTP-based tests)
func (*ExampleTestSuite) SetHandler ¶
func (s *ExampleTestSuite) SetHandler(handler http.Handler)
SetHandler sets the HTTP handler for HTTP-based tests
func (*ExampleTestSuite) SetupSuite ¶
func (s *ExampleTestSuite) SetupSuite()
SetupSuite initializes the test suite
func (*ExampleTestSuite) SetupTest ¶
func (s *ExampleTestSuite) SetupTest()
SetupTest sets up HTTP server if handler is configured
func (*ExampleTestSuite) TearDownTest ¶
func (s *ExampleTestSuite) TearDownTest()
TearDownTest stops the HTTP server after each test
func (*ExampleTestSuite) TestHealth ¶
func (s *ExampleTestSuite) TestHealth()
TestHealth tests the /health endpoint (for HTTP-based tests)
func (*ExampleTestSuite) URL ¶
func (s *ExampleTestSuite) URL() string
URL returns the HTTP server URL (for HTTP-based tests)
func (*ExampleTestSuite) WithMCPSession ¶
func (s *ExampleTestSuite) WithMCPSession(handler *mcpio.Handler, testFunc func(*mcp.ClientSession))
WithMCPSession tests an MCP server using in-memory transport
type IntegrationSuite ¶
IntegrationSuite provides common setup and teardown for integration tests
func (*IntegrationSuite) SetupSuite ¶
func (s *IntegrationSuite) SetupSuite()
SetupSuite builds the example binaries needed for integration testing
func (*IntegrationSuite) SetupTest ¶
func (s *IntegrationSuite) SetupTest()
SetupTest initializes the context for each test
func (*IntegrationSuite) TearDownSuite ¶
func (s *IntegrationSuite) TearDownSuite()
TearDownSuite cleans up built binaries
type MCPError ¶
type MCPError struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
MCPError represents an MCP error
type MCPRequest ¶
type MCPRequest struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params any `json:"params,omitempty"`
ID int `json:"id"`
}
MCPRequest represents a JSON-RPC request
type MCPResponse ¶
type MCPResponse struct {
JSONRPC string `json:"jsonrpc"`
Result json.RawMessage `json:"result,omitempty"`
Error *MCPError `json:"error,omitempty"`
ID int `json:"id"`
}
MCPResponse represents a JSON-RPC response
type MCPSession ¶
type MCPSession struct {
*mcp.ClientSession
// contains filtered or unexported fields
}
MCPSession wraps an MCP client session with automatic cleanup
func ConnectInMemory ¶
func ConnectInMemory(t *testing.T, handler *mcpio.Handler) *MCPSession
ConnectInMemory sets up an in-memory MCP client/server connection for testing. It starts the server in a goroutine and connects a client, returning the session. Cleanup is automatically registered via t.Cleanup().
func ConnectWithProgressCapture ¶
func ConnectWithProgressCapture(t *testing.T, handler *mcpio.Handler) (*MCPSession, func() []*mcp.ProgressNotificationParams)
ConnectWithProgressCapture sets up an in-memory MCP client/server connection that captures progress notifications. Returns the session and a function to retrieve captured notifications (thread-safe).
func (*MCPSession) Close ¶
func (s *MCPSession) Close()
Close closes the MCP session and logs any errors
type MockRequestContext ¶
MockRequestContext is a mock implementation of mcpio.RequestContext interface
func NewMockRequestContext ¶
func NewMockRequestContext(session *capabilities.Session) *MockRequestContext
NewMockRequestContext creates a new mock request context with auto-configured mock expectations. Tests can override the default return values by calling .On() methods.
func (*MockRequestContext) GetHeaders ¶
func (m *MockRequestContext) GetHeaders() http.Header
GetHeaders returns all request headers
func (*MockRequestContext) GetIdentifier ¶
func (m *MockRequestContext) GetIdentifier() string
GetIdentifier returns the request identifier
func (*MockRequestContext) GetMeta ¶
func (m *MockRequestContext) GetMeta() map[string]any
GetMeta returns metadata from the request parameters
func (*MockRequestContext) GetProgressToken ¶
func (m *MockRequestContext) GetProgressToken() any
GetProgressToken returns the progress token from the request
func (*MockRequestContext) GetSession ¶
func (m *MockRequestContext) GetSession() *capabilities.Session
GetSession returns the session capability for advanced features
func (*MockRequestContext) GetTokenInfo ¶
func (m *MockRequestContext) GetTokenInfo() *auth.TokenInfo
GetTokenInfo returns authentication token information
type MockServerSession ¶
MockServerSession is a test mock for the serverSession interface. It mocks the MCP SDK's ServerSession at the lowest level.
func (*MockServerSession) Close ¶
func (m *MockServerSession) Close() error
func (*MockServerSession) CreateMessage ¶
func (m *MockServerSession) CreateMessage(ctx context.Context, params *mcp.CreateMessageParams) (*mcp.CreateMessageResult, error)
func (*MockServerSession) Elicit ¶
func (m *MockServerSession) Elicit(ctx context.Context, params *mcp.ElicitParams) (*mcp.ElicitResult, error)
func (*MockServerSession) ID ¶
func (m *MockServerSession) ID() string
func (*MockServerSession) InitializeParams ¶
func (m *MockServerSession) InitializeParams() *mcp.InitializeParams
func (*MockServerSession) ListRoots ¶
func (m *MockServerSession) ListRoots(ctx context.Context, params *mcp.ListRootsParams) (*mcp.ListRootsResult, error)
func (*MockServerSession) Log ¶
func (m *MockServerSession) Log(ctx context.Context, params *mcp.LoggingMessageParams) error
func (*MockServerSession) NotifyProgress ¶
func (m *MockServerSession) NotifyProgress(ctx context.Context, params *mcp.ProgressNotificationParams) error
func (*MockServerSession) Wait ¶
func (m *MockServerSession) Wait() error
type MockSession ¶
type MockSession struct {
*MockServerSession
Session *capabilities.Session
}
MockSession is a backwards-compatible wrapper that provides both the mock and the Session for tests. Tests should use the Session field for WithSession.
func NewMockSession ¶
func NewMockSession() *MockSession
NewMockSession creates a MockSession with both the low-level mock and the Session wrapper.
func (*MockSession) SetupElicitation ¶
func (m *MockSession) SetupElicitation()
SetupElicitation configures the mock to support elicitation. Call this before setting up Elicit expectations.
func (*MockSession) SetupNoCapabilities ¶
func (m *MockSession) SetupNoCapabilities()
SetupNoCapabilities configures the mock with no capabilities. Use this when testing capability checks that should return false.
func (*MockSession) SetupSampling ¶
func (m *MockSession) SetupSampling()
SetupSampling configures the mock to support sampling.