server

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: Apache-2.0 Imports: 17 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 server serves a set of tools as an MCP server. It enforces the permission decision for every tool: denied tools are left out of tools/list, and a call that names one anyway gets a denial result without any upstream request (docs/SPEC.md section 4). Every call is written to the audit log (section 6).

Index

Constants

View Source
const HealthPath = "/healthz"

HealthPath answers 200 without a key, for load balancers and scripts that wait for the server to be up. It says nothing about the API.

View Source
const MCPPath = "/mcp"

MCPPath is where the MCP endpoint is served over HTTP.

View Source
const MinHTTPKey = 16

MinHTTPKey is the shortest key HTTPHandler accepts.

View Source
const (
	StoppedMessage = "" /* 126-byte string literal not displayed */

)

Result texts for a call refused because of the audit log.

Variables

This section is empty.

Functions

func DeniedMessage

func DeniedMessage(tool string) string

DeniedMessage is the result text for a call to a tool the policy denies.

func HTTPHandler

func HTTPHandler(srv *mcp.Server, key string, logger *slog.Logger) (http.Handler, error)

HTTPHandler serves srv over Streamable HTTP (docs/SPEC.md section 5).

Every request to MCPPath must carry "Authorization: Bearer <key>". A request a browser sends from another site is refused, so a web page can't reach a writgate on the visitor's machine or network.

The transport is stateless: each request stands alone and gets a JSON response, so any number of instances can sit behind a load balancer. A tool call is cancelled when its HTTP request is.

func New

func New(cfg Config) (*mcp.Server, error)

New builds the MCP server. Decisions are made once, at startup: one policy per instance, so they can't change while it runs.

func UnresolvedMessage

func UnresolvedMessage(tool, key string) string

UnresolvedMessage is the result text for a call refused because an earlier attempt at the same action has an unknown result.

Types

type Config

type Config struct {
	Name    string // server name reported to clients
	Version string
	Tools   []*tools.Tool
	Client  *upstream.Client
	Policy  *policy.Policy
	Audit   *audit.Log // nil serves without an audit log, for tests
	// Secrets are values to keep out of the audit log wherever they appear,
	// such as the upstream API key.
	Secrets []string
	// Unresolved are the intent records of calls whose result is still
	// unknown after recovery. Each blocks a new attempt at the same action
	// under a different Idempotency-Key.
	Unresolved []audit.Record
	Logger     *slog.Logger // nil discards logs
}

Config is what New needs.

Jump to

Keyboard shortcuts

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