testutil

package
v0.0.0-...-3f40f48 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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(serverBuilder func() (*mcp.Server, error), testFunc func(*mcp.ClientSession))

WithMCPSession tests an MCP server using in-memory transport

type IntegrationSuite

type IntegrationSuite struct {
	suite.Suite
	ProjectRoot string
	Ctx         context.Context
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL