adapter

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

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

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:

  1. Converts aggregator types to SDK types
  2. Creates handlers using HandlerFactory
  3. 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) 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) 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)
}

HandlerFactory creates handlers that route MCP requests to backends.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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