Documentation
¶
Index ¶
- Constants
- type AsyncStagingManager
- type Config
- type Error
- type FileIntegrityCheck
- type FileLock
- type LogData
- type LogLevel
- type LogMessage
- type MCPError
- type Notification
- type PromptArgumentDefinition
- type PromptContent
- type PromptDefinition
- type PromptMessage
- type Request
- type ResourceContent
- type ResourceDefinition
- type Response
- type SafetyConfig
- type SafetyFile
- type SafetyManager
- func (sm *SafetyManager) AtomicWrite(path, content string) error
- func (sm *SafetyManager) LockFile(path string) (*FileLock, error)
- func (sm *SafetyManager) ReleaseLock(path string) error
- func (sm *SafetyManager) ValidateFileIntegrity(files []FileIntegrityCheck) error
- func (sm *SafetyManager) ValidateOperation(op *SafetyOperation) error
- type SafetyOperation
- type StagingManager
- func (sm *StagingManager) ApplyStage(stageID string, autoApplied bool) (*models.Apply, error)
- func (sm *StagingManager) CleanupExpiredStages() error
- func (sm *StagingManager) CreateStage(stage *models.Stage) error
- func (sm *StagingManager) GetStage(id string) (*models.Stage, error)
- func (sm *StagingManager) ListPendingStages(sessionID string) ([]models.Stage, error)
- type StdioServer
- func (s *StdioServer) Close() error
- func (s *StdioServer) LogDebug(message string, data ...LogData)
- func (s *StdioServer) LogError(message string, data ...LogData)
- func (s *StdioServer) LogInfo(message string, data ...LogData)
- func (s *StdioServer) LogWarning(message string, data ...LogData)
- func (s *StdioServer) RegisterTool(name string, handler ToolHandler)
- func (s *StdioServer) Start() error
- type ToolDefinition
- type ToolHandler
- type Transaction
- type TransactionLog
- func (tl *TransactionLog) BeginTransaction(targetPath, tmpPath, backupPath string) string
- func (tl *TransactionLog) CompleteTransaction(txID string)
- func (tl *TransactionLog) FailTransaction(txID string, reason error) error
- func (tl *TransactionLog) GetPendingTransactions() []*Transaction
- func (tl *TransactionLog) GetSummary() TransactionSummary
- func (tl *TransactionLog) RollbackAll() error
- func (tl *TransactionLog) RollbackTransaction(txID string) error
- type TransactionSummary
Constants ¶
const ( // JSON-RPC 2.0 standard error codes ParseError = -32700 // Invalid JSON was received InvalidRequest = -32600 // The JSON sent is not a valid Request object MethodNotFound = -32601 // The method does not exist InvalidParams = -32602 // Invalid method parameters InternalError = -32603 // Internal JSON-RPC error // Custom domain error codes (10xxx range) LanguageNotFound = 10001 // No provider for the specified language SyntaxError = 10002 // Source code parsing failed NoMatches = 10003 // Query returned no results TransformFailed = 10004 // Transformation operation failed StageNotFound = 10005 // Staging ID doesn't exist StageExpired = 10006 // Staging has expired AlreadyApplied = 10007 // Stage was already applied DatabaseError = 10008 // Database operation failed ConfidenceTooLow = 10009 // Confidence below threshold ValidationFailed = 10010 // Code validation failed FileSystemError = 10011 // File system operation failed // Safety error codes (11xxx range) SafetyViolation = 11001 // General safety violation FileTooLarge = 11002 // File exceeds size limit TooManyFiles = 11003 // Too many files in operation TotalSizeTooLarge = 11004 // Total operation size too large FileModified = 11005 // File was modified externally FileLocked = 11006 // File is locked by another process LockTimeout = 11007 // Could not acquire file lock AtomicWriteFailed = 11008 // Atomic write operation failed BackupFailed = 11009 // Backup creation failed RollbackFailed = 11010 // Rollback operation failed PerFileConfidenceLow = 11011 // Individual file confidence too low )
Error codes following JSON-RPC 2.0 standard and custom domain errors
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AsyncStagingManager ¶
type AsyncStagingManager struct {
*StagingManager
// contains filtered or unexported fields
}
AsyncStagingManager handles staging with goroutine pool
func NewAsyncStagingManager ¶
func NewAsyncStagingManager(db *gorm.DB, config Config) *AsyncStagingManager
NewAsyncStagingManager creates concurrent staging manager
func (*AsyncStagingManager) BatchCreateStages ¶
func (asm *AsyncStagingManager) BatchCreateStages(stages []*models.Stage) []error
BatchCreateStages creates multiple stages concurrently
func (*AsyncStagingManager) Close ¶
func (asm *AsyncStagingManager) Close()
Close shuts down worker pool
func (*AsyncStagingManager) CreateStageAsync ¶
func (asm *AsyncStagingManager) CreateStageAsync(stage *models.Stage) <-chan error
CreateStageAsync stages transformation without blocking
type Config ¶
type Config struct {
// Database
DatabaseURL string
// Auto-apply settings
AutoApplyEnabled bool
AutoApplyThreshold float64
// Staging
StagingTTL time.Duration
// Session limits
MaxStagesPerSession int
MaxAppliesPerSession int
// Safety Configuration
Safety SafetyConfig
// Debug
Debug bool
}
Config holds the MCP server configuration
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a config with sensible defaults
type Error ¶
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
Error represents a JSON-RPC 2.0 error
type FileIntegrityCheck ¶ added in v1.2.0
type LogLevel ¶ added in v1.2.0
type LogLevel string
LogLevel represents the severity level of a log message
type LogMessage ¶ added in v1.2.0
type LogMessage struct {
Level LogLevel `json:"level"`
Data LogData `json:"data,omitempty"`
Logger string `json:"logger,omitempty"`
}
LogMessage represents a log message according to MCP specification
type MCPError ¶
type MCPError struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
MCPError represents a structured error for the MCP protocol
func NewMCPError ¶
NewMCPError creates a new MCP error with optional data
type Notification ¶
type Notification struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
Notification is a request without an ID (no response expected)
type PromptArgumentDefinition ¶ added in v1.2.0
type PromptArgumentDefinition struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
}
PromptArgumentDefinition describes an argument for a prompt
type PromptContent ¶ added in v1.2.0
PromptContent represents the content of a prompt response
type PromptDefinition ¶ added in v1.2.0
type PromptDefinition struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Arguments []PromptArgumentDefinition `json:"arguments,omitempty"`
}
PromptDefinition describes a prompt available to the client
func GetPromptDefinitions ¶ added in v1.2.0
func GetPromptDefinitions() []PromptDefinition
GetPromptDefinitions returns all available prompt definitions
type PromptMessage ¶ added in v1.2.0
type PromptMessage struct {
Role string `json:"role"`
Content []PromptContent `json:"content"`
}
PromptMessage represents a prompt message
type Request ¶
type Request struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
ID any `json:"id"`
}
Request represents a JSON-RPC 2.0 request
type ResourceContent ¶ added in v1.2.0
type ResourceContent struct {
URI string `json:"uri"`
MimeType string `json:"mimeType"`
Text string `json:"text,omitempty"`
Blob []byte `json:"blob,omitempty"`
}
ResourceContent represents the content of a resource
type ResourceDefinition ¶ added in v1.2.0
type ResourceDefinition struct {
URI string `json:"uri"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
MimeType string `json:"mimeType,omitempty"`
Annotations map[string]any `json:"annotations,omitempty"`
}
ResourceDefinition describes a resource available to the client
func GetResourceDefinitions ¶ added in v1.2.0
func GetResourceDefinitions() []ResourceDefinition
GetResourceDefinitions returns all available resource definitions
type Response ¶
type Response struct {
JSONRPC string `json:"jsonrpc"`
Result any `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
ID any `json:"id"`
}
Response represents a JSON-RPC 2.0 response
func ErrorResponse ¶
ErrorResponse creates a JSON-RPC error response
func ErrorResponseWithData ¶
ErrorResponseWithData creates a JSON-RPC error response with additional data
func SuccessResponse ¶
Standard JSON-RPC error codes SuccessResponse creates a success response
type SafetyConfig ¶ added in v1.2.0
type SafetyConfig struct {
// File operation limits
MaxFiles int `json:"max_files"` // Max files per operation
MaxFileSize int64 `json:"max_file_size"` // Max size per file (bytes)
MaxTotalSize int64 `json:"max_total_size"` // Max total operation size (bytes)
// Confidence validation
ConfidenceMode string `json:"confidence_mode"` // "global", "per_file", "both"
PerFileThreshold float64 `json:"per_file_threshold"` // Individual file threshold
GlobalThreshold float64 `json:"global_threshold"` // Overall operation threshold
// Hash validation
ValidateFileHashes bool `json:"validate_file_hashes"` // Check files weren't modified externally
// Atomic writes
AtomicWrites bool `json:"atomic_writes"` // Use atomic write operations
UseFsync bool `json:"use_fsync"` // Use fsync for durability
// Backup & rollback
CreateBackups bool `json:"create_backups"` // Create .bak files before writes
BackupSuffix string `json:"backup_suffix"` // Backup file suffix
TransactionLog bool `json:"transaction_log"` // Enable transaction logging
// Concurrency safety
FileLocking bool `json:"file_locking"` // Use file locking
LockTimeout time.Duration `json:"lock_timeout"` // Lock acquisition timeout
}
SafetyConfig holds safety-related configuration
type SafetyFile ¶ added in v1.2.0
type SafetyManager ¶ added in v1.2.0
type SafetyManager struct {
// contains filtered or unexported fields
}
SafetyManager handles all safety-related operations
func NewSafetyManager ¶ added in v1.2.0
func NewSafetyManager(config SafetyConfig) *SafetyManager
NewSafetyManager creates a new safety manager with the given config
func (*SafetyManager) AtomicWrite ¶ added in v1.2.0
func (sm *SafetyManager) AtomicWrite(path, content string) error
AtomicWrite performs an atomic write operation
func (*SafetyManager) LockFile ¶ added in v1.2.0
func (sm *SafetyManager) LockFile(path string) (*FileLock, error)
LockFile acquires an exclusive lock on a file
func (*SafetyManager) ReleaseLock ¶ added in v1.2.0
func (sm *SafetyManager) ReleaseLock(path string) error
ReleaseLock releases a file lock
func (*SafetyManager) ValidateFileIntegrity ¶ added in v1.2.0
func (sm *SafetyManager) ValidateFileIntegrity(files []FileIntegrityCheck) error
ValidateFileIntegrity checks if files haven't been modified externally
func (*SafetyManager) ValidateOperation ¶ added in v1.2.0
func (sm *SafetyManager) ValidateOperation(op *SafetyOperation) error
ValidateOperation checks if an operation meets safety requirements
type SafetyOperation ¶ added in v1.2.0
type SafetyOperation struct {
Files []SafetyFile `json:"files"`
GlobalConfidence float64 `json:"global_confidence"`
}
type StagingManager ¶
type StagingManager struct {
// contains filtered or unexported fields
}
StagingManager handles staging and applying transformations
func NewStagingManager ¶
func NewStagingManager(db *gorm.DB, config Config) *StagingManager
NewStagingManager creates a new staging manager
func (*StagingManager) ApplyStage ¶
ApplyStage applies a staged transformation
func (*StagingManager) CleanupExpiredStages ¶
func (sm *StagingManager) CleanupExpiredStages() error
CleanupExpiredStages marks expired stages
func (*StagingManager) CreateStage ¶
func (sm *StagingManager) CreateStage(stage *models.Stage) error
CreateStage creates a new staged transformation
func (*StagingManager) GetStage ¶
func (sm *StagingManager) GetStage(id string) (*models.Stage, error)
GetStage retrieves a stage by ID
func (*StagingManager) ListPendingStages ¶
func (sm *StagingManager) ListPendingStages(sessionID string) ([]models.Stage, error)
ListPendingStages lists all pending stages for a session
type StdioServer ¶
type StdioServer struct {
// contains filtered or unexported fields
}
StdioServer handles MCP communication over stdio
func NewStdioServer ¶
func NewStdioServer(config Config) (*StdioServer, error)
NewStdioServer creates a new MCP server that communicates over stdio
func (*StdioServer) LogDebug ¶ added in v1.2.0
func (s *StdioServer) LogDebug(message string, data ...LogData)
LogDebug sends a debug level log notification
func (*StdioServer) LogError ¶ added in v1.2.0
func (s *StdioServer) LogError(message string, data ...LogData)
LogError sends an error level log notification
func (*StdioServer) LogInfo ¶ added in v1.2.0
func (s *StdioServer) LogInfo(message string, data ...LogData)
LogInfo sends an info level log notification
func (*StdioServer) LogWarning ¶ added in v1.2.0
func (s *StdioServer) LogWarning(message string, data ...LogData)
LogWarning sends a warning level log notification
func (*StdioServer) RegisterTool ¶
func (s *StdioServer) RegisterTool(name string, handler ToolHandler)
RegisterTool adds a custom tool handler
func (*StdioServer) Start ¶
func (s *StdioServer) Start() error
Start begins processing JSON-RPC requests from stdin
type ToolDefinition ¶
type ToolDefinition struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema map[string]any `json:"inputSchema"`
}
ToolDefinition describes a tool for the client
func GetToolDefinitions ¶
func GetToolDefinitions() []ToolDefinition
GetToolDefinitions returns all available tool definitions
type ToolHandler ¶
type ToolHandler func(params json.RawMessage) (any, error)
ToolHandler represents a function that handles a tool call
type Transaction ¶ added in v1.2.0
type Transaction struct {
ID string `json:"id"`
TargetPath string `json:"target_path"`
TmpPath string `json:"tmp_path"`
BackupPath string `json:"backup_path"`
Status string `json:"status"` // "pending", "completed", "failed", "rolled_back"
Error string `json:"error,omitempty"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
}
Transaction represents a file operation transaction
type TransactionLog ¶ added in v1.2.0
type TransactionLog struct {
// contains filtered or unexported fields
}
TransactionLog manages transaction logging for rollback capability
func NewTransactionLog ¶ added in v1.2.0
func NewTransactionLog() *TransactionLog
NewTransactionLog creates a new transaction log
func (*TransactionLog) BeginTransaction ¶ added in v1.2.0
func (tl *TransactionLog) BeginTransaction(targetPath, tmpPath, backupPath string) string
BeginTransaction starts a new transaction
func (*TransactionLog) CompleteTransaction ¶ added in v1.2.0
func (tl *TransactionLog) CompleteTransaction(txID string)
CompleteTransaction marks a transaction as completed
func (*TransactionLog) FailTransaction ¶ added in v1.2.0
func (tl *TransactionLog) FailTransaction(txID string, reason error) error
FailTransaction marks a transaction as failed and triggers rollback
func (*TransactionLog) GetPendingTransactions ¶ added in v1.2.0
func (tl *TransactionLog) GetPendingTransactions() []*Transaction
GetPendingTransactions returns all pending transactions
func (*TransactionLog) GetSummary ¶ added in v1.2.0
func (tl *TransactionLog) GetSummary() TransactionSummary
GetSummary returns a summary of the transaction log
func (*TransactionLog) RollbackAll ¶ added in v1.2.0
func (tl *TransactionLog) RollbackAll() error
RollbackAll rolls back all pending transactions
func (*TransactionLog) RollbackTransaction ¶ added in v1.2.0
func (tl *TransactionLog) RollbackTransaction(txID string) error
RollbackTransaction performs rollback for a specific transaction
type TransactionSummary ¶ added in v1.2.0
type TransactionSummary struct {
TotalTransactions int `json:"total_transactions"`
PendingTransactions int `json:"pending_transactions"`
CompletedTransactions int `json:"completed_transactions"`
FailedTransactions int `json:"failed_transactions"`
RolledBackTransactions int `json:"rolled_back_transactions"`
}
TransactionSummary provides a summary of transaction log state