mcptools

package
v0.46.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 23 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

Index

Constants

View Source
const (
	// RunScriptToolName runs a script the AI assistant wrote.
	RunScriptToolName = "run_script"
	// ScriptDocsToolName serves the documentation for writing one.
	ScriptDocsToolName = "script_docs"
)
View Source
const (
	SurfaceWebChat = toolsurface.WebChat
	SurfaceMCP     = toolsurface.MCP
)

Variables

This section is empty.

Functions

func AIScriptTool added in v0.45.0

func AIScriptTool(name string) bool

AIScriptTool reports whether a tool is one of the AI script tools, which only users holding the Run AI Scripts permission are offered.

func ExecuteTool

func ExecuteTool(name string, params map[string]interface{}, user *model.User) (interface{}, error)

func ExecuteToolContext added in v0.45.0

func ExecuteToolContext(ctx context.Context, name string, params map[string]interface{}, user *model.User) (interface{}, error)

ExecuteToolContext runs a built-in tool. ctx is the MCP request's: Go tools read the calling surface from it.

func GetAllMCPTools

func GetAllMCPTools() []mcp.MCPTool

GetAllMCPTools returns all MCP tools with their Visibility field set appropriately

func GetEmbeddedFS

func GetEmbeddedFS() fs.FS

func GetMCPTools

func GetMCPTools(visibility string) []mcp.MCPTool

func LoadTools

func LoadTools(toolsPath string, disabledTools []string) error

func ParseAlwaysConfirm added in v0.45.0

func ParseAlwaysConfirm(tomlContent []byte) any

ParseAlwaysConfirm returns a tool's always_confirm setting as the value of its lmchatkit.AlwaysConfirmMetaKey _meta entry: true when every call must be confirmed, or a map of the argument values that pick the calls that must (always_confirm = { mode = "write" }). The web assistant asks for those calls every time and offers no "Always Allow". Nil when unset.

func ParseHandler added in v0.45.0

func ParseHandler(tomlContent []byte) string

ParseHandler returns the tool's handler kind: "go" for a tool implemented in Go (go_tools.go), "" for a scripted tool (the .py beside the TOML).

func ParseMetadata

func ParseMetadata(tomlContent []byte) (*toolmetadata.ToolMetadata, error)

func ParseRequiresApproval added in v0.25.1

func ParseRequiresApproval(tomlContent []byte) bool

ParseRequiresApproval reports whether a tool's TOML sets requires_approval (or its older name requires_permission).

func ReloadTools

func ReloadTools(toolsPath string, disabledTools []string) (int, error)

func ToolHints added in v0.45.0

func ToolHints(tomlContent string) (*mcp.ToolAnnotations, map[string]any)

ToolHints returns the annotations and _meta a user script tool's TOML asks for: requires_approval and always_confirm give destructiveHint, and always_confirm also the lmchatkit always-confirm rule. Both nil when the TOML asks for neither.

func UserCanRunAIScripts added in v0.45.0

func UserCanRunAIScripts(user *model.User) bool

UserCanRunAIScripts reports whether run_script and script_docs are loaded and the user holds the permission to use them.

func WithSurface added in v0.45.0

func WithSurface(ctx context.Context, surface Surface) context.Context

WithSurface marks ctx as coming from a surface that approves tool calls.

Types

type GoToolHandler added in v0.45.0

type GoToolHandler func(ctx context.Context, params map[string]interface{}, user *model.User) (interface{}, error)

GoToolHandler implements a built-in tool in Go. ctx is the MCP request's.

type Surface added in v0.45.0

type Surface = toolsurface.Surface

Surface names where a tool call came from, so a tool can tell whether a person approved it. The web assistant asks the user before tool calls and shows their arguments; an MCP client is expected to do the same for a tool marked destructive. The OpenAI compatible endpoints, scripts calling knot.mcp and in-process API calls run tools with no one to ask, and carry no surface (in-process calls strip it, see toolsurface.Strip).

func SurfaceFrom added in v0.45.0

func SurfaceFrom(ctx context.Context) Surface

SurfaceFrom returns the surface ctx was marked with, "" when none.

type Tool

type Tool struct {
	Name             string
	Script           string
	Metadata         *toolmetadata.ToolMetadata
	RequiresApproval bool
	// AlwaysConfirm is the tool's always_confirm setting (ParseAlwaysConfirm),
	// published in its tools/list _meta; nil when unset.
	AlwaysConfirm any
	// Handler is set for a tool implemented in Go (handler = "go" in its
	// TOML, see go_tools.go), which has no script.
	Handler GoToolHandler
}

func GetTool

func GetTool(name string) (*Tool, bool)

func ListTools

func ListTools() []*Tool

func (*Tool) ModelOnly added in v0.45.0

func (t *Tool) ModelOnly() bool

ModelOnly reports whether only the model may call the tool, not an MCP Apps view: tools that need the user's approval.

Jump to

Keyboard shortcuts

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