toolapproval

package
v0.28.2 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckToolApproval

func CheckToolApproval(ctx context.Context, userID, toolName string, args map[string]any) error

CheckToolApproval is called from the tool provider before executing a tool. If the context carries an SSE writer (web chat) and the tool requires approval, it blocks until the user responds. External MCP clients have no SSE writer and skip the check entirely.

func SetManager

func SetManager(m *Manager)

Types

type Event

type Event struct {
	RequestID  string         `json:"request_id"`
	InstanceID string         `json:"instance_id"`
	ToolName   string         `json:"tool_name"`
	Arguments  map[string]any `json:"arguments,omitempty"`
	ExpiresAt  int64          `json:"expires_at"`
}

Event is the JSON payload sent as a tool_approval SSE comment.

type EventWriter

type EventWriter interface {
	WriteEvent(eventType string, data any) error
}

EventWriter is satisfied by rest.StreamWriter (and mcpopenai.SSEEventWriter).

type Forwarder

type Forwarder interface {
	ForwardToolApproval(req *ResponseRequest) (bool, error)
}

Forwarder forwards an approval response to the originating instance via gossip.

type Manager

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

Manager tracks pending tool approvals in memory. Each approval is owned by the instance that started the tool call. When a response arrives on a different instance behind a load balancer it is forwarded via gossip.

func GetManager

func GetManager() *Manager

func NewManager

func NewManager() *Manager

func (*Manager) HandleResponse

func (m *Manager) HandleResponse(w http.ResponseWriter, r *http.Request)

HandleResponse is the HTTP handler for POST /v1/chat/tool-approvals.

func (*Manager) Request

func (m *Manager) Request(ctx context.Context, writer EventWriter, userID, toolName string, args map[string]any) error

Request writes a tool_approval SSE event and blocks until the user responds, the timeout expires, or the context is cancelled.

func (*Manager) Respond

func (m *Manager) Respond(req *ResponseRequest) bool

Respond delivers an approval/denial to the waiting Request. Returns false if no matching pending request exists or the user does not own it.

type ResponseRequest

type ResponseRequest struct {
	RequestID  string `json:"request_id"`
	InstanceID string `json:"instance_id"`
	Approved   bool   `json:"approved"`
	UserID     string `json:"user_id,omitempty"`
}

ResponseRequest is sent by the browser and forwarded between instances.

Jump to

Keyboard shortcuts

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