context

package
v2.0.0-...-e411800 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvVarXDGConfigHome is the XDG Base Directory env var name for config files.
	EnvVarXDGConfigHome = "XDG_CONFIG_HOME"

	// EnvVarXDGCacheHome is the XDG Base Directory env var name for cache file.
	EnvVarXDGCacheHome = "XDG_CACHE_HOME"
)

Variables

This section is empty.

Functions

func AppDirName

func AppDirName() string

AppDirName returns the name of the application directory for use in user-specific operations where data is being written.

func EnsureAtLeastRegularDir

func EnsureAtLeastRegularDir(path string) error

EnsureAtLeastRegularDir creates a directory with standard permissions if it doesn't exist, and verifies that it has at least the required regular permissions if it already exists. It does not attempt to repair ownership or permissions: if they are wrong, it returns an error. Used for cache directories, data directories, and documentation.

func EnsureAtLeastSecureDir

func EnsureAtLeastSecureDir(path string) error

EnsureAtLeastSecureDir creates a directory with secure permissions if it doesn't exist, and verifies that it has at least the required secure permissions if it already exists. It does not attempt to repair ownership or permissions: if they are wrong, it returns an error.

func UserSpecificCacheDir

func UserSpecificCacheDir() (string, error)

UserSpecificCacheDir returns the directory that should be used to store any user-specific cache files. It adheres to the XDG Base Directory Specification, respecting the XDG_CACHE_HOME environment variable. When XDG_CACHE_HOME is not set, it defaults to ~/.cache/mcpd/ See: https://specifications.freedesktop.org/basedir-spec/latest/

func UserSpecificConfigDir

func UserSpecificConfigDir() (string, error)

UserSpecificConfigDir returns the directory that should be used to store any user-specific configuration. It adheres to the XDG Base Directory Specification, respecting the XDG_CONFIG_HOME environment variable. When XDG_CONFIG_HOME is not set, it defaults to ~/.config/mcpd/ See: https://specifications.freedesktop.org/basedir-spec/latest/

Types

type DefaultLoader

type DefaultLoader struct{}

DefaultLoader loads execution context configurations.

func (*DefaultLoader) Load

func (d *DefaultLoader) Load(path string) (Modifier, error)

Load loads an execution context configuration from the specified path.

type ExecutionContextConfig

type ExecutionContextConfig struct {
	Servers map[string]ServerExecutionContext `toml:"servers"`
	// contains filtered or unexported fields
}

ExecutionContextConfig stores execution context data for all configured MCP servers.

func NewExecutionContextConfig

func NewExecutionContextConfig(path string) *ExecutionContextConfig

NewExecutionContextConfig returns a newly initialized ExecutionContextConfig.

func (*ExecutionContextConfig) Get

Get retrieves the execution context for the specified server name.

func (*ExecutionContextConfig) List

List returns all server execution contexts sorted by name.

func (*ExecutionContextConfig) SaveConfig

func (c *ExecutionContextConfig) SaveConfig() error

SaveConfig saves the execution context configuration to a file with secure permissions. Used for runtime execution contexts that may contain sensitive data.

func (*ExecutionContextConfig) SaveExportedConfig

func (c *ExecutionContextConfig) SaveExportedConfig() error

SaveExportedConfig saves the execution context configuration to a file with regular permissions. Used for exported configurations that are sanitized and suitable for sharing.

func (*ExecutionContextConfig) Upsert

Upsert updates the execution context for the given server name. If the context is empty and does not exist in config, it does nothing. If the context is empty and previously existed in config, it deletes the entry. If the context differs from the existing one in config, it updates it. If the context is new and non-empty, it adds it. Returns the operation performed (Created, Updated, Deleted, or Noop), and writes changes to disk if applicable.

type Exporter

type Exporter interface {
	// Export handles exporting runtime execution context data to the specified path.
	// It returns a map which can be used by the caller, and is intended to contain
	// additional information such as the contract data for processing.
	Export(path string) (map[string]string, error)
}

type Loader

type Loader interface {
	Load(path string) (Modifier, error)
}

type Modifier

type Modifier interface {
	Get(name string) (ServerExecutionContext, bool)
	Upsert(ctx ServerExecutionContext) (UpsertResult, error)
	List() []ServerExecutionContext
}

type ServerExecutionContext

type ServerExecutionContext struct {
	// Name is the server name.
	Name string `toml:"-"`

	// Args contains command-line arguments with environment variables expanded.
	// NOTE: Use runtime.Server.SafeArgs() for filtered access when starting servers.
	Args []string `toml:"args,omitempty"`

	// Env contains environment variables with values expanded.
	// NOTE: Use runtime.Server.SafeEnv() for filtered access when starting servers.
	Env map[string]string `toml:"env,omitempty"`

	// RawEnv stores unexpanded environment variables used for cross-server filtering decisions.
	RawEnv map[string]string `toml:"-"`

	// RawArgs stores unexpanded command-line arguments used for cross-server filtering decisions.
	RawArgs []string `toml:"-"`
}

ServerExecutionContext stores execution context data for an MCP server.

The Args and Env fields contain expanded values with environment variables resolved. These should not be used directly when starting MCP servers, as they may contain cross-server references that pose security risks.

Instead, use the server's SafeArgs() and SafeEnv() methods (in the runtime package) which filter out cross-server references using the RawArgs and RawEnv fields.

func (*ServerExecutionContext) Equals

Equals checks if this ServerExecutionContext is equal to another.

func (*ServerExecutionContext) IsEmpty

func (s *ServerExecutionContext) IsEmpty() bool

IsEmpty returns true if the ServerExecutionContext has no args or env vars.

type UpsertResult

type UpsertResult string
const (
	Created UpsertResult = "created"
	Updated UpsertResult = "updated"
	Deleted UpsertResult = "deleted"
	Noop    UpsertResult = "noop"
)

Jump to

Keyboard shortcuts

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