commands

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package commands implements individual commands for the MCP CLI.

Package commands implements individual commands for the MCP CLI.

Index

Constants

View Source
const (
	FlagFormat      = "--format"
	FlagFormatShort = "-f"
	FlagParams      = "--params"
	FlagParamsShort = "-p"
	FlagHelp        = "--help"
	FlagHelpShort   = "-h"
)

flags.

View Source
const (
	EntityTypeTool   = "tool"
	EntityTypePrompt = "prompt"
	EntityTypeRes    = "resource"
)

entity types.

Variables

View Source
var (
	// FormatOption is the format option for the command, valid values are "table", "json", and
	// "pretty".
	FormatOption string
	// ParamsString is the params for the command.
	ParamsString string
)
View Source
var CreateClientFunc = func(args []string) (*client.Client, error) {
	if len(args) == 0 {
		return nil, ErrCommandRequired
	}

	isHTTP := func(str string) bool {
		return strings.HasPrefix(str, "http://") || strings.HasPrefix(str, "https://")
	}

	if len(args) == 1 {
		server, found := alias.GetServerCommand(args[0])
		if found {
			if isHTTP(server) {
				return client.NewHTTP(server), nil
			}
			cmdParts := client.ParseCommandString(server)
			return client.NewStdio(cmdParts), nil
		}
	}

	if len(args) == 1 && isHTTP(args[0]) {
		return client.NewHTTP(args[0]), nil
	}

	return client.NewStdio(args), nil
}

CreateClientFunc is the function used to create MCP clients. This can be replaced in tests to use a mock transport.

View Source
var (
	ErrCommandRequired = fmt.Errorf("command to execute is required when using stdio transport")
)

sentinel errors.

View Source
var Version = "dev"

Version information placeholder.

Functions

func AliasCmd

func AliasCmd() *cobra.Command

AliasCmd creates the alias command.

func CallCmd

func CallCmd() *cobra.Command

CallCmd creates the call command.

func FormatAndPrintResponse

func FormatAndPrintResponse(cmd *cobra.Command, resp map[string]any, err error) error

FormatAndPrintResponse formats and prints an MCP response in the format specified by FormatOption.

func GetPromptCmd

func GetPromptCmd() *cobra.Command

GetPromptCmd creates the get-prompt command.

func LoadProxyConfig

func LoadProxyConfig() (map[string]map[string]string, error)

LoadProxyConfig loads the proxy configuration from the config file.

func MockCmd

func MockCmd() *cobra.Command

MockCmd creates the mock command.

func NewCmd

func NewCmd() *cobra.Command

NewCmd returns a new 'new' command for scaffolding MCP projects.

func ProcessFlags

func ProcessFlags(args []string) []string

ProcessFlags processes command line flags, sets the format option, and returns the remaining arguments. Supported format options: json, pretty, and table.

For example, if the input arguments are ["tools", "--format", "pretty", "npx", "-y", "@modelcontextprotocol/server-filesystem", "~"], it would return ["npx", "-y", "@modelcontextprotocol/server-filesystem", "~"] and set the format option to "pretty".

func PromptsCmd

func PromptsCmd() *cobra.Command

PromptsCmd creates the prompts command.

func ProxyCmd

func ProxyCmd() *cobra.Command

ProxyCmd creates the proxy command.

func ProxyStartCmd

func ProxyStartCmd() *cobra.Command

ProxyStartCmd creates the proxy start command.

func ProxyToolCmd

func ProxyToolCmd() *cobra.Command

ProxyToolCmd creates the proxy tool command.

func ReadResourceCmd

func ReadResourceCmd() *cobra.Command

ReadResourceCmd creates the read-resource command.

func ResourcesCmd

func ResourcesCmd() *cobra.Command

ResourcesCmd creates the resources command.

func RootCmd

func RootCmd() *cobra.Command

RootCmd creates the root command.

func SaveProxyConfig

func SaveProxyConfig(config map[string]map[string]string) error

SaveProxyConfig saves the proxy configuration to the config file.

func ShellCmd

func ShellCmd() *cobra.Command

ShellCmd creates the shell command.

func ToolsCmd

func ToolsCmd() *cobra.Command

ToolsCmd creates the tools command.

func VersionCmd

func VersionCmd() *cobra.Command

VersionCmd creates the version command.

Types

type MockTransport

type MockTransport struct {
	ExecuteFunc func(method string, params any) (map[string]any, error)
}

MockTransport implements the transport.Transport interface for testing.

func (*MockTransport) Execute

func (m *MockTransport) Execute(method string, params any) (map[string]any, error)

Execute calls the mock implementation.

Jump to

Keyboard shortcuts

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