server

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package server runs an MCP server the way every katbyte MCP tool serves one: over stdio for a client that starts it, or over Streamable HTTP for an always-on deployment, behind a bearer token and with a health probe a container can ask.

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 asked for: a container
	// with a token configured would otherwise never be healthy.
	HealthPath = "/healthz"
)

Variables

This section is empty.

Functions

func CheckAuth

func CheckAuth(o Options) error

CheckAuth is what stands between an address to listen on and an open port: with no bearer token it is an error, unless the operator said that no auth is wanted. A blank token in a copied .env used to come up serving 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 HTTP routes: the MCP endpoint at Path behind the bearer check, and the health probe at HealthPath outside it. It is apart from Run so the routes and the check can be tested, or mounted in a server of the caller's own, without binding a port.

func Run

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

Run serves srv until the context ends: over stdio when no address is given, otherwise over HTTP (see Handler), which also stops on SIGINT and SIGTERM and then 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 asks for
	// none, which Run refuses without AllowNoAuth.
	AuthToken string
	// AllowNoAuth is the operator saying, in so many words, that anyone who
	// can reach the port may use every tool.
	AllowNoAuth bool
	// Name is the tool's own name, "abs-mcp" say: the realm a client sent
	// away is told.
	Name string
	// EnvPrefix is what the tool's environment variables begin with, "ABS"
	// for ABS_AUTH_TOKEN, so what the operator is told names the variable
	// to set.
	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