om

package module
v0.0.6 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)

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 Authorization added in v0.0.6

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 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"`
	Authorization *Authorization `json:"authorization,omitempty"`
}

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 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