testengine

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallResult

type CallResult struct {
	Result        *mcp.CallToolResult
	Duration      time.Duration
	ToolsEnabled  []string
	ToolsDisabled []string
}

CallResult wraps the result of a tool call with additional metadata.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine wires together a process manager, bridge, and MCP client for testing tool processes.

func New

func New(file string, opts ...Option) *Engine

New creates a new Engine for the given tool file.

func (*Engine) CallTool

func (e *Engine) CallTool(ctx context.Context, name string, args map[string]any) (*CallResult, error)

CallTool calls a tool by name with the given arguments.

func (*Engine) GetPrompt

func (e *Engine) GetPrompt(ctx context.Context, name string, args map[string]string) (*mcp.GetPromptResult, error)

GetPrompt gets a prompt by name with the given arguments.

func (*Engine) ListPrompts

func (e *Engine) ListPrompts(ctx context.Context) ([]*mcp.Prompt, error)

ListPrompts returns the prompts available from the server.

func (*Engine) ListResources

func (e *Engine) ListResources(ctx context.Context) ([]*mcp.Resource, error)

ListResources returns the resources available from the server.

func (*Engine) ListTools

func (e *Engine) ListTools(ctx context.Context) ([]*mcp.Tool, error)

ListTools returns the tools available from the server.

func (*Engine) OnToolsChanged

func (e *Engine) OnToolsChanged(fn func([]*mcp.Tool))

OnToolsChanged registers a callback for tool list changes.

func (*Engine) ReadResource

func (e *Engine) ReadResource(ctx context.Context, uri string) (*mcp.ReadResourceResult, error)

ReadResource reads a resource by URI.

func (*Engine) Reload

func (e *Engine) Reload(ctx context.Context) error

Reload reloads the tool process and refreshes the bridge.

func (*Engine) Start

func (e *Engine) Start(ctx context.Context) error

Start initializes the process manager, bridge, and MCP client connection.

func (*Engine) Stop

func (e *Engine) Stop()

Stop shuts down the engine.

func (*Engine) Trace

func (e *Engine) Trace() *TraceLog

Trace returns the protocol trace log.

type Option

type Option func(*engineConfig)

Option configures the Engine.

func WithCallTimeout

func WithCallTimeout(d time.Duration) Option

WithCallTimeout sets the timeout for tool calls.

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger sets the logger for the engine.

func WithRuntime

func WithRuntime(runtime string) Option

WithRuntime overrides the auto-detected runtime command.

type TraceEntry

type TraceEntry struct {
	Seq       uint64    `json:"seq"`
	Timestamp time.Time `json:"timestamp"`
	Direction string    `json:"direction"` // "send" or "recv"
	Raw       string    `json:"raw"`       // full JSON-RPC message
	Method    string    `json:"method,omitempty"`
}

TraceEntry records a single JSON-RPC message.

type TraceLog

type TraceLog struct {
	// contains filtered or unexported fields
}

TraceLog provides thread-safe storage and pub/sub for protocol trace entries.

func NewTraceLog

func NewTraceLog() *TraceLog

NewTraceLog creates a new TraceLog.

func (*TraceLog) Clear

func (t *TraceLog) Clear()

Clear removes all recorded entries.

func (*TraceLog) Entries

func (t *TraceLog) Entries() []TraceEntry

Entries returns a snapshot of all recorded entries.

func (*TraceLog) Subscribe

func (t *TraceLog) Subscribe() chan TraceEntry

Subscribe returns a channel that receives new entries as they are recorded.

func (*TraceLog) Unsubscribe

func (t *TraceLog) Unsubscribe(ch chan TraceEntry)

Unsubscribe removes a subscription channel.

func (*TraceLog) Writer

func (t *TraceLog) Writer() io.Writer

Writer returns an io.Writer that parses LoggingTransport output lines and records them as TraceEntries.

Jump to

Keyboard shortcuts

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