Documentation
¶
Overview ¶
Package testutil provides shared testing utilities for MCP server tests.
Package testutil provides schema validation helpers for testing MCP tools
Index ¶
- func ChatMCPServerMock(t *testing.T, status int, response []byte) *mcp.Server
- func CheckMessage(t *testing.T, result mcp.Result)
- func DeskClientMock(status int, response []byte) (*deskclient.Client, *httptest.Server)
- func DeskMCPServerMock(t *testing.T, status int, response []byte) (*mcp.Server, func())
- func ExecuteToolRequest(t *testing.T, mcpServer *mcp.Server, toolName string, args map[string]any, ...)
- func GetInvalidTestData() map[string]map[string]map[string]any
- func GetValidTestData() map[string]map[string]map[string]any
- func ProjectsEngineMock(status int, response []byte) *twapi.Engine
- func ProjectsMCPServerMock(t *testing.T, status int, response []byte) *mcp.Server
- func ProjectsMCPServerMockWithRequestBody(t *testing.T, status int, response []byte) (*mcp.Server, *[]byte)
- func ProjectsMCPServerRoutedMock(t *testing.T, routes []ProjectsMockRoute, fallbackStatus int, ...) *mcp.Server
- func ProjectsMCPServerSequencedMock(t *testing.T, status int, responses ...[]byte) *mcp.Server
- func SpacesMCPServerMock(t *testing.T, status int, response []byte) (*mcp.Server, func())
- type ExecuteToolRequestOption
- type ExecuteToolRequestOptions
- type ProjectsMockRoute
- type ProjectsSessionMock
- type SchemaValidationTestSuite
- type ToolRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChatMCPServerMock ¶ added in v1.21.4
ChatMCPServerMock creates a mock MCP server for twchat testing. The twchat tools ride the shared twapi.Engine, so it reuses ProjectsEngineMock to return the canned HTTP response.
func CheckMessage ¶
CheckMessage validates that a message represents a successful tool execution
func DeskClientMock ¶
DeskClientMock creates a mock desk client with a test server
func DeskMCPServerMock ¶
DeskMCPServerMock creates a mock MCP server for twdesk testing It injects the test server URL into the request context so handlers use the correct endpoint
func ExecuteToolRequest ¶
func ExecuteToolRequest( t *testing.T, mcpServer *mcp.Server, toolName string, args map[string]any, optFuncs ...ExecuteToolRequestOption, )
ExecuteToolRequest executes a tool request and validates the response
func GetInvalidTestData ¶ added in v1.5.8
GetInvalidTestData returns invalid test data for all tools
func GetValidTestData ¶ added in v1.5.8
GetValidTestData returns valid test data for all tools. All required fields (including nullable optional ones) must be provided — pass nil to satisfy a required nullable field without setting a value.
func ProjectsEngineMock ¶
ProjectsEngineMock creates a mock twapi.Engine with the given HTTP response
func ProjectsMCPServerMock ¶
ProjectsMCPServerMock creates a mock MCP server for twprojects testing
func ProjectsMCPServerMockWithRequestBody ¶ added in v1.23.0
func ProjectsMCPServerMockWithRequestBody(t *testing.T, status int, response []byte) (*mcp.Server, *[]byte)
ProjectsMCPServerMockWithRequestBody is like ProjectsMCPServerMock but also captures the body of the most recent HTTP request the engine sent, so tests can assert on the serialized request payload. The returned pointer is populated after a tool invokes the engine.
func ProjectsMCPServerRoutedMock ¶ added in v1.21.0
func ProjectsMCPServerRoutedMock( t *testing.T, routes []ProjectsMockRoute, fallbackStatus int, fallbackBody []byte, ) *mcp.Server
ProjectsMCPServerRoutedMock creates a mock MCP server for twprojects testing whose engine returns different responses based on a substring match against the request URL. Use this when a single tool dispatches calls to multiple endpoints that need distinct status codes (e.g. record create, which lists fields with 200 before posting the record with 201). Requests that don't match any route fall back to fallbackStatus/fallbackBody.
func ProjectsMCPServerSequencedMock ¶ added in v1.24.1
ProjectsMCPServerSequencedMock creates a mock MCP server for twprojects testing whose engine returns the given response bodies in order, one per HTTP request the engine makes. Once the sequence is exhausted the final body is repeated. This lets tests drive a tool's internal pagination loop with a distinct body per page, or exercise a never-ending "hasMore" by supplying a single always-more body. All responses share the same status code.
Types ¶
type ExecuteToolRequestOption ¶ added in v1.6.2
type ExecuteToolRequestOption func(*ExecuteToolRequestOptions)
ExecuteToolRequestOption is a function that modifies ExecuteToolRequestOptions.
func ExecuteToolRequestWithCheckMessage ¶ added in v1.6.2
func ExecuteToolRequestWithCheckMessage(f func(t *testing.T, result mcp.Result)) ExecuteToolRequestOption
ExecuteToolRequestWithCheckMessage executes a tool request and validates the response with a custom check function. Any nil function will be ignored.
type ExecuteToolRequestOptions ¶ added in v1.6.2
type ExecuteToolRequestOptions struct {
// contains filtered or unexported fields
}
ExecuteToolRequestOptions represents options for ExecuteToolRequest.
type ProjectsMockRoute ¶ added in v1.21.0
ProjectsMockRoute pairs a substring match against the request URL path with the status and body to return when it matches.
type ProjectsSessionMock ¶
type ProjectsSessionMock struct{}
ProjectsSessionMock implements a mock session for twprojects testing
func (ProjectsSessionMock) Authenticate ¶
Authenticate implements the Authenticate method for ProjectsSessionMock
func (ProjectsSessionMock) Server ¶
func (s ProjectsSessionMock) Server() string
Server implements the Server method for ProjectsSessionMock
type SchemaValidationTestSuite ¶ added in v1.5.8
type SchemaValidationTestSuite struct {
// contains filtered or unexported fields
}
SchemaValidationTestSuite provides a comprehensive test suite for validating MCP tool JSON schemas
func NewSchemaValidationTestSuite ¶ added in v1.5.8
func NewSchemaValidationTestSuite() *SchemaValidationTestSuite
NewSchemaValidationTestSuite creates a new test suite with all twdesk tools
func (*SchemaValidationTestSuite) GetTool ¶ added in v1.5.8
func (s *SchemaValidationTestSuite) GetTool(toolName string) (toolsets.ToolWrapper, bool)
GetTool returns a tool by name if it exists
func (*SchemaValidationTestSuite) RunAllSchemaValidationTests ¶ added in v1.5.8
func (s *SchemaValidationTestSuite) RunAllSchemaValidationTests(t *testing.T)
RunAllSchemaValidationTests runs comprehensive schema validation tests for all tools
func (*SchemaValidationTestSuite) RunToolSchemaValidation ¶ added in v1.5.8
func (s *SchemaValidationTestSuite) RunToolSchemaValidation(t *testing.T, toolName string, tool toolsets.ToolWrapper)
RunToolSchemaValidation runs schema validation tests for a single tool (exported version)
type ToolRequest ¶
type ToolRequest struct {
mcp.CallToolRequest
JSONRPC string `json:"jsonrpc"`
ID int64 `json:"id"`
}
ToolRequest represents a tool request for testing