core

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 23 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 core is what every protocol om serves shares: the MCP tool catalog, the JSON Schema definitions tools share, the inputs a host supplies, credentials, the limits on each upstream exchange, and the MCP server itself.

core knows no protocol. A protocol package, such as internal/openapi, compiles its source into a Draft of [Operation]s, and each Operation says, as pure functions, what to send for a call (Operation.Request) and what the agent receives for the answer (Operation.Result). core does all I/O: it fills the server URL, attaches credentials, sends, bounds the exchange, and checks results against output schemas. A protocol package never sees a credential value, an http.Client or a lookup function.

Operation's methods take core types, so only packages inside om can implement it.

Index

Constants

View Source
const DocumentLimit = 32 << 20

DocumentLimit is the most om reads of a document, such as an API's description, where a tool's result may hold 1 MiB.

Variables

This section is empty.

Functions

func CheckServer

func CheckServer(address *url.URL, hostname string) error

CheckServer refuses an API server om will not send requests to: anything but an https URL with a host and without credentials, a query or a fragment, whose port is between 1 and 65535 and whose hostname is an IP address or DNS labels. hostname is the address's hostname with its server variables filled with their defaults. The error reads after the server's name in its source, such as "OpenAPI server".

func CookieName

func CookieName(name string) bool

CookieName reports whether name can name a cookie.

func Encode

func Encode(value string) string

Encode percent-encodes value for a URL path segment, query or cookie.

func EnvName

func EnvName(name string) string

EnvName is the input name om gives a value that name identifies in its source, such as a security scheme or a server variable.

func Finish

func Finish(draft Draft) (Catalog, []Omission, error)

Finish applies, in the draft's order, the rules every protocol shares, which om.Compile documents, and unions the OAuth scopes of inputs that name one issuer, so the catalog's JSON is deterministic.

func Join

func Join(pairs []Pair, delimiter string) string

Join writes pairs as name=value, separated by delimiter.

func SendableHeader

func SendableHeader(name string) bool

SendableHeader reports whether om may set a request header named name: an RFC 9110 token that is not a header the transport owns, nor one om sets itself, Accept and Content-Type, which would replace a credential sent in them.

Types

type APIKey

type APIKey struct {
	In    Location
	Name  string
	Input string
}

APIKey sends Input's value as the header, query parameter or cookie Name.

type Arguments

type Arguments struct {
	// Raw is the arguments object as the client sent it, so numbers keep their precision.
	Raw json.RawMessage
	// Values is Raw decoded, with numbers as float64.
	Values map[string]any
}

Arguments are a tool call's arguments after they satisfied the tool's input schema.

type Authorization

type Authorization struct {
	Issuer string   `json:"issuer"`
	Scopes []string `json:"scopes,omitempty"`
}

Authorization is the RFC 8414 §2 issuer of the authorization server that issues an access token and the scopes the operations that send it require.

type Basic

type Basic struct {
	Username string
	Password string
}

Basic sends the Username and Password inputs as RFC 7617 basic credentials.

type Bearer

type Bearer struct {
	Input string
}

Bearer sends Input's value as an RFC 6750 §2.1 bearer token.

type Candidate

type Candidate struct {
	Operation Operation
	Needs     []Need
	// Where names the operation in an omission, such as "GET /widgets".
	Where string
}

Candidate is one compiled operation and the inputs it needs.

type Catalog

type Catalog struct {
	Server      string
	Inputs      []Input
	Definitions map[string]json.RawMessage
	Operations  []Operation
}

Catalog is a compiled API as core serves it: its operations, the definitions their schemas share, and the upstream they reach. Operations are sorted by name, and names are unique MCP tool names, when Finish built the catalog; a decoded model is checked again by Catalog.Handler.

func (Catalog) Handler

func (c Catalog) Handler(implementation *mcp.Implementation, options *mcp.ServerOptions, lookup Lookup, transport http.RoundTripper) (http.Handler, error)

Handler serves the catalog's operations as MCP tools over Streamable HTTP, statelessly, as implementation. It is the only place a stored model fails structurally: a bad name, a duplicate, or a schema that does not compile fails the whole catalog with an error, never a panic.

It pages tools/list itself and answers tools/call through the SDK's tool dispatch, which gives the result the resultType that MCP 2026-07-28 clients require.

func (Catalog) Page

func (c Catalog) Page(cursor string) (*mcp.ListToolsResult, error)

Page is the page of tools a tools/list cursor names. The cursor is the decimal index of the page's first operation, so it is valid across replicas holding the same model. A cursor Page did not issue is invalid params.

func (Catalog) Tool

func (c Catalog) Tool(name string) (*mcp.Tool, error)

Tool is the MCP tool named name, standalone: its schemas carry the definitions they reach as local $defs. It is nil when the catalog has no such tool.

type Credential

type Credential interface {
	// contains filtered or unexported methods
}

Credential is where a request carries a secret input. Only core implements it, because only core reads secrets.

type Draft

type Draft struct {
	// Title, Version and Description identify the API, as the MCP server's implementation.
	Title, Version, Description string
	// Server is the URL template operations are sent to. Its {name} variables are among Inputs, each with a Default.
	Server string
	// Inputs are the values the whole API needs, such as server variables.
	Inputs []Need
	// Definitions are the shared schemas any candidate may reference as "#/$defs/<Name>". Finish keeps those the kept
	// tools reach.
	Definitions map[string]json.RawMessage
	// Candidates are the operations the protocol could compile, in the protocol's source order.
	Candidates []Candidate
	// Omitted are the operations the protocol could not compile.
	Omitted []Omission
}

Draft is what a protocol package compiles its source to, before core decides which operations every host can serve.

type Input

type Input struct {
	Name          string         `json:"name"`
	Default       *string        `json:"default,omitempty"`
	Choices       []string       `json:"choices,omitempty"`
	Authorization *Authorization `json:"authorization,omitempty"`
}

Input is a value the host supplies by name, as om.Input documents. A credential with Authorization is sent as a Bearer token.

type Location

type Location string

Location is where an API key goes.

const (
	Header Location = "header"
	Query  Location = "query"
	Cookie Location = "cookie"
)

type Lookup

type Lookup func(ctx context.Context, name string) (string, bool)

Lookup supplies an input's value by name. A credential whose value is empty counts as missing; a server variable that is not found takes its default.

type Need

type Need struct {
	Input
	Source string
}

Need is an input and where in the source it comes from, which names it when two sources claim one input name.

type Omission

type Omission struct {
	Operation string
	Reason    string
}

Omission is an operation a model leaves out, and why.

func (Omission) String

func (o Omission) String() string

type Operation

type Operation interface {
	// Listing is the tool tools/list shows for the operation, with schemas as stored.
	Listing() Tool
	// Annotations are the hints the protocol gives about the operation's effect, such as HTTP's safe and idempotent
	// methods.
	Annotations() *mcp.ToolAnnotations
	// Request is what to send for arguments that already satisfy the tool's input schema. A [Refusal] is shown to the
	// agent.
	Request(Arguments) (Request, error)
	// Result is what the agent receives for the API's answer. A [Refusal] is shown to the agent. When the tool has an
	// output schema, core checks Outcome.Structured against it before any agent sees it.
	Result(Response) (Outcome, error)
}

Operation is one tool and the way its protocol reaches the API.

type Outcome

type Outcome struct {
	// Text is the result's text content; empty for none.
	Text string
	// Structured is the result's structuredContent. It is set exactly when the tool has an output schema, and core
	// refuses the result unless it satisfies that schema.
	Structured json.RawMessage
}

Outcome is a call's result before core checks it.

type Pair

type Pair struct{ Name, Value string }

Pair is one name and value, already encoded for where it is sent.

type Refusal

type Refusal string

Refusal is an error whose text the agent sees. Any other error a call meets reaches the agent only as "Could not complete the upstream request."

func (Refusal) Error

func (r Refusal) Error() string

type Request

type Request struct {
	Method string
	// Path is appended to the server URL. It is empty or begins with "/", and it is already percent-encoded.
	Path string
	// Header never carries a credential: core attaches Security after the operation builds the request.
	Header http.Header
	// Query and Cookies are percent-encoded name and value pairs, in the order they are sent.
	Query   []Pair
	Cookies []Pair
	// Body is sent as application/json when it is not nil.
	Body []byte
	// Security is every credential the request carries, attached by core from the host's inputs.
	Security Security
}

Request is what an operation sends, before core fills in the server and the credentials.

type Response

type Response struct {
	Status int
	Header http.Header
	Body   string
}

Response is the API's answer, read within the limits of the Upstream that exchanged it.

func (Response) Refusal added in v0.0.15

func (r Response) Refusal() Refusal

Refusal is what the agent sees for a response its protocol does not read as an answer: "HTTP 502: Bad gateway", or "HTTP 503" when the body is empty.

type Security

type Security []Credential

Security is every credential one request carries. Its JSON is strict: a credential kind this version of om does not attach fails to decode, so no model is served without the credentials it declares.

func (Security) MarshalJSON

func (s Security) MarshalJSON() ([]byte, error)

func (*Security) UnmarshalJSON

func (s *Security) UnmarshalJSON(data []byte) error

type Tool

type Tool struct {
	Name         string          `json:"name"`
	Title        string          `json:"title,omitempty"`
	Description  string          `json:"description,omitempty"`
	InputSchema  json.RawMessage `json:"inputSchema"`
	OutputSchema json.RawMessage `json:"outputSchema,omitempty"`
}

Tool is the protocol-neutral part of one operation: the MCP tool it is listed as. A protocol's stored operation embeds it, so its fields are part of every model's JSON.

InputSchema is a JSON Schema 2020-12 object schema whose root "type" is the string "object". Both schemas reference shared definitions only as "#/$defs/<Name>", which resolve in the catalog's Definitions, and store no "$schema".

func (Tool) Listing added in v0.0.15

func (t Tool) Listing() Tool

Listing is the tool as stored, which every protocol's operation lists by embedding Tool.

type Upstream

type Upstream struct {
	// Server is the URL template every request's Path is appended to; Inputs with a Default fill its {name} variables.
	Server string
	Inputs []Input
	// contains filtered or unexported fields
}

Upstream sends requests to the API at Server. It is the only place om reads an input's value and the only place an upstream exchange is bounded, so every protocol gets the same limits: 30 seconds, no redirects, 1 MiB of UTF-8. A host whose transport has a shorter timer, such as a response-header timeout, ends an exchange sooner.

func NewUpstream

func NewUpstream(server string, inputs []Input, lookup Lookup, transport http.RoundTripper) Upstream

NewUpstream is the upstream of the API at server, whose inputs lookup supplies and whose requests transport carries.

func (Upstream) Exchange

func (u Upstream) Exchange(ctx context.Context, request Request) (Response, error)

Exchange sends request and reads the answer within core's limits.

func (Upstream) ForDocument added in v0.0.15

func (u Upstream) ForDocument() Upstream

ForDocument is u for an exchange that reads a document rather than a tool's result, within DocumentLimit.

Jump to

Keyboard shortcuts

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