Documentation
¶
Overview ¶
Package bridge adapts deliberately registered typed application operations to bounded, authenticated MCP, JSON HTTP and explicit private file transfer. Products supply credential verification and current admission; their application services still own domain authorization. Bridge does not issue credentials or implement OAuth login, consent, refresh, revocation storage, or account linking.
SPDX-License-Identifier: MPL-2.0
SPDX-License-Identifier: MPL-2.0
SPDX-License-Identifier: MPL-2.0
SPDX-License-Identifier: MPL-2.0
SPDX-License-Identifier: MPL-2.0
SPDX-License-Identifier: MPL-2.0
SPDX-License-Identifier: MPL-2.0
Index ¶
- Variables
- func AddTool[In, Out any](r *Registrar, tool *mcp.Tool, handler func(context.Context, In) (Out, error)) (err error)
- func Confirm(ctx context.Context, reference string)
- func JSONHandler[In, Out any](operation string, decode func(*http.Request) (In, error), ...) (http.Handler, error)
- func StreamHandler[In any](operation string, decode func(*http.Request) (In, error), ...) (http.Handler, error)
- func Version() string
- type Caller
- type Config
- type Credential
- type Diagnostic
- type Endpoint
- type Fault
- type Limits
- type Outcome
- type Registrar
- type Request
- type VerifyToken
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidCredential = errors.New("invalid bridge credential")
ErrInvalidCredential marks credentials that are invalid, expired, revoked, or issued for another resource. Other verifier errors mean verification is unavailable. Neither error's original text is returned to the client.
Functions ¶
func AddTool ¶
func AddTool[In, Out any](r *Registrar, tool *mcp.Tool, handler func(context.Context, In) (Out, error)) (err error)
AddTool binds one ordinary typed application operation. The handler obtains its verified Caller from RequestFromContext and must call its usual service authorization. Tool annotations describe effects but never grant authority. SDK schema inference/validation is retained. Handler errors use Fault when safe fields, a known outcome, or an authorized recovery reference are known.
func Confirm ¶
Confirm records an already confirmed success and an authorized recovery reference before output serialization. It performs no mutation or lookup. Calling it is a trusted product assertion, not client-supplied evidence. References must be at most 256 bytes with no control characters.
func JSONHandler ¶
func JSONHandler[In, Out any](operation string, decode func(*http.Request) (In, error), invoke func(context.Context, In) (Out, error)) (http.Handler, error)
JSONHandler binds one fixed, typed HTTP operation. Mount it deliberately in a product/component router under NewJSONHTTP. Decode must cheaply validate all transport input without effects, sensitive lookups or trusting identity claims. Invoke obtains verified attribution through RequestFromContext and calls the ordinary typed Service with its normal current authorization. Both callbacks must be concurrency-safe and honor the request context and published bounds.
A Fault supplies approved public guidance and an optional HTTPStatus (400..599). Its private Cause remains protected. An error after Invoke defaults to Unknown; use the owning service's actual outcome, and Confirm for a success reference. No partial typed output is used on error; retain reconciliation data in Fault.
func StreamHandler ¶
func StreamHandler[In any](operation string, decode func(*http.Request) (In, error), invoke func(context.Context, In, http.ResponseWriter) error) (http.Handler, error)
StreamHandler binds one explicit binary HTTP operation under NewStreamingHTTP. Decode validates cheap transport input before the operation gate. Invoke must call its ordinary authorized Service, honor context, return writer failures, and delay success headers until the content is known to be safe to deliver. It may set a successful status, content type/disposition and exact length. Request identity, no-store and nosniff headers remain boundary-owned.
An error before any header is sent becomes a bounded safe Problem Details response. After headers, the endpoint aborts the transfer without appending JSON. Original writer/body causes and known outcomes remain protected. Invoke success (or Confirm) survives a later delivery failure. No retry is performed.
Types ¶
type Caller ¶
Caller is verified product identity. None of these fields comes from client JSON, MCP clientInfo, forwarded headers, or a claimed actor.
type Config ¶
type Config struct {
ResourceURL string
AuthorizationServers []string
Scopes []string
AllowedOrigins []string
Verify VerifyToken
// Admit checks current administrator enablement and client/user connection
// admission on every authenticated HTTP request. ErrDenied is a deliberate
// denial; other errors mean admission cannot currently be evaluated.
Admit func(context.Context, Caller) error
// Gate can only narrow access to a registered operation. The ordinary
// application service must still authorize the verified principal itself.
Gate func(context.Context, Caller, string) error
// Diagnostic is required. It receives protected original causes and one
// terminal event per operation, including success. It must be concurrent,
// honor context and own access, storage, export, retention and repetition
// budgets. It is not an atomic business audit record.
Diagnostic func(context.Context, Diagnostic)
Limits Limits
}
Config is copied by New. HTTPS is required except for loopback development. The canonical public Host must be preserved by an ingress proxy; forwarded headers never establish authority. Scopes are all required for admission.
type Credential ¶
Credential is the result of product-supplied verification. Scopes narrow access to this transport; they do not replace live application authorization.
type Diagnostic ¶
type Diagnostic struct {
Request Request
Phase string
Dispatched bool
Outcome Outcome
Code string
Reference string
Cause error
}
Diagnostic is protected evidence, not a public error or an atomic audit event. A terminal operation event has Phase "complete" on success, "invoke" on an application error, "input" before dispatch, or "output" on SDK output failure. A separate "delivery" failure retains the actual known operation outcome.
type Endpoint ¶
type Endpoint struct {
// contains filtered or unexported fields
}
Endpoint is an immutable resource-server HTTP handler. Construction and idle registration start no background work. Mount MetadataHandler at the RFC 9728 well-known path derived from ResourceURL, for example /.well-known/oauth-protected-resource/mcp for https://example.com/mcp.
func New ¶
New validates configuration and completes fixed tool registration before exposing the endpoint. The Registrar is valid only inside register.
func NewJSONHTTP ¶
NewJSONHTTP composes an authenticated, bounded JSON HTTP resource server. ResourceURL identifies its canonical path prefix and resource audience. Bind explicit routes to JSONHandler; this constructor never discovers operations, starts an MCP server, or acquires a connection/session/background worker.
Verify must verify credentials for this HTTP resource, independently of a sibling MCP resource's audience. Admit and each fixed operation's Gate remain current per request; neither replaces the owning Service's authorization. The profile buffers bounded JSON responses. It is not a binary/streaming file transfer profile. The enclosing server owns TLS, header and ingress limits.
func NewStreamingHTTP ¶
NewStreamingHTTP composes a private authenticated HTTP resource with explicit bounded file transfers. JSONHandler routes still buffer their JSON responses; only StreamHandler can deliver bytes directly. Credential verification, current admission, operation gates and owning Service authorization are the same as NewJSONHTTP. Construction starts no sessions or background work.
The server/middleware must support actual socket read and write deadlines; otherwise requests fail before dispatch. Flushing is also required for successful file delivery; an unavailable or failed final flush preserves the known invocation outcome and is reported as a delivery failure. Limits bound total body bytes, response bytes, request duration and concurrency, not a whole-file buffer. Products must choose limits suitable for their file profile. This constructor adds no multipart parser, range support, public cache, SSE or URL fetcher.
func (*Endpoint) MetadataHandler ¶
MetadataHandler serves public, configured resource metadata. It performs no discovery fetch, does not infer issuer/host from the request and issues no token.
func (*Endpoint) ServeHTTP ¶
func (e *Endpoint) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles the endpoint's bounded MCP or JSON HTTP profile. Each request verifies the credential and current admission; no connection principal or business permission is cached. No request or operation is automatically replayed.
type Fault ¶
type Fault struct {
Code string `json:"code"`
Message string `json:"message"`
Action string `json:"action"`
Fields map[string]string `json:"fields,omitempty"`
Outcome Outcome `json:"outcome"`
Reference string `json:"reference,omitempty"`
Cause error `json:"-"`
// HTTPStatus optionally selects a safe 400..599 JSON HTTP status. MCP tool
// failures ignore it and retain their ordinary isError representation.
HTTPStatus int `json:"-"`
}
Fault is a product-approved safe transport projection plus a protected cause. Message, Action, Fields and Reference must already be suitable for this caller. Cause is never serialized and is intentionally not an unwrap chain exposed to remote clients. A post-dispatch ordinary error defaults to Unknown; only owning operation evidence may establish NotExecuted or NotCommitted.
type Limits ¶
type Limits struct {
RequestBytes int64
// ResponseBytes must be at least 4096, reserving enough encoded space for
// an exact maximum-length recovery reference and bounded failure guidance.
// It bounds buffered JSON or the total explicitly streamed response bytes.
ResponseBytes int64
Concurrent int
Timeout time.Duration
}
Limits bounds active work. Zero values select 64 KiB input, 1 MiB response, 16 concurrent requests and a 15 second request deadline. Application handlers must also bound produced objects and honor cancellation; Go cannot forcibly stop an uncooperative in-process callback.
type Outcome ¶
type Outcome string
Outcome is evidence about the operation, independently of response delivery.
type Registrar ¶
type Registrar struct {
// contains filtered or unexported fields
}
Registrar binds typed tools only while New's registration callback is active. It delegates schemas and invocation mechanics to the official SDK; its small name set rejects accidental replacement rather than supplying a dispatcher.
type Request ¶
Request contains only Bridge-generated or verifier-bound attribution. Operation is a fixed binding name while its handler runs. Channel is "mcp" or "http", selected by the endpoint rather than any client claim.
type VerifyToken ¶
type VerifyToken func(context.Context, string) (Credential, error)
VerifyToken must authenticate the issuer and intended resource/audience, check expiry and current revocation, and bind the user and client. The callback is concurrent, context-bounded, and must not log its bearer argument.