om

package module
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 10 Imported by: 1 module, 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.

README

om

CI Go Go Reference MIT License Discord

A Go gopher biting into an OpenAPI document

om serves an OpenAPI document as an MCP server, with one tool per API operation.

Install

go install github.com/holon-sh/om/cmd/om@latest

Usage

om serve https://example.com/openapi.yaml

om serve https://api.example.com works too when the API publishes an API catalog or a service-desc link; failing those, it tries the recommended openapi.json and openapi.yaml under the URL.

The server listens at http://127.0.0.1:3000/mcp; set HOST and PORT to change that. om serve lists any operations it skipped and the environment variables that hold your API credentials. Server variables default to the document's values; override one with OM_ and its name in upper case.

The server has no authentication of its own. Put it behind one before exposing it beyond localhost.

Embed

Compile a document once, store the model, and serve it wherever you need it:

target, err := discover.ParseTarget("https://api.example.com")
offers := discover.Offers(ctx, http.DefaultTransport, target) // every OpenAPI description it publishes
data, at, err := discover.Get(ctx, http.DefaultTransport, offers[0].URL)
compiled, err := om.Compile(ctx, om.OpenAPI{Data: data, Location: at.URL()})
model, err := json.Marshal(compiled.Document)

var served om.Document
err = json.Unmarshal(model, &served)
handler, err := served.Handler(func(_ context.Context, name string) (string, bool) { return os.LookupEnv(name) }, http.DefaultTransport)
http.Handle("/mcp", handler)

License

MIT. The om gopher is based on the Go gopher by Renee French, licensed under CC BY 4.0.

Documentation

Overview

Package om serves an API as an MCP server, one tool per operation. Compile turns an OpenAPI document into a Document: a model a host stores as JSON and serves with Document.Handler.

This package is the whole public surface for compiling and serving. A host never sees an operation's protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authorization added in v0.0.6

type Authorization = core.Authorization

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 Compiled added in v0.0.13

type Compiled struct {
	// Document is the model a host stores and serves.
	Document Document
	// Omitted are the operations Document leaves out, each with its reason: first those the protocol cannot compile,
	// then those the rules every protocol shares leave out, each in source order.
	Omitted []Omission
}

Compiled is what one source compiles to.

func Compile added in v0.0.13

func Compile(ctx context.Context, source Source) (Compiled, error)

Compile turns source into a Document and the operations it left out. Every protocol ends in the same rules: an operation is left out when its name is not an MCP tool name or is taken, when its schemas do not compile, or when an input it needs takes the name of an input from elsewhere in the source; operations and inputs are sorted by name; and only the definitions kept tools reach are stored. It fails when no operation is left.

type Document added in v0.0.3

type Document struct {
	Title       string
	Version     string
	Description string
	// Server is the URL every operation is sent to. Its {name} variables are filled from the Inputs that have a
	// Default. A host may replace it with another URL template of the same API; holon replaces it with the app's URL.
	Server string
	Inputs []Input
	// contains filtered or unexported fields
}

Document is a compiled API: its identity, its server, the inputs a host supplies, and its tools, each with the way its protocol reaches the API. Its JSON encoding is the model a host stores between compiling and serving.

A Document is servable when Compile made it, or when it decoded from a model of a protocol and format this version of om serves. Any other Document, including the zero one, decodes without error and is refused by every method, so a host reports one refusal, from Document.Implementation, wherever it asks.

func (Document) Handler added in v0.0.3

func (d Document) Handler(lookup func(ctx context.Context, name string) (string, bool), transport http.RoundTripper) (http.Handler, error)

Handler serves the document's operations as MCP 2026-07-28 tools over Streamable HTTP, statelessly. lookup supplies an input's value by name; transport carries the upstream requests. It refuses a model it cannot serve with an error, never a panic.

func (Document) Implementation added in v0.0.7

func (d Document) Implementation() (*mcp.Implementation, *mcp.ServerOptions, error)

Implementation is the MCP server om serves the document as and the options it serves it with. It refuses a model of a protocol or format this version of om does not serve.

func (Document) MarshalJSON added in v0.0.13

func (d Document) MarshalJSON() ([]byte, error)

MarshalJSON writes the model: the protocol's key with its format first, then the shared fields, then the operations in the protocol's own shape. The same Document always encodes to the same bytes, so a host may store it by digest.

func (Document) Tool added in v0.0.10

func (d Document) Tool(name string) (*mcp.Tool, error)

Tool is the tool named name, standalone, as tools/list shows it, with its schemas as json.RawMessage. It is nil when the document has no such tool.

func (Document) Tools added in v0.0.7

func (d Document) Tools(cursor string) (*mcp.ListToolsResult, error)

Tools is the page of tools a tools/list cursor names: as many standalone tools as fit in 256 KiB of names, descriptions and schemas, and at least one. Its cacheScope is public, since a model's tools do not depend on who asks. A cursor Tools did not issue is invalid params.

func (*Document) UnmarshalJSON added in v0.0.13

func (d *Document) UnmarshalJSON(data []byte) error

UnmarshalJSON reads a model. A model of a protocol or format this version of om does not serve decodes without its operations, whose shape it cannot know, and every method then refuses it. A model of a format it serves decodes strictly: an operation it cannot send, such as one with an unknown credential, fails the decode.

type Input

type Input = core.Input

Input is a value the host supplies by name: a server variable when it has a default, a credential when it has none. A credential with Authorization is an OAuth 2.0 access token, which operations send as an RFC 6750 §2.1 bearer token.

type Omission

type Omission = core.Omission

Omission is an operation a Document leaves out, and why. Its String is "<operation>: <reason>", where the operation is "GET /widgets" for OpenAPI.

type OpenAPI added in v0.0.13

type OpenAPI struct {
	// Data is the document, as JSON or YAML.
	Data []byte
	// Location is where Data came from, which resolves a relative server URL. It is nil when unknown.
	Location *url.URL
}

OpenAPI is an OpenAPI 3.0, 3.1 or 3.2 document. Its first server is the Document's server, and its security schemes are the credentials each operation sends.

type Source added in v0.0.13

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

Source is what om compiles: an OpenAPI document.

Directories

Path Synopsis
cmd
om command
Package discover finds the OpenAPI descriptions an API publishes, from an HTTPS URL.
Package discover finds the OpenAPI descriptions an API publishes, from an HTTPS URL.
internal
core
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.
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.
openapi
Package openapi is om's OpenAPI protocol: it compiles an OpenAPI 3.0–3.2 document into a core.Draft of operations, and each operation sends itself as an HTTP request with parameters serialized in the styles OpenAPI defines.
Package openapi is om's OpenAPI protocol: it compiles an OpenAPI 3.0–3.2 document into a core.Draft of operations, and each operation sends itself as an HTTP request with parameters serialized in the styles OpenAPI defines.

Jump to

Keyboard shortcuts

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