Help us shape the future of Go! Take the 2026 Go Developer Survey

mcpserver

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoCurrentNovel = errors.New("当前没有打开的小说")

ErrNoCurrentNovel 表示 Goink 界面当前没有打开的小说。

Functions

This section is empty.

Types

type CurrentNovel

type CurrentNovel struct {
	ID    int64
	Title string
}

CurrentNovel 是每次 MCP 调用看到的当前小说快照。

type CurrentNovelFunc

type CurrentNovelFunc func(context.Context) (CurrentNovel, error)

CurrentNovelFunc 在请求开始时读取当前小说,不使用上次打开的历史设置。

type Endpoint

type Endpoint struct {
	URL   string
	Token string
}

Endpoint 是显式启动本地服务后返回的连接信息。Token 只在启动时返回。

type LocalView added in v1.7.0

type LocalView struct {
	Config         servercfg.Local `json:"config"`
	AvailableTools []string        `json:"available_tools"`
	Token          string          `json:"token"`
	Status         Status          `json:"status"`
	LastError      string          `json:"last_error"`
}

type Repository added in v1.7.0

type Repository interface {
	Load() (servercfg.State, error)
	Save(servercfg.State) error
}

type Server

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

Server 将明确选中的 Goink 工具提供为本地 MCP 协议端点。

func New

func New(registry *mcp_tools.Registry, db *gorm.DB, current CurrentNovelFunc, logger *slog.Logger) *Server

New 构建默认不监听的服务,工具权限通过 SetAllowedTools 设置。

func (*Server) AvailableTools added in v1.7.0

func (s *Server) AvailableTools() []string

AvailableTools 返回 Registry 中全部可选工具;内置工具由 Server 单独提供。

func (*Server) SetAllowedTools added in v1.7.0

func (s *Server) SetAllowedTools(names []string) error

SetAllowedTools 只在旧请求排空后替换策略,运行中的请求始终使用原来的不可变白名单。

func (*Server) SetPort added in v1.7.0

func (s *Server) SetPort(port int) error

SetPort 在服务停止时设置端口;0 供测试显式申请临时端口。

func (*Server) SetToolContextProvider added in v1.7.0

func (s *Server) SetToolContextProvider(provider ToolContextProvider) error

SetToolContextProvider 在启动前注入依赖,运行中不允许更换。

func (*Server) Start

func (s *Server) Start(token string) (Endpoint, error)

Start 使用调用方提供的令牌启动本地服务;令牌的生成和持久化由管理层负责。

func (*Server) Status added in v1.7.0

func (s *Server) Status() Status

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop 停止接收新请求,等待在途调用结束;超时后强制关闭连接。

type Service added in v1.7.0

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

Service 编排本地 Server 配置、令牌与运行状态。

func NewService added in v1.7.0

func NewService(store Repository, server *Server) (*Service, error)

New 加载失败时仍返回停用的 Service,供应用展示错误并统一关闭;异常配置不会被覆盖。

func (*Service) Close added in v1.7.0

func (s *Service) Close(ctx context.Context) error

func (*Service) LocalSettings added in v1.7.0

func (s *Service) LocalSettings() LocalView

func (*Service) Restore added in v1.7.0

func (s *Service) Restore() error

Restore 只在应用核心模块初始化完成后调用。

func (*Service) RevokeCredential added in v1.7.0

func (s *Service) RevokeCredential(ctx context.Context) error

RevokeCredential 同时持久化关闭状态,重启应用也不能使旧凭据重新生效。

func (*Service) RotateCredential added in v1.7.0

func (s *Service) RotateCredential(ctx context.Context) (LocalView, error)

func (*Service) SaveLocal added in v1.7.0

func (s *Service) SaveLocal(ctx context.Context, config servercfg.Local) (LocalView, error)

SaveLocal 返回当前已保存的令牌;启停失败后也可通过 LocalSettings 再次读取。

type Status added in v1.7.0

type Status struct {
	Running  bool   `json:"running"`
	Stopping bool   `json:"stopping"`
	URL      string `json:"url"`
}

type ToolContextProvider added in v1.7.0

type ToolContextProvider func(context.Context) (context.Context, mcp_tools.ToolContext)

ToolContextProvider 注入工具依赖及桌面上下文;返回的上下文须保留请求的取消和截止时间。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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