schema

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: 11 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 schema turns a tool's raw parameters and body into the argument set the model sees, and builds the MCP input schema from it (SPEC §3.5 rules 3, 6 and 7). It is pure.

  • Forbidden headers (auth, cookies, hop-by-hop, Host, X-Forwarded-*, Content-Length, Content-Type, ...) are removed: the model never sets them.
  • Fixed parameters stay in Params (so the proxy can inject them) but are Hidden and never appear in the input schema.
  • Object JSON bodies are flattened into InBody parameters. A field that collides becomes body_<name>; if that collides too, the whole body is nested under one InBodyRoot parameter instead. Fields are never dropped.
  • Model-facing names are sanitized to [A-Za-z0-9_.-] (<= 64 bytes) and unique case-insensitively; UpstreamName keeps the original.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidArgs = errors.New("invalid arguments")

ErrInvalidArgs means tool-call arguments failed validation.

Functions

func DecodeArgs

func DecodeArgs(raw json.RawMessage) (map[string]any, error)

DecodeArgs decodes raw arguments into a map, keeping numbers as json.Number so large integers keep full precision.

func InputSchema

func InputSchema(t model.Tool) json.RawMessage

InputSchema builds the MCP input schema from t's visible parameters. Unknown arguments are rejected (additionalProperties: false).

func IsForbiddenHeader

func IsForbiddenHeader(name string) bool

IsForbiddenHeader reports whether a header may never be a tool parameter.

func Prepare

func Prepare(t model.Tool, opts Options) model.Tool

Prepare returns a copy of t with its final parameter list. t is not modified.

Types

type Options

type Options struct {
	Fixed []string
}

Options configures Prepare.

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator checks tool-call arguments against a tool's input schema (SPEC §3.7 step 4). The input schema sets additionalProperties: false, so unknown arguments (including attempts to set hidden fixed params) fail.

func NewValidator

func NewValidator(t model.Tool) *Validator

NewValidator compiles t's input schema. If that fails (for example, a spec uses an ECMA-262-only regex), it falls back to a minimal schema that still enforces required arguments and rejects unknown ones; Degraded then reports true. It never falls back to accepting anything.

func (*Validator) Degraded

func (v *Validator) Degraded() bool

Degraded reports whether the full schema could not be compiled.

func (*Validator) Validate

func (v *Validator) Validate(raw json.RawMessage) error

Validate checks raw JSON arguments. Empty or null arguments mean {}.

Jump to

Keyboard shortcuts

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