Documentation
¶
Overview ¶
Package om serves an API as an MCP server, one tool per operation. Compile turns an OpenAPI document, or a GraphQL schema and trusted documents, 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 ¶
- func Introspect(ctx context.Context, endpoint string, credential Credential, ...) ([]byte, error)
- type APIKeyHeader
- type Authorization
- type BearerToken
- type Compiled
- type Credential
- type Document
- func (d Document) Handler(lookup func(ctx context.Context, name string) (string, bool), ...) (http.Handler, error)
- func (d Document) Implementation() (*mcp.Implementation, *mcp.ServerOptions, error)
- func (d Document) MarshalJSON() ([]byte, error)
- func (d Document) Tool(name string) (*mcp.Tool, error)
- func (d Document) Tools(cursor string) (*mcp.ListToolsResult, error)
- func (d *Document) UnmarshalJSON(data []byte) error
- type GraphQL
- type Input
- type Omission
- type OpenAPI
- type Source
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Introspect ¶ added in v0.0.15
func Introspect(ctx context.Context, endpoint string, credential Credential, lookup func(ctx context.Context, name string) (string, bool), transport http.RoundTripper) ([]byte, error)
Introspect fetches the schema of the GraphQL API at endpoint, as the introspection result GraphQL.Schema takes. It sends credential, whose input lookup supplies, through transport, within 30 seconds in all, and reads up to 32 MiB, the limits discover.Get reads an OpenAPI description within: a schema is a document, and the published schemas of large APIs exceed the 1 MiB a tool's result may hold. A host calls it while compiling, never while serving: a Document's tools never depend on a live schema.
Types ¶
type APIKeyHeader ¶ added in v0.0.15
type APIKeyHeader struct {
Name string
}
APIKeyHeader sends an input as the header Name: OM_X_API_KEY for X-Api-Key. Name may be Authorization, for APIs that take a key there without the Bearer scheme.
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 BearerToken ¶ added in v0.0.15
type BearerToken struct{}
BearerToken sends the input OM_TOKEN as an RFC 6750 §2.1 bearer token. The token is one the host stores, such as an API key or a personal access token. A GraphQL schema names no OAuth issuer, and a GraphQL endpoint rarely answers with an RFC 9728 challenge that would, so a GraphQL source declares no OAuth authorization.
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
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 Credential ¶ added in v0.0.3
type Credential interface {
// contains filtered or unexported methods
}
Credential is how a GraphQL API authenticates every request: a BearerToken or an APIKeyHeader. om names the input that holds the secret, as it does for an OpenAPI security scheme, and the host supplies its value.
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
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
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
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 GraphQL ¶ added in v0.0.15
type GraphQL struct {
// Endpoint is the URL om sends every operation to, as a GraphQL over HTTP POST: https, with a host, and without
// credentials, a query or a fragment. It is the Document's server.
Endpoint string
// Schema is the API's schema: SDL, or the JSON of an introspection result, which [Introspect] fetches.
Schema []byte
// Operations are the trusted documents by file name: executable GraphQL documents whose named operations become
// tools. A fragment defined in one may be spread in another.
Operations map[string][]byte
// Credential is what every operation sends to authenticate. It is nil for an API that needs none.
Credential Credential
}
GraphQL is a GraphQL API and the trusted documents that choose its tools: each named query or mutation becomes one tool, named after the operation, whose input is its variables and whose result is its response's data and errors. A GraphQL schema names neither the API's endpoint nor how it authenticates, so GraphQL carries both.
type 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 ¶
Omission is an operation a Document leaves out, and why. Its String is "<operation>: <reason>", where the operation is "GET /widgets" for OpenAPI and "query Viewer" for GraphQL.
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.
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. |
|
graphql
Package graphql is om's GraphQL protocol: trusted documents, the named operations of executable GraphQL documents validated against the API's schema, served as one tool per named query or mutation.
|
Package graphql is om's GraphQL protocol: trusted documents, the named operations of executable GraphQL documents validated against the API's schema, served as one tool per named query or mutation. |
|
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. |