Documentation
¶
Index ¶
- func ExampleMockMCPServer_receivedRequests()
- func ExampleNewMockMCPServer_withCalls()
- func StdioServerCommand(t testing.TB) []string
- type APIKey
- type Call
- type CallError
- type IncomingHTTPRequest
- type IncomingRequest
- type MockMCPServer
- func (m *MockMCPServer) BaseURL() *url.URL
- func (m *MockMCPServer) Close()
- func (m *MockMCPServer) ReceivedHTTPRequests() []IncomingHTTPRequest
- func (m *MockMCPServer) ReceivedRequests() []IncomingRequest
- func (m *MockMCPServer) Start(t testing.TB)
- func (m *MockMCPServer) StartInMemory(t testing.TB) *mcp.InMemoryTransport
- func (m *MockMCPServer) StartStdio(t testing.TB) *mcp.IOTransport
- func (m *MockMCPServer) TLSCertPEM() ([]byte, error)
- func (m *MockMCPServer) WaitForRequests(ctx context.Context, n int) error
- type Option
- func WithCalls(calls ...Call) Option
- func WithHostHandler(host string, handler http.Handler) Option
- func WithKeepalivePings() Option
- func WithOAuthDiscoveryResources() Option
- func WithOAuthProtection() Option
- func WithProtectedResourceMetadata(meta oauthex.ProtectedResourceMetadata) Option
- func WithRequiredHeader(name, value string) Option
- func WithRequiredHeaderFor(name, value string, predicate func(*http.Request) bool) Option
- func WithTLSServer() Option
- func WithToolListChangedNotificationsDisabled() Option
- func WithUnixSocketPath(path string) Option
- func WithWWWAuthenticateProbe() Option
- type ProgressUpdate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExampleMockMCPServer_receivedRequests ¶
func ExampleMockMCPServer_receivedRequests()
ExampleMockMCPServer_receivedRequests demonstrates inspecting the recorded tool invocations after the client finishes calling the MCP server.
func ExampleNewMockMCPServer_withCalls ¶
func ExampleNewMockMCPServer_withCalls()
ExampleNewMockMCPServer_withCalls shows how to queue scripted tool calls when constructing the mock server.
func StdioServerCommand ¶
StdioServerCommand returns the command args to launch the stdio MCP server script. It fails the test if the script cannot be prepared.
Types ¶
type Call ¶
type Call struct {
Tool string
Result json.RawMessage
DynamicResult func(json.RawMessage) (json.RawMessage, error)
Error *CallError
Progress []ProgressUpdate
ResponseHeaders http.Header
}
Call defines a scripted tool invocation.
type CallError ¶
type CallError struct {
Message string
}
CallError describes the error payload returned by the tool.
type IncomingHTTPRequest ¶
IncomingHTTPRequest captures an HTTP request received by the mock server.
type IncomingRequest ¶
type IncomingRequest struct {
Tool string
Arguments json.RawMessage
Headers http.Header
}
IncomingRequest captures the tool arguments and headers that reached the mock.
type MockMCPServer ¶
type MockMCPServer struct {
// contains filtered or unexported fields
}
func NewMockMCPServer ¶
func NewMockMCPServer(opts ...Option) *MockMCPServer
NewMockMCPServer constructs an empty mock server configured by optional options.
func (*MockMCPServer) BaseURL ¶
func (m *MockMCPServer) BaseURL() *url.URL
BaseURL returns the HTTP endpoint the MCP client should connect to.
func (*MockMCPServer) Close ¶
func (m *MockMCPServer) Close()
Close shuts down the server and asserts all scripted calls were consumed.
func (*MockMCPServer) ReceivedHTTPRequests ¶
func (m *MockMCPServer) ReceivedHTTPRequests() []IncomingHTTPRequest
ReceivedHTTPRequests returns all HTTP requests observed by the mock server.
func (*MockMCPServer) ReceivedRequests ¶
func (m *MockMCPServer) ReceivedRequests() []IncomingRequest
ReceivedRequests returns the recorded tool requests in order.
func (*MockMCPServer) Start ¶
func (m *MockMCPServer) Start(t testing.TB)
Start launches the mock MCP server and registers cleanup with t.
func (*MockMCPServer) StartInMemory ¶
func (m *MockMCPServer) StartInMemory(t testing.TB) *mcp.InMemoryTransport
StartInMemory launches the mock MCP server on an in-memory transport.
func (*MockMCPServer) StartStdio ¶
func (m *MockMCPServer) StartStdio(t testing.TB) *mcp.IOTransport
StartStdio launches the mock MCP server over stdio and returns a client transport. Note that stdio is process-wide, so this method should not be used concurrently.
func (*MockMCPServer) TLSCertPEM ¶
func (m *MockMCPServer) TLSCertPEM() ([]byte, error)
TLSCertPEM returns the server certificate PEM for TLS-enabled servers.
func (*MockMCPServer) WaitForRequests ¶
func (m *MockMCPServer) WaitForRequests(ctx context.Context, n int) error
WaitForRequests blocks until at least n tool calls have completed or ctx expires.
type Option ¶
type Option func(*MockMCPServer)
MockMCPServer hosts a Streamable HTTP MCP server backed by scripted tool handlers.
func WithHostHandler ¶
WithHostHandler serves requests for host with handler before the default MCP routes.
func WithKeepalivePings ¶
func WithKeepalivePings() Option
WithKeepalivePings injects SSE keepalive ping events ahead of streamable responses.
func WithOAuthDiscoveryResources ¶
func WithOAuthDiscoveryResources() Option
WithOAuthDiscoveryResources enables the well-known OAuth ProtectedResourceMetaData endpoint.
func WithOAuthProtection ¶
func WithOAuthProtection() Option
WithOAuthProtection enables OAuth discovery endpoints and protects the MCP server with auth.RequireBearerToken using a static in-memory API key set.
func WithProtectedResourceMetadata ¶
func WithProtectedResourceMetadata(meta oauthex.ProtectedResourceMetadata) Option
WithProtectedResourceMetadata sets the metadata returned by the well-known OAuth Protected Resource Metadata endpoint.
func WithRequiredHeader ¶
WithRequiredHeader requires every HTTP request to carry name: value.
func WithRequiredHeaderFor ¶
WithRequiredHeaderFor requires matching HTTP requests to carry name: value.
func WithTLSServer ¶
func WithTLSServer() Option
WithTLSServer starts the mock MCP server with TLS enabled.
func WithToolListChangedNotificationsDisabled ¶
func WithToolListChangedNotificationsDisabled() Option
WithToolListChangedNotificationsDisabled disables tool list changed notifications.
func WithUnixSocketPath ¶
WithUnixSocketPath makes the mock serve HTTP over the provided Unix-domain socket.
func WithWWWAuthenticateProbe ¶
func WithWWWAuthenticateProbe() Option
WithWWWAuthenticateProbe enables a 401 response with WWW-Authenticate header for empty POST probes.
type ProgressUpdate ¶
ProgressUpdate emits a notifications/progress event during a streaming response.