server

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 13 Imported by: 0

README

MCP server for Boost

Factory for an MCP server built on the official SDK github.com/modelcontextprotocol/go-sdk. It serves over streamable HTTP or stdio and satisfies extra/multiserver.Server (Serve(ctx) / Shutdown(ctx)).

import "github.com/xgodev/boost/factory/contrib/modelcontextprotocol/go-sdk/v1/server"

Usage

boost.Start()

srv, err := server.NewServer(ctx, mcplog.Register, otel.Register)
if err != nil {
    log.Fatal(err)
}
mcp.AddTool(srv.Instance(), &mcp.Tool{Name: "greet", Description: "says hello"}, greet)

srv.Serve(ctx) // HTTP: blocks until Shutdown
  • Instance() is the SDK *mcp.Server: register tools, prompts and resources on it.
  • Handler() is the streamable HTTP handler, to mount on your own mux (echo, net/http).
  • Plugins run once, inside the constructor; a plugin error fails the constructor.
  • NewServerWithConfigPath(ctx, path) reads a second server from another root (e.g. boost.factory.mcp.server.admin), falling back to the defaults below.

Full example: examples/greet.

Configuration

Root boost.factory.mcp.server (env BOOST_FACTORY_MCP_SERVER_*).

Key Default Description
.name "" implementation name sent on initialize; empty uses boost.applicationName
.version "" implementation version sent on initialize; empty uses the binary's main module version (go version -m), 0.0.0 when unstamped
.instructions "" instructions the client may add to its system prompt
.transport HTTP HTTP (streamable HTTP on port/path) or STDIO
.port 8090 HTTP transport port
.path /mcp HTTP transport path
.stateless false HTTP without session state (no server-to-client requests)
.jsonResponse false HTTP answers application/json instead of text/event-stream (env ..._JSON__RESPONSE)
.sessionTimeout 0 HTTP idle session timeout; 0 never closes (env ..._SESSION__TIMEOUT)
.keepAlive 0 ping interval that closes dead sessions; 0 disables (env ..._KEEP__ALIVE)

Plugins

Each plugin is a server.Plugin with its own .enabled key under boost.factory.mcp.server.plugins.

Plugin Keys What it does
plugins/local/wrapper/log .log.enabled (true), .log.level (DEBUG) logs method, tool, duration and error of every call through wrapper/log; errors log at ERROR, tool results with isError are flagged
plugins/contrib/go.opentelemetry.io/otel/v1 .otel.enabled (true) one server span per call from the boost otel factory, continuing the trace the client sent in _meta

fx

fx/modules/factory/contrib/modelcontextprotocol/go-sdk/v1/server provides *server.Server and *mcp.Server, takes []server.Plugin from the graph and joins the multiserver group.

Documentation

Index

Constants

View Source
const (
	TransportHTTP  = "HTTP"
	TransportSTDIO = "STDIO"
)

Transports accepted by Options.Transport (case-insensitive).

View Source
const (

	// PluginsRoot is where each server plugin package roots its keys.
	PluginsRoot = root + ".plugins"
)

Variables

This section is empty.

Functions

func ConfigAdd

func ConfigAdd(path string)

ConfigAdd registers the server keys under path, so one binary can run a second MCP server (another port, another tool set) from its own path.

Types

type Options

type Options struct {
	Name           string
	Version        string
	Instructions   string
	Transport      string
	Port           int
	Path           string
	Stateless      bool
	JSONResponse   bool
	SessionTimeout time.Duration
	KeepAlive      time.Duration
}

Options configures the MCP server.

func NewOptions

func NewOptions() (*Options, error)

NewOptions returns options from the default config path.

func NewOptionsWithPath

func NewOptionsWithPath(path string) (*Options, error)

NewOptionsWithPath returns options from path, falling back to the root defaults.

type Plugin

type Plugin func(context.Context, *Server) error

Plugin customizes the server right after it is built, before Serve.

type Server

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

Server wraps an *mcp.Server and serves it over the configured transport.

func NewServer

func NewServer(ctx context.Context, plugins ...Plugin) (*Server, error)

NewServer builds a server from the default config path.

func NewServerWithConfigPath

func NewServerWithConfigPath(ctx context.Context, path string, plugins ...Plugin) (*Server, error)

NewServerWithConfigPath builds a server from the given config path.

func NewServerWithOptions

func NewServerWithOptions(ctx context.Context, o *Options, plugins ...Plugin) (*Server, error)

NewServerWithOptions builds a server from o and runs the plugins on it.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the streamable HTTP handler, to mount the server on an existing HTTP server (echo, net/http) instead of its own port.

func (*Server) Instance

func (s *Server) Instance() *mcp.Server

Instance returns the wrapped server; register tools, prompts and resources on it.

func (*Server) Options

func (s *Server) Options() *Options

Options returns the options the server was built with.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context)

Serve blocks serving the configured transport until Shutdown or a serve error.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context)

Shutdown stops a running Serve; it is a no-op when nothing is serving.

Directories

Path Synopsis
examples
greet command
Command greet serves one MCP tool over streamable HTTP on :8090/mcp.
Command greet serves one MCP tool over streamable HTTP on :8090/mcp.
plugins
contrib/go.opentelemetry.io/otel/v1
Package otel opens an OpenTelemetry span for every MCP call the server receives, continuing the trace the client sent in _meta.
Package otel opens an OpenTelemetry span for every MCP call the server receives, continuing the trace the client sent in _meta.
local/wrapper/log
Package log logs every MCP call the server receives through wrapper/log: method, tool, duration and error.
Package log logs every MCP call the server receives through wrapper/log: method, tool, duration and error.

Jump to

Keyboard shortcuts

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