sessiontools

package
v0.0.0-...-cb06f26 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: GPL-3.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ToolListDirectory = "list_directory"
	ToolStat          = "stat"
	ToolReadText      = "read_text"
	ToolSaveText      = "save_text"
	ToolMkdir         = "mkdir"
	ToolRename        = "rename"
	ToolDelete        = "delete"

	MaxDirectoryEntries   = 200
	MaxTextBytes          = 32 * 1024
	ExpectedVersionAbsent = "absent"
)
View Source
const (
	MCPProtocolVersion = 1
	MCPToolsetRevision = 1
	MCPWireVersion     = "2026-07-28"

	MCPAgentMetaKey      = "com.jumpserver/agent"
	MCPServerInfoMetaKey = "io.modelcontextprotocol/serverInfo"

	MCPManifestFrame     = "mcp.manifest"
	MCPRequestFrame      = "mcp.request"
	MCPResponseFrame     = "mcp.response"
	MCPCancelFrame       = "mcp.cancel"
	MCPCancelResultFrame = "mcp.cancel_result"
)
View Source
const (
	MCPToolTerminalContext  = "terminal_context"
	MCPToolTerminalSnapshot = "terminal_snapshot"
	MCPToolDatabaseSchema   = "database_schema"
)
View Source
const (
	MCPToolExecuteCommand    = "execute_command"
	MCPToolExecuteShell      = "execute_shell"
	MCPToolExecuteSQL        = "execute_sql"
	MCPToolExecuteRedis      = "execute_redis"
	MCPToolExecuteMongoDB    = "execute_mongodb"
	MCPExecutionModesMetaKey = "com.jumpserver/executionModes"
	MCPToolKindMetaKey       = "com.jumpserver/toolKind"
	MCPCommandPolicyMetaKey  = "com.jumpserver/commandPolicy"
	MCPShellReadOnlyPolicy   = "shell-readonly-v1"
	MCPExecutionAuto         = "auto"
	MCPExecutionPTY          = "pty"
	MCPExecutionBackground   = "background"
)
View Source
const (
	MaxToolResultBytes = 128 * 1024
	MaxToolSchemaBytes = 64 * 1024
)

Variables

This section is empty.

Functions

func HashValue

func HashValue(value any) (string, error)

func ProtocolSupportsBackgroundExecutor

func ProtocolSupportsBackgroundExecutor(protocol string) bool

func ValidateSchema

func ValidateSchema(raw json.RawMessage) error

ValidateSchema verifies a complete JSON Schema without resolving references outside the schema document.

Types

type CommandACLDecision

type CommandACLDecision struct {
	Action    string   `json:"action"`
	ACLID     string   `json:"acl_id,omitempty"`
	ItemID    string   `json:"item_id,omitempty"`
	Name      string   `json:"name,omitempty"`
	Matched   string   `json:"matched,omitempty"`
	DetailURL string   `json:"detail_url,omitempty"`
	Reviewers []string `json:"reviewers,omitempty"`
	Processor string   `json:"processor,omitempty"`
	Reviewed  bool     `json:"reviewed,omitempty"`
}

type CommandConstraints

type CommandConstraints struct {
	BackgroundEligible  bool
	MaxExecutionSeconds int
}

type CommandExecutor

type CommandExecutor interface {
	Execute(context.Context, string, func(string)) (string, *int, error)
	Close() error
}

func NewDatabaseExecutor

func NewDatabaseExecutor(
	ctx context.Context,
	config DatabaseConfig,
) (CommandExecutor, error)

type CommandValidator

type CommandValidator func(string) (CommandConstraints, error)

func ProtocolCommandValidator

func ProtocolCommandValidator(protocol string) CommandValidator

type ContextSnapshot

type ContextSnapshot struct {
	SessionKind      string `json:"session_kind,omitempty"`
	InteractionMode  string `json:"interaction_mode,omitempty"`
	CommandLanguage  string `json:"command_language,omitempty"`
	Dialect          string `json:"dialect,omitempty"`
	Protocol         string `json:"protocol"`
	ConnectionMethod string `json:"connection_method,omitempty"`
	AssetID          string `json:"asset_id,omitempty"`
	AssetName        string `json:"asset_name,omitempty"`
	AssetAddress     string `json:"asset_address,omitempty"`
	PlatformID       int    `json:"platform_id,omitempty"`
	PlatformCategory string `json:"platform_category,omitempty"`
	PlatformType     string `json:"platform_type,omitempty"`
	PlatformName     string `json:"platform_name,omitempty"`
	BaseOS           string `json:"base_os,omitempty"`
	Charset          string `json:"charset,omitempty"`
	Database         string `json:"database,omitempty"`
	Schema           string `json:"schema,omitempty"`
}

ContextSnapshot is the explicit, credential-free part of a resource session context that a tool consumer is allowed to retain.

type DatabaseConfig

type DatabaseConfig struct {
	Protocol         string
	Host             string
	Port             int
	ServerName       string
	Username         string
	Password         string
	Database         string
	UseSSL           bool
	PGSSLMode        string
	CACert           string
	ClientCert       string
	ClientKey        string
	AllowInvalidCert bool
	Encrypt          bool
	DisableEncrypt   bool
	ClusterMode      bool
	AuthSource       string
	ConnectionOpts   string
	ProxyURL         string
	DataMaskingRules []model.DataMaskingRule
}

type DirectoryResult

type DirectoryResult struct {
	Path      string      `json:"path"`
	Entries   []FileEntry `json:"entries"`
	Truncated bool        `json:"truncated,omitempty"`
}

type ExecutionUnavailableError

type ExecutionUnavailableError struct {
	Cause error
}

func (*ExecutionUnavailableError) Error

func (e *ExecutionUnavailableError) Error() string

func (*ExecutionUnavailableError) Unwrap

func (e *ExecutionUnavailableError) Unwrap() error

type FileEntry

type FileEntry struct {
	Name    string `json:"name"`
	Path    string `json:"path"`
	Exists  bool   `json:"exists"`
	Size    int64  `json:"size"`
	Perm    string `json:"perm"`
	ModTime int64  `json:"modTime"`
	IsDir   bool   `json:"isDir"`
	Version string `json:"version"`
}

type FileExecutor

FileExecutor is bound to the already authorized SFTP resource. It must not open an untracked connection or bypass the active session's permissions.

type FileToolCapabilities

type FileToolCapabilities struct {
	ReadText bool
	SaveText bool
	Mkdir    bool
	Rename   bool
	Delete   bool
}

type MCPCallToolResult

type MCPCallToolResult struct {
	Content           []MCPTextContent `json:"content"`
	StructuredContent any              `json:"structuredContent,omitempty"`
	IsError           bool             `json:"isError,omitempty"`
	Meta              map[string]any   `json:"_meta"`
}

MCPCallToolResult is the standard tools/call result forwarded by Luna.

type MCPCommandHooks

type MCPCommandHooks struct {
	CommandACLCheck  func(string) CommandACLDecision
	CommandACLReview func(
		context.Context,
		CommandACLDecision,
		string,
	) (CommandACLDecision, error)
	BackgroundRecord    func(string, string, *int, *CommandACLDecision)
	ExecutionGuard      func() error
	BackgroundGuard     func() error
	BackgroundAvailable func() bool
	PTYExecute          func(
		context.Context,
		string,
		*CommandACLDecision,
	) (string, *int, error)
}

type MCPCommandResult

type MCPCommandResult struct {
	Command         string              `json:"command"`
	Execution       string              `json:"execution"`
	Output          string              `json:"output"`
	OutputTruncated bool                `json:"output_truncated,omitempty"`
	ExitCode        *int                `json:"exit_code,omitempty"`
	CommandACL      *CommandACLDecision `json:"command_acl,omitempty"`
}

type MCPCommandToolOptions

type MCPCommandToolOptions struct {
	Executor CommandExecutor
	Validate CommandValidator
	Protocol string
	Hooks    MCPCommandHooks
}

type MCPDispatcher

type MCPDispatcher struct {
	// contains filtered or unexported fields
}

MCPDispatcher validates and executes calls for one resource session. It is deliberately connection-bound: no agent/model state is kept here.

func NewMCPDispatcher

func NewMCPDispatcher(
	ctx context.Context,
	options MCPDispatcherOptions,
) (*MCPDispatcher, error)

func (*MCPDispatcher) AnnounceManifest

func (d *MCPDispatcher) AnnounceManifest() error

func (*MCPDispatcher) Close

func (d *MCPDispatcher) Close()

func (*MCPDispatcher) HandleCancel

func (d *MCPDispatcher) HandleCancel(data []byte) error

func (*MCPDispatcher) HandleRequest

func (d *MCPDispatcher) HandleRequest(data []byte) error

type MCPDispatcherOptions

type MCPDispatcherOptions struct {
	ResourceSessionID string
	Profile           string
	Context           ContextSnapshot
	Handlers          []MCPToolHandler
	Emit              func(MCPOutbound)
}

type MCPManifest

type MCPManifest struct {
	Version           int                 `json:"version"`
	ResourceSessionID string              `json:"resource_session_id"`
	Profile           string              `json:"profile"`
	Context           ContextSnapshot     `json:"context,omitempty"`
	Revision          int                 `json:"revision"`
	Tools             []MCPToolDefinition `json:"tools"`
}

type MCPOutbound

type MCPOutbound struct {
	Type string
	Data []byte
}

type MCPRPCError

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

type MCPResponse

type MCPResponse struct {
	JSONRPC string       `json:"jsonrpc"`
	ID      string       `json:"id"`
	Result  any          `json:"result,omitempty"`
	Error   *MCPRPCError `json:"error,omitempty"`
}

type MCPTextContent

type MCPTextContent struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

type MCPToolDefinition

type MCPToolDefinition struct {
	Name         string         `json:"name"`
	Title        string         `json:"title,omitempty"`
	Description  string         `json:"description,omitempty"`
	Icons        []ToolIcon     `json:"icons,omitempty"`
	InputSchema  map[string]any `json:"inputSchema"`
	OutputSchema map[string]any `json:"outputSchema,omitempty"`
	Annotations  map[string]any `json:"annotations,omitempty"`
	Meta         map[string]any `json:"_meta,omitempty"`
}

type MCPToolHandler

type MCPToolHandler interface {
	Definition() MCPToolDefinition
	Call(context.Context, json.RawMessage) (any, error)
}

func NewCommandTool

func NewCommandTool(options MCPCommandToolOptions) (MCPToolHandler, error)

func NewDatabaseSchemaTool

func NewDatabaseSchemaTool(
	provider SQLMetadataProvider,
	guard func() error,
) (MCPToolHandler, error)

func NewFileToolHandlers

func NewFileToolHandlers(
	executor FileExecutor,
	capabilities FileToolCapabilities,
) ([]MCPToolHandler, error)

func NewTerminalContextTool

func NewTerminalContextTool(provider func() any) (MCPToolHandler, error)

func NewTerminalSnapshotTool

func NewTerminalSnapshotTool(provider func() (any, error)) (MCPToolHandler, error)

type MongoDBExecutor

type MongoDBExecutor struct {
	// contains filtered or unexported fields
}

func NewMongoDBExecutor

func NewMongoDBExecutor(
	ctx context.Context,
	config DatabaseConfig,
) (*MongoDBExecutor, error)

func (*MongoDBExecutor) Close

func (e *MongoDBExecutor) Close() error

func (*MongoDBExecutor) Execute

func (e *MongoDBExecutor) Execute(
	ctx context.Context,
	command string,
	onOutput func(string),
) (string, *int, error)

type MySQLConfig

type MySQLConfig = DatabaseConfig

type MySQLExecutor

type MySQLExecutor struct {
	// contains filtered or unexported fields
}

func NewMySQLExecutor

func NewMySQLExecutor(ctx context.Context, config MySQLConfig) (*MySQLExecutor, error)

func (*MySQLExecutor) Close

func (e *MySQLExecutor) Close() error

func (*MySQLExecutor) Execute

func (e *MySQLExecutor) Execute(
	ctx context.Context, command string, onOutput func(string),
) (string, *int, error)

func (*MySQLExecutor) InvalidateSQLMetadata

func (e *MySQLExecutor) InvalidateSQLMetadata()

func (*MySQLExecutor) LookupSQLSchema

func (e *MySQLExecutor) LookupSQLSchema(
	ctx context.Context, request SQLSchemaLookupRequest,
) (SQLSchemaLookupResult, error)

func (*MySQLExecutor) SQLMetadataScope

func (e *MySQLExecutor) SQLMetadataScope() string

type MySQLSanitizer

type MySQLSanitizer struct {
	// contains filtered or unexported fields
}

func NewMySQLSanitizer

func NewMySQLSanitizer(rules []model.DataMaskingRule) *MySQLSanitizer

func (*MySQLSanitizer) Sanitize

func (s *MySQLSanitizer) Sanitize(column, value string) string

type NativeSQLExecutor

type NativeSQLExecutor struct {
	// contains filtered or unexported fields
}

func NewNativeSQLExecutor

func NewNativeSQLExecutor(
	ctx context.Context,
	config DatabaseConfig,
) (*NativeSQLExecutor, error)

func (*NativeSQLExecutor) Close

func (e *NativeSQLExecutor) Close() error

func (*NativeSQLExecutor) Execute

func (e *NativeSQLExecutor) Execute(
	ctx context.Context,
	command string,
	onOutput func(string),
) (string, *int, error)

func (*NativeSQLExecutor) InvalidateSQLMetadata

func (e *NativeSQLExecutor) InvalidateSQLMetadata()

func (*NativeSQLExecutor) LookupSQLSchema

func (e *NativeSQLExecutor) LookupSQLSchema(
	ctx context.Context, request SQLSchemaLookupRequest,
) (SQLSchemaLookupResult, error)

func (*NativeSQLExecutor) SQLMetadataScope

func (e *NativeSQLExecutor) SQLMetadataScope() string

type RedisExecutor

type RedisExecutor struct {
	// contains filtered or unexported fields
}

func NewRedisExecutor

func NewRedisExecutor(
	ctx context.Context,
	config DatabaseConfig,
) (*RedisExecutor, error)

func (*RedisExecutor) Close

func (e *RedisExecutor) Close() error

func (*RedisExecutor) Execute

func (e *RedisExecutor) Execute(
	ctx context.Context,
	command string,
	onOutput func(string),
) (string, *int, error)

type SQLMetadataProvider

type SQLMetadataProvider interface {
	SQLMetadataScope() string
	LookupSQLSchema(context.Context, SQLSchemaLookupRequest) (SQLSchemaLookupResult, error)
	InvalidateSQLMetadata()
}

type SQLSchemaColumn

type SQLSchemaColumn struct {
	Name     string  `json:"name"`
	Type     string  `json:"type"`
	Nullable bool    `json:"nullable"`
	Default  *string `json:"default"`
	Ordinal  int     `json:"-"`
}

type SQLSchemaLookupRequest

type SQLSchemaLookupRequest struct {
	Tables []string `json:"tables"`
	Query  string   `json:"query"`
}

type SQLSchemaLookupResult

type SQLSchemaLookupResult struct {
	Database  string           `json:"database"`
	Matches   []string         `json:"matches,omitempty"`
	Tables    []SQLTableSchema `json:"tables"`
	Truncated bool             `json:"truncated,omitempty"`
}

type SQLTableSchema

type SQLTableSchema struct {
	Database string            `json:"database"`
	Schema   string            `json:"schema,omitempty"`
	Table    string            `json:"table"`
	Columns  []SQLSchemaColumn `json:"columns"`
}

type SSHExecutor

type SSHExecutor struct {
	// contains filtered or unexported fields
}

func NewSSHExecutor

func NewSSHExecutor(client *srvconn.SSHClient) *SSHExecutor

func (*SSHExecutor) Close

func (e *SSHExecutor) Close() error

func (*SSHExecutor) Execute

func (e *SSHExecutor) Execute(
	ctx context.Context, command string, onOutput func(string),
) (string, *int, error)

type TerminalCommandResult

type TerminalCommandResult struct {
	Command string
	Output  string
}

type TerminalObserver

type TerminalObserver struct {
	// contains filtered or unexported fields
}

TerminalObserver keeps a bounded local terminal view. Feed never leaves the Koko process; Snapshot is exposed only through the current session tool.

func NewTerminalObserver

func NewTerminalObserver(width, height int) (*TerminalObserver, error)

func (*TerminalObserver) Begin

func (o *TerminalObserver) Begin(command string) (<-chan TerminalCommandResult, error)

func (*TerminalObserver) Cancel

func (o *TerminalObserver) Cancel()

func (*TerminalObserver) Close

func (o *TerminalObserver) Close() error

func (*TerminalObserver) Feed

func (o *TerminalObserver) Feed(data []byte)

func (*TerminalObserver) Resize

func (o *TerminalObserver) Resize(width, height int)

func (*TerminalObserver) Snapshot

func (o *TerminalObserver) Snapshot() string

type TextResult

type TextResult struct {
	Path      string `json:"path"`
	Exists    bool   `json:"exists"`
	Content   string `json:"content"`
	Version   string `json:"version"`
	Truncated bool   `json:"truncated,omitempty"`
}

type ToolIcon

type ToolIcon struct {
	Source   string   `json:"src"`
	MIMEType string   `json:"mimeType,omitempty"`
	Sizes    []string `json:"sizes,omitempty"`
	Theme    string   `json:"theme,omitempty"`
}

type ValueSanitizer

type ValueSanitizer interface {
	Sanitize(column, value string) string
}

Jump to

Keyboard shortcuts

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