commands

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package commands provides a shared interface for REPL command implementations.

This package defines the Command interface that all REPL commands must implement, enabling a clean registry pattern and improved testability. Commands are responsible for their own parsing, execution, and completion logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseCommand

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

BaseCommand provides common functionality for all REPL commands. It encapsulates shared dependencies and utility methods that most commands need, reducing code duplication and ensuring consistent behavior across the command system.

Key features:

  • Dependency injection for client, logger, and transport
  • Argument parsing and validation utilities
  • Common completion helpers for tools, resources, and prompts
  • Consistent error handling patterns

func NewBaseCommand

func NewBaseCommand(client ClientInterface, output OutputLogger, transport TransportInterface) *BaseCommand

NewBaseCommand creates a new base command with the specified dependencies. This constructor ensures all commands have access to the core functionality they need while maintaining clean separation of concerns.

Args:

  • client: MCP client interface for operations
  • output: Logger interface for user-facing output
  • transport: Transport interface for capability checking

Returns:

  • Configured base command instance

type CallCommand

type CallCommand struct {
	*BaseCommand
}

CallCommand executes tools with arguments

func NewCallCommand

func NewCallCommand(client ClientInterface, output OutputLogger, transport TransportInterface) *CallCommand

NewCallCommand creates a new call command

func (*CallCommand) Aliases

func (c *CallCommand) Aliases() []string

Aliases returns command aliases

func (*CallCommand) Completions

func (c *CallCommand) Completions(input string) []string

Completions returns possible completions

func (*CallCommand) Description

func (c *CallCommand) Description() string

Description returns the command description

func (*CallCommand) Execute

func (c *CallCommand) Execute(ctx context.Context, args []string) error

Execute calls a tool with the given arguments

func (*CallCommand) Usage

func (c *CallCommand) Usage() string

Usage returns the usage string

type ClientInterface

type ClientInterface interface {
	// Cache access methods return the currently cached items
	GetToolCache() []mcp.Tool
	GetResourceCache() []mcp.Resource
	GetPromptCache() []mcp.Prompt
	RefreshToolCache(ctx context.Context) error
	RefreshResourceCache(ctx context.Context) error
	RefreshPromptCache(ctx context.Context) error

	// Core MCP operations for executing commands
	CallTool(ctx context.Context, name string, args map[string]interface{}) (*mcp.CallToolResult, error)
	GetResource(ctx context.Context, uri string) (*mcp.ReadResourceResult, error)
	GetPrompt(ctx context.Context, name string, args map[string]string) (*mcp.GetPromptResult, error)

	// Formatters access for consistent output formatting
	// Returns the concrete Formatters type that will be cast by commands
	GetFormatters() interface{}
}

ClientInterface defines the interface that commands need from the client. This interface abstracts the client functionality required by commands, enabling them to access cached data and perform operations without depending directly on the concrete client implementation.

The interface provides:

  • Access to cached tools, resources, and prompts
  • Core MCP operations (tool calls, resource access, prompt execution)
  • Formatter access for consistent output formatting

type Command

type Command interface {
	// Execute runs the command with the given arguments
	Execute(ctx context.Context, args []string) error

	// Usage returns the usage string for the command
	Usage() string

	// Description returns a brief description of what the command does
	Description() string

	// Completions returns possible completions for the command
	// The input arg is the current partial input for context
	Completions(input string) []string

	// Aliases returns alternative names for this command
	Aliases() []string
}

Command represents a REPL command that can be executed interactively.

type ContextCommand

type ContextCommand struct {
	*BaseCommand
	// contains filtered or unexported fields
}

ContextCommand handles context listing and switching in the REPL. This command allows users to view available contexts, see the current context, and switch between contexts without leaving the REPL. When switching contexts, it automatically reconnects to the new endpoint.

func NewContextCommand

func NewContextCommand(client ClientInterface, output OutputLogger, transport TransportInterface, onContextChange func(string), onReconnect ReconnectFunc) *ContextCommand

NewContextCommand creates a new context command.

Args:

  • client: MCP client interface for operations
  • output: Logger interface for user-facing output
  • transport: Transport interface for capability checking
  • onContextChange: Callback function called when context is switched (updates prompt)
  • onReconnect: Callback function to reconnect to the new endpoint

Returns:

  • Configured context command instance

func (*ContextCommand) Aliases

func (c *ContextCommand) Aliases() []string

Aliases returns alternative names for the context command.

func (*ContextCommand) Completions

func (c *ContextCommand) Completions(input string) []string

Completions returns possible completions for the context command.

func (*ContextCommand) Description

func (c *ContextCommand) Description() string

Description returns a brief description of what the command does.

func (*ContextCommand) Execute

func (c *ContextCommand) Execute(ctx context.Context, args []string) error

Execute runs the context command with the given arguments. Subcommands:

  • (no args): Show current context
  • list/ls: List all available contexts
  • use/switch <name>: Switch to a different context

The ctx parameter is passed through to subcommands for cancellation support.

func (*ContextCommand) GetContextNames

func (c *ContextCommand) GetContextNames() []string

GetContextNames returns available context names for completion. This method is exported for use by the REPL completer.

func (*ContextCommand) Usage

func (c *ContextCommand) Usage() string

Usage returns the usage string for the context command.

type DescribeCommand

type DescribeCommand struct {
	*BaseCommand
}

DescribeCommand shows detailed information about tools, resources, or prompts

func NewDescribeCommand

func NewDescribeCommand(client ClientInterface, output OutputLogger, transport TransportInterface) *DescribeCommand

NewDescribeCommand creates a new describe command

func (*DescribeCommand) Aliases

func (d *DescribeCommand) Aliases() []string

Aliases returns command aliases

func (*DescribeCommand) Completions

func (d *DescribeCommand) Completions(input string) []string

Completions returns possible completions

func (*DescribeCommand) Description

func (d *DescribeCommand) Description() string

Description returns the command description

func (*DescribeCommand) Execute

func (d *DescribeCommand) Execute(ctx context.Context, args []string) error

Execute describes a tool, resource, or prompt

func (*DescribeCommand) Usage

func (d *DescribeCommand) Usage() string

Usage returns the usage string

type ExitCommand

type ExitCommand struct {
	*BaseCommand
}

ExitCommand handles REPL exit

func NewExitCommand

func NewExitCommand(client ClientInterface, output OutputLogger, transport TransportInterface) *ExitCommand

NewExitCommand creates a new exit command

func (*ExitCommand) Aliases

func (e *ExitCommand) Aliases() []string

Aliases returns command aliases

func (*ExitCommand) Completions

func (e *ExitCommand) Completions(input string) []string

Completions returns possible completions

func (*ExitCommand) Description

func (e *ExitCommand) Description() string

Description returns the command description

func (*ExitCommand) Execute

func (e *ExitCommand) Execute(ctx context.Context, args []string) error

Execute exits the REPL

func (*ExitCommand) Usage

func (e *ExitCommand) Usage() string

Usage returns the usage string

type FilterCommand

type FilterCommand struct {
	*BaseCommand
}

FilterCommand filters tools by pattern and description

func NewFilterCommand

func NewFilterCommand(client ClientInterface, output OutputLogger, transport TransportInterface) *FilterCommand

NewFilterCommand creates a new filter command

func (*FilterCommand) Aliases

func (f *FilterCommand) Aliases() []string

Aliases returns command aliases

func (*FilterCommand) Completions

func (f *FilterCommand) Completions(input string) []string

Completions returns possible completions

func (*FilterCommand) Description

func (f *FilterCommand) Description() string

Description returns the command description

func (*FilterCommand) Execute

func (f *FilterCommand) Execute(ctx context.Context, args []string) error

Execute filters tools based on the discovery-tier options.

After the "tools" target, options are given as key=value pairs (pattern, description, query, labels, case_sensitive, detailed, limit, offset). A bare argument with no "=" is treated as the name pattern, so the common "filter tools core_*" shorthand keeps working.

func (*FilterCommand) Usage

func (f *FilterCommand) Usage() string

Usage returns the usage string

type FormatterInterface

type FormatterInterface interface {
	// List formatting methods for displaying collections
	FormatToolsList(tools []mcp.Tool) string
	FormatResourcesList(resources []mcp.Resource) string
	FormatPromptsList(prompts []mcp.Prompt) string

	// Detail formatting methods for individual items
	FormatToolDetail(tool mcp.Tool) string
	FormatResourceDetail(resource mcp.Resource) string
	FormatPromptDetail(prompt mcp.Prompt) string

	// Search utilities for finding items by identifier
	FindTool(tools []mcp.Tool, name string) *mcp.Tool
	FindResource(resources []mcp.Resource, uri string) *mcp.Resource
	FindPrompt(prompts []mcp.Prompt, name string) *mcp.Prompt
}

FormatterInterface defines the interface for formatting operations. This provides a clean abstraction for commands to format MCP data consistently across different output modes and contexts.

The interface supports:

  • List formatting for browsing available items
  • Detail formatting for comprehensive item information
  • Search and lookup utilities for finding specific items

type GetCommand

type GetCommand struct {
	*BaseCommand
}

GetCommand retrieves resources

func NewGetCommand

func NewGetCommand(client ClientInterface, output OutputLogger, transport TransportInterface) *GetCommand

NewGetCommand creates a new get command

func (*GetCommand) Aliases

func (g *GetCommand) Aliases() []string

Aliases returns command aliases

func (*GetCommand) Completions

func (g *GetCommand) Completions(input string) []string

Completions returns possible completions

func (*GetCommand) Description

func (g *GetCommand) Description() string

Description returns the command description

func (*GetCommand) Execute

func (g *GetCommand) Execute(ctx context.Context, args []string) error

Execute retrieves a resource

func (*GetCommand) Usage

func (g *GetCommand) Usage() string

Usage returns the usage string

type HelpCommand

type HelpCommand struct {
	*BaseCommand
	// contains filtered or unexported fields
}

HelpCommand shows available commands and usage information

func NewHelpCommand

func NewHelpCommand(client ClientInterface, output OutputLogger, transport TransportInterface, registry *Registry) *HelpCommand

NewHelpCommand creates a new help command

func (*HelpCommand) Aliases

func (h *HelpCommand) Aliases() []string

Aliases returns command aliases

func (*HelpCommand) Completions

func (h *HelpCommand) Completions(input string) []string

Completions returns possible completions

func (*HelpCommand) Description

func (h *HelpCommand) Description() string

Description returns the command description

func (*HelpCommand) Execute

func (h *HelpCommand) Execute(ctx context.Context, args []string) error

Execute shows help information

func (*HelpCommand) Usage

func (h *HelpCommand) Usage() string

Usage returns the usage string

type ListCommand

type ListCommand struct {
	*BaseCommand
}

ListCommand lists available tools, resources, or prompts

func NewListCommand

func NewListCommand(client ClientInterface, output OutputLogger, transport TransportInterface) *ListCommand

NewListCommand creates a new list command

func (*ListCommand) Aliases

func (l *ListCommand) Aliases() []string

Aliases returns command aliases

func (*ListCommand) Completions

func (l *ListCommand) Completions(input string) []string

Completions returns possible completions

func (*ListCommand) Description

func (l *ListCommand) Description() string

Description returns the command description

func (*ListCommand) Execute

func (l *ListCommand) Execute(ctx context.Context, args []string) error

Execute lists tools, resources, or prompts

func (*ListCommand) Usage

func (l *ListCommand) Usage() string

Usage returns the usage string

type NotificationsCommand

type NotificationsCommand struct {
	*BaseCommand
}

NotificationsCommand handles enabling/disabling notifications

func NewNotificationsCommand

func NewNotificationsCommand(client ClientInterface, output OutputLogger, transport TransportInterface) *NotificationsCommand

NewNotificationsCommand creates a new notifications command

func (*NotificationsCommand) Aliases

func (n *NotificationsCommand) Aliases() []string

Aliases returns command aliases

func (*NotificationsCommand) Completions

func (n *NotificationsCommand) Completions(input string) []string

Completions returns possible completions

func (*NotificationsCommand) Description

func (n *NotificationsCommand) Description() string

Description returns the command description

func (*NotificationsCommand) Execute

func (n *NotificationsCommand) Execute(ctx context.Context, args []string) error

Execute enables or disables notification display

func (*NotificationsCommand) Usage

func (n *NotificationsCommand) Usage() string

Usage returns the usage string

type OutputLogger

type OutputLogger interface {
	// User-facing output (goes to stdout, no timestamps)
	Output(format string, args ...interface{})     // For command results
	OutputLine(format string, args ...interface{}) // Same as Output but with newline

	// System messages (structured logging with timestamps)
	Info(format string, args ...interface{})    // Status messages
	Debug(format string, args ...interface{})   // Debug information
	Error(format string, args ...interface{})   // Error messages
	Success(format string, args ...interface{}) // Success messages

	// Configuration
	SetVerbose(verbose bool)
}

OutputLogger defines the interface for structured command output. This separates user-facing output from system logging.

type PromptCommand

type PromptCommand struct {
	*BaseCommand
}

PromptCommand gets prompts with arguments

func NewPromptCommand

func NewPromptCommand(client ClientInterface, output OutputLogger, transport TransportInterface) *PromptCommand

NewPromptCommand creates a new prompt command

func (*PromptCommand) Aliases

func (p *PromptCommand) Aliases() []string

Aliases returns command aliases

func (*PromptCommand) Completions

func (p *PromptCommand) Completions(input string) []string

Completions returns possible completions

func (*PromptCommand) Description

func (p *PromptCommand) Description() string

Description returns the command description

func (*PromptCommand) Execute

func (p *PromptCommand) Execute(ctx context.Context, args []string) error

Execute gets a prompt with the given arguments

func (*PromptCommand) Usage

func (p *PromptCommand) Usage() string

Usage returns the usage string

type ReconnectFunc

type ReconnectFunc func(ctx context.Context, endpoint string) error

ReconnectFunc is the function signature for reconnecting to a new endpoint.

type Registry

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

Registry manages available commands for the REPL.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new command registry.

func (*Registry) AllCompletions

func (r *Registry) AllCompletions() []string

AllCompletions returns all possible command completions.

func (*Registry) Get

func (r *Registry) Get(name string) (Command, bool)

Get retrieves a command by name or alias.

func (*Registry) List

func (r *Registry) List() []string

List returns all registered command names.

func (*Registry) Register

func (r *Registry) Register(name string, cmd Command)

Register adds a command to the registry.

type StorageProvider

type StorageProvider interface {
	GetCurrentContextName() (string, error)
	Load() (*musterctx.ContextConfig, error)
	GetContext(name string) (*musterctx.Context, error)
	GetContextNames() ([]string, error)
	SetCurrentContext(name string) error
}

StorageProvider abstracts context storage operations for testability. This interface allows injecting mock storage in tests.

type TransportInterface

type TransportInterface interface {
	// SupportsNotifications returns whether the transport supports real-time notifications
	SupportsNotifications() bool
}

TransportInterface defines the interface for transport capability checking. Commands use this to adapt their behavior based on transport capabilities, particularly for features like real-time notifications.

type WorkflowCommand

type WorkflowCommand struct {
	*BaseCommand
}

WorkflowCommand executes workflows with parameters

func NewWorkflowCommand

func NewWorkflowCommand(client ClientInterface, output OutputLogger, transport TransportInterface) *WorkflowCommand

NewWorkflowCommand creates a new workflow command

func (*WorkflowCommand) Aliases

func (w *WorkflowCommand) Aliases() []string

Aliases returns command aliases

func (*WorkflowCommand) Completions

func (w *WorkflowCommand) Completions(input string) []string

Completions returns possible completions

func (*WorkflowCommand) Description

func (w *WorkflowCommand) Description() string

Description returns the command description

func (*WorkflowCommand) Execute

func (w *WorkflowCommand) Execute(ctx context.Context, args []string) error

Execute executes a workflow with the given parameters

func (*WorkflowCommand) Usage

func (w *WorkflowCommand) Usage() string

Usage returns the usage string

Jump to

Keyboard shortcuts

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