ctl

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 21 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 ctl 实现 Gately 的命令行客户端与 MCP 服务器:二者都通过 HTTP + API 令牌调用运行中的实例, 不重复任何业务逻辑,接口清单直接来自实例的 OpenAPI 文档。

Index

Constants

View Source
const DefaultURL = "http://127.0.0.1:16680"

DefaultURL 是未指定地址时连接的本机管理地址。

Variables

This section is empty.

Functions

func ConfigPath

func ConfigPath() string

ConfigPath 返回配置文件路径(~/.config/gately/ctl.json 或系统等价目录)。

func RunCtl

func RunCtl(args []string, stdout, stderr io.Writer) int

RunCtl 执行 `gately ctl` 子命令,返回退出码。

func RunMCP

func RunMCP(args []string, stdin io.Reader, stdout, stderr io.Writer) int

RunMCP 执行 `gately mcp` 子命令。

func ServeMCP

func ServeMCP(ctx context.Context, c *Client, opts MCPOptions, r io.Reader, w io.Writer, logw io.Writer) error

ServeMCP 在 r/w 上运行 MCP 服务(每行一个 JSON-RPC 消息),直到输入关闭。

Types

type APIError

type APIError struct {
	Status  int
	Message string
}

APIError 是服务端返回的错误。

func (*APIError) Error

func (e *APIError) Error() string

type Client

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

Client 是调用管理 API 的客户端。

func NewClient

func NewClient(c Config) (*Client, error)

NewClient 创建客户端。

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, body []byte) ([]byte, error)

Do 发送请求并返回响应体。path 以 / 开头,可包含查询串。非 2xx 状态返回 *APIError。

func (*Client) FetchOperations

func (c *Client) FetchOperations(ctx context.Context) ([]Operation, error)

FetchOperations 从实例读取 OpenAPI 文档,返回令牌可访问的接口。

type Config

type Config struct {
	URL   string `json:"url"`
	Token string `json:"token"`
	// Insecure 跳过 HTTPS 证书校验,仅用于自签名证书的内网实例
	Insecure bool `json:"insecure,omitempty"`
}

Config 是连接配置。

func LoadConfig

func LoadConfig() Config

LoadConfig 依次读取配置文件、环境变量(GATELY_URL / GATELY_TOKEN),后者优先。

type MCPOptions

type MCPOptions struct {
	// AllowWrite 为 false 时只暴露只读(GET)接口
	AllowWrite bool
}

MCPOptions 控制暴露哪些工具。

type Operation

type Operation struct {
	Method  string
	Path    string
	Tag     string
	Summary string
	Desc    string
	// Scope 为所需令牌权限(如 ddns:write),空表示任意令牌
	Scope string
	// PathParams 为路径中的参数名
	PathParams []string
	// Body 为请求体的 JSON Schema(已展开引用),nil 表示无请求体
	Body any
	// HasBody 表示接口接受请求体(Body 可能为空对象)
	HasBody bool
}

Operation 是 OpenAPI 文档中的一个接口。

func ParseOperations

func ParseOperations(data []byte) ([]Operation, error)

ParseOperations 解析 OpenAPI JSON。

func (Operation) IsRead

func (o Operation) IsRead() bool

IsRead 判断是否为只读接口。

func (Operation) IsReadOnly added in v0.6.0

func (o Operation) IsReadOnly() bool

IsReadOnly 判断接口是否真正只读:GET 但需要写权限的接口(取回密码明文的 secrets、 容器 exec、私钥下载等)不算只读,MCP 默认只读模式下不暴露。

type Tool

type Tool struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	InputSchema map[string]any `json:"inputSchema"`
	Annotations map[string]any `json:"annotations,omitempty"`
	// contains filtered or unexported fields
}

Tool 是暴露给 MCP 客户端的一个工具,对应一个管理接口。

func BuildTools

func BuildTools(ops []Operation, opts MCPOptions) []Tool

BuildTools 把接口清单转换为工具列表。

Jump to

Keyboard shortcuts

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