mcpadapter

package module
v0.0.0-...-e4f5610 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2025 License: MIT Imports: 17 Imported by: 0

README ΒΆ

MCP Server Adapter

Description

GitHub Workflow Status GitHub go.mod Go version License

The mcp-server-adapter is a Go package designed to simplify the integration of Model Context Protocol (MCP) servers with LangChain Go applications. It acts as an intermediary, allowing LangChain agents to seamlessly discover, use, and manage tools exposed by various MCP servers. This adapter handles server lifecycle management, configuration watching, and the conversion of MCP tools into a format consumable by LangChain.

Note: This project is currently a work in progress. While functional, it may undergo significant changes, including breaking API changes, as it evolves.

Features

  • Seamless LangChain Integration: Exposes MCP server tools as native LangChain tools.Tool objects.
  • MCP Server Lifecycle Management: Start, stop, and monitor the status of multiple MCP servers.
  • Dynamic Configuration: Supports loading server configurations from a JSON file and hot-reloading changes.
  • Server Status and Configuration Access: Easily check if a server is disabled or retrieve its full configuration.
  • File Watcher: Automatically detects and reacts to changes in the configuration file, restarting affected servers.
  • Multiple Transport Support: Connects to MCP servers via standard I/O (stdio), Server-Sent Events (SSE), and HTTP transports.
  • Robust Error Handling: Includes mechanisms for safely closing server connections and handling common errors.
  • Extensible: Designed with interfaces for easy extension and testing (e.g., custom client factories).

Installation

This project requires Go 1.21 or higher.

  1. Clone the repository:
    git clone https://github.com/denkhaus/mcp-server-adapter.git
    cd mcp-server-adapter
    
  2. Install dependencies:
    go mod tidy
    
  3. Build the project:
    go build ./...
    

Running Examples

The examples can be built and run using the provided Makefile. Navigate to the project root and use make commands.

For instance, to build all examples:

make build-examples

To run a specific example, like the demo:

make run-demo

Usage

The mcp-server-adapter is typically used within a Go application to manage connections to MCP servers and integrate their tools into an LLM agent.

  1. Define your MCP server configuration: Create a JSON file (e.g., config.json) specifying the MCP servers your application needs to connect to. See examples/mcp-spec-config.json for a practical example.

    {
      "mcpServers": {
        "fetcher": {
          "command": "npx",
          "args": ["-y", "fetcher-mcp"],
          "transport": "stdio"
        },
        "tavily-mcp": {
          "command": "npx",
          "args": ["-y", "tavily-mcp@0.1.3"],
          "transport": "stdio"
        }
      }
    }
    
  2. Initialize the adapter:

    package main
    
    import (
    	"context"
    	"log"
    	"time"
    
    	"github.com/denkhaus/mcp-server-adapter"
    )
    
    func main() {
    	adapter, err := mcpadapter.New(
    		mcpadapter.WithConfigPath("./config.json"),
    		mcpadapter.WithLogLevel("info"),
    		mcpadapter.WithFileWatcher(true), // Enable hot-reloading of config
    	)
    	if err != nil {
    		log.Fatalf("Failed to create MCP adapter: %v", err)
    	}
    	defer adapter.Close()
    
        ctx := context.Background()
    
    	// Start all configured MCP servers
    	if err := adapter.StartAllServers(ctx); err != nil {
    		log.Fatalf("Failed to start all MCP servers: %v", err)
    	}
    
    	// Wait for servers to be ready
    	if err := adapter.WaitForServersReady(ctx, 30*time.Second); err != nil {
    		log.Fatalf("Servers not ready: %v", err)
    	}
    
    	// Get all available tools from all running servers
    	allTools, err := adapter.GetAllTools(ctx)
    	if err != nil {
    		log.Fatalf("Failed to get LangChain tools: %v", err)
    	}
    
    	log.Printf("Available tools: %d", len(allTools))
    	for _, tool := range allTools {
    		log.Printf("- %s: %s", tool.Name(), tool.Description())
    	}
    
        // Example: Check if a server is disabled
        isDisabled, err := adapter.IsServerDisabled("fetcher")
        if err != nil {
            log.Printf("Error checking if server is disabled: %v", err)
        } else if isDisabled {
            log.Printf("Server 'fetcher' is disabled.")
        } else {
            log.Printf("Server 'fetcher' is enabled.")
        }
    
        // Example: Get server configuration
        serverConfig, err := adapter.GetServerConfig("tavily-mcp")
        if err != nil {
            log.Printf("Error getting server config: %v", err)
        } else {
            log.Printf("Server 'tavily-mcp' command: %s", serverConfig.Command)
        }
    
    	// Example: Using a tool (replace with actual tool usage)
    	// If you have a "fetcher.fetch_url" tool, you could call it like this:
    	// if len(allTools) > 0 {
    	// 	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
    	// 	defer cancel()
    	// 	result, err := allTools[0].Call(ctx, `{"url": "https://example.com"}`)
    	// 	if err != nil {
    	// 		log.Printf("Tool call failed: %v", err)
    	// 	} else {
    	// 		log.Printf("Tool result: %s", result)
    	// 	}
    	// }
    }
    

API Changes

To improve clarity and consistency, the following API functions have been renamed:

  • GetServerStatus(serverName string) ServerStatus is now GetServerStatusByName(serverName string) ServerStatus.
  • GetLangChainTools(ctx context.Context, serverName string) ([]tools.Tool, error) is now GetToolsByServerName(ctx context.Context, serverName string) ([]tools.Tool, error).
  • GetAllLangChainTools(ctx context.Context) ([]tools.Tool, error) is now GetAllTools(ctx context.Context) ([]tools.Tool, error).

Examples

The mcp-server-adapter includes several examples to demonstrate its capabilities and integration with LangChain applications. For detailed usage, code, and technical specifications, please refer to the examples/ directory, and especially the examples/EXAMPLES_SUMMARY.md file.

Here's a summary of the key examples:

Makefile Targets

This project uses a Makefile to automate various tasks, including building, testing, linting, and running examples. Below is a comprehensive list of available make targets:

Build Targets
  • make build-all: Build all binaries.
  • make build-examples: Build all example binaries.
  • make build-demo: Build demo example.
  • make build-agent: Build agent example.
  • make build-server: Build server example.
  • make build-simple-demo: Build simple demo example.
Test Targets
  • make test: Run all tests.
  • make test-examples: Run all example tests with timeout.
  • make test-demo: Test demo example (with timeout).
  • make test-agent: Test agent example (with timeout).
  • make test-simple-demo: Test simple demo example (with timeout).
  • make test-servers: Test individual MCP servers.
  • make test-config: Validate configuration files.
Linting and Code Quality Targets
  • make lint: Run golangci-lint.
  • make lint-fix: Run golangci-lint with auto-fix.
  • make fmt: Format Go code.
  • make vet: Run go vet.
  • make check: Run all code quality checks.
  • make ci: Complete CI pipeline.
Development Targets
  • make run-demo: Build and run demo.
  • make run-agent: Build and run agent.
  • make run-simple-demo: Build and run simple demo.
Cleanup
  • make clean: Clean build artifacts.
Help
  • make help: Show this help message.

1. πŸ–₯️ MCP Server (examples/server/)
  • Purpose: Demonstrates how to create a basic MCP server using mark3labs/mcp-go.
  • Features: Implements a fetch_url tool for web content retrieval via stdio transport.
2. πŸ€– LangChain Agent (examples/agent/)
  • Purpose: Shows how to integrate MCP tools with LangChain agents.
  • Features: Supports multi-LLM (OpenAI, Google AI, Anthropic), combines MCP tools with standard LangChain tools, and manages MCP server lifecycle automatically.
3. πŸš€ Simple Demo (examples/simple-demo/)
  • Purpose: A basic demonstration without requiring LLM API keys.
  • Features: Shows MCP adapter creation and tool discovery, tests tool execution with real HTTP requests, and has no external dependencies beyond Go.
4. πŸ§ͺ Test Servers (examples/test-servers/)
  • Purpose: Provides simple MCP servers implemented in different languages (Node.js, Python) for testing purposes.
5. βš™οΈ Configuration Files (examples/config.json, examples/enhanced-config.json, examples/mcp-spec-config.json)
  • Purpose: Illustrates various configurations for MCP servers, including stdio and sse transports, and different command arguments.

Configuration

The mcp-server-adapter is configured via a JSON file. The Config struct (defined in config.go and types.go) outlines the expected structure.

Key configuration options include:

  • mcpServers: A map where keys are server names and values are ServerConfig objects.
  • ServerConfig:
    • command: (Required for stdio transport) The command to execute the MCP server.
    • args: (Optional) Arguments to pass to the command.
    • cwd: (Optional) The working directory for the server process.
    • env: (Optional) Environment variables for the server process.
    • disabled: (Optional, true/false) If true, the server will not be started.
    • transport: (Optional, default stdio) The communication transport (stdio, sse, http).
    • url: (Required for sse, http transports) The URL of the MCP server.
    • headers: (Optional) HTTP headers for sse or http transports.
    • timeout: (Optional) Timeout for server operations.
    • Method: (Optional, default POST for http transport) The HTTP method for http transport (e.g., GET, POST).
    • tool_prefix: (Optional, default empty string) A custom prefix for resolved tool names. When specified, the tool name format changes from serverName.toolName to tool_prefix/toolname. Example: "tool_prefix": "magic-prefix"
    • alwaysAllow: (Optional) A list of tool names that are always permitted, usable for permissions or access control.

Inspiration

This project was inspired by langchaingo-mcp-adapter.

Contributing

Contributions are welcome! Please refer to the project's issue tracker for open tasks, or submit pull requests with improvements and bug fixes. Ensure your code adheres to the existing style and conventions.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation ΒΆ

Overview ΒΆ

Package mcpadapter provides a simplified MCP Server Adapter using mark3labs/mcp-go client and langchaingo.

Package mcpadapter provides configuration management for the simplified MCP adapter.

Package mcpadapter provides LangChain tool implementation using mark3labs/mcp-go.

Package mcpadapter provides types for the simplified MCP adapter.

Index ΒΆ

Constants ΒΆ

View Source
const (
	// Transport types
	TransportStdio = "stdio"
	TransportSSE   = "sse"
	TransportHTTP  = "http"
)

Variables ΒΆ

This section is empty.

Functions ΒΆ

func NewClientFactory ΒΆ

func NewClientFactory() *clientFactory

NewClientFactory creates a new client factory

Types ΒΆ

type ClientFactoryInterface ΒΆ

type ClientFactoryInterface interface {
	CreateClient(config *ServerConfig) (mcpclient.MCPClient, error)
}

ClientFactoryInterface defines the interface for creating MCPClient instances. This allows for mocking the client creation process in tests.

type Config ΒΆ

type Config struct {
	McpServers map[string]*ServerConfig `json:"mcpServers"`
}

Config represents the complete adapter configuration.

type MCPAdapter ΒΆ

type MCPAdapter interface {
	// Server lifecycle management
	StartServer(ctx context.Context, serverName string) error
	StartAllServers(ctx context.Context) error
	StopServer(serverName string) error
	Close() error

	// Status monitoring
	GetServerStatusByName(serverName string) ServerStatus
	GetAllServerStatuses() map[string]ServerStatus
	WaitForServersReady(ctx context.Context, timeout time.Duration) error

	// Tool access
	GetToolsByServerName(ctx context.Context, serverName string) ([]tools.Tool, error)
	GetAllTools(ctx context.Context) ([]tools.Tool, error)

	// Configuration
	IsConfigWatcherRunning() bool
	IsServerDisabled(serverName string) (bool, error)

	GetConfig() *Config
	GetServerConfig(serverName string) (*ServerConfig, error)
}

MCPAdapter defines the interface for MCP adapter operations.

func New ΒΆ

func New(options ...Option) (MCPAdapter, error)

New creates a new MCP adapter using mark3labs/mcp-go client.

type MCPTool ΒΆ

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

MCPTool implements the LangChain Tool interface for MCP tools using mark3labs/mcp-go.

func (*MCPTool) Call ΒΆ

func (t *MCPTool) Call(ctx context.Context, input string) (string, error)

Call executes the MCP tool using mark3labs/mcp-go client.

func (*MCPTool) Description ΒΆ

func (t *MCPTool) Description() string

Description returns the description of the tool, including JSON schema if available.

func (*MCPTool) Name ΒΆ

func (t *MCPTool) Name() string

Name returns the name of the tool.

type MockAdapter ΒΆ

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

MockAdapter is a mock implementation of MCPAdapter for testing purposes.

func NewMockAdapter ΒΆ

func NewMockAdapter() *MockAdapter

NewMockAdapter creates a new mock adapter for testing.

func (*MockAdapter) AddMockServer ΒΆ

func (m *MockAdapter) AddMockServer(name string, serverConfig *ServerConfig)

AddMockServer adds a mock server configuration.

func (*MockAdapter) Close ΒΆ

func (m *MockAdapter) Close() error

Close simulates closing the adapter.

func (*MockAdapter) GetAllServerStatuses ΒΆ

func (m *MockAdapter) GetAllServerStatuses() map[string]ServerStatus

GetAllServerStatuses returns all mock server statuses.

func (*MockAdapter) GetAllTools ΒΆ

func (m *MockAdapter) GetAllTools(ctx context.Context) ([]tools.Tool, error)

GetAllTools returns all mock tools from all servers.

func (*MockAdapter) GetConfig ΒΆ

func (m *MockAdapter) GetConfig() *Config

GetConfig returns the current mock complete configuration.

func (*MockAdapter) GetGetAllToolsCalls ΒΆ

func (m *MockAdapter) GetGetAllToolsCalls() int

GetGetAllToolsCalls returns the number of times GetAllLangChainTools was called.

func (*MockAdapter) GetGetToolsCalls ΒΆ

func (m *MockAdapter) GetGetToolsCalls() []string

GetGetToolsCalls returns the list of servers that GetToolsByServerName was called for.

func (*MockAdapter) GetServerConfig ΒΆ

func (m *MockAdapter) GetServerConfig(serverName string) (*ServerConfig, error)

GetServerConfig returns the configuration for a specific mock server.

func (*MockAdapter) GetServerStatusByName ΒΆ

func (m *MockAdapter) GetServerStatusByName(serverName string) ServerStatus

GetServerStatusByName returns the mock status for a server.

func (*MockAdapter) GetStartServerCalls ΒΆ

func (m *MockAdapter) GetStartServerCalls() []string

GetStartServerCalls returns the list of servers that StartServer was called for.

func (*MockAdapter) GetStopServerCalls ΒΆ

func (m *MockAdapter) GetStopServerCalls() []string

GetStopServerCalls returns the list of servers that StopServer was called for.

func (*MockAdapter) GetToolsByServerName ΒΆ

func (m *MockAdapter) GetToolsByServerName(ctx context.Context, serverName string) ([]tools.Tool, error)

GetToolsByServerName returns mock tools for a server.

func (*MockAdapter) IsConfigWatcherRunning ΒΆ

func (m *MockAdapter) IsConfigWatcherRunning() bool

IsConfigWatcherRunning returns the mock config watcher status.

func (*MockAdapter) IsServerDisabled ΒΆ

func (m *MockAdapter) IsServerDisabled(serverName string) (bool, error)

IsServerDisabled checks if a server is disabled in the mock configuration.

func (*MockAdapter) Reset ΒΆ

func (m *MockAdapter) Reset()

Reset clears all mock state and call tracking.

func (*MockAdapter) SetConfigWatcher ΒΆ

func (m *MockAdapter) SetConfigWatcher(running bool)

SetConfigWatcher sets whether the config watcher should appear to be running.

func (*MockAdapter) SetError ΒΆ

func (m *MockAdapter) SetError(operation string, err error)

SetError sets an error to be returned for a specific operation. Operations: "start", "stop", "tools", "alltools"

func (*MockAdapter) SetMockClientCloseFunc ΒΆ

func (m *MockAdapter) SetMockClientCloseFunc(f func() error)

SetMockClientCloseFunc sets the mock function for MockMCPClient.Close.

func (*MockAdapter) SetMockClientCompleteFunc ΒΆ

func (m *MockAdapter) SetMockClientCompleteFunc(f func(
	ctx context.Context,
	request mcp.CompleteRequest,
) (*mcp.CompleteResult, error))

SetMockClientCompleteFunc sets the mock function for MockMCPClient.Complete.

func (*MockAdapter) SetMockClientGetPromptFunc ΒΆ

func (m *MockAdapter) SetMockClientGetPromptFunc(f func(
	ctx context.Context,
	request mcp.GetPromptRequest,
) (*mcp.GetPromptResult, error))

SetMockClientGetPromptFunc sets the mock function for MockMCPClient.GetPrompt.

func (*MockAdapter) SetMockClientGetResourcesFunc ΒΆ

func (m *MockAdapter) SetMockClientGetResourcesFunc(f func(
	ctx context.Context,
	request mcp.ReadResourceRequest,
) (*mcp.ReadResourceResult, error))

SetMockClientGetResourcesFunc sets the mock function for MockMCPClient.GetResources.

func (*MockAdapter) SetMockClientInitializeFunc ΒΆ

func (m *MockAdapter) SetMockClientInitializeFunc(f func(
	ctx context.Context,
	request mcp.InitializeRequest,
) (*mcp.InitializeResult, error))

SetMockClientInitializeFunc sets the mock function for MockMCPClient.Initialize.

func (*MockAdapter) SetMockClientListPromptsByPageFunc ΒΆ

func (m *MockAdapter) SetMockClientListPromptsByPageFunc(f func(
	ctx context.Context,
	request mcp.ListPromptsRequest,
) (*mcp.ListPromptsResult, error))

SetMockClientListPromptsByPageFunc sets the mock function for MockMCPClient.ListPromptsByPage.

func (*MockAdapter) SetMockClientListPromptsFunc ΒΆ

func (m *MockAdapter) SetMockClientListPromptsFunc(f func(
	ctx context.Context,
	request mcp.ListPromptsRequest,
) (*mcp.ListPromptsResult, error))

SetMockClientListPromptsFunc sets the mock function for MockMCPClient.ListPrompts.

func (*MockAdapter) SetMockClientListResourceTemplatesByPageFunc ΒΆ

func (m *MockAdapter) SetMockClientListResourceTemplatesByPageFunc(f func(
	ctx context.Context,
	request mcp.ListResourceTemplatesRequest,
) (*mcp.ListResourceTemplatesResult, error))

SetMockClientListResourceTemplatesByPageFunc sets the mock function for MockMCPClient.ListResourceTemplatesByPage.

func (*MockAdapter) SetMockClientListResourceTemplatesFunc ΒΆ

func (m *MockAdapter) SetMockClientListResourceTemplatesFunc(f func(
	ctx context.Context,
	request mcp.ListResourceTemplatesRequest,
) (*mcp.ListResourceTemplatesResult, error))

SetMockClientListResourceTemplatesFunc sets the mock function for MockMCPClient.ListResourceTemplates.

func (*MockAdapter) SetMockClientListResourcesByPageFunc ΒΆ

func (m *MockAdapter) SetMockClientListResourcesByPageFunc(f func(
	ctx context.Context,
	request mcp.ListResourcesRequest,
) (*mcp.ListResourcesResult, error))

SetMockClientListResourcesByPageFunc sets the mock function for MockMCPClient.ListResourcesByPage.

func (*MockAdapter) SetMockClientListResourcesFunc ΒΆ

func (m *MockAdapter) SetMockClientListResourcesFunc(f func(
	ctx context.Context,
	request mcp.ListResourcesRequest,
) (*mcp.ListResourcesResult, error))

SetMockClientListResourcesFunc sets the mock function for MockMCPClient.ListResources.

func (*MockAdapter) SetMockClientListToolsByPageFunc ΒΆ

func (m *MockAdapter) SetMockClientListToolsByPageFunc(f func(
	ctx context.Context,
	request mcp.ListToolsRequest,
) (*mcp.ListToolsResult, error))

SetMockClientListToolsByPageFunc sets the mock function for MockMCPClient.ListToolsByPage.

func (*MockAdapter) SetMockClientListToolsFunc ΒΆ

func (m *MockAdapter) SetMockClientListToolsFunc(f func(
	ctx context.Context,
	request mcp.ListToolsRequest,
) (*mcp.ListToolsResult, error))

SetMockClientListToolsFunc sets the mock function for MockMCPClient.ListTools.

func (*MockAdapter) SetMockClientOnNotificationFunc ΒΆ

func (m *MockAdapter) SetMockClientOnNotificationFunc(f func(handler func(notification mcp.JSONRPCNotification)))

SetMockClientOnNotificationFunc sets the mock function for MockMCPClient.OnNotification.

func (*MockAdapter) SetMockClientUseToolFunc ΒΆ

func (m *MockAdapter) SetMockClientUseToolFunc(f func(
	ctx context.Context,
	request mcp.CallToolRequest,
) (*mcp.CallToolResult, error))

SetMockClientUseToolFunc sets the mock function for MockMCPClient.UseTool.

func (*MockAdapter) SetMockConfig ΒΆ

func (m *MockAdapter) SetMockConfig(config *Config)

SetMockConfig sets the complete mock configuration.

func (*MockAdapter) SetServerStatus ΒΆ

func (m *MockAdapter) SetServerStatus(serverName string, status ServerStatus)

SetServerStatus sets the status for a mock server.

func (*MockAdapter) SetServerTools ΒΆ

func (m *MockAdapter) SetServerTools(serverName string, serverTools []tools.Tool)

SetServerTools sets the tools that a mock server should return.

func (*MockAdapter) SetStartDelay ΒΆ

func (m *MockAdapter) SetStartDelay(delay time.Duration)

SetStartDelay sets a delay for server start operations.

func (*MockAdapter) StartAllServers ΒΆ

func (m *MockAdapter) StartAllServers(ctx context.Context) error

StartAllServers simulates starting all configured servers.

func (*MockAdapter) StartServer ΒΆ

func (m *MockAdapter) StartServer(ctx context.Context, serverName string) error

StartServer simulates starting a server.

func (*MockAdapter) StopServer ΒΆ

func (m *MockAdapter) StopServer(serverName string) error

StopServer simulates stopping a server.

func (*MockAdapter) WaitForServersReady ΒΆ

func (m *MockAdapter) WaitForServersReady(ctx context.Context, timeout time.Duration) error

WaitForServersReady simulates waiting for servers to be ready.

type MockMCPClient ΒΆ

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

MockMCPClient is a mock implementation of client.MCPClient for testing.

func (*MockMCPClient) CallTool ΒΆ

func (mc *MockMCPClient) CallTool(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)

CallTool implements client.MCPClient.

func (*MockMCPClient) Close ΒΆ

func (mc *MockMCPClient) Close() error

Close implements client.MCPClient.

func (*MockMCPClient) Complete ΒΆ

func (mc *MockMCPClient) Complete(ctx context.Context, request mcp.CompleteRequest) (*mcp.CompleteResult, error)

Complete implements client.MCPClient.

func (*MockMCPClient) GetPrompt ΒΆ

func (mc *MockMCPClient) GetPrompt(ctx context.Context, request mcp.GetPromptRequest) (*mcp.GetPromptResult, error)

GetPrompt implements client.MCPClient.

func (*MockMCPClient) Initialize ΒΆ

func (mc *MockMCPClient) Initialize(ctx context.Context, request mcp.InitializeRequest) (*mcp.InitializeResult, error)

Initialize implements client.MCPClient.

func (*MockMCPClient) ListPrompts ΒΆ

func (mc *MockMCPClient) ListPrompts(
	ctx context.Context,
	request mcp.ListPromptsRequest,
) (*mcp.ListPromptsResult, error)

ListPrompts implements client.MCPClient.

func (*MockMCPClient) ListPromptsByPage ΒΆ

func (mc *MockMCPClient) ListPromptsByPage(
	ctx context.Context,
	request mcp.ListPromptsRequest,
) (*mcp.ListPromptsResult, error)

ListPromptsByPage implements client.MCPClient.

func (*MockMCPClient) ListResourceTemplates ΒΆ

func (mc *MockMCPClient) ListResourceTemplates(
	ctx context.Context,
	request mcp.ListResourceTemplatesRequest,
) (*mcp.ListResourceTemplatesResult, error)

ListResourceTemplates implements client.MCPClient.

func (*MockMCPClient) ListResourceTemplatesByPage ΒΆ

func (mc *MockMCPClient) ListResourceTemplatesByPage(
	ctx context.Context,
	request mcp.ListResourceTemplatesRequest,
) (*mcp.ListResourceTemplatesResult, error)

ListResourceTemplatesByPage implements client.MCPClient.

func (*MockMCPClient) ListResources ΒΆ

func (mc *MockMCPClient) ListResources(
	ctx context.Context,
	request mcp.ListResourcesRequest,
) (*mcp.ListResourcesResult, error)

ListResources implements client.MCPClient.

func (*MockMCPClient) ListResourcesByPage ΒΆ

func (mc *MockMCPClient) ListResourcesByPage(
	ctx context.Context,
	request mcp.ListResourcesRequest,
) (*mcp.ListResourcesResult, error)

ListResourcesByPage implements client.MCPClient.

func (*MockMCPClient) ListTools ΒΆ

func (mc *MockMCPClient) ListTools(ctx context.Context, request mcp.ListToolsRequest) (*mcp.ListToolsResult, error)

ListTools implements client.MCPClient.

func (*MockMCPClient) ListToolsByPage ΒΆ

func (mc *MockMCPClient) ListToolsByPage(
	ctx context.Context,
	request mcp.ListToolsRequest,
) (*mcp.ListToolsResult, error)

ListToolsByPage implements client.MCPClient.

func (*MockMCPClient) OnNotification ΒΆ

func (mc *MockMCPClient) OnNotification(handler func(notification mcp.JSONRPCNotification))

OnNotification implements client.MCPClient.

func (*MockMCPClient) Ping ΒΆ

func (mc *MockMCPClient) Ping(ctx context.Context) error

Ping implements client.MCPClient.

func (*MockMCPClient) ReadResource ΒΆ

func (mc *MockMCPClient) ReadResource(
	ctx context.Context,
	request mcp.ReadResourceRequest,
) (*mcp.ReadResourceResult, error)

ReadResource implements client.MCPClient.

func (*MockMCPClient) SetLevel ΒΆ

func (mc *MockMCPClient) SetLevel(ctx context.Context, request mcp.SetLevelRequest) error

SetLevel implements client.MCPClient.

func (*MockMCPClient) Subscribe ΒΆ

func (mc *MockMCPClient) Subscribe(ctx context.Context, request mcp.SubscribeRequest) error

Subscribe implements client.MCPClient.

func (*MockMCPClient) Unsubscribe ΒΆ

func (mc *MockMCPClient) Unsubscribe(ctx context.Context, request mcp.UnsubscribeRequest) error

Unsubscribe implements client.MCPClient.

type MockTool ΒΆ

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

MockTool is a simple mock tool implementation.

func NewMockTool ΒΆ

func NewMockTool(name, description string) *MockTool

NewMockTool creates a new mock tool.

func (*MockTool) Call ΒΆ

func (m *MockTool) Call(ctx context.Context, input string) (string, error)

Call simulates calling the tool.

func (*MockTool) Description ΒΆ

func (m *MockTool) Description() string

Description returns the tool description.

func (*MockTool) Name ΒΆ

func (m *MockTool) Name() string

Name returns the tool name.

func (*MockTool) SetError ΒΆ

func (m *MockTool) SetError(err error)

SetError sets an error that the mock tool should return.

func (*MockTool) SetResult ΒΆ

func (m *MockTool) SetResult(result string)

SetResult sets the result that the mock tool should return.

type Option ΒΆ

type Option func(*adapterImpl) error

Option represents a configuration option for the adapter.

func WithClientFactory ΒΆ

func WithClientFactory(factory ClientFactoryInterface) Option

WithClientFactory injects a custom ClientFactory (e.g., for testing).

func WithConfig ΒΆ

func WithConfig(config *Config) Option

WithConfig sets the configuration directly instead of loading from file.

func WithConfigPath ΒΆ

func WithConfigPath(path string) Option

WithConfigPath sets the configuration file path.

func WithConfigWatchCallback ΒΆ

func WithConfigWatchCallback(callback func(*Config) error) Option

WithConfigWatchCallback sets a custom callback for configuration changes.

func WithFileWatcher ΒΆ

func WithFileWatcher(enabled bool) Option

WithFileWatcher enables or disables automatic configuration file watching.

func WithLogLevel ΒΆ

func WithLogLevel(level string) Option

WithLogLevel sets the logging level.

func WithLogger ΒΆ

func WithLogger(logger *log.Logger) Option

WithLogger sets a custom logger.

type ServerConfig ΒΆ

type ServerConfig struct {
	Command     string            `json:"command"`
	Args        []string          `json:"args,omitempty"`
	Cwd         string            `json:"cwd,omitempty"`
	Env         map[string]string `json:"env,omitempty"`
	Disabled    bool              `json:"disabled,omitempty"`
	AlwaysAllow []string          `json:"alwaysAllow,omitempty"`

	// Extended fields for transport abstraction
	Transport  string            `json:"transport,omitempty"`
	URL        string            `json:"url,omitempty"`
	Method     string            `json:"method,omitempty"`
	Headers    map[string]string `json:"headers,omitempty"`
	Timeout    time.Duration     `json:"timeout,omitempty"`
	ToolPrefix string            `json:"tool_prefix,omitempty"`
}

ServerConfig represents configuration for a single MCP server.

type ServerStatus ΒΆ

type ServerStatus int

ServerStatus represents the current status of a server.

const (
	StatusStopped ServerStatus = iota
	StatusStarting
	StatusRunning
	StatusError
)

func (ServerStatus) String ΒΆ

func (s ServerStatus) String() string

Directories ΒΆ

Path Synopsis
examples
agent command
demo command
Package main demonstrates the MCP Server Adapter using mark3labs/mcp-go and langchaingo.
Package main demonstrates the MCP Server Adapter using mark3labs/mcp-go and langchaingo.
server command
simple-demo command

Jump to

Keyboard shortcuts

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