cli

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CurrentVersion string

CurrentVersion is set from main.go

View Source
var ExecCmd = &ucli.Command{
	Name:      "exec",
	Usage:     "Execute JavaScript code to orchestrate multiple MCP tool calls",
	ArgsUsage: "<code | ->",
	Description: `Execute JavaScript code that can call multiple MCP tools with logic.

Use this when you need to:
- Chain multiple tool calls
- Process data between calls
- Use conditionals or loops
- Aggregate results

For single tool calls, use 'invoke' instead.

The 'mcp.callTool(name, params)' function is available to call tools.
Tool names can be in either format:
  - JS name (camelCase): githubSearchRepos
  - Original name: github__search_repos

Examples:
  # Chain tool calls (config mode)
  mh exec -c config.json 'const user = mcp.callTool("dbGetUser", {id: 1}); mcp.callTool("emailSend", {to: user.email})'

  # Read code from stdin
  cat script.js | mh exec -c config.json -

  # With remote server (use tool names directly)
  mh exec -u http://localhost:3000 'const a = mcp.callTool("add", {x: 1, y: 2}); mcp.callTool("multiply", {x: a, y: 3})'

  # With stdio server (use tool names directly)
  mh exec --stdio 'mcp.callTool("echo", {message: "hello"})' -- npx @modelcontextprotocol/server-everything

  # JSON output
  mh exec -c config.json --json 'mcp.callTool("githubListRepos", {})'`,
	Flags:  MCPClientFlags(),
	Before: ValidateMCPClientFlags,
	Action: runExec,
}

ExecCmd is the exec subcommand that executes JavaScript code against MCP tools

View Source
var InspectCmd = &ucli.Command{
	Name:      "inspect",
	Usage:     "Inspect a tool from an MCP service",
	ArgsUsage: "<tool-name>",
	Description: `Show detailed information about a specific tool from an MCP service.

Provide --url (-u) for a remote MCP service, --config (-c) to load local
stdio/http/sse servers from config, or --stdio to spawn a subprocess.
Takes tool name as a required positional argument.

Tool names can be in either format:
  - JS name (camelCase): githubSearchRepos
  - Original name: github__search_repos

Examples:
  # Inspect a tool
  mh inspect -u http://localhost:3000 myTool

  # Inspect a tool with JSON output
  mh inspect -u http://localhost:3000 myTool --json

  # Inspect a tool using SSE transport
  mh inspect -u http://localhost:3000 -t sse myTool

  # Inspect a tool from config (stdio/http/sse)
  mh inspect -c config.json githubSearchRepos

  # Inspect a tool from a stdio MCP server
  mh inspect --stdio echo -- npx @modelcontextprotocol/server-everything`,
	Flags:  MCPClientFlags(),
	Before: ValidateMCPClientFlags,
	Action: runInspect,
}

InspectCmd is the inspect subcommand that shows details of a specific tool

View Source
var InvokeCmd = &ucli.Command{
	Name:      "invoke",
	Usage:     "Invoke a tool on an MCP service",
	ArgsUsage: "<tool-name> [params-json | -]",
	Description: `Invoke a tool on an MCP service with optional JSON parameters.

Provide --url (-u) for a remote MCP service, --config (-c) to load local
stdio/http/sse servers from config, or --stdio to spawn a subprocess.
Takes tool name as a required positional argument.
Parameters can be provided as:
  - A JSON string argument
  - "-" to read JSON from stdin
  - Omitted for tools with no required parameters

Tool names can be in either format:
  - JS name (camelCase): githubSearchRepos
  - Original name: github__search_repos

Examples:
  # Invoke a tool with no parameters
  mh invoke -u http://localhost:3000 myTool

  # Invoke a tool with JSON parameters
  mh invoke -u http://localhost:3000 myTool '{"key": "value"}'

  # Invoke a tool with parameters from stdin
  echo '{"key": "value"}' | mh invoke -u http://localhost:3000 myTool -

  # Invoke a tool with JSON output
  mh invoke -u http://localhost:3000 myTool '{"key": "value"}' --json

  # Invoke a tool from config (stdio/http/sse)
  mh invoke -c config.json githubSearchRepos '{"query": "mcp"}'

  # Invoke a tool from a stdio MCP server
  mh invoke --stdio echo '{"message": "hello"}' -- npx @modelcontextprotocol/server-everything`,
	Flags:  MCPClientFlags(),
	Before: ValidateMCPClientFlags,
	Action: runInvoke,
}

InvokeCmd is the invoke subcommand that invokes a tool on an MCP service

View Source
var ListCmd = &ucli.Command{
	Name:  "list",
	Usage: "List tools from an MCP service",
	Description: `List all available tools from an MCP service.

Provide --url (-u) for a remote MCP service, --config (-c) to load local
stdio/http/sse servers from config, or --stdio to spawn a subprocess.

Examples:
  # List tools from a remote server
  mh list -u http://localhost:3000

  # List tools with JSON output
  mh list -u http://localhost:3000 --json

  # List tools using SSE transport
  mh list -u http://localhost:3000 -t sse

  # List tools from config (stdio/http/sse)
  mh list -c config.json

  # List tools filtered by server
  mh list -c config.json --server github

  # List tools filtered by keywords
  mh list -c config.json --query "search,file"

  # List tools from a stdio MCP server
  mh list --stdio -- npx @modelcontextprotocol/server-everything`,
	Flags: append(MCPClientFlags(),
		&ucli.StringFlag{
			Name:  "server",
			Usage: "filter tools by server name",
		},
		&ucli.StringFlag{
			Name:  "query",
			Usage: "comma-separated keywords for search (matches name or description)",
		},
	),
	Before: ValidateMCPClientFlags,
	Action: runList,
}

ListCmd is the list subcommand that lists tools from an MCP service

View Source
var ServeCmd = &ucli.Command{
	Name:  "serve",
	Usage: "Start the MCP hub server",
	Description: `Start the MCP hub server with the specified transport.

Transport Types:
  stdio  - Standard input/output (default, for CLI integration)
  http   - HTTP server with StreamableHTTP protocol
  sse    - HTTP server with Server-Sent Events protocol

Examples:
  # Run with stdio transport (default)
  mh serve -c config.json

  # Run with HTTP transport on port 8080
  mh serve -c config.json -t http -p 8080

  # Run with SSE transport on custom host and port
  mh serve -c config.json -t sse --host 0.0.0.0 -p 3000

  # Run with verbose logging
  mh serve -c config.json --verbose`,
	Flags:  MCPServeFlags(),
	Action: runServe,
}

ServeCmd is the serve subcommand that starts the MCP hub server

View Source
var SkillsCmd = &ucli.Command{
	Name:  "skills",
	Usage: "Discover and install agent skills",
	Description: `Search and install skills from the open agent skills ecosystem.

Skills are modular packages that extend agent capabilities with specialized
knowledge, workflows, and tools.

Examples:
  # Search for skills
  mh skills find react
  mh skills find "pr review"

  # Install a skill
  mh skills add vercel-labs/agent-skills@react-best-practices`,
	Commands: []*ucli.Command{
		skillsFindCmd,
		skillsAddCmd,
	},
}

SkillsCmd is the skills subcommand for discovering and installing agent skills

View Source
var UpdateCmd = &ucli.Command{
	Name:  "update",
	Usage: "Update mh to the latest version",
	Description: `Check for updates and upgrade mh to the latest version.

Examples:
  # Check and update to latest
  mh update

  # Check only (dry run)
  mh update --check`,
	Flags: []ucli.Flag{
		&ucli.BoolFlag{
			Name:  "check",
			Usage: "only check for updates, don't install",
		},
	},
	Action: runUpdate,
}

UpdateCmd is the update subcommand that updates hub to the latest version

Functions

func MCPClientFlags added in v0.2.0

func MCPClientFlags() []ucli.Flag

MCPClientFlags are flags shared by commands that connect to MCP servers (list, inspect, invoke, exec)

func MCPServeFlags added in v0.2.0

func MCPServeFlags() []ucli.Flag

MCPServeFlags are flags for the serve command

func ValidateMCPClientFlags added in v0.2.0

func ValidateMCPClientFlags(ctx context.Context, cmd *ucli.Command) (context.Context, error)

ValidateMCPClientFlags validates the mutual exclusivity of connection flags. Returns an error if none or multiple connection modes are specified.

Types

type ConfigClient

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

func NewConfigClient

func NewConfigClient(ctx context.Context, configPath string, logger *slog.Logger, timeout time.Duration) (*ConfigClient, error)

func (*ConfigClient) CallTool

func (c *ConfigClient) CallTool(ctx context.Context, namespacedName string, params json.RawMessage) (*mcp.CallToolResult, error)

func (*ConfigClient) Close

func (c *ConfigClient) Close() error

func (*ConfigClient) GetTool

func (c *ConfigClient) GetTool(ctx context.Context, namespacedName string) (*mcp.Tool, error)

func (*ConfigClient) ListTools

func (c *ConfigClient) ListTools(ctx context.Context) ([]*mcp.Tool, error)

type RemoteClient

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

RemoteClient connects to remote MCP services

func NewRemoteClient

func NewRemoteClient(ctx context.Context, opts RemoteClientOpts) (*RemoteClient, error)

NewRemoteClient creates a new RemoteClient and connects to the remote MCP service

func (*RemoteClient) CallTool

func (c *RemoteClient) CallTool(ctx context.Context, name string, params json.RawMessage) (*mcp.CallToolResult, error)

CallTool invokes a tool on the remote MCP server

func (*RemoteClient) Close

func (c *RemoteClient) Close() error

Close closes the connection to the remote MCP server

func (*RemoteClient) GetTool

func (c *RemoteClient) GetTool(ctx context.Context, name string) (*mcp.Tool, error)

GetTool returns a specific tool by name

func (*RemoteClient) ListTools

func (c *RemoteClient) ListTools(ctx context.Context) ([]*mcp.Tool, error)

ListTools returns all available tools from the remote MCP server

type RemoteClientOpts

type RemoteClientOpts struct {
	ServerURL string
	Transport string // "http" or "sse"
	Headers   map[string]string
	Timeout   int // seconds
	Logger    *slog.Logger
}

RemoteClientOpts contains options for creating a RemoteClient

type StdioClient

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

StdioClient connects to an MCP server via stdio (spawning a subprocess)

func NewStdioClient

func NewStdioClient(ctx context.Context, opts StdioClientOpts) (*StdioClient, error)

NewStdioClient creates a new StdioClient and connects to the spawned MCP server

func (*StdioClient) CallTool

func (c *StdioClient) CallTool(ctx context.Context, name string, params json.RawMessage) (*mcp.CallToolResult, error)

CallTool invokes a tool on the stdio MCP server

func (*StdioClient) Close

func (c *StdioClient) Close() error

Close closes the connection to the stdio MCP server

func (*StdioClient) GetTool

func (c *StdioClient) GetTool(ctx context.Context, name string) (*mcp.Tool, error)

GetTool returns a specific tool by name

func (*StdioClient) ListTools

func (c *StdioClient) ListTools(ctx context.Context) ([]*mcp.Tool, error)

ListTools returns all available tools from the stdio MCP server

type StdioClientOpts

type StdioClientOpts struct {
	Command []string // Command and arguments to spawn
	Timeout int      // seconds
	Logger  *slog.Logger
}

StdioClientOpts contains options for creating a StdioClient

Jump to

Keyboard shortcuts

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