ship

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrExecutorNotSet is returned when a container tool has no executor function
	ErrExecutorNotSet = errors.New("tool executor function is not set")

	// ErrToolNotFound is returned when a requested tool is not found in the registry
	ErrToolNotFound = errors.New("tool not found")

	// ErrInvalidParameter is returned when a parameter validation fails
	ErrInvalidParameter = errors.New("invalid parameter")

	// ErrDaggerEngineNotAvailable is returned when Dagger engine is not available
	ErrDaggerEngineNotAvailable = errors.New("dagger engine not available")
)
View Source
var DefaultRegistry = NewRegistry()

Global default registry used by Ship CLI

Functions

This section is empty.

Types

type ContainerTool

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

ContainerTool implements Tool interface for container-based tools

func (*ContainerTool) Description

func (t *ContainerTool) Description() string

Description returns the tool description

func (*ContainerTool) Execute

func (t *ContainerTool) Execute(ctx context.Context, params map[string]interface{}, engine *dagger.Engine) (*ToolResult, error)

Execute runs the container tool

func (*ContainerTool) Name

func (t *ContainerTool) Name() string

Name returns the tool name

func (*ContainerTool) Parameters

func (t *ContainerTool) Parameters() []Parameter

Parameters returns the tool parameters

type ContainerToolConfig

type ContainerToolConfig struct {
	Description string
	Image       string
	Command     []string
	Parameters  []Parameter
	Execute     ToolExecutor
}

ContainerToolConfig represents configuration for a container-based tool

type MCPAdapter added in v0.6.2

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

MCPAdapter allows users to bring their own mcp-go server and add Ship tools to it

Example (AttachToServer)

Integration test pattern for users wanting to test their setup

ctx := context.Background()

// User's existing MCP server
mcpServer := server.NewMCPServer("my-app", "1.0.0")

// Create Ship adapter with infrastructure tools
adapter := NewMCPAdapter()

// In real usage, you'd add actual tools:
// adapter.AddTool(tools.NewTFLintTool())
// adapter.AddTool(tools.NewCheckovTool())

// Attach Ship tools to existing server
if err := adapter.AttachToServer(ctx, mcpServer); err != nil {
	panic(err)
}

// Clean up
defer adapter.Close()

// Your server now has both your tools and Ship's containerized tools
// server.ServeStdio(mcpServer)

func NewMCPAdapter added in v0.6.2

func NewMCPAdapter() *MCPAdapter

NewMCPAdapter creates a new adapter for integrating Ship tools into existing MCP servers

func (*MCPAdapter) AddContainerTool added in v0.6.2

func (a *MCPAdapter) AddContainerTool(name string, config ContainerToolConfig) *MCPAdapter

AddContainerTool creates and adds a container-based tool to the adapter

func (*MCPAdapter) AddTool added in v0.6.2

func (a *MCPAdapter) AddTool(tool Tool) *MCPAdapter

AddTool adds a Ship tool to the adapter registry

func (*MCPAdapter) AddTools added in v0.6.2

func (a *MCPAdapter) AddTools(tools ...Tool) *MCPAdapter

AddTools adds multiple Ship tools to the adapter registry

func (*MCPAdapter) AttachToServer added in v0.6.2

func (a *MCPAdapter) AttachToServer(ctx context.Context, mcpServer *server.MCPServer) error

AttachToServer attaches all Ship tools to an existing mcp-go server

func (*MCPAdapter) Close added in v0.6.2

func (a *MCPAdapter) Close() error

Close shuts down the adapter and cleans up resources

func (*MCPAdapter) GetEngine added in v0.6.2

func (a *MCPAdapter) GetEngine() *dagger.Engine

GetEngine returns the adapter's Dagger engine

func (*MCPAdapter) GetRegistry added in v0.6.2

func (a *MCPAdapter) GetRegistry() *Registry

GetRegistry returns the adapter's registry

func (*MCPAdapter) ImportRegistry added in v0.6.2

func (a *MCPAdapter) ImportRegistry(registry *Registry) *MCPAdapter

ImportRegistry imports all tools from a Ship registry

func (*MCPAdapter) WithEngine added in v0.6.2

func (a *MCPAdapter) WithEngine(engine *dagger.Engine) *MCPAdapter

WithEngine sets the Dagger engine for the adapter

type MCPProxy

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

MCPProxy manages connections to external MCP servers and creates proxy tools

func NewMCPProxy

func NewMCPProxy(config MCPServerConfig) *MCPProxy

NewMCPProxy creates a new MCP proxy for an external server

func (*MCPProxy) Close

func (p *MCPProxy) Close() error

Close closes the connection to the external MCP server

func (*MCPProxy) Connect

func (p *MCPProxy) Connect(ctx context.Context) error

Connect establishes connection to the external MCP server

func (*MCPProxy) DiscoverTools

func (p *MCPProxy) DiscoverTools(ctx context.Context) ([]Tool, error)

DiscoverTools queries the external server for available tools and returns proxy tools

type MCPServer

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

MCPServer represents an MCP server with tools, prompts, and resources

func (*MCPServer) Close

func (s *MCPServer) Close() error

Close shuts down the server and cleans up resources

func (*MCPServer) GetEngine

func (s *MCPServer) GetEngine() *dagger.Engine

GetEngine returns the server's Dagger engine (may be nil if not started)

func (*MCPServer) GetMCPGoServer

func (s *MCPServer) GetMCPGoServer() *server.MCPServer

GetMCPGoServer returns the underlying mcp-go server instance

func (*MCPServer) GetRegistry

func (s *MCPServer) GetRegistry() *Registry

GetRegistry returns the server's registry

func (*MCPServer) LogError

func (s *MCPServer) LogError(message string)

LogError logs an error message to stderr

func (*MCPServer) LogInfo

func (s *MCPServer) LogInfo(message string)

LogInfo logs an info message to stderr

func (*MCPServer) ServeHTTP

func (s *MCPServer) ServeHTTP(host string, port int) error

ServeHTTP starts the server using HTTP transport

func (*MCPServer) ServeStdio

func (s *MCPServer) ServeStdio() error

ServeStdio starts the server using stdio transport

func (*MCPServer) Start

func (s *MCPServer) Start(ctx context.Context) error

Start initializes the server with a Dagger engine

func (*MCPServer) WriteOutput

func (s *MCPServer) WriteOutput(w io.Writer, message string) error

WriteOutput writes server output to a writer (useful for testing)

type MCPServerConfig

type MCPServerConfig struct {
	Name        string            `json:"name"`
	Command     string            `json:"command,omitempty"`
	Args        []string          `json:"args,omitempty"`
	Env         map[string]string `json:"env,omitempty"`
	BaseURL     string            `json:"baseUrl,omitempty"`
	Transport   string            `json:"transport"` // "stdio", "http", "sse"
	Disabled    bool              `json:"disabled,omitempty"`
	AutoApprove []string          `json:"autoApprove,omitempty"`
	Variables   []Variable        `json:"variables,omitempty"` // Framework-defined variables
}

MCPServerConfig represents configuration for connecting to an external MCP server

type Parameter

type Parameter struct {
	Name        string   `json:"name"`
	Type        string   `json:"type"`
	Description string   `json:"description,omitempty"`
	Required    bool     `json:"required,omitempty"`
	Enum        []string `json:"enum,omitempty"`
}

Parameter represents a tool parameter

type Prompt

type Prompt interface {
	Name() string
	Description() string
	Arguments() []PromptArgument
}

Prompt represents an MCP prompt

type PromptArgument

type PromptArgument struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Required    bool   `json:"required,omitempty"`
}

PromptArgument represents a prompt argument

type ProxyTool

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

ProxyTool represents a tool that proxies calls to an external MCP server

func NewProxyTool

func NewProxyTool(name, description string, parameters []Parameter, mcpClient client.MCPClient, externalToolName string) *ProxyTool

NewProxyTool creates a new proxy tool that forwards calls to an external MCP server

func (*ProxyTool) Description

func (p *ProxyTool) Description() string

Description returns the tool description

func (*ProxyTool) Execute

func (p *ProxyTool) Execute(ctx context.Context, params map[string]interface{}, engine *dagger.Engine) (*ToolResult, error)

Execute forwards the tool call to the external MCP server

func (*ProxyTool) Name

func (p *ProxyTool) Name() string

Name returns the tool name

func (*ProxyTool) Parameters

func (p *ProxyTool) Parameters() []Parameter

Parameters returns the tool parameters

type Registry

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

Registry manages a collection of tools, prompts, and resources

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new registry

func (*Registry) Clear

func (r *Registry) Clear()

Clear removes all registered items

func (*Registry) GetAllTools

func (r *Registry) GetAllTools() map[string]Tool

GetAllTools returns all registered tools

func (*Registry) GetPrompt

func (r *Registry) GetPrompt(name string) (Prompt, error)

GetPrompt retrieves a prompt by name

func (*Registry) GetResource

func (r *Registry) GetResource(uri string) (Resource, error)

GetResource retrieves a resource by URI

func (*Registry) GetTool

func (r *Registry) GetTool(name string) (Tool, error)

GetTool retrieves a tool by name

func (*Registry) ImportFrom

func (r *Registry) ImportFrom(other *Registry) error

ImportFrom imports all tools from another registry

func (*Registry) ListTools

func (r *Registry) ListTools() []string

ListTools returns all registered tool names

func (*Registry) RegisterPrompt

func (r *Registry) RegisterPrompt(prompt Prompt) error

RegisterPrompt registers a prompt in the registry

func (*Registry) RegisterResource

func (r *Registry) RegisterResource(resource Resource) error

RegisterResource registers a resource in the registry

func (*Registry) RegisterTool

func (r *Registry) RegisterTool(tool Tool) error

RegisterTool registers a tool in the registry

func (*Registry) ToolCount

func (r *Registry) ToolCount() int

ToolCount returns the number of registered tools

type Resource

type Resource interface {
	URI() string
	Name() string
	Description() string
	MIMEType() string
}

Resource represents an MCP resource

type ServerBuilder

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

ServerBuilder provides a fluent API for building MCP servers

func NewServer

func NewServer(name, version string) *ServerBuilder

NewServer creates a new server builder

func (*ServerBuilder) AddContainerTool

func (b *ServerBuilder) AddContainerTool(name string, config ContainerToolConfig) *ServerBuilder

AddContainerTool creates and adds a container-based tool

func (*ServerBuilder) AddPrompt

func (b *ServerBuilder) AddPrompt(prompt Prompt) *ServerBuilder

AddPrompt adds a prompt to the server

func (*ServerBuilder) AddResource

func (b *ServerBuilder) AddResource(resource Resource) *ServerBuilder

AddResource adds a resource to the server

func (*ServerBuilder) AddTool

func (b *ServerBuilder) AddTool(tool Tool) *ServerBuilder

AddTool adds a single tool to the server

func (*ServerBuilder) AddTools

func (b *ServerBuilder) AddTools(tools ...Tool) *ServerBuilder

AddTools adds multiple tools to the server

func (*ServerBuilder) Build

func (b *ServerBuilder) Build() *MCPServer

Build creates the MCP server instance

func (*ServerBuilder) ImportRegistry

func (b *ServerBuilder) ImportRegistry(registry *Registry) *ServerBuilder

ImportRegistry imports all items from another registry

type Tool

type Tool interface {
	Name() string
	Description() string
	Parameters() []Parameter
	Execute(ctx context.Context, params map[string]interface{}, engine *dagger.Engine) (*ToolResult, error)
}

Tool represents a tool that can be executed via MCP

func NewContainerTool

func NewContainerTool(name string, config ContainerToolConfig) Tool

NewContainerTool creates a new container-based tool

type ToolExecutor

type ToolExecutor func(ctx context.Context, params map[string]interface{}, engine *dagger.Engine) (*ToolResult, error)

ToolExecutor is a function type for executing container-based tools

type ToolResult

type ToolResult struct {
	Content  string                 `json:"content"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
	Error    error                  `json:"error,omitempty"`
}

ToolResult represents the result of a tool execution

type ToolRouter added in v0.6.2

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

ToolRouter provides a way to selectively route tools to different MCP servers

func NewToolRouter added in v0.6.2

func NewToolRouter() *ToolRouter

NewToolRouter creates a new tool router

func (*ToolRouter) AddRoute added in v0.6.2

func (r *ToolRouter) AddRoute(pattern string, adapter *MCPAdapter) *ToolRouter

AddRoute adds a route for a specific tool or tool pattern to an adapter

func (*ToolRouter) RouteToServer added in v0.6.2

func (r *ToolRouter) RouteToServer(ctx context.Context, routes map[string]*server.MCPServer) error

RouteToServer routes tools based on patterns to different MCP servers

type Variable

type Variable struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Required    bool   `json:"required"`
	Default     string `json:"default,omitempty"`
	Secret      bool   `json:"secret,omitempty"` // If true, value should be treated as sensitive
}

Variable represents a configurable environment variable for MCP servers

Jump to

Keyboard shortcuts

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