debug

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildReplayScript added in v0.9.1

func BuildReplayScript(events []*Event, conn ConnectionInfo) string

BuildReplayScript turns a recorded event stream into a runnable shell script of equivalent `mcp-tui` CLI commands. Only replayable client→server requests (tools/call, resources/read, prompts/get) are translated — every other event type is skipped. The script is directly usable for CLI automation: it targets the same server the recording was made against.

func CreateDebugClient

func CreateDebugClient(impl *officialMCP.Implementation, tracer *EventTracer, extra ...*officialMCP.ClientOptions) *officialMCP.Client

CreateDebugClient creates an MCP client with enhanced debugging capabilities. Optional extra ClientOptions are merged on top of the debug defaults so that callers can install handlers (e.g. CreateMessageHandler for sampling) while still getting tracing middleware. When extra is nil the default debug options are used as-is.

Types

type ConnectionInfo added in v0.9.1

type ConnectionInfo struct {
	Transport string // "stdio", "sse", "http", "streamable-http"
	Command   string // STDIO server command
	Args      []string
	URL       string // HTTP/SSE server URL
}

ConnectionInfo carries the minimum connection details needed to reconstruct an equivalent `mcp-tui` CLI invocation for a recorded session. It is a plain value struct so the debug package does not need to import the config package (which would create an import cycle) — callers translate their own ConnectionConfig into this shape.

type DebugClientOptions

type DebugClientOptions struct {
	*officialMCP.ClientOptions
	EventTracer *EventTracer
}

DebugClientOptions provides enhanced client options with tracing

func NewDebugClientOptions

func NewDebugClientOptions(tracer *EventTracer) *DebugClientOptions

NewDebugClientOptions creates client options with integrated event tracing

type DebugSession

type DebugSession struct {
	*officialMCP.ClientSession
	// contains filtered or unexported fields
}

DebugSession wraps a ClientSession with enhanced debugging capabilities

func NewDebugSession

func NewDebugSession(session *officialMCP.ClientSession, tracer *EventTracer) *DebugSession

NewDebugSession creates a debug-enabled session wrapper

func (*DebugSession) ExportSessionEvents

func (ds *DebugSession) ExportSessionEvents() ([]byte, error)

ExportSessionEvents exports all events for this session

func (*DebugSession) GetEventTracer

func (ds *DebugSession) GetEventTracer() *EventTracer

GetEventTracer returns the associated event tracer

func (*DebugSession) GetTracingStatistics

func (ds *DebugSession) GetTracingStatistics() map[string]interface{}

GetTracingStatistics returns event tracing statistics for this session

func (*DebugSession) TraceSessionState

func (ds *DebugSession) TraceSessionState(state string, details map[string]interface{})

TraceSessionState traces session state changes

type Event

type Event struct {
	ID        string                 `json:"id"`
	Type      EventType              `json:"type"`
	Timestamp time.Time              `json:"timestamp"`
	SessionID string                 `json:"session_id,omitempty"`
	Method    string                 `json:"method,omitempty"`
	RequestID interface{}            `json:"request_id,omitempty"`
	Data      map[string]interface{} `json:"data,omitempty"`
	Duration  *time.Duration         `json:"duration,omitempty"`
}

Event represents a traced MCP event

type EventTracer

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

EventTracer provides comprehensive MCP event tracing capabilities

func NewEventTracer

func NewEventTracer(maxEvents int) *EventTracer

NewEventTracer creates a new MCP event tracer

func (*EventTracer) Clear

func (et *EventTracer) Clear()

Clear removes all traced events

func (*EventTracer) ExportEvents

func (et *EventTracer) ExportEvents() ([]byte, error)

ExportEvents exports events in JSON format

func (*EventTracer) GetEvents

func (et *EventTracer) GetEvents() []*Event

GetEvents returns a copy of all traced events

func (*EventTracer) GetRecentEvents

func (et *EventTracer) GetRecentEvents(count int) []*Event

GetRecentEvents returns the most recent N events

func (*EventTracer) GetStatistics

func (et *EventTracer) GetStatistics() map[string]interface{}

GetEventsByType returns events filtered by type GetStatistics returns event tracing statistics

func (*EventTracer) SetEnabled

func (et *EventTracer) SetEnabled(enabled bool)

SetEnabled enables or disables event tracing

func (*EventTracer) SetSessionID

func (et *EventTracer) SetSessionID(sessionID string)

SetSessionID sets the current session ID for event correlation

func (*EventTracer) TraceConnectionEnd

func (et *EventTracer) TraceConnectionEnd(startEvent *Event, success bool, error string) *Event

TraceConnectionEnd records a connection end event with duration

func (*EventTracer) TraceConnectionStart

func (et *EventTracer) TraceConnectionStart(transportType string, target string) *Event

TraceConnectionStart records a connection start event

func (*EventTracer) TraceError

func (et *EventTracer) TraceError(operation string, error error, context map[string]interface{}) *Event

TraceError records an error event

func (*EventTracer) TraceNotificationReceived

func (et *EventTracer) TraceNotificationReceived(method string, params interface{}) *Event

TraceNotificationReceived records an incoming MCP notification

func (*EventTracer) TraceProgress

func (et *EventTracer) TraceProgress(progressToken interface{}, progress float64, operation string) *Event

TraceProgress records progress notifications

func (*EventTracer) TraceRequestSent

func (et *EventTracer) TraceRequestSent(method string, requestID interface{}, params interface{}) *Event

TraceRequestSent records an outgoing MCP request

func (*EventTracer) TraceResponseReceived

func (et *EventTracer) TraceResponseReceived(requestID interface{}, result interface{}, error interface{}) *Event

TraceResponseReceived records an incoming MCP response

func (*EventTracer) TraceSessionState

func (et *EventTracer) TraceSessionState(state string, details map[string]interface{}) *Event

TraceSessionState records session state changes

func (*EventTracer) TraceTransportState

func (et *EventTracer) TraceTransportState(state string, details map[string]interface{}) *Event

TraceTransportState records transport state changes

type EventType

type EventType int

EventType represents different types of MCP events

const (
	EventConnectionStart EventType = iota
	EventConnectionEnd
	EventRequestSent
	EventResponseReceived
	EventNotificationSent
	EventNotificationReceived
	EventError
	EventTransportState
	EventSessionState
	EventProgress
)

func (EventType) String

func (e EventType) String() string

type TracingMiddleware

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

TracingMiddleware creates MCP middleware that integrates with the event tracer

func NewTracingMiddleware

func NewTracingMiddleware(tracer *EventTracer) *TracingMiddleware

NewTracingMiddleware creates a new tracing middleware

func (*TracingMiddleware) CreateProgressHandler

func (tm *TracingMiddleware) CreateProgressHandler() func(ctx context.Context, req *officialMCP.ProgressNotificationClientRequest)

CreateProgressHandler creates a progress notification handler with tracing

func (*TracingMiddleware) CreateSendingMiddleware

func (tm *TracingMiddleware) CreateSendingMiddleware() officialMCP.Middleware

CreateSendingMiddleware creates middleware for outgoing MCP requests

func (*TracingMiddleware) TraceNotificationReceived

func (tm *TracingMiddleware) TraceNotificationReceived(method string, params interface{})

TraceNotificationReceived can be called directly to trace incoming notifications

type TransportDebugger

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

TransportDebugger provides transport-specific debugging capabilities

func NewTransportDebugger

func NewTransportDebugger(tracer *EventTracer, transportType string) *TransportDebugger

NewTransportDebugger creates a transport-specific debugger

func (*TransportDebugger) TraceConnectionEnd

func (td *TransportDebugger) TraceConnectionEnd(startEvent *Event, success bool, error string) *Event

TraceConnectionEnd traces transport connection end

func (*TransportDebugger) TraceConnectionStart

func (td *TransportDebugger) TraceConnectionStart(target string) *Event

TraceConnectionStart traces transport connection start

func (*TransportDebugger) TraceTransportError

func (td *TransportDebugger) TraceTransportError(operation string, err error, context map[string]interface{}) *Event

TraceTransportError traces transport-specific errors

func (*TransportDebugger) TraceTransportState

func (td *TransportDebugger) TraceTransportState(state string, details map[string]interface{}) *Event

TraceTransportState traces transport state changes

Jump to

Keyboard shortcuts

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