Documentation
¶
Overview ¶
Package adapter provides a layer between aggregator and SDK.
The HandlerFactory interface and its default implementation create MCP request handlers that route to backend workloads, bridging the gap between the MCP SDK
Index ¶
- type CapabilityAdapter
- func (a *CapabilityAdapter) ToCompositeToolSDKTools(tools []vmcp.Tool, workflowExecutors map[string]WorkflowExecutor) ([]server.ServerTool, error)
- func (a *CapabilityAdapter) ToSDKPrompts(prompts []vmcp.Prompt) []server.ServerPrompt
- func (a *CapabilityAdapter) ToSDKResources(resources []vmcp.Resource) []server.ServerResource
- func (a *CapabilityAdapter) ToSDKTools(tools []vmcp.Tool) ([]server.ServerTool, error)
- type DefaultHandlerFactory
- func (*DefaultHandlerFactory) CreateCompositeToolHandler(toolName string, workflow WorkflowExecutor) func(context.Context, mcp.CallToolRequest) (*mcp.CallToolResult, error)
- func (f *DefaultHandlerFactory) CreatePromptHandler(promptName string) func(context.Context, mcp.GetPromptRequest) (*mcp.GetPromptResult, error)
- func (f *DefaultHandlerFactory) CreateResourceHandler(uri string) func(context.Context, mcp.ReadResourceRequest) ([]mcp.ResourceContents, error)
- func (f *DefaultHandlerFactory) CreateToolHandler(toolName string) func(context.Context, mcp.CallToolRequest) (*mcp.CallToolResult, error)
- type HandlerFactory
- type WorkflowExecutor
- type WorkflowResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CapabilityAdapter ¶
type CapabilityAdapter struct {
// contains filtered or unexported fields
}
CapabilityAdapter converts aggregator domain models to SDK types.
This is the Anti-Corruption Layer between:
- Domain model (aggregator.AggregatedCapabilities)
- External library (mark3labs/mcp-go SDK types)
The adapter:
- Converts aggregator types to SDK types
- Creates handlers using HandlerFactory
- Returns SDK-ready capabilities
This keeps the server layer from knowing about aggregator internals.
func NewCapabilityAdapter ¶
func NewCapabilityAdapter(handlerFactory HandlerFactory) *CapabilityAdapter
NewCapabilityAdapter creates a new capability adapter.
func (*CapabilityAdapter) ToCompositeToolSDKTools ¶ added in v0.6.6
func (a *CapabilityAdapter) ToCompositeToolSDKTools( tools []vmcp.Tool, workflowExecutors map[string]WorkflowExecutor, ) ([]server.ServerTool, error)
ToCompositeToolSDKTools converts composite tools to SDK ServerTool format with workflow handlers.
This method is similar to ToSDKTools but uses composite tool workflow handlers instead of backend routing handlers. For each composite tool:
- Marshals InputSchema to JSON (SDK expects RawInputSchema as []byte)
- Creates workflow handler via HandlerFactory.CreateCompositeToolHandler
- Wraps in server.ServerTool struct
The workflowExecutors map provides the workflow executor for each tool name. Returns error if schema marshaling fails or workflow executor is missing for any tool.
Authorization note: Composite tools are registered per-session based on session-discovered tools. Currently, if a workflow references tools that a user lacks access to, the workflow registration will fail hard with an error. Future enhancement: gracefully disable workflows with missing required tools while logging for audit purposes, preventing privilege escalation while improving user experience.
func (*CapabilityAdapter) ToSDKPrompts ¶
func (a *CapabilityAdapter) ToSDKPrompts(prompts []vmcp.Prompt) []server.ServerPrompt
ToSDKPrompts converts vmcp prompts to SDK ServerPrompt format.
For each prompt:
- Maps vmcp.Prompt fields to mcp.Prompt fields
- Converts prompt arguments to SDK format
- Creates handler via HandlerFactory
- Wraps in server.ServerPrompt struct
Note: SDK v0.43.0 does not support per-session prompts yet. This method is provided for future use.
func (*CapabilityAdapter) ToSDKResources ¶
func (a *CapabilityAdapter) ToSDKResources(resources []vmcp.Resource) []server.ServerResource
ToSDKResources converts vmcp resources to SDK ServerResource format.
For each resource:
- Maps vmcp.Resource fields to mcp.Resource fields
- Creates handler via HandlerFactory
- Wraps in server.ServerResource struct
func (*CapabilityAdapter) ToSDKTools ¶
func (a *CapabilityAdapter) ToSDKTools(tools []vmcp.Tool) ([]server.ServerTool, error)
ToSDKTools converts vmcp tools to SDK ServerTool format.
For each tool:
- Marshals InputSchema to JSON (SDK expects RawInputSchema as []byte)
- Creates handler via HandlerFactory
- Wraps in server.ServerTool struct
Returns error if schema marshaling fails for any tool.
type DefaultHandlerFactory ¶
type DefaultHandlerFactory struct {
// contains filtered or unexported fields
}
DefaultHandlerFactory creates MCP request handlers that route to backend workloads.
func NewDefaultHandlerFactory ¶
func NewDefaultHandlerFactory(rt router.Router, backendClient vmcp.BackendClient) *DefaultHandlerFactory
NewDefaultHandlerFactory creates a new default handler factory.
func (*DefaultHandlerFactory) CreateCompositeToolHandler ¶ added in v0.6.6
func (*DefaultHandlerFactory) CreateCompositeToolHandler( toolName string, workflow WorkflowExecutor, ) func(context.Context, mcp.CallToolRequest) (*mcp.CallToolResult, error)
CreateCompositeToolHandler creates a handler that executes composite tool workflows.
This handler differs from backend tool handlers in that it executes multi-step workflows via the composer instead of routing to a single backend. The workflow orchestrates calls to multiple backend tools and handles elicitation, conditions, and error handling.
The handler:
- Extracts parameters from the MCP request
- Invokes the workflow executor
- Converts workflow results to MCP tool result format
- Handles workflow errors gracefully
Workflow execution errors are returned as MCP tool errors (not HTTP errors), ensuring consistent error handling across all tool types.
func (*DefaultHandlerFactory) CreatePromptHandler ¶
func (f *DefaultHandlerFactory) CreatePromptHandler(promptName string) func( context.Context, mcp.GetPromptRequest, ) (*mcp.GetPromptResult, error)
CreatePromptHandler creates a prompt handler that routes to the appropriate backend.
func (*DefaultHandlerFactory) CreateResourceHandler ¶
func (f *DefaultHandlerFactory) CreateResourceHandler(uri string) func( context.Context, mcp.ReadResourceRequest, ) ([]mcp.ResourceContents, error)
CreateResourceHandler creates a resource handler that routes to the appropriate backend.
func (*DefaultHandlerFactory) CreateToolHandler ¶
func (f *DefaultHandlerFactory) CreateToolHandler( toolName string, ) func(context.Context, mcp.CallToolRequest) (*mcp.CallToolResult, error)
CreateToolHandler creates a tool handler that routes to the appropriate backend.
type HandlerFactory ¶
type HandlerFactory interface {
// CreateToolHandler creates a handler that routes tool calls to backends.
CreateToolHandler(toolName string) func(context.Context, mcp.CallToolRequest) (*mcp.CallToolResult, error)
// CreateResourceHandler creates a handler that routes resource reads to backends.
CreateResourceHandler(uri string) func(context.Context, mcp.ReadResourceRequest) ([]mcp.ResourceContents, error)
// CreatePromptHandler creates a handler that routes prompt requests to backends.
CreatePromptHandler(promptName string) func(context.Context, mcp.GetPromptRequest) (*mcp.GetPromptResult, error)
// CreateCompositeToolHandler creates a handler for composite tool workflows.
// This handler executes multi-step workflows via the composer instead of routing to a single backend.
CreateCompositeToolHandler(
toolName string,
workflow WorkflowExecutor,
) func(context.Context, mcp.CallToolRequest) (*mcp.CallToolResult, error)
}
HandlerFactory creates handlers that route MCP requests to backends.
type WorkflowExecutor ¶ added in v0.6.6
type WorkflowExecutor interface {
// ExecuteWorkflow executes the workflow with the given parameters.
ExecuteWorkflow(ctx context.Context, params map[string]any) (*WorkflowResult, error)
}
WorkflowExecutor executes composite tool workflows. This interface abstracts the composer to enable testing without full composer setup.
type WorkflowResult ¶ added in v0.6.6
type WorkflowResult struct {
// Output contains the workflow output data (typically from the last step).
Output map[string]any
// Error contains error information if the workflow failed.
Error error
}
WorkflowResult represents the result of a workflow execution.