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
- func CheckServer(address *url.URL, hostname string) error
- func CookieName(name string) bool
- func Encode(value string) string
- func EnvName(name string) string
- func Finish(draft Draft) (Catalog, []Omission, error)
- func Join(pairs []Pair, delimiter string) string
- func SendableHeader(name string) bool
- type APIKey
- type Arguments
- type Authorization
- type Basic
- type Bearer
- type Candidate
- type Catalog
- type Credential
- type Draft
- type Input
- type Location
- type Lookup
- type Need
- type Omission
- type Operation
- type Outcome
- type Pair
- type Refusal
- type Request
- type Response
- type Security
- type Tool
- type Upstream
Constants ¶
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 ¶
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 ¶
CookieName reports whether name can name a cookie.
func EnvName ¶
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 ¶
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 SendableHeader ¶
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 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 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.
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 Lookup ¶
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 ¶
Need is an input and where in the source it comes from, which names it when two sources claim one input name.
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."
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 ¶
Response is the API's answer, read within the limits of the Upstream that exchanged it.
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 (*Security) UnmarshalJSON ¶
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".
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) ForDocument ¶ added in v0.0.15
ForDocument is u for an exchange that reads a document rather than a tool's result, within DocumentLimit.