Documentation
¶
Overview ¶
Package bridge wraps foreign tool surfaces — local command-line programs, remote MCP servers, pasted tools/list payloads — as xyz command entries. One declarative config (xyz.json) then yields the same command on all three xyz-go fronts: CLI subcommands, HTTP routes and MCP tools.
The core primitive is NewTool: a JSON Schema subset plus an Invoker becomes a *spec.Entry the xyz-go frontends consume directly, with no compile-time struct and no reflection beyond what the frontends read from the field metadata. Everything else in this package (exec adapters, MCP proxies, config loading) produces schemas and invokers for it.
Index ¶
- Constants
- func Load(ctx context.Context, source string) (*registry.Registry, error)
- func LoadDefault(ctx context.Context) (*registry.Registry, error)
- func NewTool(name, summary, description string, input any, inv Invoker) (*spec.Entry, error)
- func ParseAndBuild(ctx context.Context, data []byte) (*registry.Registry, error)
- type Config
- type ExecConfig
- type Invoker
- type MCPConfig
- type MCPProxy
- type RemoteTool
- type ToolConfig
Constants ¶
const DefaultConfigName = "xyz.json"
DefaultConfigName is the file the gateway looks for in the current directory when XYZ_CONFIG is unset.
const Version = "0.1.0"
Version identities this bridge in the MCP client handshake.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
Load reads the config from a local path or an http(s) URL and builds the registry. An empty source falls back to LoadDefault's lookup order. URLs are fetched afresh on every process start — the "resolve once per run" model the gateway documents.
func LoadDefault ¶
LoadDefault locates the config by convention: XYZ_CONFIG (a path or URL) wins, otherwise ./xyz.json in the current directory.
Types ¶
type Config ¶
type Config struct {
Tools []ToolConfig `json:"tools"`
}
Config is the xyz.json document: a declarative list of tools, each carried by exactly one adapter.
func ParseConfig ¶
ParseConfig parses the xyz.json document shape.
type ExecConfig ¶
type ExecConfig struct {
// Program is the executable. Args optionally carry {name} templates.
Program string `json:"program"`
Args []string `json:"args,omitempty"`
// Env adds or overrides environment entries; values use the same
// {name} interpolation. The inherited environment is preserved.
Env map[string]string `json:"env,omitempty"`
// Timeout bounds one invocation ("30s" default; the caller's context
// deadline, when set, still wins).
Timeout string `json:"timeout,omitempty"`
// MaxOutput caps returned stdout bytes (default 1 MiB).
MaxOutput int64 `json:"max_output,omitempty"`
}
ExecConfig declares a local command-line adapter. Every call spawns one process; Args and Env entries may reference input properties as {name} placeholders.
type Invoker ¶
Invoker runs one tool call with schema-normalized arguments and returns the value every frontend renders: plain text for exec tools, a native JSON value for MCP proxies.
func ExecInvoker ¶
func ExecInvoker(cfg ExecConfig) Invoker
ExecInvoker binds the config to an Invoker. The result is the trimmed stdout text; a non-zero exit makes the call fail with the program's stderr as the message, mapped through the xyz error taxonomy (internal, or unavailable on timeout / spawn failure).
type MCPConfig ¶
type MCPConfig struct {
Command string `json:"command"`
Args []string `json:"args,omitempty"`
// Tools limits proxying to these remote tool names; empty proxies all.
Tools []string `json:"tools,omitempty"`
// Prefix renames proxied tools to "<prefix><tool>"; empty falls back to
// the config tool name plus "." as the namespace.
Prefix string `json:"prefix,omitempty"`
}
MCPConfig declares a proxied stdio MCP server. The gateway launches the command once per process, performs the handshake and tools/list up front, and forwards every subsequent call through the official SDK client. The server process lives until the gateway exits (Close is offered for explicit teardown).
type MCPProxy ¶
type MCPProxy struct {
// contains filtered or unexported fields
}
MCPProxy is a live proxied server connection. tools maps the displayed (namespaced) name to the remote tool description.
func StartMCPProxy ¶
StartMCPProxy launches the server process, completes the MCP handshake and lists its tools. Proxied names carry the namespace prefix.
func (*MCPProxy) Close ¶
func (p *MCPProxy) Close()
Close kills the server process; the OS would reap it at gateway exit anyway, this is the explicit path.
func (*MCPProxy) InvokeTool ¶
InvokeTool returns an Invoker that forwards calls to one proxied tool. Tool-level errors (isError results) surface as internal errors carrying the remote text; transport failures surface as unavailable, so the gateway inherits the same taxonomy it would produce natively.
type RemoteTool ¶
type RemoteTool struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Input map[string]any `json:"input,omitempty"` // raw inputSchema subset
}
RemoteTool is one tool discovered via tools/list, the shape consumed by ImportToolsList and carried by MCPProxy.
func ImportToolsList ¶
func ImportToolsList(raw []byte) ([]RemoteTool, error)
ImportToolsList parses a tools/list response or a bare tool array into remote tool descriptors — the "paste a string" path: combine with an invoker (MCPProxy.InvokeTool, or custom) and NewTool to turn a pasted listing into three-channel commands with no config file at all.
type ToolConfig ¶
type ToolConfig struct {
Name string `json:"name"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
Input map[string]any `json:"input,omitempty"` // JSON Schema subset for the arguments
Exec *ExecConfig `json:"exec,omitempty"` // local command adapter
MCP *MCPConfig `json:"mcp,omitempty"` // stdio MCP server proxy
}
ToolConfig declares one dynamic tool.