server

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package server wires together the security pipeline and registers MCP tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHTTPHandler

func NewHTTPHandler(core *Core, opts ...ServerOptions) http.Handler

NewHTTPHandler returns an http.Handler serving MCP over SSE.

func NewMCPServer

func NewMCPServer(core *Core, opts ...ServerOptions) *mcp.Server

func RunStdio

func RunStdio(ctx context.Context, core *Core, opts ...ServerOptions) error

Types

type ConnectInput

type ConnectInput struct {
	Host         string `json:"host" jsonschema:"Hostname or IP address"`
	User         string `json:"user,omitempty" jsonschema:"SSH username (default root)"`
	Port         int    `json:"port,omitempty" jsonschema:"SSH port (default 22)"`
	IdentityFile string `json:"identity_file,omitempty" jsonschema:"Path to SSH identity file"`
}

type Core

type Core struct {
	Registry map[string]*manifest.Manifest
	Runner   Executor

	Parse       func(string) (*parser.Pipeline, error)
	Validate    func(*parser.Pipeline, map[string]*manifest.Manifest) error
	Reconstruct func(*parser.Pipeline, bool, bool) string
	Truncate    func(string, string, int, int, ...int) output.CommandResult

	DefaultTimeout   int
	MaxOutputBytes   int
	MaxDownloadBytes int
	DownloadDir      string
	MaxSleepSeconds  int
	// contains filtered or unexported fields
}

func NewCore

func NewCore(registry map[string]*manifest.Manifest, runner Executor, logger *slog.Logger, opts ...CoreOption) *Core

func (*Core) Close

func (c *Core) Close(ctx context.Context) error

Close disconnects all SSH sessions and clears internal state. Internal state is always cleared even if the disconnect fails. It is safe to call multiple times.

func (*Core) Connect

func (c *Core) Connect(ctx context.Context, in ConnectInput) (map[string]any, error)

func (*Core) Disconnect

func (c *Core) Disconnect(ctx context.Context, in DisconnectInput) (map[string]any, error)

func (*Core) DownloadFile

func (c *Core) DownloadFile(ctx context.Context, in DownloadInput) (DownloadResult, error)

func (*Core) Execute

func (c *Core) Execute(ctx context.Context, in ExecuteInput) (output.CommandResult, error)

func (*Core) Logger

func (c *Core) Logger() *slog.Logger

Logger returns the logger used by this Core.

func (*Core) Provision

func (c *Core) Provision(ctx context.Context, in ProvisionInput) (map[string]any, error)

func (*Core) Sleep

func (c *Core) Sleep(ctx context.Context, in SleepInput) (map[string]any, error)

type CoreOption

type CoreOption func(*Core)

func WithDefaultTimeout

func WithDefaultTimeout(seconds int) CoreOption

func WithDownloadDir

func WithDownloadDir(dir string) CoreOption

func WithMaxDownloadBytes

func WithMaxDownloadBytes(bytes int) CoreOption

func WithMaxOutputBytes

func WithMaxOutputBytes(bytes int) CoreOption

func WithMaxSleepSeconds

func WithMaxSleepSeconds(seconds int) CoreOption

type DisconnectInput

type DisconnectInput struct {
	Host string `json:"host,omitempty" jsonschema:"Hostname to disconnect; empty disconnects all"`
}

type DownloadInput

type DownloadInput struct {
	RemotePath string `json:"remote_path" jsonschema:"Absolute path to file on remote server"`
	LocalDir   string `json:"local_dir,omitempty" jsonschema:"Local directory to save to (default: /tmp/shellguard-downloads/)"`
	Host       string `json:"host,omitempty" jsonschema:"Hostname when multiple connections exist"`
}

type DownloadResult

type DownloadResult struct {
	LocalPath string `json:"local_path"`
	SizeBytes int64  `json:"size_bytes"`
	Filename  string `json:"filename"`
}

type ExecuteInput

type ExecuteInput struct {
	Command string `json:"command" jsonschema:"Shell command or pipeline to execute"`
	Host    string `json:"host,omitempty" jsonschema:"Hostname when multiple connections exist"`
}

type Executor

type Executor interface {
	Connect(ctx context.Context, params ssh.ConnectionParams) error
	Execute(ctx context.Context, host, command string, timeout time.Duration) (ssh.ExecResult, error)
	ExecuteRaw(ctx context.Context, host, command string, timeout time.Duration) (ssh.ExecResult, error)
	SFTPSession(host string) (ssh.SFTPClient, error)
	Disconnect(ctx context.Context, host string) error
}

Executor runs commands on remote targets.

type ProbeResult

type ProbeResult struct {
	Missing []string
	Arch    string
}

type ProvisionInput

type ProvisionInput struct {
	Host string `json:"host,omitempty" jsonschema:"Hostname to provision. Required when connected to multiple servers."`
}

type ServerOptions

type ServerOptions struct {
	// Name is the MCP server implementation name. Default: "shellguard".
	Name string
	// Version is the MCP server implementation version. Default: "0.2.0".
	Version string
}

type SleepInput

type SleepInput struct {
	Seconds float64 `json:"seconds" jsonschema:"Duration to sleep in seconds"`
}

Jump to

Keyboard shortcuts

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