server

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: GPL-3.0 Imports: 12 Imported by: 1

Documentation

Overview

Package server runs an MCP server over stdio for a client that starts it, or over HTTP for an always-on one, behind a bearer token and with a health probe.

Index

Constants

View Source
const (
	// Path is where the MCP endpoint is served over HTTP.
	Path = "/mcp"
	// HealthPath answers "ok" to a GET with no token, or a container with a token would never be healthy.
	HealthPath = httpd.HealthPath
)
View Source
const DefaultInstructions = `` /* 646-byte string literal not displayed */

DefaultInstructions is what every server tells a client that connects, before its own words: what the registry makes true of every tool, said once so no tool's description has to.

Variables

This section is empty.

Functions

func CheckAuth

func CheckAuth(o Options) error

CheckAuth refuses to listen with no bearer token unless the operator said so: a blank token in a copied .env once served every tool to the whole network with one line of warning.

func Handler

func Handler(srv *mcp.Server, o Options) http.Handler

Handler is the routes: the MCP endpoint at Path behind the bearer check, the health probe at HealthPath outside it. Apart from Run so they can be tested or mounted elsewhere without a port.

func Instructions added in v0.6.1

func Instructions(own ...string) string

Instructions is DefaultInstructions and then the server's own, a paragraph each, for mcp.ServerOptions. A server wanting other words altogether sets the options itself.

func Run

func Run(ctx context.Context, srv *mcp.Server, o Options) error

Run serves srv until the context ends: over stdio with no address, else over HTTP (Handler), which also stops on SIGINT or SIGTERM and lets requests under way finish.

Types

type Options

type Options struct {
	// Listen is the address to serve Streamable HTTP on, ":8080" say. Empty serves stdio.
	Listen string
	// AuthToken is the bearer token an HTTP client must send. Empty is none, which Run refuses without AllowNoAuth.
	AuthToken string
	// AllowNoAuth is the operator saying that anyone who can reach the port may use every tool.
	AllowNoAuth bool
	// Name is the tool's name, "abs-mcp": the realm a refused client is told.
	Name string
	// EnvPrefix starts the tool's environment variables, "ABS" for ABS_AUTH_TOKEN, so messages name the right one.
	EnvPrefix string
}

Options says how to serve.

Jump to

Keyboard shortcuts

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