auth

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package auth provides ready-made [mcpx.AuthFunc] implementations for the two most common authentication shapes carried in [mcpx.ServerConfig.Auth].

  • Bearer — for {"auth": {"token": "..."}}; sets Authorization: Bearer <token>.
  • HeaderToken — for {"auth": {"tokenName": "X-MCP-AUTH", "value": "..."}}; sets the named header verbatim, no Bearer prefix.

Pass the helper directly to [mcpx.WithAuthFunc]:

import (
    mcpx "github.com/inhuman/mcp-multiplexer"
    "github.com/inhuman/mcp-multiplexer/auth"
)

mx, err := mcpx.New(ctx, cfg, mcpx.WithAuthFunc(auth.Bearer))

For multi-scheme dispatch (mixing schemes per server) write your own [mcpx.AuthFunc] that switches on data["scheme"] and delegates to one of the helpers.

The package depends only on the standard library and the parent module — importing it does not pull additional third-party dependencies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bearer

func Bearer(_ context.Context, _ string, r *http.Request, data map[string]any) error

Bearer reads data["token"] (string) and sets `Authorization: Bearer <token>` on the request.

Expected JSON shape inside [mcpx.ServerConfig.Auth]:

{"auth": {"token": "..."}}

Returns an error if data["token"] is missing, not a string, or empty.

Compatible with [mcpx.AuthFunc]:

mcpx.New(ctx, cfg, mcpx.WithAuthFunc(auth.Bearer))

func HeaderToken

func HeaderToken(_ context.Context, _ string, r *http.Request, data map[string]any) error

HeaderToken reads data["tokenName"] (header name, string) and data["value"] (raw token, string) and sets that header on the request verbatim — no `Bearer ` prefix.

Expected JSON shape inside [mcpx.ServerConfig.Auth]:

{"auth": {"tokenName": "X-MCP-AUTH", "value": "..."}}

Returns an error if any required key is missing, not a string, or empty.

Compatible with [mcpx.AuthFunc]:

mcpx.New(ctx, cfg, mcpx.WithAuthFunc(auth.HeaderToken))

Types

This section is empty.

Jump to

Keyboard shortcuts

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