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
- Variables
- func HTTPHandler(cfg Config, token string, logger *slog.Logger) http.Handler
- func ListenAddr(s string) (string, error)
- func New(cfg Config) *mcp.Server
- func Serve(ctx context.Context, cfg Config, t mcp.Transport) error
- func ServeHTTP(ctx context.Context, cfg Config, addr, token string, ...) error
- type CallLog
- type Config
- type Tool
Constants ¶
const ConfirmTimeout = 5 * time.Minute
ConfirmTimeout is how long an answer to a confirmation stays valid.
const HTTPPath = "/mcp"
HTTPPath is where the Streamable HTTP endpoint lives.
Variables ¶
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 ¶
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 ¶
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 ¶
New builds the MCP server. Tools the mode can never run, and tools set to deny, are not listed at all.
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).