mcpadapter

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package mcpadapter bridges github.com/v8tix/mcp-toolkit with react-agent.

It provides RegistryExecutor — a concurrent, retry-aware model.ToolExecutor backed by a mcp-toolkit [llmregistry.Registry]. Tools that implement observable.Tool are executed via ExecuteRx (retry + exponential backoff); plain handler.ExecutableTool implementations fall back to a simple rxgo.Defer wrapper.

Quick start

reg := registry.New(tools...)
defs, executor := mcpadapter.FromRegistry(reg)

a := agent.New(client, defs, executor).
         WithInstructions("You are a helpful assistant.").
         WithMaxSteps(10)

result, _, err := a.Run(ctx, "What is the weather in Paris?")

MCP tools

To use tools discovered from a live MCP session:

mcpTools := mcp.NewTools(discoveredNames, session).Build()
reg      := registry.New(mcpTools...)
defs, executor := mcpadapter.FromRegistry(reg)

Concurrent execution

RegistryExecutor.Execute fans out all tool calls concurrently via rxgo.Merge and restores the original call order before returning. Errors are encoded into ToolResult.Status="error" so the agent loop always continues and lets the LLM reason about any failures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Defs

Defs converts a slice of mcp-toolkit ToolDefinitions to model.ToolDefinitions. Pass the result as the defs argument to agent.New().

defs := mcpadapter.Defs(reg.All())

func FromRegistry

func FromRegistry(reg *registry.Registry) ([]model.ToolDefinition, model.ToolExecutor)

FromRegistry is a convenience helper that returns both tool definitions and a RegistryExecutor from a single registry — the two values needed by agent.New().

defs, executor := mcpadapter.FromRegistry(reg)
a := agent.New(client, defs, executor, agent.WithInstructions("..."))

Types

type RegistryExecutor

type RegistryExecutor struct {
	// contains filtered or unexported fields
}

RegistryExecutor implements model.ToolExecutor using mcp-toolkit's concurrent observable dispatch with retry and exponential backoff.

Use NewRegistryExecutor to construct one, or call FromRegistry for a one-liner that also returns the tool definitions.

func NewRegistryExecutor

func NewRegistryExecutor(reg *registry.Registry) *RegistryExecutor

NewRegistryExecutor creates a RegistryExecutor backed by reg.

func (*RegistryExecutor) Execute

func (e *RegistryExecutor) Execute(ctx context.Context, calls []model.ToolCall) ([]model.ToolResult, error)

Execute fans out all tool calls concurrently via rxgo.Merge, waits for all results, restores the original call order, and returns []model.ToolResult.

Errors are never returned as Go errors — they are encoded into ToolResult.Status="error" so the agent loop can always continue the conversation and let the LLM reason about the failure.

Jump to

Keyboard shortcuts

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