tools

package
v0.0.0-...-a431a9e Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 16 Imported by: ? 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 tools turns the tools of an MCP server into what a shell and a script can use: a command per group of tools, with a subcommand per tool, and a Python package with a module per group and a function per tool.

A tool named notes_listNotes is the command `notes list-notes` and the function notes.list_notes().

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call(ctx context.Context, cs *mcp.ClientSession, files *commands.CommandFS, name string, arguments json.RawMessage) (json.RawMessage, error)

Call calls one tool and returns its result as JSON: the structured result when the tool gives one, else its text. A result that is a file, such as an image, is written to /tmp through files, the filesystem of the command that made the call, so the shell's rules for a write hold; it is named by its path, a line each after the text, or under "_files" in a structured result. A link to a resource is named by its URI.

func Command

func Command(name string, sources []Source, group []Tool) commands.Command

Command is one group of tools as a command called name: `name --help` lists its tools, `name tool --help` a tool's arguments, and `name tool --argument value` calls the tool and prints its result: text as it is, anything else as JSON.

func Groups

func Groups(tools []Tool) map[string][]Tool

Groups sorts tools by their group.

func Host

func Host(ctx context.Context, request []byte) []byte

Host answers a program's host call (see wasm.Program.Host). The request is {"source": index, "tool": name, "arguments": {...}} and the reply {"ok": true, "result": ...} or {"ok": false, "error": "..."}. The generated Python package speaks it.

func Kebab

func Kebab(s string) string

Kebab is a name as a command line spells it: listNotes is list-notes.

func Modules

func Modules(groups []string) []string

Modules is the Python module of each group, in the order given: the group's name as Python spells it, so that my-server is my_server, made unique.

func With

func With(ctx context.Context, sources []Source, files *commands.CommandFS) context.Context

With returns a context whose programs' host calls reach the tools of sources, and save a result that is a file through files, the filesystem of the command that runs the program.

func WritePython

func WritePython(dir string, tools []Tool) error

WritePython writes the tools as a Python package in the directory dir, replacing what is there: a module per group and a function per tool, with the tool's description and arguments as the function's own. A script that has dir's parent on its path writes `from <dir's name> import notes; notes.list_notes()`. Each module is replaced in one step, so that a script importing the package meanwhile finds every module whole; a module of a group that is gone is removed last.

Types

type Source

type Source struct {
	Name    string
	Session *mcp.ClientSession
}

A Source is one MCP server. With a Name, the server is one command and one Python module of that name, and each of its tools a subcommand and a function. Without one, its tools are grouped by the part of their name before the first underscore, as a server that serves several apps names them.

type Tool

type Tool struct {
	*mcp.Tool
	Group, Short string
	Source       int // the tool's source, as an index into the sources it was listed from
}

A Tool is a listed tool: the group it is in, its name within the group, and which source serves it.

func List

func List(ctx context.Context, sources []Source) ([]Tool, error)

List is every tool the sources offer now.

Jump to

Keyboard shortcuts

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