Documentation
¶
Overview ¶
Package testmcp provides an in-process mock MCP server backed by the official MCP Go SDK. It is used by tests that need to exercise proxy or client code paths against a real MCP endpoint without depending on an external process.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSSEServer ¶
NewSSEServer returns a running httptest.Server that speaks the legacy MCP HTTP+SSE transport and exposes the tools registered on s.
func NewStreamableHTTPServer ¶
NewStreamableHTTPServer returns a running httptest.Server that speaks the MCP Streamable HTTP transport and exposes the tools registered on s.
Types ¶
type Server ¶
type Server struct {
// Tools are the tools the mock server will register before starting.
// Appending to Tools after a transport server has been constructed has
// no effect — registration happens once, at server start.
Tools []Tool
}
Server collects the tools a mock MCP server should expose. Populate Tools, then hand the Server to NewStreamableHTTPServer or NewSSEServer to get a running httptest.Server speaking the corresponding MCP transport.
type Tool ¶
type Tool struct {
// Annotations carries optional UI hints (title, read-only, destructive,
// idempotent, open-world).
Annotations *mcp.ToolAnnotations
// Description is the human-readable tool description returned to MCP
// clients.
Description string
// Icons lists optional icon references for the tool.
Icons []mcp.Icon
// InputSchema is the JSON Schema object describing the tool's accepted
// arguments. Marshaled to [encoding/json.RawMessage] before being passed
// to the MCP SDK so tests can supply arbitrary shapes.
InputSchema map[string]any
// Meta carries optional protocol-level metadata.
Meta mcp.Meta
// Name is the tool's programmatic identifier (the value clients send as
// "name" in a tools/call request).
Name string
// OutputSchema is the optional JSON Schema describing structured tool
// output. When nil the server emits no output schema.
OutputSchema map[string]any
// Response controls the content the mock returns when this tool is
// invoked.
Response ToolResponse
// Title is the optional UI-facing tool name.
Title string
}
Tool describes a single tool that the mock MCP server will expose. Fields mirror mcp.Tool so tests can exercise the full tool-definition surface, plus a Response field that controls what a tool call returns.
type ToolResponse ¶
type ToolResponse struct {
// Content is the list of content blocks returned to the MCP client.
// Each entry mirrors the MCP content-object shape — currently only
// type="text" entries (with a "text" string) are materialized by the
// mock.
Content []map[string]any
// IsError, when true, causes the mock to return a CallToolResult with
// IsError set so tests can exercise tool-side error handling without
// producing a protocol-level error.
IsError bool
}
ToolResponse is the content returned when a Tool is called.