mcp

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 40 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mcp is `remohop mcp`: a Model Context Protocol server on stdio that exposes RemoHop's remote shell, port forwarding, clipboard, screenshot, system information and file services as tools, so an AI agent can operate remote machines by their 9-digit ID.

The server is a thin layer over the Go client APIs of the service packages. It keeps one P2P session per target in a pool (see pool), never prompts for credentials (it has no terminal: the protocol owns stdin and stdout) and never writes anything but protocol messages to stdout.

Index

Constants

View Source
const (
	DefaultIdleTimeout = 10 * time.Minute
)

Defaults for Options.

Variables

This section is empty.

Functions

func DefaultDownloadDir

func DefaultDownloadDir() (string, error)

DefaultDownloadDir is where the MCP tools write when `remohop mcp` is not given --download-dir: a remohop folder in the user's Downloads.

Types

type DialFunc

type DialFunc func(ctx context.Context, target string) (*peer.Conn, error)

DialFunc establishes an authenticated session with target (a 9-digit ID, a saved alias or host:port). It must not prompt: the MCP server's stdin and stdout belong to the protocol.

type Options

type Options struct {
	// Dial connects to a target. Required.
	Dial DialFunc
	// DefaultTarget is used when a tool call omits "target".
	DefaultTarget string
	// IdleTimeout closes sessions unused for this long; 0 means
	// DefaultIdleTimeout, negative disables idle closing.
	IdleTimeout time.Duration
	// DialTimeout bounds one dial; 0 means 60 seconds.
	DialTimeout time.Duration
	// Version is reported to clients.
	Version string
	// Logger receives diagnostics; it must never write to stdout. Nil
	// discards them.
	Logger *slog.Logger
	// ReadOnly offers only the tools that change nothing (no commands,
	// writes, input, clipboard changes or forwards). It is a convenience on
	// this side; what a host allows is enforced by the host (grants).
	ReadOnly bool
	// WriteDirs are the directories on this computer that tools may
	// write to (downloads, saved screenshots and clipboard contents); a
	// relative path lands in the first. Nil means DefaultDownloadDir.
	// What a tool writes comes from a remote machine and the model may
	// have been misled, so it must not reach ~/.ssh, shell startup files
	// and the like.
	WriteDirs []string
}

Options configures a Server.

type Server

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

Server is the MCP server. Create it with New, serve it with Run, and call Close to release the sessions and forwards if Run was not used.

func New

func New(opts Options) *Server

New builds a server with every RemoHop tool registered.

func (*Server) Close

func (s *Server) Close()

Close stops the forwards and closes every pooled session. It is safe to call more than once.

func (*Server) Protocol

func (s *Server) Protocol() *sdk.Server

Protocol returns the underlying SDK server, for connecting it to a custom transport (tests use an in-memory one).

func (*Server) Run

func (s *Server) Run(ctx context.Context, t sdk.Transport) error

Run serves MCP over t until the client disconnects or ctx is cancelled, then closes every session and forward.

Jump to

Keyboard shortcuts

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