mcpserver

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mcpserver serves tools over MCP (SPEC §3.7).

Each call runs: policy check, argument validation, then proxy.Call. Every failure after the tool lookup is an isError result; only malformed JSON-RPC and unknown tools are protocol errors (the SDK handles those). Handlers recover panics. Nothing here writes to stdout: in serve and run, stdout carries JSON-RPC, and logs go to the configured (stderr) logger.

Index

Constants

View Source
const ConfirmTimeout = 5 * time.Minute

ConfirmTimeout is how long an answer to a confirmation stays valid.

View Source
const HTTPPath = "/mcp"

HTTPPath is where the Streamable HTTP endpoint lives.

Variables

View Source
var ErrNotLoopback = errors.New("the HTTP transport only listens on loopback (127.0.0.1 or ::1)")

ErrNotLoopback means an HTTP listen address isn't on this machine only.

Functions

func HTTPHandler

func HTTPHandler(cfg Config, token string, logger *slog.Logger) http.Handler

HTTPHandler serves cfg's tools over Streamable HTTP at /mcp, guarded as SPEC T15 requires: every request needs "Authorization: Bearer <token>" (compared in constant time), a browser Origin must be a loopback origin, cross-site browser requests are refused, and the Host must be loopback (DNS rebinding; the SDK checks this too).

func ListenAddr

func ListenAddr(s string) (string, error)

ListenAddr normalizes an HTTP listen address and refuses anything but loopback (SPEC T15): ":8931" and "8931" mean 127.0.0.1:8931, and "localhost" is 127.0.0.1.

func New

func New(cfg Config) *mcp.Server

New builds the MCP server. Tools the mode can never run, and tools set to deny, are not listed at all.

func Serve

func Serve(ctx context.Context, cfg Config, t mcp.Transport) error

Serve runs the server on t until ctx is done or the client disconnects.

func ServeHTTP

func ServeHTTP(ctx context.Context, cfg Config, addr, token string, ready func(endpoint string)) error

ServeHTTP listens on addr (see ListenAddr) and serves until ctx is done. ready, if set, gets the endpoint URL once listening.

Types

type CallLog

type CallLog struct {
	Record  func(store.Call)
	API     string
	Toolset string
	Args    config.LogArgs
	Preview bool
}

CallLog sends one redacted record per call to the call log (SPEC §3.7 step 9).

type Config

type Config struct {
	Name     string
	Version  string
	Tools    []Tool
	Mode     policy.Mode
	Target   proxy.Target
	Doer     httpx.Doer
	Redactor *redact.Redactor
	Logger   *slog.Logger
	Log      *CallLog
	Limit    *policy.Limiter
}

Config configures a server.

type Tool

type Tool struct {
	Tool     model.Tool
	Override policy.Override
	Limit    *policy.Limiter
	Fields   *jsonpick.Picker
}

Tool is one tool to serve: a prepared model.Tool (see schema.Prepare) and its per-tool policy.

Jump to

Keyboard shortcuts

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