dockermcpgateway

package module
v0.42.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container struct {
	testcontainers.Container
	// contains filtered or unexported fields
}

Container represents the DockerMCPGateway container type used in the module

func Run

Run creates an instance of the DockerMCPGateway container type

Example
ctx := context.Background()

ctr, err := dmcpg.Run(
	ctx, "docker/mcp-gateway:latest",
	dmcpg.WithTools("curl", []string{"curl"}),
	dmcpg.WithTools("duckduckgo", []string{"fetch_content", "search"}),
	dmcpg.WithTools("github-official", []string{"add_issue_comment"}),
)
defer func() {
	if err := testcontainers.TerminateContainer(ctr); err != nil {
		log.Printf("failed to terminate container: %s", err)
	}
}()
if err != nil {
	log.Printf("failed to start container: %s", err)
	return
}

state, err := ctr.State(ctx)
if err != nil {
	log.Printf("failed to get container state: %s", err)
	return
}

fmt.Println(state.Running)
fmt.Println(len(ctr.Tools()))
Output:
true
3
Example (ConnectMCPClient)
// run_mcp_gateway {
ctx := context.Background()

ctr, err := dmcpg.Run(
	ctx, "docker/mcp-gateway:latest",
	dmcpg.WithTools("curl", []string{"curl"}),
	dmcpg.WithTools("duckduckgo", []string{"fetch_content", "search"}),
	dmcpg.WithTools("github-official", []string{"add_issue_comment"}),
)
defer func() {
	if err := testcontainers.TerminateContainer(ctr); err != nil {
		log.Printf("failed to terminate container: %s", err)
	}
}()
if err != nil {
	log.Printf("failed to start container: %s", err)
	return
}
// }

// get_gateway {
gatewayEndpoint, err := ctr.GatewayEndpoint(ctx)
if err != nil {
	log.Printf("failed to get gateway endpoint: %s", err)
	return
}
// }

// connect_mcp_client {
transport := &mcp.SSEClientTransport{
	Endpoint: gatewayEndpoint,
}

client := mcp.NewClient(&mcp.Implementation{Name: "mcp-client", Version: "v1.0.0"}, nil)

cs, err := client.Connect(context.Background(), transport, nil)
if err != nil {
	log.Printf("Failed to connect to MCP gateway: %v", err)
	return
}
// }

// list_tools {
mcpTools, err := cs.ListTools(context.Background(), &mcp.ListToolsParams{})
if err != nil {
	log.Printf("Failed to list tools: %v", err)
	return
}
// }

fmt.Println(len(mcpTools.Tools))
fmt.Println(len(ctr.Tools()))

func (*Container) GatewayEndpoint

func (c *Container) GatewayEndpoint(ctx context.Context) (string, error)

GatewayEndpoint returns the endpoint for the DockerMCPGateway container. It uses the mapped port for the default port (8811/tcp) and the "http" protocol.

func (*Container) Tools

func (c *Container) Tools() map[string][]string

Tools returns the tools configured for the DockerMCPGateway container, indexed by server name. The keys are the server names and the values are slices of tool names.

type Option

type Option func(*options) error

Option is an option for the DockerMCPGateway container.

func WithSecret

func WithSecret(key, value string) Option

WithServers sets the servers to use in the DockerMCPGateway container. Multiple calls to this function will append to the existing values.

func WithSecrets

func WithSecrets(secrets map[string]string) Option

WithSecrets sets the secrets to use in the DockerMCPGateway container. Multiple calls to this function will merge the secrets into the existing map.

func WithTools

func WithTools(server string, tools []string) Option

WithTools sets a server's tools to use in the DockerMCPGateway container. Multiple calls to this function with the same server will append to the existing tools for that server. No duplicate tools will be added for the same server.

func (Option) Customize

Customize is a NOOP. It's defined to satisfy the testcontainers.ContainerCustomizer interface.

Jump to

Keyboard shortcuts

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