mcp

package
v0.260507.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsVirtualTool added in v0.260507.1

func IsVirtualTool(normalizedName string, registry *runtime.VirtualToolRegistry) bool

IsVirtualTool reports whether the normalized MCP tool should execute server-side.

func RegisterRoutes

func RegisterRoutes(router *swagger.RouteGroup, handler *Handler, localHandler *local.Handler, transportHandler *local.TransportHandler)

RegisterRoutes registers all MCP configuration routes with swagger documentation

Types

type AnthropicBetaAdapter added in v0.260507.1

type AnthropicBetaAdapter struct{}

AnthropicBetaAdapter implements FormatAdapter for Anthropic Beta API

func NewAnthropicBetaAdapter added in v0.260507.1

func NewAnthropicBetaAdapter() *AnthropicBetaAdapter

NewAnthropicBetaAdapter creates a new Anthropic Beta adapter

func (*AnthropicBetaAdapter) AppendToolResults added in v0.260507.1

func (a *AnthropicBetaAdapter) AppendToolResults(req, resp any, results []any) (any, error)

func (*AnthropicBetaAdapter) BuildAssistantMessage added in v0.260507.1

func (a *AnthropicBetaAdapter) BuildAssistantMessage(response any) (any, error)

func (*AnthropicBetaAdapter) BuildToolMessage added in v0.260507.1

func (a *AnthropicBetaAdapter) BuildToolMessage(result ToolExecutionResult) any

func (*AnthropicBetaAdapter) ClassifyEvent added in v0.260507.1

func (a *AnthropicBetaAdapter) ClassifyEvent(event any) EventType

func (*AnthropicBetaAdapter) ExtractToolFromEvent added in v0.260507.1

func (a *AnthropicBetaAdapter) ExtractToolFromEvent(event any) (Tool, bool)

func (*AnthropicBetaAdapter) ExtractTools added in v0.260507.1

func (a *AnthropicBetaAdapter) ExtractTools(response any) ([]Tool, error)

func (*AnthropicBetaAdapter) ExtractUsage added in v0.260507.1

func (a *AnthropicBetaAdapter) ExtractUsage(response any) (TokenUsage, error)

func (*AnthropicBetaAdapter) FilterVirtualTools added in v0.260507.1

func (a *AnthropicBetaAdapter) FilterVirtualTools(response any, externalTools []Tool) (any, error)

func (*AnthropicBetaAdapter) IsVirtualTool added in v0.260507.1

func (a *AnthropicBetaAdapter) IsVirtualTool(tool Tool, registry *runtime.VirtualToolRegistry) bool

func (*AnthropicBetaAdapter) NewRequest added in v0.260507.1

func (a *AnthropicBetaAdapter) NewRequest() any

func (*AnthropicBetaAdapter) NewResponse added in v0.260507.1

func (a *AnthropicBetaAdapter) NewResponse() any

func (*AnthropicBetaAdapter) RewriteEventIndex added in v0.260507.1

func (a *AnthropicBetaAdapter) RewriteEventIndex(event any, offset int) ([]byte, error)

func (*AnthropicBetaAdapter) SendEvent added in v0.260507.1

func (a *AnthropicBetaAdapter) SendEvent(c *gin.Context, eventType string, payload []byte) error

func (*AnthropicBetaAdapter) SendFinalMessage added in v0.260507.1

func (a *AnthropicBetaAdapter) SendFinalMessage(c *gin.Context) error

func (*AnthropicBetaAdapter) SendKeepAlive added in v0.260507.1

func (a *AnthropicBetaAdapter) SendKeepAlive(c *gin.Context) error

func (*AnthropicBetaAdapter) SetupSSEHeaders added in v0.260507.1

func (a *AnthropicBetaAdapter) SetupSSEHeaders(c *gin.Context)

func (*AnthropicBetaAdapter) ShouldSuppressEvent added in v0.260507.1

func (a *AnthropicBetaAdapter) ShouldSuppressEvent(event any, virtualRegistry *runtime.VirtualToolRegistry) bool

func (*AnthropicBetaAdapter) SplitVirtualExternal added in v0.260507.1

func (a *AnthropicBetaAdapter) SplitVirtualExternal(
	tools []Tool,
	registry *runtime.VirtualToolRegistry,
) (virtual, external []Tool, externalIDs []string)

type AnthropicBetaForwarder added in v0.260507.1

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

AnthropicBetaForwarder implements Forwarder for Anthropic Beta API

func NewAnthropicBetaForwarder added in v0.260507.1

func NewAnthropicBetaForwarder(clientPool ClientPoolGetter, ctxGetter ForwardContextGetter) *AnthropicBetaForwarder

func (*AnthropicBetaForwarder) ForwardNonStream added in v0.260507.1

func (f *AnthropicBetaForwarder) ForwardNonStream(
	ctx context.Context,
	provider any,
	model string,
	req any,
) (any, error)

func (*AnthropicBetaForwarder) ForwardStream added in v0.260507.1

func (f *AnthropicBetaForwarder) ForwardStream(
	ctx context.Context,
	provider any,
	model string,
	req any,
) (StreamHandle, error)

type AnthropicBetaStreamHandle added in v0.260507.1

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

AnthropicBetaStreamHandle wraps Beta stream

func (*AnthropicBetaStreamHandle) Close added in v0.260507.1

func (h *AnthropicBetaStreamHandle) Close() error

func (*AnthropicBetaStreamHandle) Current added in v0.260507.1

func (h *AnthropicBetaStreamHandle) Current() any

func (*AnthropicBetaStreamHandle) Err added in v0.260507.1

func (*AnthropicBetaStreamHandle) Next added in v0.260507.1

func (h *AnthropicBetaStreamHandle) Next() bool

type AnthropicBetaTool added in v0.260507.1

type AnthropicBetaTool struct {
	ToolUseBlock anthropic.BetaToolUseBlock
}

AnthropicBetaTool implements Tool interface for Anthropic Beta ToolUseBlock

func (*AnthropicBetaTool) Arguments added in v0.260507.1

func (t *AnthropicBetaTool) Arguments() string

func (*AnthropicBetaTool) ID added in v0.260507.1

func (t *AnthropicBetaTool) ID() string

func (*AnthropicBetaTool) Name added in v0.260507.1

func (t *AnthropicBetaTool) Name() string

type AnthropicV1Adapter added in v0.260507.1

type AnthropicV1Adapter struct{}

AnthropicV1Adapter implements FormatAdapter for Anthropic V1 API

func NewAnthropicV1Adapter added in v0.260507.1

func NewAnthropicV1Adapter() *AnthropicV1Adapter

NewAnthropicV1Adapter creates a new Anthropic V1 adapter

func (*AnthropicV1Adapter) AppendToolResults added in v0.260507.1

func (a *AnthropicV1Adapter) AppendToolResults(req, resp any, results []any) (any, error)

func (*AnthropicV1Adapter) BuildAssistantMessage added in v0.260507.1

func (a *AnthropicV1Adapter) BuildAssistantMessage(response any) (any, error)

func (*AnthropicV1Adapter) BuildToolMessage added in v0.260507.1

func (a *AnthropicV1Adapter) BuildToolMessage(result ToolExecutionResult) any

func (*AnthropicV1Adapter) ClassifyEvent added in v0.260507.1

func (a *AnthropicV1Adapter) ClassifyEvent(event any) EventType

func (*AnthropicV1Adapter) ExtractToolFromEvent added in v0.260507.1

func (a *AnthropicV1Adapter) ExtractToolFromEvent(event any) (Tool, bool)

func (*AnthropicV1Adapter) ExtractTools added in v0.260507.1

func (a *AnthropicV1Adapter) ExtractTools(response any) ([]Tool, error)

func (*AnthropicV1Adapter) ExtractUsage added in v0.260507.1

func (a *AnthropicV1Adapter) ExtractUsage(response any) (TokenUsage, error)

func (*AnthropicV1Adapter) FilterVirtualTools added in v0.260507.1

func (a *AnthropicV1Adapter) FilterVirtualTools(response any, externalTools []Tool) (any, error)

func (*AnthropicV1Adapter) IsVirtualTool added in v0.260507.1

func (a *AnthropicV1Adapter) IsVirtualTool(tool Tool, registry *runtime.VirtualToolRegistry) bool

func (*AnthropicV1Adapter) NewRequest added in v0.260507.1

func (a *AnthropicV1Adapter) NewRequest() any

func (*AnthropicV1Adapter) NewResponse added in v0.260507.1

func (a *AnthropicV1Adapter) NewResponse() any

func (*AnthropicV1Adapter) RewriteEventIndex added in v0.260507.1

func (a *AnthropicV1Adapter) RewriteEventIndex(event any, offset int) ([]byte, error)

func (*AnthropicV1Adapter) SendEvent added in v0.260507.1

func (a *AnthropicV1Adapter) SendEvent(c *gin.Context, eventType string, payload []byte) error

func (*AnthropicV1Adapter) SendFinalMessage added in v0.260507.1

func (a *AnthropicV1Adapter) SendFinalMessage(c *gin.Context) error

func (*AnthropicV1Adapter) SendKeepAlive added in v0.260507.1

func (a *AnthropicV1Adapter) SendKeepAlive(c *gin.Context) error

func (*AnthropicV1Adapter) SetupSSEHeaders added in v0.260507.1

func (a *AnthropicV1Adapter) SetupSSEHeaders(c *gin.Context)

func (*AnthropicV1Adapter) ShouldSuppressEvent added in v0.260507.1

func (a *AnthropicV1Adapter) ShouldSuppressEvent(event any, virtualRegistry *runtime.VirtualToolRegistry) bool

func (*AnthropicV1Adapter) SplitVirtualExternal added in v0.260507.1

func (a *AnthropicV1Adapter) SplitVirtualExternal(
	tools []Tool,
	registry *runtime.VirtualToolRegistry,
) (virtual, external []Tool, externalIDs []string)

type AnthropicV1Forwarder added in v0.260507.1

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

AnthropicV1Forwarder implements Forwarder for Anthropic V1 API

func NewAnthropicV1Forwarder added in v0.260507.1

func NewAnthropicV1Forwarder(clientPool ClientPoolGetter, ctxGetter ForwardContextGetter) *AnthropicV1Forwarder

func (*AnthropicV1Forwarder) ForwardNonStream added in v0.260507.1

func (f *AnthropicV1Forwarder) ForwardNonStream(
	ctx context.Context,
	provider any,
	model string,
	req any,
) (any, error)

func (*AnthropicV1Forwarder) ForwardStream added in v0.260507.1

func (f *AnthropicV1Forwarder) ForwardStream(
	ctx context.Context,
	provider any,
	model string,
	req any,
) (StreamHandle, error)

type AnthropicV1StreamHandle added in v0.260507.1

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

AnthropicV1StreamHandle wraps MessageStream

func (*AnthropicV1StreamHandle) Close added in v0.260507.1

func (h *AnthropicV1StreamHandle) Close() error

func (*AnthropicV1StreamHandle) Current added in v0.260507.1

func (h *AnthropicV1StreamHandle) Current() any

func (*AnthropicV1StreamHandle) Err added in v0.260507.1

func (h *AnthropicV1StreamHandle) Err() error

func (*AnthropicV1StreamHandle) Next added in v0.260507.1

func (h *AnthropicV1StreamHandle) Next() bool

type AnthropicV1Tool added in v0.260507.1

type AnthropicV1Tool struct {
	anthropic.ToolUseBlock
}

AnthropicV1Tool implements Tool interface for Anthropic V1 ToolUseBlock

func (*AnthropicV1Tool) Arguments added in v0.260507.1

func (t *AnthropicV1Tool) Arguments() string

func (*AnthropicV1Tool) ID added in v0.260507.1

func (t *AnthropicV1Tool) ID() string

func (*AnthropicV1Tool) Name added in v0.260507.1

func (t *AnthropicV1Tool) Name() string

type ClientPoolGetter added in v0.260507.1

type ClientPoolGetter interface {
	GetAnthropicClient(ctx context.Context, provider *typ.Provider, model string) *client.AnthropicClient
	GetOpenAIClient(ctx context.Context, provider *typ.Provider, model string) *client.OpenAIClient
}

ClientPoolGetter matches client.ClientPool interface

type EventType added in v0.260507.1

type EventType int

EventType represents the type of streaming event

const (
	EventText EventType = iota
	EventToolStart
	EventToolDelta
	EventToolStop
	MessageDelta
	MessageStop
	EventUnknown
)

type FormatAdapter added in v0.260507.1

type FormatAdapter interface {
	// Request/Response types
	NewRequest() any
	NewResponse() any

	// Tool extraction and classification
	ExtractTools(response any) ([]Tool, error)
	IsVirtualTool(tool Tool, registry *runtime.VirtualToolRegistry) bool
	SplitVirtualExternal(tools []Tool, registry *runtime.VirtualToolRegistry) (virtual, external []Tool, externalIDs []string)

	// Message building
	BuildAssistantMessage(response any) (any, error)
	BuildToolMessage(result ToolExecutionResult) any
	AppendToolResults(req any, resp any, results []any) (any, error)
	FilterVirtualTools(response any, externalTools []Tool) (any, error)

	// Streaming setup
	SetupSSEHeaders(c *gin.Context)
	SendEvent(c *gin.Context, eventType string, payload []byte) error
	SendKeepAlive(c *gin.Context) error
	SendFinalMessage(c *gin.Context) error

	// Event processing (streaming only)
	ClassifyEvent(event any) EventType
	ExtractToolFromEvent(event any) (Tool, bool)
	// ShouldSuppressEvent is called for delta and stop events after ExtractToolFromEvent.
	//
	// Design note: suppress logic is format-dependent. Anthropic adapters suppress
	// virtual tool events at the start stage (bufferToolEvent in handleToolStartEvent),
	// so delta/stop events never reach the client and ShouldSuppressEvent returns false.
	// OpenAI adapters must suppress at delta stage because function names appear in
	// delta.ToolCalls, not at start; hence OpenAI's implementation checks the name here.
	ShouldSuppressEvent(event any, virtualRegistry *runtime.VirtualToolRegistry) bool
	RewriteEventIndex(event any, offset int) ([]byte, error)

	// Usage extraction
	ExtractUsage(response any) (TokenUsage, error)
}

FormatAdapter abstracts differences between API formats (Anthropic/OpenAI)

type ForwardContextGetter added in v0.260507.1

type ForwardContextGetter interface {
	NewForwardContext(ctx context.Context, provider *typ.Provider) *forwarding.ForwardContext
}

ForwardContextGetter provides ForwardContext

type ForwardResult added in v0.260507.1

type ForwardResult struct {
	Message any
	Cancel  context.CancelFunc
}

ForwardResult wraps non-streaming response with cancel func

type Forwarder added in v0.260507.1

type Forwarder interface {
	ForwardStream(ctx context.Context, provider any, model string, req any) (StreamHandle, error)
	ForwardNonStream(ctx context.Context, provider any, model string, req any) (any, error)
}

Forwarder handles forwarding requests to upstream providers

type GenericLoopProcessor added in v0.260507.1

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

GenericLoopProcessor implements format-agnostic non-streaming MCP tool handling

func NewGenericLoopProcessor added in v0.260507.1

func NewGenericLoopProcessor(
	ctx context.Context,
	s ServerOps,
	provider *typ.Provider,
	hc *protocol.HandleContext,
	virtualRegistry *runtime.VirtualToolRegistry,
	recorder ProtocolRecorder,
	adapter FormatAdapter,
	forwarder Forwarder,
	toolExecutor ToolExecutor,
	pendingManager PendingResultsManager,
	config InterceptorConfig,
) *GenericLoopProcessor

NewGenericLoopProcessor creates a new generic non-streaming processor

func (*GenericLoopProcessor) Run added in v0.260507.1

func (p *GenericLoopProcessor) Run(req any) (any, error)

Run executes the non-streaming processor loop

type GenericStreamInterceptor added in v0.260507.1

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

GenericStreamInterceptor implements format-agnostic streaming MCP tool handling

func NewGenericStreamInterceptor added in v0.260507.1

func NewGenericStreamInterceptor(
	c *gin.Context,
	s ServerOps,
	provider *typ.Provider,
	hc *protocol.HandleContext,
	virtualRegistry *runtime.VirtualToolRegistry,
	recorder ProtocolRecorder,
	adapter FormatAdapter,
	forwarder Forwarder,
	config InterceptorConfig,
) *GenericStreamInterceptor

NewGenericStreamInterceptor creates a new generic streaming interceptor

func (*GenericStreamInterceptor) Run added in v0.260507.1

func (i *GenericStreamInterceptor) Run(req any) error

Run executes the streaming interceptor loop

func (*GenericStreamInterceptor) SetPendingResultsManager added in v0.260507.1

func (i *GenericStreamInterceptor) SetPendingResultsManager(manager PendingResultsManager)

SetPendingResultsManager injects optional pending-result stashing behavior for mixed tool outputs.

type Handler

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

Handler handles MCP configuration HTTP requests

func NewHandler

func NewHandler(cfg *config.Config) *Handler

NewHandler creates a new MCP handler

func (*Handler) GetLocalHandler added in v0.260414.2000

func (h *Handler) GetLocalHandler() *local.Handler

GetLocalHandler returns the local mode handler

func (*Handler) GetMCPRuntimeConfig

func (h *Handler) GetMCPRuntimeConfig(c *gin.Context)

GetMCPRuntimeConfig returns the global MCP runtime configuration

func (*Handler) GetTransportHandler added in v0.260414.2000

func (h *Handler) GetTransportHandler() *local.TransportHandler

GetTransportHandler returns the transport handler for local mode

func (*Handler) IsMCPEnabled added in v0.260414.2000

func (h *Handler) IsMCPEnabled() bool

IsMCPEnabled checks if MCP feature is enabled via scenario flag

func (*Handler) SetMCPRuntimeConfig

func (h *Handler) SetMCPRuntimeConfig(c *gin.Context)

SetMCPRuntimeConfig sets the global MCP runtime configuration

type InterceptorConfig added in v0.260507.1

type InterceptorConfig struct {
	MaxRounds        int
	EnableGuardrails bool
	DisableUsage     bool
	ResponseModel    string
	// OnBeforeRound is called at the start of each round after round 0.
	// Use this to reset per-round state that lives outside the interceptor
	// (e.g. guardrails stream accumulator). The interceptor does not know
	// what this callback does — it only calls it.
	OnBeforeRound func(round int) error
}

InterceptorConfig configures the generic interceptors

type MCPRuntimeConfigRequest

type MCPRuntimeConfigRequest struct {
	Sources               []typ.MCPSourceConfig `json:"sources,omitempty"`
	RequestTimeout        int                   `json:"request_timeout,omitempty"`          // seconds, default: 30
	StripDisabledMCPTools bool                  `json:"strip_disabled_mcp_tools,omitempty"` // dangerous: strip disabled MCP declarations/tool_calls
}

MCPRuntimeConfigRequest is the API request for setting MCP runtime config

type MCPRuntimeConfigResponse

type MCPRuntimeConfigResponse struct {
	Success bool                  `json:"success"`
	Config  *typ.MCPRuntimeConfig `json:"config,omitempty"`
	Error   string                `json:"error,omitempty"`
}

MCPRuntimeConfigResponse is the API response for MCP runtime config

type OpenAIChatAdapter added in v0.260507.1

type OpenAIChatAdapter struct{}

OpenAIChatAdapter implements FormatAdapter for OpenAI Chat Completions API

func NewOpenAIChatAdapter added in v0.260507.1

func NewOpenAIChatAdapter() *OpenAIChatAdapter

NewOpenAIChatAdapter creates a new OpenAI Chat adapter

func (*OpenAIChatAdapter) AppendToolResults added in v0.260507.1

func (o *OpenAIChatAdapter) AppendToolResults(req, resp any, results []any) (any, error)

func (*OpenAIChatAdapter) BuildAssistantMessage added in v0.260507.1

func (o *OpenAIChatAdapter) BuildAssistantMessage(response any) (any, error)

func (*OpenAIChatAdapter) BuildToolMessage added in v0.260507.1

func (o *OpenAIChatAdapter) BuildToolMessage(result ToolExecutionResult) any

func (*OpenAIChatAdapter) ClassifyEvent added in v0.260507.1

func (o *OpenAIChatAdapter) ClassifyEvent(event any) EventType

func (*OpenAIChatAdapter) ExtractToolFromEvent added in v0.260507.1

func (o *OpenAIChatAdapter) ExtractToolFromEvent(event any) (Tool, bool)

func (*OpenAIChatAdapter) ExtractTools added in v0.260507.1

func (o *OpenAIChatAdapter) ExtractTools(response any) ([]Tool, error)

func (*OpenAIChatAdapter) ExtractUsage added in v0.260507.1

func (o *OpenAIChatAdapter) ExtractUsage(response any) (TokenUsage, error)

func (*OpenAIChatAdapter) FilterVirtualTools added in v0.260507.1

func (o *OpenAIChatAdapter) FilterVirtualTools(response any, externalTools []Tool) (any, error)

func (*OpenAIChatAdapter) IsVirtualTool added in v0.260507.1

func (o *OpenAIChatAdapter) IsVirtualTool(tool Tool, registry *runtime.VirtualToolRegistry) bool

func (*OpenAIChatAdapter) NewRequest added in v0.260507.1

func (o *OpenAIChatAdapter) NewRequest() any

func (*OpenAIChatAdapter) NewResponse added in v0.260507.1

func (o *OpenAIChatAdapter) NewResponse() any

func (*OpenAIChatAdapter) RewriteEventIndex added in v0.260507.1

func (o *OpenAIChatAdapter) RewriteEventIndex(event any, offset int) ([]byte, error)

func (*OpenAIChatAdapter) SendEvent added in v0.260507.1

func (o *OpenAIChatAdapter) SendEvent(c *gin.Context, eventType string, payload []byte) error

func (*OpenAIChatAdapter) SendFinalMessage added in v0.260507.1

func (o *OpenAIChatAdapter) SendFinalMessage(c *gin.Context) error

func (*OpenAIChatAdapter) SendKeepAlive added in v0.260507.1

func (o *OpenAIChatAdapter) SendKeepAlive(c *gin.Context) error

func (*OpenAIChatAdapter) SetupSSEHeaders added in v0.260507.1

func (o *OpenAIChatAdapter) SetupSSEHeaders(c *gin.Context)

func (*OpenAIChatAdapter) ShouldSuppressEvent added in v0.260507.1

func (o *OpenAIChatAdapter) ShouldSuppressEvent(event any, virtualRegistry *runtime.VirtualToolRegistry) bool

func (*OpenAIChatAdapter) SplitVirtualExternal added in v0.260507.1

func (o *OpenAIChatAdapter) SplitVirtualExternal(
	tools []Tool,
	registry *runtime.VirtualToolRegistry,
) (virtual, external []Tool, externalIDs []string)

type OpenAIChatForwarder added in v0.260507.1

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

OpenAIChatForwarder implements Forwarder for OpenAI Chat API

func NewOpenAIChatForwarder added in v0.260507.1

func NewOpenAIChatForwarder(clientPool ClientPoolGetter, ctxGetter ForwardContextGetter) *OpenAIChatForwarder

func (*OpenAIChatForwarder) ForwardNonStream added in v0.260507.1

func (f *OpenAIChatForwarder) ForwardNonStream(
	ctx context.Context,
	provider any,
	model string,
	req any,
) (any, error)

func (*OpenAIChatForwarder) ForwardStream added in v0.260507.1

func (f *OpenAIChatForwarder) ForwardStream(
	ctx context.Context,
	provider any,
	model string,
	req any,
) (StreamHandle, error)

type OpenAIChatStreamHandle added in v0.260507.1

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

OpenAIChatStreamHandle wraps OpenAI stream

func (*OpenAIChatStreamHandle) Close added in v0.260507.1

func (h *OpenAIChatStreamHandle) Close() error

func (*OpenAIChatStreamHandle) Current added in v0.260507.1

func (h *OpenAIChatStreamHandle) Current() any

func (*OpenAIChatStreamHandle) Err added in v0.260507.1

func (h *OpenAIChatStreamHandle) Err() error

func (*OpenAIChatStreamHandle) Next added in v0.260507.1

func (h *OpenAIChatStreamHandle) Next() bool

type OpenAIChunkTool added in v0.260507.1

type OpenAIChunkTool struct {
	ToolCall openai.ChatCompletionChunkChoiceDeltaToolCall
}

OpenAIChunkTool implements Tool interface for OpenAI ChatCompletionChunk tool calls

func (*OpenAIChunkTool) Arguments added in v0.260507.1

func (t *OpenAIChunkTool) Arguments() string

func (*OpenAIChunkTool) ID added in v0.260507.1

func (t *OpenAIChunkTool) ID() string

func (*OpenAIChunkTool) Name added in v0.260507.1

func (t *OpenAIChunkTool) Name() string

type OpenAIMessageTool added in v0.260507.1

type OpenAIMessageTool struct {
	ToolCall openai.ChatCompletionMessageToolCallUnion
}

OpenAIMessageTool implements Tool interface for OpenAI ChatCompletionMessage tool calls

func (*OpenAIMessageTool) Arguments added in v0.260507.1

func (t *OpenAIMessageTool) Arguments() string

func (*OpenAIMessageTool) ID added in v0.260507.1

func (t *OpenAIMessageTool) ID() string

func (*OpenAIMessageTool) Name added in v0.260507.1

func (t *OpenAIMessageTool) Name() string

type OpenAITool added in v0.260507.1

type OpenAITool = OpenAIMessageTool

For now, use the message tool type

type PendingResultsInjectorBeta added in v0.260507.1

type PendingResultsInjectorBeta interface {
	InjectPendingVirtualResultsAnthropicBeta(req *anthropic.BetaMessageNewParams)
}

PendingResultsInjectorBeta defines injection for Anthropic Beta

type PendingResultsInjectorOpenAI added in v0.260507.1

type PendingResultsInjectorOpenAI interface {
	InjectPendingVirtualResultsOpenAI(req *openai.ChatCompletionNewParams)
}

PendingResultsInjectorOpenAI defines injection for OpenAI

type PendingResultsInjectorV1 added in v0.260507.1

type PendingResultsInjectorV1 interface {
	InjectPendingVirtualResultsAnthropicV1(req *anthropic.MessageNewParams)
}

PendingResultsInjectorV1 defines injection for Anthropic V1

type PendingResultsManager added in v0.260507.1

type PendingResultsManager interface {
	Stash(anchorIDs []string, results []ToolExecutionResult) error
	Inject(req any) (any, error)
	Clear(anchorID string) error
}

PendingResultsManager handles stashing and injecting pending tool results

type PendingResultsStasher added in v0.260507.1

type PendingResultsStasher interface {
	StashPendingVirtualToolResults(anchorIDs []string, results []VirtualToolExecutionResult)
}

PendingResultsStasher defines the stash functionality

type ProtocolRecorder added in v0.260507.1

type ProtocolRecorder interface {
	RecordError(err error)
	SetAssembledResponse(resp any)
	RecordResponse(provider any, model string)
}

ProtocolRecorder abstracts protocol recording operations

type ResponseDecision added in v0.260507.1

type ResponseDecision int

ResponseDecision represents the decision after classifying a response

const (
	DecisionNoTools ResponseDecision = iota
	DecisionPureVirtual
	DecisionPureExternal
	DecisionMixed
)

type ServerOps added in v0.260507.1

type ServerOps interface {
	TrackUsage(c *gin.Context, input, output, cache int)
	CallMCPTool(ctx context.Context, toolName, arguments string, messages []map[string]any) (string, error)
	GetRecorder() ProtocolRecorder
}

ServerOps abstracts server operations needed by interceptors/processors

type ServerPendingResultsManager added in v0.260507.1

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

ServerPendingResultsManager implements PendingResultsManager by wrapping server's stash/inject logic

func NewServerPendingResultsManager added in v0.260507.1

func NewServerPendingResultsManager(
	stasher PendingResultsStasher,
	injectorV1 PendingResultsInjectorV1,
	injectorBeta PendingResultsInjectorBeta,
	injectorOpenAI PendingResultsInjectorOpenAI,
) *ServerPendingResultsManager

func (*ServerPendingResultsManager) Clear added in v0.260507.1

func (m *ServerPendingResultsManager) Clear(anchorID string) error

func (*ServerPendingResultsManager) Inject added in v0.260507.1

func (m *ServerPendingResultsManager) Inject(req any) (any, error)

func (*ServerPendingResultsManager) Stash added in v0.260507.1

func (m *ServerPendingResultsManager) Stash(
	anchorIDs []string,
	results []ToolExecutionResult,
) error

type ServerToolExecutor added in v0.260507.1

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

ServerToolExecutor implements ToolExecutor by wrapping server's MCP tool execution

func NewServerToolExecutor added in v0.260507.1

func NewServerToolExecutor(s ToolExecutorServer) *ServerToolExecutor

func (*ServerToolExecutor) ExecuteTool added in v0.260507.1

func (e *ServerToolExecutor) ExecuteTool(
	ctx context.Context,
	tool Tool,
	messages []map[string]any,
) (ToolExecutionResult, error)

func (*ServerToolExecutor) ExecuteTools added in v0.260507.1

func (e *ServerToolExecutor) ExecuteTools(
	ctx context.Context,
	tools []Tool,
	messages []map[string]any,
) ([]ToolExecutionResult, error)

type StreamHandle added in v0.260507.1

type StreamHandle interface {
	Next() bool
	Current() any
	Err() error
	Close() error
}

StreamHandle represents a generic streaming response

type TokenUsage added in v0.260507.1

type TokenUsage struct {
	InputTokens  int
	OutputTokens int
	CacheTokens  int
}

TokenUsage represents token usage information

type Tool added in v0.260507.1

type Tool interface {
	ID() string
	Name() string
	Arguments() string
}

Tool represents a tool call in a format-agnostic way

type ToolExecutionResult added in v0.260507.1

type ToolExecutionResult struct {
	ToolUseID string
	Content   string
	IsError   bool
}

ToolExecutionResult represents the result of executing a tool

type ToolExecutor added in v0.260507.1

type ToolExecutor interface {
	ExecuteTool(ctx context.Context, tool Tool, messages []map[string]any) (ToolExecutionResult, error)
	ExecuteTools(ctx context.Context, tools []Tool, messages []map[string]any) ([]ToolExecutionResult, error)
}

ToolExecutor handles execution of virtual tools

type ToolExecutorServer added in v0.260507.1

type ToolExecutorServer interface {
	CallMCPTool(ctx context.Context, toolName, arguments string, messages []map[string]any) (string, error)
}

ToolExecutorServer defines the server methods needed for tool execution

type VirtualToolExecutionResult added in v0.260507.1

type VirtualToolExecutionResult struct {
	ToolUseID string
	Content   string
	IsError   bool
}

VirtualToolExecutionResult matches the server's internal type

Jump to

Keyboard shortcuts

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