mcp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseStdioTransportConfig

func ParseStdioTransportConfig(cfg map[string]any) (string, error)

ParseStdioTransportConfig extracts a stdio transport server name from cfg. Exported for Task 2.5b reuse. Returns an error if 'server' is present but not a string.

Types

type HTTPTransportConfig

type HTTPTransportConfig struct {
	// Address is the TCP address on which the HTTP MCP server listens,
	// e.g. "0.0.0.0:8080" or "127.0.0.1:0".
	Address string
}

HTTPTransportConfig holds configuration for an HTTPTransportModule.

func ParseHTTPTransportConfig

func ParseHTTPTransportConfig(cfg map[string]any) (HTTPTransportConfig, string, error)

ParseHTTPTransportConfig extracts an HTTPTransportConfig from cfg along with the server module name. Exported for Task 2.5b reuse.

type HTTPTransportModule

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

HTTPTransportModule attaches a Streamable-HTTP transport to a ServerModule and implements modular.Module, modular.Startable, and modular.Stoppable.

func NewHTTPTransportModule

func NewHTTPTransportModule(name string, cfg HTTPTransportConfig, server *ServerModule) *HTTPTransportModule

NewHTTPTransportModule constructs an HTTPTransportModule with a direct ServerModule reference. server must be non-nil and its Init must have been called before this module's Init is invoked.

func NewHTTPTransportModuleByName

func NewHTTPTransportModuleByName(name string, cfg HTTPTransportConfig, serverName string) *HTTPTransportModule

NewHTTPTransportModuleByName constructs an HTTPTransportModule that resolves its ServerModule from the application registry during Init. This is the factory-friendly constructor used by MCPPlugin.

func (*HTTPTransportModule) Address

func (m *HTTPTransportModule) Address() string

Address returns the address the HTTP server is actually bound to after Start. Before Start it returns an empty string. Useful when Address is "host:0" and the OS assigns an ephemeral port.

func (*HTTPTransportModule) Dependencies

func (m *HTTPTransportModule) Dependencies() []string

Dependencies implements modular.DependencyAware. When constructed via NewHTTPTransportModuleByName the transport declares the server as a dependency so the modular framework initialises and starts it first.

func (*HTTPTransportModule) Init

Init implements modular.Module. If constructed via NewHTTPTransportModuleByName, it resolves the ServerModule from the application registry; otherwise it validates the directly wired ServerModule has been initialised.

func (*HTTPTransportModule) Name

func (m *HTTPTransportModule) Name() string

Name implements modular.Module.

func (*HTTPTransportModule) Start

Start implements modular.Startable. It binds the listener synchronously so that bind failures (port in use, permission denied) are returned immediately. The HTTP server is then served in a background goroutine. http.ErrServerClosed is swallowed because it is the expected termination signal from Stop.

func (*HTTPTransportModule) Stop

Stop implements modular.Stoppable. It performs a graceful HTTP shutdown, waiting at most until ctx is cancelled.

type Implementation

type Implementation struct {
	Name    string
	Version string
}

Implementation holds identification metadata for an MCP server.

type MCPPlugin

type MCPPlugin struct {
	plugin.BaseEnginePlugin
}

MCPPlugin registers the four MCP module types and the mcp.tool trigger with the workflow engine.

func New

func New() *MCPPlugin

New returns an MCPPlugin ready to be passed to engine.LoadPlugin.

func (*MCPPlugin) ModuleFactories

func (p *MCPPlugin) ModuleFactories() map[string]plugin.ModuleFactory

ModuleFactories returns factories for the four MCP module types.

func (*MCPPlugin) ModuleSchemas

func (p *MCPPlugin) ModuleSchemas() []*schema.ModuleSchema

ModuleSchemas returns UI schema definitions for the four MCP module types.

func (*MCPPlugin) TriggerFactories

func (p *MCPPlugin) TriggerFactories() map[string]plugin.TriggerFactory

TriggerFactories returns a factory for the mcp.tool trigger type.

type RegisteredTool

type RegisteredTool struct {
	Tool    *mcpsdk.Tool
	Handler mcpsdk.ToolHandler
}

RegisteredTool pairs an MCP Tool descriptor with its handler.

type ServerConfig

type ServerConfig struct {
	Implementation     Implementation
	RegistryModuleName string // defaults to "mcp.tool-registry" if empty
}

ServerConfig is the configuration for a ServerModule.

func ParseServerConfig

func ParseServerConfig(cfg map[string]any) (ServerConfig, error)

ParseServerConfig extracts a ServerConfig from a raw config map. Exported so the gRPC adapter in Task 2.5b can reuse it.

Returns an error when required keys are missing or malformed (e.g. implementation block is not a map). Callers relying on validation — like the gRPC adapter — should surface the error; factories that are expected to log-and-retry can ignore it.

type ServerModule

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

ServerModule is a modular.Module that owns and initialises an MCP server.

func NewServerModule

func NewServerModule(name string, cfg ServerConfig) *ServerModule

NewServerModule constructs a ServerModule with the given logical name and config.

func (*ServerModule) Init

func (m *ServerModule) Init(app modular.Application) error

Init implements modular.Module. It creates the underlying MCP server and stashes the application for use in Start.

func (*ServerModule) Name

func (m *ServerModule) Name() string

Name returns the module's unique identifier within the application.

func (*ServerModule) Server

func (m *ServerModule) Server() *mcpsdk.Server

Server returns the underlying *mcpsdk.Server, which is non-nil after a successful call to Init.

func (*ServerModule) Start

func (m *ServerModule) Start(_ context.Context) error

Start implements modular.Startable. It resolves the ToolRegistry from the application service registry and replays all registered tools onto the underlying MCP server. Transports must start after ServerModule (declared via Dependencies()) so the server is fully equipped before serving begins.

func (*ServerModule) ToolNames

func (m *ServerModule) ToolNames() []string

ToolNames returns the names of all tools currently registered on the underlying MCP server. It proxies through the ToolRegistry rather than the SDK internals to remain SDK-version agnostic. Returns nil if Init has not yet been called.

type StdioTransportModule

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

StdioTransportModule attaches a stdio transport to a ServerModule and implements modular.Module, modular.Startable, and modular.Stoppable.

Start spawns a goroutine that runs the MCP server over stdin/stdout. Stop cancels the internal context that drives the Run goroutine, so the transport shuts down regardless of whether the caller cancels the start context.

func NewStdioTransportModule

func NewStdioTransportModule(name string, server *ServerModule) *StdioTransportModule

NewStdioTransportModule constructs a StdioTransportModule with a direct ServerModule reference. server must be non-nil and its Init must have been called before this module's Init is invoked.

func NewStdioTransportModuleByName

func NewStdioTransportModuleByName(name, serverName string) *StdioTransportModule

NewStdioTransportModuleByName constructs a StdioTransportModule that resolves its ServerModule from the application registry during Init. This is the factory-friendly constructor used by MCPPlugin.

func (*StdioTransportModule) Dependencies

func (m *StdioTransportModule) Dependencies() []string

Dependencies implements modular.DependencyAware. When constructed via NewStdioTransportModuleByName the transport declares the server as a dependency so the modular framework initialises and starts it first.

func (*StdioTransportModule) Init

Init implements modular.Module. If constructed via NewStdioTransportModuleByName, it resolves the ServerModule from the application registry; otherwise it validates the directly wired ServerModule has been initialised.

func (*StdioTransportModule) Name

func (m *StdioTransportModule) Name() string

Name implements modular.Module.

func (*StdioTransportModule) Start

func (m *StdioTransportModule) Start(ctx context.Context) error

Start implements modular.Startable. It spawns a goroutine that runs the MCP server over a StdioTransport. The goroutine exits when the internal cancel context is cancelled — either by Stop or by the parent ctx. Start returns an error if called while already running.

func (*StdioTransportModule) Stop

Stop implements modular.Stoppable. It cancels the context that drives the Run goroutine, triggering an orderly shutdown.

type ToolRegistry

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

ToolRegistry is a thread-safe store of MCP tools to be registered with a ServerModule. It is intentionally a separate module so that plugins can contribute tools without importing ServerModule directly.

func NewToolRegistry

func NewToolRegistry(name string) *ToolRegistry

NewToolRegistry creates an empty ToolRegistry with the given module name.

func (*ToolRegistry) Add

func (r *ToolRegistry) Add(tool *mcpsdk.Tool, h mcpsdk.ToolHandler)

Add appends a tool and its handler to the registry. Safe for concurrent use.

func (*ToolRegistry) All

func (r *ToolRegistry) All() []RegisteredTool

All returns a snapshot copy of all registered tools in insertion order. Callers may freely mutate the returned slice without affecting the registry.

func (*ToolRegistry) Init

Init implements modular.Module (no-op; service registration is via ProvidesServices).

func (*ToolRegistry) Name

func (r *ToolRegistry) Name() string

Name implements modular.Module.

func (*ToolRegistry) ProvidesServices

func (r *ToolRegistry) ProvidesServices() []modular.ServiceProvider

ProvidesServices implements modular.ServiceAware. It registers the registry itself under its module name so ServerModule and ToolTrigger can look it up.

func (*ToolRegistry) RequiresServices

func (r *ToolRegistry) RequiresServices() []modular.ServiceDependency

RequiresServices implements modular.ServiceAware (no requirements).

type ToolTrigger

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

ToolTrigger is an interfaces.Trigger that registers a pipeline as an MCP tool. Each call to Configure (one per pipeline that names this trigger) registers one new tool on the shared ToolRegistry. The ServerModule then picks those tools up during its Start phase (Task 2.5).

NOTE: _config_dir is NOT injected into pipeline trigger configs by the engine today (only module configs receive it). As a result, $ref paths in input_schema must be absolute, or the caller must supply a "config_dir" key in the trigger config map. This limitation will be addressed in a later upstream change.

func NewToolTrigger

func NewToolTrigger() *ToolTrigger

NewToolTrigger creates an uninitialised ToolTrigger. The returned instance satisfies modular.Module and interfaces.Trigger; its service dependencies are resolved during Configure.

func (*ToolTrigger) Configure

func (t *ToolTrigger) Configure(app modular.Application, triggerConfig any) error

Configure implements interfaces.Trigger.

It is called once per pipeline that declares this trigger type. The engine injects a "workflowType" key of the form "pipeline:<name>" before calling Configure so the trigger knows which pipeline to dispatch to.

Supported keys in triggerConfig (map[string]any):

workflowType   string  injected by engine: "pipeline:<pipelineName>"
server         string  modular service name of the ServerModule
registry       string  modular service name of the ToolRegistry (default: "mcp.tool-registry")
name           string  MCP tool name
description    string  human-readable description
input_schema   map     inline JSON-schema or {$ref: "./path.json"}
output_schema  map     optional output schema (not validated at call time)
config_dir     string  base directory for $ref resolution (see type doc)

func (*ToolTrigger) Dependencies

func (t *ToolTrigger) Dependencies() []string

Dependencies implements modular.Module. The trigger has no declared module dependencies; it resolves its runtime dependencies (ToolRegistry, PipelineExecutor) from the service registry inside Configure.

func (*ToolTrigger) Init

func (t *ToolTrigger) Init(_ modular.Application) error

Init implements modular.Module. No-op; wiring is deferred to Configure.

func (*ToolTrigger) Name

func (t *ToolTrigger) Name() string

Name implements modular.Module.

func (*ToolTrigger) Start

func (t *ToolTrigger) Start(_ context.Context) error

Start implements modular.Startable. No-op; the tool is already registered with the ToolRegistry during Configure.

func (*ToolTrigger) Stop

func (t *ToolTrigger) Stop(_ context.Context) error

Stop implements modular.Stoppable. No-op.

type ToolTriggerConfig

type ToolTriggerConfig struct {
	// ServerModuleName is the modular service name of the ServerModule
	// that owns the MCP server to register tools on ("server" key in YAML).
	ServerModuleName string

	// RegistryModuleName is the modular service name of the ToolRegistry.
	// Defaults to "mcp.tool-registry" if omitted.
	RegistryModuleName string

	// ToolName is the MCP tool name exposed to LLM clients ("name" key).
	ToolName string

	// Description is the human-readable tool description.
	Description string

	// InputSchema is an inline JSON-schema map or a single-key
	// {$ref: "./path/to/schema.json"} map. Top-level type must be "object".
	InputSchema map[string]any

	// OutputSchema is an optional inline JSON-schema for the tool output.
	// Currently recorded but not validated at call time.
	OutputSchema map[string]any
}

ToolTriggerConfig is the structured form of a trigger configuration block for the mcp.tool trigger type. In YAML-driven workflows the engine deserialises trigger config into a map[string]any; ToolTrigger.Configure reads the keys directly from that map.

Field names here document the supported YAML keys for reference only — no struct-tag based decode is performed; see Configure for the actual parsing.

Jump to

Keyboard shortcuts

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