reqctx

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package reqctx carries the HTTP request a protocol handler is being served for (MCP tools, JSON-RPC methods) on the Go context, the per-request MCP registrations a middleware makes, and the process-wide transport mode that transport() reports. It is shared by scriptling.runtime and scriptling.mcp so neither has to import the other.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTransportBuiltin

func NewTransportBuiltin(help string) *object.Builtin

NewTransportBuiltin builds the transport() function shared by the scriptling.runtime.mcp and scriptling.runtime.jsonrpc sub-libraries: it answers "how am I being served" so one setup script can work in every mode — over stdio the middleware never runs, so per-request registrations have to be made unconditionally (or statically) there instead.

func RequestContextBuiltins

func RequestContextBuiltins() map[string]*object.Builtin

RequestContextBuiltins returns the get_request / request_context pair shared by scriptling.mcp.tool and scriptling.runtime.jsonrpc, so tool scripts and JSON-RPC handlers — which receive only their parameters — can reach the HTTP request they are being served for. Over the stdio transports there is no HTTP request: get_request() returns None and request_context() an empty dict.

func RequestContextFrom

func RequestContextFrom(ctx context.Context) *object.Instance

RequestContextFrom returns the request stashed on ctx, or nil when there is none (e.g. the stdio transports, which have no HTTP request).

func SetTransport

func SetTransport(t string)

SetTransport records how the process is serving, for transport(): "stdio" for the JSON-RPC / MCP / plugin stdio servers, "http" for the HTTP server, "" when the script is not being served at all. Serving hosts set it before the setup script runs.

func Transport

func Transport() string

Transport returns the process-wide serving mode set by SetTransport.

func WithRequestContext

func WithRequestContext(ctx context.Context, req *object.Instance) context.Context

WithRequestContext attaches req to ctx so handler-side accessors can reach it. The request's context dict is replaced with a deep copy first: a JSON-RPC batch fans one request out to several concurrent handlers, and the copy keeps them from sharing mutable state with each other or with anything that still holds the original dict.

Types

type RequestRegistrations

type RequestRegistrations struct {
	Tools     []*object.Dict
	Resources []*object.Dict
	Prompts   []*object.Dict
	// contains filtered or unexported fields
}

RequestRegistrations collects the request-scoped MCP entries registered for the request being served. Entries are the raw registration dicts as the middleware produced them; the server converts them into per-request MCP providers once the middleware has passed. Nil tool/resource/prompt entry kinds are simply not exposed for that request.

func RegistrationsFrom

func RegistrationsFrom(ctx context.Context) *RequestRegistrations

RegistrationsFrom returns the registrations attached to ctx, or nil when the context is not one of the server's stashed request contexts.

func (*RequestRegistrations) AddPrompt

func (r *RequestRegistrations) AddPrompt(entry *object.Dict)

AddPrompt records a register_request_prompt registration dict.

func (*RequestRegistrations) AddResource

func (r *RequestRegistrations) AddResource(entry *object.Dict)

AddResource records a register_request_resource registration dict.

func (*RequestRegistrations) AddTool

func (r *RequestRegistrations) AddTool(entry *object.Dict)

AddTool records a register_request_tool registration dict.

func (*RequestRegistrations) Empty

func (r *RequestRegistrations) Empty() bool

Empty reports whether nothing was registered for this request.

Jump to

Keyboard shortcuts

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