mcpcontext

package
v1.130.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package mcpcontext provides context helpers for MCP session state. These are in a separate package to avoid import cycles between middleware and toolkit packages.

Index

Constants

View Source
const SourceScript = "script"

SourceScript labels a call arriving from a managed script's host bindings. It is defined here, rather than in pkg/middleware alongside the other source labels, so a toolkit can recognize it without importing middleware (which would form an import cycle); middleware's SourceScript is this constant.

Variables

This section is empty.

Functions

func GetAuthToken added in v1.78.0

func GetAuthToken(ctx context.Context) string

GetAuthToken retrieves the inbound authentication token from the context, or "" when none was set.

func GetPersona added in v1.130.0

func GetPersona(ctx context.Context) string

GetPersona returns the persona the call was authorized under, or "" when nothing recorded it -- an outbound call made outside a tool call, such as a catalog refresh, or one assembled without the tool-call middleware.

func GetProgressToken

func GetProgressToken(ctx context.Context) any

GetProgressToken retrieves the progress token from the context.

func GetServerSession

func GetServerSession(ctx context.Context) *mcp.ServerSession

GetServerSession retrieves the ServerSession from the context.

func GetSource added in v1.130.0

func GetSource(ctx context.Context) string

GetSource returns how the call arrived, or "" when nothing recorded it.

func WithAuthToken added in v1.78.0

func WithAuthToken(ctx context.Context, token string) context.Context

WithAuthToken stores the inbound authentication token (the bearer or API key that authenticated the MCP session) on the context. It lives here, rather than in pkg/middleware, so toolkit packages can read it without importing middleware (which would form an import cycle). The auth middleware writes it; the api-gateway toolkit reads it to forward the acting caller's identity on identity-passthrough connections.

func WithPersona added in v1.130.0

func WithPersona(ctx context.Context, persona string) context.Context

WithPersona records the persona the call was authorized under. It lives here for the reason WithSource does: pkg/middleware imports the toolkit packages, so a toolkit cannot read the PlatformContext that already holds the name. The tool-call middleware writes it once the authorizer has resolved the persona; the api-gateway toolkit's instrumented transport reads it to label every outbound call with the principal that caused it (#1615).

func WithProgressToken

func WithProgressToken(ctx context.Context, token any) context.Context

WithProgressToken adds a progress token to the context.

func WithServerSession

func WithServerSession(ctx context.Context, ss *mcp.ServerSession) context.Context

WithServerSession adds a ServerSession to the context.

func WithSource added in v1.130.0

func WithSource(ctx context.Context, source string) context.Context

WithSource records how a call arrived, using the labels pkg/middleware defines. It lives here so a toolkit can vary on the caller without importing middleware. The tool-call middleware writes it from the PlatformContext it has just resolved; the api-gateway toolkit reads it to tell a managed script's call from a model's.

Types

This section is empty.

Jump to

Keyboard shortcuts

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