om

package module
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 23 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 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 := compile.Compile(ctx, data, 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

Index

Constants

View Source
const Format = 2

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"`
	Definitions map[string]json.RawMessage `json:"definitions,omitempty"`
	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(ctx context.Context, 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.

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 format this version of om does not serve.

func (Document) Tool added in v0.0.10

func (d Document) Tool(o Operation) (*mcp.Tool, error)

Tool is the MCP tool the operation is served as.

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. A cursor Tools did not issue is invalid params.

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"`
	OutputSchema json.RawMessage `json:"outputSchema,omitempty"`
	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
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

Jump to

Keyboard shortcuts

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