Help us shape the future of Go! Take the 2026 Go Developer Survey

rpc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package rpc contains opt-in JSON-RPC integration. Its resolver must run the host's ordinary authentication/policy; wrapping an unauthenticated handler does not inherit the wrapped handler's private authorization callbacks.

Index

Constants

This section is empty.

Variables

View Source
var ErrStreamProtocol = errors.New("invalid MCP subscription stream")

Functions

func DecodeHeaderValue

func DecodeHeaderValue(value string) (string, error)

func EncodeHeaderValue

func EncodeHeaderValue(value string) string

EncodeHeaderValue implements the July header sentinel, including escaping a literal sentinel-shaped value. The JSON body remains the source of truth.

func HeadersFromContext

func HeadersFromContext(ctx context.Context) http.Header

func ValidRequestID

func ValidRequestID(id any) bool

ValidRequestID accepts MCP string/integer request IDs without admitting null, booleans, objects or fractional JSON numbers into execution/control routing.

func ValidRequestMetadata

func ValidRequestMetadata(params json.RawMessage) bool

ValidRequestMetadata checks required protocol/capability metadata. ClientInfo is optional in July core and must never serve as authenticated authority. Host decorators must validate it before admitting task-augmented execution.

func WithNotificationSink

func WithNotificationSink(ctx context.Context, notify func(context.Context, *jsonrpc.Notification) error) context.Context

Types

type Caller

type Caller interface {
	Call(context.Context, Request) (json.RawMessage, error)
}

type CallerFunc

type CallerFunc func(context.Context, Request) (json.RawMessage, error)

func (CallerFunc) Call

func (f CallerFunc) Call(ctx context.Context, request Request) (json.RawMessage, error)

type ConsumerError

type ConsumerError struct{ Cause error }

func (*ConsumerError) Error

func (e *ConsumerError) Error() string

func (*ConsumerError) Unwrap

func (e *ConsumerError) Unwrap() error

type ContextNotifier

type ContextNotifier struct{}

func (ContextNotifier) Notify

func (ContextNotifier) Notify(ctx context.Context, notification *jsonrpc.Notification) error

type DecideTool

type DecideTool func(context.Context, tasks.Owner, *jsonrpc.Request) (Decision, error)

DecideTool is pure planning/policy. It must never start execution. Schedule through the canonical runtime only after its owned task creation is durable.

type Decision

type Decision struct {
	Create   *tasks.CreateOptions
	Required bool
}

type HTTPCaller

type HTTPCaller struct {
	HeaderProvider func(context.Context) (http.Header, error)
	// contains filtered or unexported fields
}

HTTPCaller is a bounded JSON/SSE request adapter, with no retries or redirects. Configure host authentication through Client.Transport or HeaderProvider.

func NewHTTPCaller

func NewHTTPCaller(endpoint string, client *http.Client) (*HTTPCaller, error)

func (*HTTPCaller) Call

func (c *HTTPCaller) Call(ctx context.Context, request Request) (json.RawMessage, error)

func (*HTTPCaller) Listen

func (c *HTTPCaller) Listen(ctx context.Context, request Request, notify func(json.RawMessage) error) (json.RawMessage, error)

type HTTPHandler

type HTTPHandler struct {
	Build func(context.Context, transport.Notifier) transport.Handler
	// Present Origin headers are denied by default. Hosts may explicitly admit
	// approved web origins; this does not replace request authentication.
	AllowOrigin func(string) bool
}

HTTPHandler is a bounded stateless July JSON-RPC/SSE adapter. Host middleware must install authenticated request context before Owner is consulted. Build receives a request-scoped notifier, just like viant/mcp's transport handler factory. Normal methods may delegate to the host's existing handler.

func (HTTPHandler) ServeHTTP

func (h HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Handler

type Handler struct {
	Next          transport.Handler
	Service       tasks.Backend
	Owner         OwnerResolver
	Decide        DecideTool
	Notifier      transport.Notifier
	Subscriptions *SubscriptionOptions
	// contains filtered or unexported fields
}

func (*Handler) OnNotification

func (h *Handler) OnNotification(ctx context.Context, notification *jsonrpc.Notification)

func (*Handler) Serve

func (h *Handler) Serve(ctx context.Context, request *jsonrpc.Request, response *jsonrpc.Response)

type OwnerResolver

type OwnerResolver func(context.Context, *jsonrpc.Request) (tasks.Owner, error)

type Request

type Request struct {
	Method  string
	Params  json.RawMessage
	Headers http.Header
}

type SerialNotifier

type SerialNotifier struct {
	NotifyFunc func(context.Context, *jsonrpc.Notification) error
	// contains filtered or unexported fields
}

SerialNotifier prevents interleaved writes when one host transport is shared.

func (*SerialNotifier) Notify

type StreamCaller

type StreamCaller interface {
	Listen(context.Context, Request, func(json.RawMessage) error) (json.RawMessage, error)
}

StreamCaller keeps subscriptions/listen open and reports only notifications. A nil error means a correlated graceful complete response was received.

type SubscriptionOptions

type SubscriptionOptions struct {
	ReconcileInterval time.Duration
	MaxDuration       time.Duration
	MaxConcurrent     int
}

SubscriptionOptions enables the actual notification transport. Nil on Handler means unsupported. ReconcileInterval bounds loss/overflow recovery; MaxDuration bounds resource lifetime and ends with a graceful correlated result.

type TransportCaller

type TransportCaller struct {
	Transport transport.Transport
	// contains filtered or unexported fields
}

TransportCaller uses a supplied MCP transport. For HTTP, its header provider must consume HeadersFromContext; stdio needs no routing headers. It adds no retry policy and does not change the transport's authentication context.

func (*TransportCaller) Call

func (c *TransportCaller) Call(ctx context.Context, request Request) (json.RawMessage, error)

Jump to

Keyboard shortcuts

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