om

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 20 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

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:

document, skipped, err := compile.Compile(ctx, data, location)
model, err := json.Marshal(document)

var served om.Document
err = json.Unmarshal(model, &served)
handler, err := served.Handler(os.LookupEnv, http.DefaultTransport)
http.Handle("/mcp", handler)

Only compile parses OpenAPI, which can take a few hundred MB for a large document. Handler needs only the model: lookup supplies credentials and server variables by name, and transport carries every request to the API. A request that reaches the handler over a loopback connection must carry a localhost Host header, which protects it from DNS rebinding. A handler is cheap to build, so a host can build one per request: a call reads only the called operation, and tools/list returns the tools in pages of about 256 KiB. It refuses a model whose om format it does not know.

License

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

Documentation

Index

Constants

View Source
const Format = 1
View Source
const PageBytes = 256 << 10

PageBytes bounds the name, title, description and input schema bytes of the tools one tools/list page holds; a single tool larger than PageBytes is still a page of its own.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKey added in v0.0.3

type APIKey struct {
	In    Location
	Name  string
	Input string
}

type Basic added in v0.0.3

type Basic struct {
	Username string
	Password string
}

type Bearer added in v0.0.3

type Bearer struct {
	Input string
}

type Credential added in v0.0.3

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

type Document added in v0.0.3

type Document struct {
	Format      int         `json:"om"`
	Title       string      `json:"title"`
	Version     string      `json:"version"`
	Description string      `json:"description,omitempty"`
	Server      string      `json:"server"`
	Inputs      []Input     `json:"inputs"`
	Operations  []Operation `json:"operations"`
}

Document is a compiled OpenAPI document: one MCP tool per operation. Its JSON encoding is the model a host stores between compiling and serving.

func (Document) Handler added in v0.0.3

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

Handler serves the document's operations as MCP tools over Streamable HTTP, statelessly. lookup supplies an input's value by name; transport carries the upstream requests.

type Input

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

Input is a value the host supplies by name: a server variable when it has a default, a credential when it has none.

type Location added in v0.0.3

type Location string

Location is where an argument is sent, serialized in the style OpenAPI defines for it there: simple in a path or header, form in a query or cookie, and deepObject for a query object. https://spec.openapis.org/oas/v3.2.0.html#style-values

const (
	Path       Location = "path"
	Header     Location = "header"
	Query      Location = "query"
	DeepObject Location = "deepObject"
	Cookie     Location = "cookie"
)

func (*Location) UnmarshalText added in v0.0.3

func (l *Location) UnmarshalText(text []byte) error

type Operation added in v0.0.3

type Operation struct {
	Name        string          `json:"name"`
	Title       string          `json:"title,omitempty"`
	Description string          `json:"description,omitempty"`
	Method      string          `json:"method"`
	Path        string          `json:"path"`
	InputSchema json.RawMessage `json:"inputSchema"`
	Parameters  []Parameter     `json:"parameters,omitempty"`
	Body        bool            `json:"body,omitempty"`
	Security    Security        `json:"security,omitempty"`
}

type Parameter added in v0.0.3

type Parameter struct {
	Name    string   `json:"name"`
	In      Location `json:"in"`
	Explode bool     `json:"explode,omitempty"`
}

type Security added in v0.0.3

type Security []Credential

func (Security) MarshalJSON added in v0.0.3

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

func (*Security) UnmarshalJSON added in v0.0.3

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

Directories

Path Synopsis
cmd
om command

Jump to

Keyboard shortcuts

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