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
- func GetAuthToken(ctx context.Context) string
- func GetPersona(ctx context.Context) string
- func GetProgressToken(ctx context.Context) any
- func GetServerSession(ctx context.Context) *mcp.ServerSession
- func GetSource(ctx context.Context) string
- func WithAuthToken(ctx context.Context, token string) context.Context
- func WithPersona(ctx context.Context, persona string) context.Context
- func WithProgressToken(ctx context.Context, token any) context.Context
- func WithServerSession(ctx context.Context, ss *mcp.ServerSession) context.Context
- func WithSource(ctx context.Context, source string) context.Context
Constants ¶
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
GetAuthToken retrieves the inbound authentication token from the context, or "" when none was set.
func GetPersona ¶ added in v1.130.0
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 ¶
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
GetSource returns how the call arrived, or "" when nothing recorded it.
func WithAuthToken ¶ added in v1.78.0
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
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 ¶
WithProgressToken adds a progress token to the context.
func WithServerSession ¶
WithServerSession adds a ServerSession to the context.
func WithSource ¶ added in v1.130.0
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.