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 ¶
- func Call(ctx context.Context, cs *mcp.ClientSession, files *commands.CommandFS, ...) (json.RawMessage, error)
- func Command(name string, sources []Source, group []Tool) commands.Command
- func Groups(tools []Tool) map[string][]Tool
- func Host(ctx context.Context, request []byte) []byte
- func Kebab(s string) string
- func Modules(groups []string) []string
- func With(ctx context.Context, sources []Source, files *commands.CommandFS) context.Context
- func WritePython(dir string, tools []Tool) error
- type Source
- type Tool
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 ¶
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 Host ¶
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 Modules ¶
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 ¶
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 ¶
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.