mcp

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package mcp provides an ExecutionBackend implementation that wraps MCP servers.

MCPBackend translates fabric.ExecutionBackend calls into MCP tool calls, allowing any MCP server to act as a Loom backend. This enables integration with 100+ community MCP servers without writing custom backend code.

Example usage:

// Connect to MCP server
mcpClient := client.NewClient(client.Config{...})
mcpClient.Initialize(ctx, clientInfo)

// Create backend wrapping the MCP server
backend := mcp.NewMCPBackend(mcp.Config{
    Client:     mcpClient,
    Name:       "postgres",
    ToolPrefix: "postgres",  // Tools: postgres_execute_query, postgres_list_tables, etc.
})

// Use as normal ExecutionBackend
result, _ := backend.ExecuteQuery(ctx, "SELECT * FROM users")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Client is the MCP client connected to the server
	Client MCPClient

	// Name is the backend identifier (e.g., "postgres", "teradata")
	Name string

	// ToolPrefix is prepended to tool names (e.g., "postgres" → "postgres_execute_query")
	// If empty, uses Name
	ToolPrefix string

	// Logger for tracing and debugging
	Logger *zap.Logger

	// ToolMapping maps ExecutionBackend methods to MCP tool names
	// If nil, uses default mapping with ToolPrefix
	ToolMapping map[string]string

	// Capabilities override (optional)
	Capabilities *fabric.Capabilities
}

Config configures the MCP backend

type MCPBackend

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

MCPBackend implements fabric.ExecutionBackend by wrapping an MCP server. It translates ExecutionBackend method calls into MCP tool calls.

func NewMCPBackend

func NewMCPBackend(config Config) (*MCPBackend, error)

NewMCPBackend creates a new MCP-backed ExecutionBackend

func (*MCPBackend) Capabilities

func (b *MCPBackend) Capabilities() *fabric.Capabilities

Capabilities returns backend capabilities

func (*MCPBackend) Close

func (b *MCPBackend) Close() error

Close releases resources

func (*MCPBackend) ExecuteCustomOperation

func (b *MCPBackend) ExecuteCustomOperation(ctx context.Context, op string, params map[string]interface{}) (interface{}, error)

ExecuteCustomOperation executes a custom operation by calling: {prefix}_{op}

func (*MCPBackend) ExecuteQuery

func (b *MCPBackend) ExecuteQuery(ctx context.Context, query string) (*fabric.QueryResult, error)

ExecuteQuery executes a query by calling the MCP tool: {prefix}_execute_query

func (*MCPBackend) GetMetadata

func (b *MCPBackend) GetMetadata(ctx context.Context, resource string) (map[string]interface{}, error)

GetMetadata retrieves metadata by calling: {prefix}_get_metadata

func (*MCPBackend) GetSchema

func (b *MCPBackend) GetSchema(ctx context.Context, resource string) (*fabric.Schema, error)

GetSchema retrieves schema by calling: {prefix}_get_schema

func (*MCPBackend) ListResources

func (b *MCPBackend) ListResources(ctx context.Context, filters map[string]string) ([]fabric.Resource, error)

ListResources lists resources by calling: {prefix}_list_resources

func (*MCPBackend) Name

func (b *MCPBackend) Name() string

Name returns the backend identifier

func (*MCPBackend) Ping

func (b *MCPBackend) Ping(ctx context.Context) error

Ping checks backend health by calling: {prefix}_ping

type MCPClient

type MCPClient interface {
	ListTools(ctx context.Context) ([]protocol.Tool, error)
	CallTool(ctx context.Context, name string, arguments map[string]interface{}) (interface{}, error)
}

MCPClient defines the interface for MCP client operations needed by MCPBackend CallTool returns interface{} to avoid import cycles (actual type is *protocol.CallToolResult)

Jump to

Keyboard shortcuts

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