Documentation
¶
Index ¶
- Constants
- func Complete(s *Subject)
- func Publish[T any](subject *Subject, topic string, value T, conn ...net.Conn) error
- type ClientConnectedEvent
- type ClientDisconnectedEvent
- type ClientErrorEvent
- type ClientInfo
- type ClientInitializedEvent
- type ClientInitializingEvent
- type HandlerFunc
- type PromptExecutedEvent
- type RequestFailedEvent
- type ResourceAccessedEvent
- type ResourceChangedEvent
- type ResourceRegisteredEvent
- type ServerInitializedEvent
- type ServerShutdownEvent
- type Subject
- type SubjectOption
- type Subscription
- type ToolExecutedEvent
- type ToolRegisteredEvent
Constants ¶
const ( // Server lifecycle events TopicServerInitialized = "server.initialized" TopicServerShutdown = "server.shutdown" // Connection events (can be emitted by both client and server) TopicClientConnected = "client.connected" // Client connected to server TopicClientDisconnected = "client.disconnected" // Client disconnected from server // Registration events (server-side) TopicToolRegistered = "tool.registered" TopicResourceRegistered = "resource.registered" // Operation events (can be emitted by both client and server for same operations) TopicToolExecuted = "tool.executed" // Tool was executed TopicResourceAccessed = "resource.accessed" // Resource was accessed TopicResourceChanged = "resource.changed" // Resource was modified (create/update/delete) TopicPromptExecuted = "prompt.executed" // Prompt was executed // Error events TopicRequestFailed = "request.failed" // Request failed // Client-specific lifecycle events TopicClientInitializing = "client.initializing" // Client starting up TopicClientInitialized = "client.initialized" // Client ready TopicClientError = "client.error" // Client operation failed )
Standard topic constants for GoMCP events. These define the public API contract for what topics external consumers can subscribe to.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClientConnectedEvent ¶
type ClientConnectedEvent struct {
SessionID string `json:"sessionId"`
ProtocolVersion string `json:"protocolVersion"`
ConnectedAt time.Time `json:"connectedAt"`
ClientInfo ClientInfo `json:"clientInfo"`
Capabilities map[string]interface{} `json:"capabilities"`
}
ClientConnectedEvent is emitted when a client connects to the server (server-side perspective)
type ClientDisconnectedEvent ¶
type ClientDisconnectedEvent struct {
// Client-side fields
URL string `json:"url,omitempty"` // The server URL that was disconnected from
// Server-side fields
SessionID string `json:"sessionId,omitempty"` // Unique session identifier
ProtocolVersion string `json:"protocolVersion,omitempty"` // MCP protocol version used
ConnectedAt string `json:"connectedAt,omitempty"` // When the session was created (RFC3339)
DisconnectedAt string `json:"disconnectedAt,omitempty"` // When the session was closed (RFC3339)
}
ClientDisconnectedEvent is emitted when a client disconnects from a server
type ClientErrorEvent ¶
type ClientErrorEvent struct {
Error string `json:"error"` // The error message describing what failed
}
ClientErrorEvent is emitted when a client operation fails
type ClientInfo ¶
ClientInfo represents information about a connected client
type ClientInitializedEvent ¶
type ClientInitializedEvent struct {
URL string `json:"url"` // The server URL that was connected to
}
ClientInitializedEvent is emitted when a client successfully connects and initializes
type ClientInitializingEvent ¶
type ClientInitializingEvent struct {
URL string `json:"url"` // The server URL being connected to
}
ClientInitializingEvent is emitted when a client starts connecting to a server
type HandlerFunc ¶
type HandlerFunc interface{}
HandlerFunc is the function called when an event is emitted. It can optionally receive a net.Conn as its last parameter.
type PromptExecutedEvent ¶
type PromptExecutedEvent struct {
PromptName string `json:"promptName"`
Arguments map[string]interface{} `json:"arguments,omitempty"`
ExecutedAt time.Time `json:"executedAt"`
Success bool `json:"success"`
ErrorMessage string `json:"errorMessage,omitempty"`
MessageCount int `json:"messageCount,omitempty"`
}
PromptExecutedEvent is emitted when a prompt is executed
type RequestFailedEvent ¶
type RequestFailedEvent struct {
Method string `json:"method"` // The MCP method that failed (e.g., "tools/call")
RequestJSON string `json:"requestJSON"` // The actual JSON request that was sent
Error string `json:"error"` // The error message describing the failure
}
RequestFailedEvent is emitted when an MCP request fails on either client or server
type ResourceAccessedEvent ¶
type ResourceAccessedEvent struct {
URI string `json:"uri"`
Method string `json:"method"` // "resources/read", "resources/list", etc.
AccessedAt time.Time `json:"accessedAt"`
Success bool `json:"success"`
ErrorMessage string `json:"errorMessage,omitempty"`
ResponseSize int `json:"responseSize,omitempty"`
}
ResourceAccessedEvent is emitted when a resource is accessed
type ResourceChangedEvent ¶ added in v1.6.0
type ResourceChangedEvent struct {
URI string `json:"uri"`
Action string `json:"action"` // "created", "modified", "deleted"
ChangedAt time.Time `json:"changedAt"`
SessionID string `json:"sessionId,omitempty"` // Session that made the change (if applicable)
}
ResourceChangedEvent is emitted when a resource changes (created, modified, or deleted)
type ResourceRegisteredEvent ¶
type ResourceRegisteredEvent struct {
URI string `json:"uri"`
Name string `json:"name"`
Description string `json:"description"`
MimeType string `json:"mimeType"`
RegisteredAt time.Time `json:"registeredAt"`
}
ResourceRegisteredEvent is emitted when a resource is registered with the server
type ServerInitializedEvent ¶
type ServerInitializedEvent struct {
ServerName string `json:"serverName"`
ProtocolVersion string `json:"protocolVersion"`
Capabilities map[string]interface{} `json:"capabilities,omitempty"`
InitializedAt time.Time `json:"initializedAt"`
TransportType string `json:"transportType,omitempty"`
TransportEndpoint string `json:"transportEndpoint,omitempty"`
// Additional server metrics
ToolCount int `json:"toolCount"`
ResourceCount int `json:"resourceCount"`
PromptCount int `json:"promptCount"`
Metadata map[string]any `json:"metadata,omitempty"`
}
ServerInitializedEvent is emitted when the server has been initialized and is ready to accept requests
type ServerShutdownEvent ¶
type ServerShutdownEvent struct {
ServerName string `json:"serverName"`
ShutdownAt time.Time `json:"shutdownAt"`
GracefulExit bool `json:"gracefulExit"`
Reason string `json:"reason,omitempty"`
}
ServerShutdownEvent is emitted when the server is shutting down
type Subject ¶
type Subject struct {
// contains filtered or unexported fields
}
func NewSubject ¶
func NewSubject(opts ...SubjectOption) *Subject
NewSubject creates a new Subject with optional configuration.
type SubjectOption ¶
type SubjectOption func(*subjectConfig)
SubjectOption configures a Subject
func WithBufferSize ¶
func WithBufferSize(size int) SubjectOption
WithBufferSize sets the event channel buffer size
func WithLogger ¶
func WithLogger(logger *slog.Logger) SubjectOption
WithLogger sets a structured logger for event system errors
func WithReplay ¶
func WithReplay(cacheSize int) SubjectOption
WithReplay enables replay functionality with specified cache size
type Subscription ¶
type Subscription struct {
Topic string
CreatedAt int64
Handler HandlerFunc
ID string
WantsReplay bool
SentEvents map[string]bool // Replay tracking per subscription
Unsubscribe func()
}
Subscription represents a handler subscribed to a specific topic.
func Subscribe ¶
func Subscribe[T any](subject *Subject, topic string, handler interface{}, replay ...bool) Subscription
Subscribe subscribes a handler to the given topic. The handler can be either: - func(context.Context, T) error - func(context.Context, T, net.Conn) error A Subscription is returned that can be used to unsubscribe from the topic.
type ToolExecutedEvent ¶
type ToolExecutedEvent struct {
Method string `json:"method"` // The MCP method that was executed (e.g., "tools/call")
RequestJSON string `json:"requestJSON"` // The actual JSON request that was sent
ResponseJSON string `json:"responseJSON"` // The actual JSON response that was received
}
ToolExecutedEvent is emitted when an MCP request succeeds on either client or server
type ToolRegisteredEvent ¶
type ToolRegisteredEvent struct {
ToolName string `json:"toolName"`
Description string `json:"description"`
RegisteredAt time.Time `json:"registeredAt"`
Schema map[string]interface{} `json:"schema"`
Annotations map[string]interface{} `json:"annotations,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
ToolRegisteredEvent is emitted when a tool is registered with the server