Documentation
¶
Overview ¶
Package domain defines the core business logic and entities for the MCP server.
Index ¶
- Variables
- type ClientSession
- type ConnectionManager
- type Error
- type JSONRPCError
- type JSONRPCNotification
- type JSONRPCRequest
- type JSONRPCResponse
- type MessageHandler
- type Notification
- type NotificationSender
- type Prompt
- type PromptNotFoundError
- type PromptParameter
- type PromptRepository
- type PromptRequest
- type PromptResult
- type Resource
- type ResourceContents
- type ResourceNotFoundError
- type ResourceRepository
- type SSEHandler
- type SSESession
- type SessionNotFoundError
- type SessionRepository
- type Tool
- type ToolCall
- type ToolNotFoundError
- type ToolParameter
- type ToolRepository
- type ToolResult
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = NewError("not found", 404) 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 ¶
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 ¶
Error represents a domain error with an associated code.
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 ¶
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 ¶
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 ¶
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 ¶
PromptResult represents the result of a prompt rendering.
type ResourceContents ¶
ResourceContents represents the contents of a resource.
type ResourceNotFoundError ¶
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 ¶
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 ¶
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 ¶
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.