domain

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package domain defines the core business logic and entities for the MCP server.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound       = NewError("not found", 404)
	ErrUnauthorized   = NewError("unauthorized", 401)
	ErrInvalidInput   = NewError("invalid input", 400)
	ErrInternal       = NewError("internal server error", 500)
	ErrNotImplemented = NewError("not implemented", 501)
)

Common domain errors

Functions

This section is empty.

Types

type ClientSession

type ClientSession struct {
	ID        string
	UserAgent string
	Connected bool
}

ClientSession represents an active client connection to the MCP server.

func NewClientSession

func NewClientSession(userAgent string) *ClientSession

NewClientSession creates a new ClientSession with a unique ID.

type ConnectionManager

type ConnectionManager interface {
	// Add adds a session to the manager.
	AddSession(session SSESession)

	// Remove removes a session from the manager.
	RemoveSession(sessionID string)

	// Get retrieves a session by ID.
	GetSession(sessionID string) (SSESession, bool)

	// Broadcast sends an event to all sessions.
	Broadcast(event interface{}) error

	// CloseAll closes all active sessions.
	CloseAll()

	// Count returns the number of active sessions.
	Count() int
}

ConnectionManager defines the interface for managing SSE connections.

type Error

type Error struct {
	Message string
	Code    int
}

Error represents a domain error with an associated code.

func NewError

func NewError(message string, code int) *Error

NewError creates a new domain error with the given message and code.

func (*Error) Error

func (e *Error) Error() string

Error returns the error message.

type JSONRPCError

type JSONRPCError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

JSONRPCError represents a JSON-RPC error in the domain layer.

type JSONRPCNotification

type JSONRPCNotification struct {
	JSONRPC string                 `json:"jsonrpc"`
	Method  string                 `json:"method"`
	Params  map[string]interface{} `json:"params,omitempty"`
}

JSONRPCNotification represents a notification sent to clients via JSON-RPC.

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC string      `json:"jsonrpc"`
	ID      interface{} `json:"id"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params,omitempty"`
}

JSONRPCRequest represents a JSON-RPC request in the domain layer.

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPC string        `json:"jsonrpc"`
	ID      interface{}   `json:"id"`
	Result  interface{}   `json:"result,omitempty"`
	Error   *JSONRPCError `json:"error,omitempty"`
}

JSONRPCResponse represents a JSON-RPC response in the domain layer.

func CreateErrorResponse

func CreateErrorResponse(jsonrpcVersion string, id interface{}, code int, message string) JSONRPCResponse

CreateErrorResponse creates a new JSONRPCResponse with the given ID and error.

func CreateResponse

func CreateResponse(jsonrpcVersion string, id interface{}, result interface{}) JSONRPCResponse

CreateResponse creates a new JSONRPCResponse with the given ID and result.

type MessageHandler

type MessageHandler interface {
	// HandleMessage processes a raw JSON message and returns a response.
	HandleMessage(ctx context.Context, rawMessage json.RawMessage) interface{}
}

MessageHandler defines the interface for handling message processing in the SSE server.

type Notification

type Notification struct {
	Method string
	Params map[string]interface{}
}

Notification represents a notification that can be sent to clients.

func (*Notification) ToJSONRPC

func (n *Notification) ToJSONRPC(jsonrpcVersion string) JSONRPCNotification

ToJSONRPC converts a domain Notification to a JSONRPCNotification.

type NotificationSender

type NotificationSender interface {
	// SendNotification sends a notification to a specific client.
	SendNotification(ctx context.Context, sessionID string, notification *Notification) error

	// BroadcastNotification sends a notification to all connected clients.
	BroadcastNotification(ctx context.Context, notification *Notification) error
}

NotificationSender defines the interface for sending notifications to clients.

type Prompt

type Prompt struct {
	Name        string
	Description string
	Template    string
	Parameters  []PromptParameter
}

Prompt represents a prompt template that can be rendered.

type PromptNotFoundError

type PromptNotFoundError struct {
	Name string
	Err  *Error
}

PromptNotFoundError indicates that a requested prompt was not found.

func NewPromptNotFoundError

func NewPromptNotFoundError(name string) *PromptNotFoundError

NewPromptNotFoundError creates a new PromptNotFoundError.

func (*PromptNotFoundError) Error

func (e *PromptNotFoundError) Error() string

Error returns the error message.

type PromptParameter

type PromptParameter struct {
	Name        string
	Description string
	Type        string
	Required    bool
}

PromptParameter defines a parameter for a prompt template.

type PromptRepository

type PromptRepository interface {
	// GetPrompt retrieves a prompt by its name.
	GetPrompt(ctx context.Context, name string) (*Prompt, error)

	// ListPrompts returns all available prompts.
	ListPrompts(ctx context.Context) ([]*Prompt, error)

	// AddPrompt adds a new prompt to the repository.
	AddPrompt(ctx context.Context, prompt *Prompt) error

	// DeletePrompt removes a prompt from the repository.
	DeletePrompt(ctx context.Context, name string) error
}

PromptRepository defines the interface for managing prompts.

type PromptRequest

type PromptRequest struct {
	Name       string
	Parameters map[string]interface{}
	Session    *ClientSession
}

PromptRequest represents a request to render a prompt.

type PromptResult

type PromptResult struct {
	Text  string
	Error error
}

PromptResult represents the result of a prompt rendering.

type Resource

type Resource struct {
	URI         string
	Name        string
	Description string
	MIMEType    string
}

Resource represents a resource that can be requested by clients.

type ResourceContents

type ResourceContents struct {
	URI      string
	MIMEType string
	Content  []byte
	Text     string
}

ResourceContents represents the contents of a resource.

type ResourceNotFoundError

type ResourceNotFoundError struct {
	URI string
	Err *Error
}

ResourceNotFoundError indicates that a requested resource was not found.

func NewResourceNotFoundError

func NewResourceNotFoundError(uri string) *ResourceNotFoundError

NewResourceNotFoundError creates a new ResourceNotFoundError.

func (*ResourceNotFoundError) Error

func (e *ResourceNotFoundError) Error() string

Error returns the error message.

type ResourceRepository

type ResourceRepository interface {
	// GetResource retrieves a resource by its URI.
	GetResource(ctx context.Context, uri string) (*Resource, error)

	// ListResources returns all available resources.
	ListResources(ctx context.Context) ([]*Resource, error)

	// AddResource adds a new resource to the repository.
	AddResource(ctx context.Context, resource *Resource) error

	// DeleteResource removes a resource from the repository.
	DeleteResource(ctx context.Context, uri string) error
}

ResourceRepository defines the interface for managing resources.

type SSEHandler

type SSEHandler interface {
	// ServeHTTP handles HTTP requests for SSE events.
	ServeHTTP(w http.ResponseWriter, r *http.Request)

	// Start starts the SSE server.
	Start(addr string) error

	// Shutdown gracefully stops the SSE server.
	Shutdown(ctx context.Context) error

	// BroadcastEvent sends an event to all connected clients.
	BroadcastEvent(event interface{}) error

	// SendEventToSession sends an event to a specific client session.
	SendEventToSession(sessionID string, event interface{}) error
}

SSEHandler defines the interface for a server-sent events handler.

type SSESession

type SSESession interface {
	// ID returns the session identifier.
	ID() string

	// Close closes the session.
	Close()

	// NotificationChannel returns the channel used to send notifications to this session.
	NotificationChannel() chan<- string

	// Start begins processing events for this session.
	Start()

	// Context returns the session's context.
	Context() context.Context
}

SSESession represents an active SSE connection.

type SessionNotFoundError

type SessionNotFoundError struct {
	ID  string
	Err *Error
}

SessionNotFoundError indicates that a requested session was not found.

func NewSessionNotFoundError

func NewSessionNotFoundError(id string) *SessionNotFoundError

NewSessionNotFoundError creates a new SessionNotFoundError.

func (*SessionNotFoundError) Error

func (e *SessionNotFoundError) Error() string

Error returns the error message.

type SessionRepository

type SessionRepository interface {
	// GetSession retrieves a session by its ID.
	GetSession(ctx context.Context, id string) (*ClientSession, error)

	// ListSessions returns all active sessions.
	ListSessions(ctx context.Context) ([]*ClientSession, error)

	// AddSession adds a new session to the repository.
	AddSession(ctx context.Context, session *ClientSession) error

	// DeleteSession removes a session from the repository.
	DeleteSession(ctx context.Context, id string) error
}

SessionRepository defines the interface for managing client sessions.

type Tool

type Tool struct {
	Name        string
	Description string
	Parameters  []ToolParameter
}

Tool represents a tool that can be called by clients.

type ToolCall

type ToolCall struct {
	Name       string
	Parameters map[string]interface{}
	Session    *ClientSession
}

ToolCall represents a request to execute a tool.

type ToolNotFoundError

type ToolNotFoundError struct {
	Name string
	Err  *Error
}

ToolNotFoundError indicates that a requested tool was not found.

func NewToolNotFoundError

func NewToolNotFoundError(name string) *ToolNotFoundError

NewToolNotFoundError creates a new ToolNotFoundError.

func (*ToolNotFoundError) Error

func (e *ToolNotFoundError) Error() string

Error returns the error message.

type ToolParameter

type ToolParameter struct {
	Name        string
	Description string
	Type        string
	Required    bool
	Items       map[string]interface{}
}

ToolParameter defines a parameter for a tool.

type ToolRepository

type ToolRepository interface {
	// GetTool retrieves a tool by its name.
	GetTool(ctx context.Context, name string) (*Tool, error)

	// ListTools returns all available tools.
	ListTools(ctx context.Context) ([]*Tool, error)

	// AddTool adds a new tool to the repository.
	AddTool(ctx context.Context, tool *Tool) error

	// DeleteTool removes a tool from the repository.
	DeleteTool(ctx context.Context, name string) error
}

ToolRepository defines the interface for managing tools.

type ToolResult

type ToolResult struct {
	Data  interface{}
	Error error
}

ToolResult represents the result of a tool execution.

type ValidationError

type ValidationError struct {
	Field   string
	Message string
	Err     *Error
}

ValidationError indicates that input validation failed.

func NewValidationError

func NewValidationError(field, message string) *ValidationError

NewValidationError creates a new ValidationError.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error returns the error message.

Jump to

Keyboard shortcuts

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