mcpserver

package
v0.260813.2 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 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

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

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

func IsVirtualToolName

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

func ListAsMCPTools

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

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

func PopOpenAIContinuationSegment

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

func StoreOpenAIContinuationSegment

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

func ToolContentsToAnthropicBeta

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

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

func ToolContentsToAnthropicV1

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

type AnthropicBetaAdapter struct{}

AnthropicBetaAdapter implements FormatAdapter for Anthropic Beta API

func NewAnthropicBetaAdapter

func NewAnthropicBetaAdapter() *AnthropicBetaAdapter

NewAnthropicBetaAdapter creates a new Anthropic Beta adapter

func (*AnthropicBetaAdapter) AppendToolResults

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

func (*AnthropicBetaAdapter) ApplyContinuation

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

func (*AnthropicBetaAdapter) BuildAssistantMessage

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

func (*AnthropicBetaAdapter) BuildContinuationSegment

func (a *AnthropicBetaAdapter) BuildContinuationSegment(resp any, results []ToolExecutionResult) (any, error)

func (*AnthropicBetaAdapter) BuildToolMessage

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

func (*AnthropicBetaAdapter) ClassifyEvent

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

func (*AnthropicBetaAdapter) ExtractToolFromEvent

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

func (*AnthropicBetaAdapter) ExtractTools

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

func (*AnthropicBetaAdapter) ExtractUsage

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

func (*AnthropicBetaAdapter) FilterVirtualTools

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

func (*AnthropicBetaAdapter) IsVirtualTool

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

IsVirtualTool delegates to the package-level classifier so every adapter answers the same question the same way. It used to be copied per adapter, which meant a new class of server-executed tool had to be remembered in four places.

func (*AnthropicBetaAdapter) NewRequest

func (a *AnthropicBetaAdapter) NewRequest() any

func (*AnthropicBetaAdapter) NewResponse

func (a *AnthropicBetaAdapter) NewResponse() any

func (*AnthropicBetaAdapter) RewriteEventIndex

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

func (*AnthropicBetaAdapter) SendEvent

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

func (*AnthropicBetaAdapter) SendFinalMessage

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

func (*AnthropicBetaAdapter) SendKeepAlive

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

func (*AnthropicBetaAdapter) SetupSSEHeaders

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

func (*AnthropicBetaAdapter) ShouldSuppressEvent

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

func (*AnthropicBetaAdapter) SplitVirtualExternal

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

type AnthropicBetaForwarder

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

AnthropicBetaForwarder implements Forwarder for Anthropic Beta API

func NewAnthropicBetaForwarder

func NewAnthropicBetaForwarder(clientPool ClientPoolGetter, ctxGetter ForwardContextGetter) *AnthropicBetaForwarder

func (*AnthropicBetaForwarder) ForwardNonStream

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

func (*AnthropicBetaForwarder) ForwardStream

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

type AnthropicBetaStreamHandle

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

AnthropicBetaStreamHandle wraps Beta stream

func (*AnthropicBetaStreamHandle) Close

func (h *AnthropicBetaStreamHandle) Close() error

func (*AnthropicBetaStreamHandle) Current

func (h *AnthropicBetaStreamHandle) Current() any

func (*AnthropicBetaStreamHandle) Err

func (*AnthropicBetaStreamHandle) Next

func (h *AnthropicBetaStreamHandle) Next() bool

type AnthropicBetaTool

type AnthropicBetaTool struct {
	ToolUseBlock anthropic.BetaToolUseBlock
}

AnthropicBetaTool implements Tool interface for Anthropic Beta ToolUseBlock

func (*AnthropicBetaTool) Arguments

func (t *AnthropicBetaTool) Arguments() string

func (*AnthropicBetaTool) ID

func (t *AnthropicBetaTool) ID() string

func (*AnthropicBetaTool) Name

func (t *AnthropicBetaTool) Name() string

type AnthropicV1Adapter

type AnthropicV1Adapter struct{}

AnthropicV1Adapter implements FormatAdapter for Anthropic V1 API

func NewAnthropicV1Adapter

func NewAnthropicV1Adapter() *AnthropicV1Adapter

NewAnthropicV1Adapter creates a new Anthropic V1 adapter

func (*AnthropicV1Adapter) AppendToolResults

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

func (*AnthropicV1Adapter) ApplyContinuation

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

func (*AnthropicV1Adapter) BuildAssistantMessage

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

func (*AnthropicV1Adapter) BuildContinuationSegment

func (a *AnthropicV1Adapter) BuildContinuationSegment(resp any, results []ToolExecutionResult) (any, error)

func (*AnthropicV1Adapter) BuildToolMessage

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

func (*AnthropicV1Adapter) ClassifyEvent

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

func (*AnthropicV1Adapter) ExtractToolFromEvent

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

func (*AnthropicV1Adapter) ExtractTools

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

func (*AnthropicV1Adapter) ExtractUsage

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

func (*AnthropicV1Adapter) FilterVirtualTools

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

func (*AnthropicV1Adapter) IsVirtualTool

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

IsVirtualTool delegates to the package-level classifier so every adapter answers the same question the same way. It used to be copied per adapter, which meant a new class of server-executed tool had to be remembered in four places.

func (*AnthropicV1Adapter) NewRequest

func (a *AnthropicV1Adapter) NewRequest() any

func (*AnthropicV1Adapter) NewResponse

func (a *AnthropicV1Adapter) NewResponse() any

func (*AnthropicV1Adapter) RewriteEventIndex

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

func (*AnthropicV1Adapter) SendEvent

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

func (*AnthropicV1Adapter) SendFinalMessage

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

func (*AnthropicV1Adapter) SendKeepAlive

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

func (*AnthropicV1Adapter) SetupSSEHeaders

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

func (*AnthropicV1Adapter) ShouldSuppressEvent

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

func (*AnthropicV1Adapter) SplitVirtualExternal

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

type AnthropicV1Forwarder

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

AnthropicV1Forwarder implements Forwarder for Anthropic V1 API

func NewAnthropicV1Forwarder

func NewAnthropicV1Forwarder(clientPool ClientPoolGetter, ctxGetter ForwardContextGetter) *AnthropicV1Forwarder

func (*AnthropicV1Forwarder) ForwardNonStream

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

func (*AnthropicV1Forwarder) ForwardStream

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

type AnthropicV1StreamHandle

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

AnthropicV1StreamHandle wraps MessageStream

func (*AnthropicV1StreamHandle) Close

func (h *AnthropicV1StreamHandle) Close() error

func (*AnthropicV1StreamHandle) Current

func (h *AnthropicV1StreamHandle) Current() any

func (*AnthropicV1StreamHandle) Err

func (h *AnthropicV1StreamHandle) Err() error

func (*AnthropicV1StreamHandle) Next

func (h *AnthropicV1StreamHandle) Next() bool

type AnthropicV1Tool

type AnthropicV1Tool struct {
	anthropic.ToolUseBlock
}

AnthropicV1Tool implements Tool interface for Anthropic V1 ToolUseBlock

func (*AnthropicV1Tool) Arguments

func (t *AnthropicV1Tool) Arguments() string

func (*AnthropicV1Tool) ID

func (t *AnthropicV1Tool) ID() string

func (*AnthropicV1Tool) Name

func (t *AnthropicV1Tool) Name() string

type ClientPoolGetter

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

type EventType int

EventType represents the type of streaming event

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

type FormatAdapter

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

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

ForwardContextGetter provides ForwardContext

type ForwardResult

type ForwardResult struct {
	Message         any
	Cancel          context.CancelFunc
	AnthropicClient client.AnthropicClientInterface
	OpenAIClient    client.OpenAIClientInterface
}

ForwardResult wraps non-streaming response with cancel func

type Forwarder

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

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

GenericLoopProcessor implements format-agnostic non-streaming MCP tool handling

func NewGenericLoopProcessor

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

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

Run executes the non-streaming processor loop

type GenericStreamInterceptor

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

GenericStreamInterceptor implements format-agnostic streaming MCP tool handling

func NewGenericStreamInterceptor

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

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

Run executes the streaming interceptor loop

type InterceptorConfig

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 OpenAIChatAdapter

type OpenAIChatAdapter struct{}

OpenAIChatAdapter implements FormatAdapter for OpenAI Chat Completions API

func NewOpenAIChatAdapter

func NewOpenAIChatAdapter() *OpenAIChatAdapter

NewOpenAIChatAdapter creates a new OpenAI Chat adapter

func (*OpenAIChatAdapter) AppendToolResults

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

func (*OpenAIChatAdapter) ApplyContinuation

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

func (*OpenAIChatAdapter) BuildAssistantMessage

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

func (*OpenAIChatAdapter) BuildContinuationSegment

func (o *OpenAIChatAdapter) BuildContinuationSegment(resp any, results []ToolExecutionResult) (any, error)

func (*OpenAIChatAdapter) BuildToolMessage

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

func (*OpenAIChatAdapter) ClassifyEvent

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

func (*OpenAIChatAdapter) ExtractToolFromEvent

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

func (*OpenAIChatAdapter) ExtractTools

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

func (*OpenAIChatAdapter) ExtractUsage

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

func (*OpenAIChatAdapter) FilterVirtualTools

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

func (*OpenAIChatAdapter) IsVirtualTool

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

IsVirtualTool delegates to the package-level classifier so every adapter answers the same question the same way. It used to be copied per adapter, which meant a new class of server-executed tool had to be remembered in four places.

func (*OpenAIChatAdapter) NewRequest

func (o *OpenAIChatAdapter) NewRequest() any

func (*OpenAIChatAdapter) NewResponse

func (o *OpenAIChatAdapter) NewResponse() any

func (*OpenAIChatAdapter) RewriteEventIndex

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

func (*OpenAIChatAdapter) SendEvent

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

func (*OpenAIChatAdapter) SendFinalMessage

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

func (*OpenAIChatAdapter) SendKeepAlive

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

func (*OpenAIChatAdapter) SetupSSEHeaders

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

func (*OpenAIChatAdapter) ShouldSuppressEvent

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

func (*OpenAIChatAdapter) SplitVirtualExternal

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

type OpenAIChatForwarder

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

OpenAIChatForwarder implements Forwarder for OpenAI Chat API

func NewOpenAIChatForwarder

func NewOpenAIChatForwarder(clientPool ClientPoolGetter, ctxGetter ForwardContextGetter) *OpenAIChatForwarder

func (*OpenAIChatForwarder) ForwardNonStream

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

func (*OpenAIChatForwarder) ForwardStream

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

type OpenAIChatStreamHandle

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

OpenAIChatStreamHandle wraps OpenAI stream

func (*OpenAIChatStreamHandle) Close

func (h *OpenAIChatStreamHandle) Close() error

func (*OpenAIChatStreamHandle) Current

func (h *OpenAIChatStreamHandle) Current() any

func (*OpenAIChatStreamHandle) Err

func (h *OpenAIChatStreamHandle) Err() error

func (*OpenAIChatStreamHandle) Next

func (h *OpenAIChatStreamHandle) Next() bool

type OpenAIChunkTool

type OpenAIChunkTool struct {
	ToolCall openai.ChatCompletionChunkChoiceDeltaToolCall
}

OpenAIChunkTool implements Tool interface for OpenAI ChatCompletionChunk tool calls

func (*OpenAIChunkTool) Arguments

func (t *OpenAIChunkTool) Arguments() string

func (*OpenAIChunkTool) ID

func (t *OpenAIChunkTool) ID() string

func (*OpenAIChunkTool) Name

func (t *OpenAIChunkTool) Name() string

type OpenAIMessageTool

type OpenAIMessageTool struct {
	ToolCall openai.ChatCompletionMessageToolCallUnion
}

OpenAIMessageTool implements Tool interface for OpenAI ChatCompletionMessage tool calls

func (*OpenAIMessageTool) Arguments

func (t *OpenAIMessageTool) Arguments() string

func (*OpenAIMessageTool) ID

func (t *OpenAIMessageTool) ID() string

func (*OpenAIMessageTool) Name

func (t *OpenAIMessageTool) Name() string

type OpenAITool

type OpenAITool = OpenAIMessageTool

For now, use the message tool type

type ProtocolRecorder

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

ProtocolRecorder abstracts protocol recording operations

type ResponseDecision

type ResponseDecision int

ResponseDecision represents the decision after classifying a response

const (
	DecisionNoTools ResponseDecision = iota
	DecisionPureVirtual
	DecisionPureExternal
	DecisionMixed
)

type ServerOps

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

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

ServerToolExecutor implements ToolExecutor by wrapping server's MCP tool execution

func NewServerToolExecutor

func NewServerToolExecutor(s ToolExecutorServer) *ServerToolExecutor

func (*ServerToolExecutor) ExecuteTool

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

func (*ServerToolExecutor) ExecuteToolWithContext

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

func (*ServerToolExecutor) ExecuteTools

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

type StreamHandle

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

StreamHandle represents a generic streaming response

type TokenUsage

type TokenUsage struct {
	InputTokens  int
	OutputTokens int
	CacheTokens  int
}

TokenUsage represents token usage information

type Tool

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

Tool represents a tool call in a format-agnostic way

type ToolExecutionResult

type ToolExecutionResult struct {
	ToolUseID string
	Contents  []coretool.ToolContent
	IsError   bool
}

ToolExecutionResult represents the result of executing a tool

func (ToolExecutionResult) TextContent

func (r ToolExecutionResult) TextContent() string

TextContent returns the concatenated text of all text content items.

type ToolExecutor

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

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