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 ¶
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error)
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 ¶
GatewayEndpoint returns the endpoint for the DockerMCPGateway container. It uses the mapped port for the default port (8811/tcp) and the "http" protocol.
type Option ¶
type Option func(*options) error
Option is an option for the DockerMCPGateway container.
func WithSecret ¶
WithServers sets the servers to use in the DockerMCPGateway container. Multiple calls to this function will append to the existing values.
func WithSecrets ¶
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 ¶
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 ¶
func (o Option) Customize(*testcontainers.GenericContainerRequest) error
Customize is a NOOP. It's defined to satisfy the testcontainers.ContainerCustomizer interface.