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 ¶
- type Config
- type MCPBackend
- func (b *MCPBackend) Capabilities() *fabric.Capabilities
- func (b *MCPBackend) Close() error
- func (b *MCPBackend) ExecuteCustomOperation(ctx context.Context, op string, params map[string]interface{}) (interface{}, error)
- func (b *MCPBackend) ExecuteQuery(ctx context.Context, query string) (*fabric.QueryResult, error)
- func (b *MCPBackend) GetMetadata(ctx context.Context, resource string) (map[string]interface{}, error)
- func (b *MCPBackend) GetSchema(ctx context.Context, resource string) (*fabric.Schema, error)
- func (b *MCPBackend) ListResources(ctx context.Context, filters map[string]string) ([]fabric.Resource, error)
- func (b *MCPBackend) Name() string
- func (b *MCPBackend) Ping(ctx context.Context) error
- type MCPClient
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) 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) ListResources ¶
func (b *MCPBackend) ListResources(ctx context.Context, filters map[string]string) ([]fabric.Resource, error)
ListResources lists resources by calling: {prefix}_list_resources
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)