tools

package
v0.2.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ToolNameKBSearch = "kb_search"
	ToolNameKBCreate = "kb_create"
	ToolNameFetch    = "fetch"
)
View Source
const (
	DEFAULT_USER_AGENT_AUTONOMOUS = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Invoker

type Invoker = mcps.Invoker

type MCPConnection

type MCPConnection struct {
	Name      string
	URL       string
	TransType mcps.TransType
	// contains filtered or unexported fields
}

MCPConnection 表示一个到 MCP 服务器的连接

type Registry

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

func NewRegistry

func NewRegistry(sto stores.Storage, opts ...RegistryOption) *Registry

NewRegistry 创建工具注册表

func (*Registry) AddInvoker

func (r *Registry) AddInvoker(name string, fn Invoker, desc string, inputSchema map[string]any) error

AddInvoker 添加自定义工具 invoker name: 工具名称 fn: 工具调用函数 desc: 工具描述 inputSchema: 输入参数 schema

func (*Registry) AddServer

func (r *Registry) AddServer(ctx context.Context, server *mcps.Server) error

AddServer 添加一个 MCP Server 并初始化连接 仅支持远程传输类型(SSE 或 Streamable)

func (*Registry) Invoke

func (r *Registry) Invoke(ctx context.Context, name string, params map[string]any) (map[string]any, error)

func (*Registry) LoadServers

func (r *Registry) LoadServers(ctx context.Context, sto stores.Storage) error

LoadServers 加载所有 Running 状态的 MCP Server

func (*Registry) RemoveServer

func (r *Registry) RemoveServer(name string) error

RemoveServer 移除 MCP Server 连接

func (*Registry) ToolsFor

func (r *Registry) ToolsFor(ctx context.Context) []mcps.ToolDescriptor

ToolsFor 返回适合当前上下文的工具列表 如果用户有 keeper 角色,返回所有工具;否则只返回公开工具

type RegistryOption

type RegistryOption func(*Registry)

RegistryOption 用于配置 Registry 的可选参数

func WithClientInfo

func WithClientInfo(name, version string) RegistryOption

WithClientInfo 设置 MCP 客户端信息

func WithOAuthMCP

func WithOAuthMCP(endpoint string, getToken func(ctx context.Context) string) RegistryOption

WithOAuthMCP 配置 OAuth MCP

type ResultLogs

type ResultLogs map[string]any

ResultLogs 是工具调用结果的日志类型别名

func (ResultLogs) String

func (rl ResultLogs) String() string

String 实现 fmt.Stringer 接口,返回格式化的结果日志 格式为 {key: val[0:min(30,len(val)},如果值不是 string/slice/map,则为 key: ""

Jump to

Keyboard shortcuts

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