mcp

package
v0.260625.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MPL-2.0 Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 *coretool.VirtualToolRegistry) bool

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

func IsVirtualToolName added in v0.260514.1

func IsVirtualToolName(name string, registry *coretool.VirtualToolRegistry) bool

func ListAsMCPTools added in v0.260514.1

func ListAsMCPTools(r *coretool.VirtualToolRegistry) []mcpgo.Tool

ListAsMCPTools converts virtual tools to mcp.Tool slice for wire protocol use.

func PopOpenAIContinuationSegment added in v0.260514.1

func PopOpenAIContinuationSegment(sessionID typ.SessionID, providerUUID string) ([]openai.ChatCompletionMessageParamUnion, bool)

func RegisterRoutes

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

RegisterRoutes registers all MCP configuration routes with swagger documentation

func StoreOpenAIContinuationSegment added in v0.260514.1

func StoreOpenAIContinuationSegment(sessionID typ.SessionID, providerUUID string, segment []openai.ChatCompletionMessageParamUnion)

func ToolContentsToAnthropicBeta added in v0.260514.1

func ToolContentsToAnthropicBeta(contents []coretool.ToolContent) []anthropic.BetaToolResultBlockParamContentUnion

ToolContentsToAnthropicBeta converts []ToolContent to the Anthropic Beta tool result content slice.

func ToolContentsToAnthropicV1 added in v0.260514.1

func ToolContentsToAnthropicV1(contents []coretool.ToolContent) []anthropic.ToolResultBlockParamContentUnion

ToolContentsToAnthropicV1 converts []ToolContent to the Anthropic V1 tool result content slice. Text items become TextBlockParam; image items become ImageBlockParam.

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) ApplyContinuation added in v0.260514.1

func (a *AnthropicBetaAdapter) ApplyContinuation(req any, segment any) (any, error)

func (*AnthropicBetaAdapter) BuildAssistantMessage added in v0.260507.1

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

func (*AnthropicBetaAdapter) BuildContinuationSegment added in v0.260514.1

func (a *AnthropicBetaAdapter) BuildContinuationSegment(resp any, results []ToolExecutionResult) (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 *coretool.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 *coretool.VirtualToolRegistry) bool

func (*AnthropicBetaAdapter) SplitVirtualExternal added in v0.260507.1

func (a *AnthropicBetaAdapter) SplitVirtualExternal(
	tools []Tool,
	registry *coretool.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) ApplyContinuation added in v0.260514.1

func (a *AnthropicV1Adapter) ApplyContinuation(req any, segment any) (any, error)

func (*AnthropicV1Adapter) BuildAssistantMessage added in v0.260507.1

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

func (*AnthropicV1Adapter) BuildContinuationSegment added in v0.260514.1

func (a *AnthropicV1Adapter) BuildContinuationSegment(resp any, results []ToolExecutionResult) (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 *coretool.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 *coretool.VirtualToolRegistry) bool

func (*AnthropicV1Adapter) SplitVirtualExternal added in v0.260507.1

func (a *AnthropicV1Adapter) SplitVirtualExternal(
	tools []Tool,
	registry *coretool.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.AnthropicClientInterface
	GetOpenAIClient(ctx context.Context, provider *typ.Provider, model string) client.OpenAIClientInterface
}

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 *coretool.VirtualToolRegistry) bool
	SplitVirtualExternal(tools []Tool, registry *coretool.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)
	BuildContinuationSegment(resp any, results []ToolExecutionResult) (any, error)
	ApplyContinuation(req any, segment 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 *coretool.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
	AnthropicClient client.AnthropicClientInterface
	OpenAIClient    client.OpenAIClientInterface
}

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 *coretool.VirtualToolRegistry,
	recorder ProtocolRecorder,
	adapter FormatAdapter,
	forwarder Forwarder,
	toolExecutor ToolExecutor,
	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 *coretool.VirtualToolRegistry,
	recorder ProtocolRecorder,
	adapter FormatAdapter,
	forwarder Forwarder,
	toolExecutor ToolExecutor,
	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

type Handler

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

Handler handles MCP configuration HTTP requests

func NewHandler

func NewHandler(cfg *config.Config, rt ...*mcpruntime.Runtime) *Handler

NewHandler creates a new MCP handler. rt is an optional shared Runtime; when provided (e.g. from the main server) it is reused so the transport handler sees already-connected sources and registered builtins. When nil (e.g. in openapi/CLI mode) a fresh runtime is created from config.

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) ApplyContinuation added in v0.260514.1

func (o *OpenAIChatAdapter) ApplyContinuation(req any, segment any) (any, error)

func (*OpenAIChatAdapter) BuildAssistantMessage added in v0.260507.1

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

func (*OpenAIChatAdapter) BuildContinuationSegment added in v0.260514.1

func (o *OpenAIChatAdapter) BuildContinuationSegment(resp any, results []ToolExecutionResult) (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 *coretool.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 *coretool.VirtualToolRegistry) bool

func (*OpenAIChatAdapter) SplitVirtualExternal added in v0.260507.1

func (o *OpenAIChatAdapter) SplitVirtualExternal(
	tools []Tool,
	registry *coretool.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 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 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) ExecuteToolWithContext added in v0.260514.1

func (e *ServerToolExecutor) ExecuteToolWithContext(
	ctx context.Context,
	tool Tool,
	messages []map[string]any,
) (context.Context, 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
	Contents  []coretool.ToolContent
	IsError   bool
}

ToolExecutionResult represents the result of executing a tool

func (ToolExecutionResult) TextContent added in v0.260514.1

func (r ToolExecutionResult) TextContent() string

TextContent returns the concatenated text of all text content items.

type ToolExecutor added in v0.260507.1

type ToolExecutor interface {
	ExecuteToolWithContext(ctx context.Context, tool Tool, messages []map[string]any) (context.Context, ToolExecutionResult, error)
	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 {
	CallMCPToolWithHooks(ctx context.Context, toolName, arguments string, messages []map[string]any) (context.Context, coretool.ToolResult, error)
	CallMCPTool(ctx context.Context, toolName, arguments string, messages []map[string]any) (string, error)
}

ToolExecutorServer defines the server methods needed for tool execution

Jump to

Keyboard shortcuts

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