tools

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ToolNameKBSearch = "kb_search" // 知识库搜索工具
	ToolNameKBCreate = "kb_create" // 知识库创建工具
	ToolNameFetch    = "fetch"     // 网页抓取工具

	ToolNameMemoryList   = "memory_list"   // 记忆列表工具
	ToolNameMemoryRecall = "memory_recall" // 记忆召回工具
	ToolNameMemoryStore  = "memory_store"  // 记忆存储工具
	ToolNameMemoryForget = "memory_forget" // 记忆删除工具
)
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 represents a connection to an MCP server

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) ApplyToolDescriptions added in v0.2.3

func (r *Registry) ApplyToolDescriptions(descriptions map[string]string)

ApplyToolDescriptions 应用 preset 中的自定义工具描述 descriptions: toolName -> description

func (*Registry) Invoke

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

Invoke 调用指定名称的工具

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