utils

package
v1.7.8 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildMCPCallbackBaseURL added in v1.5.15

func BuildMCPCallbackBaseURL(ctx *schemas.BifrostContext) string

BuildMCPCallbackBaseURL extracts the base URL set on the BifrostContext by the HTTP middleware (e.g. "https://host"). Per-user OAuth and per-user headers resolvers append their respective paths on top.

Trailing slashes are stripped defensively. The sole writer today (lib/ctx.go BuildBaseURL) already normalizes, but OAuth providers match redirect URIs exactly — a `https://host//api/oauth/callback` produced by a future writer that forgets to trim would silently break every per-user OAuth flow. Guarding once on the read side keeps that invariant local to this function rather than spread across every potential writer.

func BuildOAuthRedirectURIFromContext added in v1.5.15

func BuildOAuthRedirectURIFromContext(ctx *schemas.BifrostContext) string

BuildOAuthRedirectURIFromContext returns the full OAuth callback URL ("<base>/api/oauth/callback") needed by the per-user OAuth flow, or empty if the base URL is unavailable.

func CanonicalizeHeaderKey added in v1.5.15

func CanonicalizeHeaderKey(key string) string

CanonicalizeHeaderKey returns the canonical lowercase + trimmed form of a single header key. Empty input returns empty.

func CanonicalizeHeaderKeys added in v1.5.15

func CanonicalizeHeaderKeys(keys []string) []string

CanonicalizeHeaderKeys returns a new slice with every entry passed through CanonicalizeHeaderKey. Nil in → nil out so a caller that uses "nil means preserve existing" semantics (e.g. resolvePerUserHeaderKeys, UpdateMCPClientConfig) keeps that signal. The input slice is not mutated.

func CanonicalizeHeaderMap added in v1.5.15

func CanonicalizeHeaderMap(m map[string]string) map[string]string

CanonicalizeHeaderMap returns a new map whose keys are passed through CanonicalizeHeaderKey. On collision (e.g. "Authorization" and "authorization" both present in the input), the last value wins — callers that need duplicate detection should run it on the raw input before calling this. Nil in → nil out.

func ExtractFilteredExtras added in v1.5.15

func ExtractFilteredExtras(ctx context.Context, config *schemas.MCPClientConfig) http.Header

ExtractFilteredExtras returns just the per-request "extra" headers carried in the BifrostContext (BifrostContextKeyMCPExtraHeaders), scoped by the client's AllowedExtraHeaders. Static config headers are NOT included here — those live on the upstream transport via StaticConfigHeaders and apply automatically to every message it carries. This function exists for the per-message CredentialStore.RequestHeaders path on shared connections.

func FlattenHeaders added in v1.5.15

func FlattenHeaders(h http.Header) map[string]string

FlattenHeaders converts an http.Header into a map[string]string suitable for mcp-go's transport.WithHTTPHeaders, used for both shared persistent connections (clientmanager) and ephemeral per-call connections (AcquireClientConn). Multi-value headers collapse to their first value.

func StaticConfigHeaders added in v1.5.15

func StaticConfigHeaders(config *schemas.MCPClientConfig) http.Header

StaticConfigHeaders returns the admin-configured static headers from config.Headers MINUS any header whose name is a credential — Authorization always, plus any name declared in config.PerUserHeaderKeys. These are the headers that are safe to expose to MCP connect-plugins via the PreConnectionHook gate — plugins may add, remove, or rewrite them.

Why exclude:

  • Authorization: credential by definition. The CredentialStore resolver for the active auth type emits the final value (config bearer for MCPAuthTypeHeaders; dynamic token for OAuth-flavored types).
  • PerUserHeaderKeys: credential schema for MCPAuthTypePerUserHeaders. If an admin accidentally (or deliberately) baked one of these names into config.Headers with a static value, exposing it to plugins would leak the static fallback. The per-user-headers resolver emits the caller's value; the static fallback should never reach the wire (and never reach plugins) for per-user-headers clients.

Comparison is case-insensitive because HTTP headers are case-insensitive on the wire but case-sensitive in Go maps.

Types

This section is empty.

Jump to

Keyboard shortcuts

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