mcpserver

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxPooledConnections  = 8
	DefaultIdleTTL        = 15 * time.Minute
	DefaultQueueWait      = 60 * time.Second
	ModelStreamHeadBytes  = 32 * 1024 // 32 KiB
	ModelStreamTailBytes  = 32 * 1024 // 32 KiB
	ModelStreamTotalLimit = ModelStreamHeadBytes + ModelStreamTailBytes
)

Variables

This section is empty.

Functions

func ServeStdio

func ServeStdio(ctx context.Context, svc *app.Service, version string) error

ServeStdio 启动 stdio MCP 服务,在连接结束或进程退出时关闭全部缓存的 SSH/SFTP 会话。

func TruncateForModel

func TruncateForModel(s string, headBytes, tailBytes int) (out string, totalBytes int, truncated bool)

TruncateForModel 限制返回给大模型的单路文本长度(默认头 32 KiB + 尾 32 KiB),保证合法 UTF-8 边界。

Types

type CloseConnectionInput

type CloseConnectionInput struct {
	Target   string `json:"target,omitempty" jsonschema:"可选目标服务器(用户@IP 或别名);为空或 * 时关闭所有缓存连接"`
	Protocol string `json:"protocol,omitempty" jsonschema:"可选协议过滤(ssh 或 sftp);为空时关闭该目标的全部协议连接"`
}

type DownloadInput

type DownloadInput struct {
	Target     string `json:"target" jsonschema:"目标服务器(用户@IP、单账号 IP 或别名)"`
	RemotePath string `json:"remote_path" jsonschema:"远端源文件或目录路径"`
	LocalPath  string `json:"local_path" jsonschema:"本机保存目标路径"`
	Overwrite  bool   `json:"overwrite,omitempty" jsonschema:"若本机目标文件已存在是否允许覆盖(默认 false)"`
	Recursive  bool   `json:"recursive,omitempty" jsonschema:"若远端源路径是目录是否递归下载(默认 false)"`
}

type ListHostsInput

type ListHostsInput struct{}

type Manager

type Manager struct {
	Service        *app.Service
	MaxConns       int
	IdleTTL        time.Duration
	QueueWait      time.Duration
	ModelHeadBytes int
	ModelTailBytes int
	// contains filtered or unexported fields
}

func NewManager

func NewManager(svc *app.Service) *Manager

func NewServer

func NewServer(svc *app.Service, version string) (*mcp.Server, *Manager)

func (*Manager) CloseAll

func (m *Manager) CloseAll() int

func (*Manager) HandleCloseConnection

func (m *Manager) HandleCloseConnection(in CloseConnectionInput) map[string]any

func (*Manager) HandleDownload

func (m *Manager) HandleDownload(ctx context.Context, in DownloadInput) map[string]any

func (*Manager) HandleListHosts

func (m *Manager) HandleListHosts(ctx context.Context) map[string]any

func (*Manager) HandleRunCommand

func (m *Manager) HandleRunCommand(ctx context.Context, in RunCommandInput) map[string]any

func (*Manager) HandleUpload

func (m *Manager) HandleUpload(ctx context.Context, in UploadInput) map[string]any

type RunCommandInput

type RunCommandInput struct {
	Target  string  `json:"target" jsonschema:"目标服务器(支持 用户@IP、已配置单账号的 IP 或别名)"`
	Command string  `json:"command" jsonschema:"要执行的单条非交互远程命令"`
	Cwd     string  `json:"cwd,omitempty" jsonschema:"可选的远端工作目录绝对路径(如 /var/log)"`
	Timeout float64 `json:"timeout,omitempty" jsonschema:"超时秒数 (0, 3600],默认 30 秒"`
}

type UploadInput

type UploadInput struct {
	LocalPath  string `json:"local_path" jsonschema:"本机源文件或目录路径"`
	Target     string `json:"target" jsonschema:"目标服务器(用户@IP、单账号 IP 或别名)"`
	RemotePath string `json:"remote_path" jsonschema:"远端目标路径(支持 ~/路径、相对家目录路径或平台允许的绝对路径)"`
	Overwrite  bool   `json:"overwrite,omitempty" jsonschema:"若远端文件已存在是否允许覆盖(默认 false)"`
	Recursive  bool   `json:"recursive,omitempty" jsonschema:"若本机源路径是目录是否递归上传(默认 false)"`
}

Jump to

Keyboard shortcuts

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