Documentation
¶
Index ¶
- Constants
- Variables
- func Contains(slice []string, value string) bool
- func FromJSON(data string, v interface{}) error
- func GetUserEmailFromContext(ctx context.Context) (string, error)
- func GetUserIDFromContext(ctx context.Context) (string, error)
- func GetUserRolesFromContext(ctx context.Context) ([]string, error)
- func GetVersion() string
- func HandleSSE(c fiber.Ctx, mcpServer *MCPServer, config *Config, log *slog.Logger) error
- func NewPlugin() plugin.Plugin
- func Ptr[T any](v T) *T
- func ToJSON(v interface{}) (string, error)
- type Config
- type ConnectionPool
- type ContextKey
- type MCPError
- type MCPServer
- type Plugin
- type RateLimitConfig
- type SSEConfig
Constants ¶
const ( CodeParseError = -32700 CodeInvalidRequest = -32600 CodeMethodNotFound = -32601 CodeInvalidParams = -32602 CodeInternalError = -32603 // Custom error codes (application-specific) CodeForbidden = -32001 CodeRateLimitExceeded = -32002 CodeResourceNotFound = -32003 CodeOperationDisabled = -32004 CodeMaxConnectionsExceeded = -32005 CodeConnectionTimeout = -32006 )
Error code constants following JSON-RPC 2.0 spec
const ( // Version is the current version of the gorest-mcp plugin Version = "0.1.0" // VersionMajor is the major version number VersionMajor = 0 // VersionMinor is the minor version number VersionMinor = 1 // VersionPatch is the patch version number VersionPatch = 0 )
Version information
Variables ¶
var ( ErrUnauthorized = errors.New("unauthorized: invalid or missing JWT token") // ErrForbidden indicates insufficient permissions ErrForbidden = errors.New("forbidden: insufficient permissions") // ErrRateLimitExceeded indicates rate limit has been exceeded ErrRateLimitExceeded = errors.New("rate limit exceeded") // ErrInvalidRequest indicates malformed request ErrInvalidRequest = errors.New("invalid request") // ErrResourceNotFound indicates requested resource doesn't exist ErrResourceNotFound = errors.New("resource not found") // ErrOperationDisabled indicates the requested operation is disabled ErrOperationDisabled = errors.New("operation disabled") // ErrMaxConnectionsExceeded indicates user has too many active connections ErrMaxConnectionsExceeded = errors.New("maximum connections exceeded") // ErrConnectionTimeout indicates connection idle timeout ErrConnectionTimeout = errors.New("connection timeout") )
Functions ¶
func GetUserEmailFromContext ¶
GetUserEmailFromContext extracts the user email from context
func GetUserIDFromContext ¶
GetUserIDFromContext extracts the user ID from context
func GetUserRolesFromContext ¶
GetUserRolesFromContext extracts the user roles from context
Types ¶
type Config ¶
type Config struct {
Enabled bool `json:"enabled" yaml:"enabled"`
EnabledOperations []string `json:"enabled_operations" yaml:"enabled_operations"`
RateLimit RateLimitConfig `json:"rate_limit" yaml:"rate_limit"`
SSE SSEConfig `json:"sse" yaml:"sse"`
LogRequests bool `json:"log_requests" yaml:"log_requests"`
LogLevel string `json:"log_level" yaml:"log_level"`
}
Config holds the MCP plugin configuration
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns the default MCP plugin configuration
func ParseConfig ¶
ParseConfig parses configuration from various formats
func (*Config) GetConnectionTimeout ¶
GetConnectionTimeout returns the connection timeout as time.Duration
func (*Config) GetHeartbeatInterval ¶
GetHeartbeatInterval returns the heartbeat interval as time.Duration
func (*Config) IsOperationEnabled ¶
IsOperationEnabled checks if a specific operation is enabled
type ConnectionPool ¶
type ConnectionPool struct {
// contains filtered or unexported fields
}
ConnectionPool tracks active SSE connections per user
func (*ConnectionPool) AddConnection ¶
func (cp *ConnectionPool) AddConnection(userID string) error
AddConnection adds a new connection for a user
func (*ConnectionPool) RemoveConnection ¶
func (cp *ConnectionPool) RemoveConnection(userID string)
RemoveConnection removes a connection for a user
type ContextKey ¶
type ContextKey string
ContextKey is a custom type for context keys to avoid collisions
const ( // ContextKeyUserID stores the authenticated user ID in context ContextKeyUserID ContextKey = "user_id" // ContextKeyUserEmail stores the authenticated user email in context ContextKeyUserEmail ContextKey = "user_email" // ContextKeyUserRoles stores the authenticated user roles in context ContextKeyUserRoles ContextKey = "user_roles" )
type MCPError ¶
type MCPError struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
Err error `json:"-"`
}
MCPError wraps an error with additional context for MCP protocol
func NewMCPError ¶
NewMCPError creates a new MCP error
type MCPServer ¶
type MCPServer struct {
// contains filtered or unexported fields
}
func NewMCPServer ¶
type RateLimitConfig ¶
type RateLimitConfig struct {
Enabled bool `json:"enabled" yaml:"enabled"`
RequestsPerMinute int `json:"requests_per_minute" yaml:"requests_per_minute"`
Burst int `json:"burst" yaml:"burst"`
}
RateLimitConfig configures rate limiting for MCP requests
type SSEConfig ¶
type SSEConfig struct {
HeartbeatInterval int `json:"heartbeat_interval" yaml:"heartbeat_interval"` // Seconds
ConnectionTimeout int `json:"connection_timeout" yaml:"connection_timeout"` // Seconds
MaxConnectionsPerUser int `json:"max_connections_per_user" yaml:"max_connections_per_user"`
}
SSEConfig configures Server-Sent Events behavior