headerbind

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package headerbind implements the x-mcp-header annotation of the Streamable HTTP transport: extracting bindings from tool input schemas, validating the spec's constraints, and encoding/decoding header values with the =?base64?...?= sentinel.

It is shared by the server (which fails loudly at registration on invalid bindings) and the client (which must exclude invalid tools from tools/list).

Index

Constants

View Source
const (
	// AnnotationKey marks a schema property for header transmission.
	AnnotationKey = "x-mcp-header"
	// Prefix is prepended to the annotated name to form the HTTP header.
	Prefix = "Mcp-Param-"

	// MaxSafeInteger bounds integer header values (±(2^53−1)).
	MaxSafeInteger = 1<<53 - 1
)

Variables

This section is empty.

Functions

func Decode

func Decode(s string) (string, error)

Decode reverses Encode. Values without the sentinel pass through unchanged.

func Encode

func Encode(s string) string

Encode applies the =?base64?...?= sentinel when the value is not safely ASCII-representable or itself matches the sentinel pattern.

func Format

func Format(v any) (string, error)

Format converts a primitive argument value to its header string form: strings as-is, integers as decimal, booleans lowercase.

func Lookup

func Lookup(args map[string]any, path []string) (any, bool)

Lookup resolves a binding path in a tool's arguments. The second return is false when the value is absent or nil (the header must then be omitted).

Types

type Binding

type Binding struct {
	Path   []string // property names from the root
	Header string   // annotated name, without the Mcp-Param- prefix
	Type   string   // "string" | "integer" | "boolean"
}

Binding is one annotated property: a chain of properties keys from the schema root to a primitive property, and the header name it maps to.

func Extract

func Extract(schema map[string]any) ([]Binding, error)

Extract walks a tool input schema and returns its header bindings. It enforces every constraint the spec places on x-mcp-header: non-empty tchar names, primitive property types (number is not permitted), case-insensitive uniqueness, and static reachability — an annotation anywhere the properties walk cannot reach (items, composition keywords, $ref targets, the schema root) makes the whole tool definition invalid, per spec, rather than being silently ignored.

func (Binding) HeaderName

func (b Binding) HeaderName() string

HeaderName returns the full HTTP header name.

Jump to

Keyboard shortcuts

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