config

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAuthzOPAURL = "http://localhost:8181"

	DefaultAuthzTimeout = 3 * time.Second

	DefaultAuthzDecisionPathList    = "/v1/data/mcp/authz/allowed_tools"
	DefaultAuthzDecisionPathCall    = "/v1/data/mcp/authz/allow"
	DefaultAuthzDecisionPathCatalog = "/v1/data/mcp/authz/allow_catalog"

	DefaultAuthzHeaderUserID     = "x-user-id"
	DefaultAuthzHeaderUserGroups = "x-user-groups"
	DefaultAuthzHeaderBypass     = "x-authz-bypass" //nolint: gosec // header name, not a credential

	DefaultAuthzInputUser     = "user"
	DefaultAuthzInputGroups   = "groups"
	DefaultAuthzInputServer   = "server"
	DefaultAuthzInputTool     = "tool"
	DefaultAuthzInputTools    = "tools"
	DefaultAuthzInputToolName = "name"
)

既定値(authz 設定省略時)。

View Source
const (
	AuthzInputFieldTypeString = "string"
	AuthzInputFieldTypeList   = "list"
	AuthzInputFieldTypeNumber = "number"
)

Value types accepted by AuthzInputHeaderField.Type, naming the JSON type the header's raw value becomes in the decision input. An empty Type is a synonym for AuthzInputFieldTypeString.

View Source
const DefaultCallTimeout = 60 * time.Second

DefaultCallTimeout is used when Server.CallTimeout is unset (<= 0) for a reverse transport server.

View Source
const DefaultFileFetchMaxSize int64 = 524288000

DefaultFileFetchMaxSize is used when FileFetchConfig.MaxSize is unset (<= 0). 500 MiB (524288000 bytes).

View Source
const DefaultIdentityClaim = "sub"

DefaultIdentityClaim is used when IdentityProfile.Claim is unset for a source: jwt profile.

View Source
const DefaultIntrospectionCacheTTL = 5 * time.Minute

DefaultIntrospectionCacheTTL is used when IdentityProfile.CacheTTL is unset (<= 0) for a source: introspection profile.

Variables

This section is empty.

Functions

func NormalizeOrigin added in v1.7.0

func NormalizeOrigin(raw string) (string, error)

NormalizeOrigin validates that raw is a bare origin (scheme + host, no path/query/fragment/userinfo) and returns it with a lowercased scheme and host. Only http/https are accepted.

Types

type AuthValue

type AuthValue struct {
	Header string `mapstructure:"header"`
	Prefix string `mapstructure:"prefix"`
	Value  string `mapstructure:"value"`
}

type AuthzConfig added in v1.11.0

type AuthzConfig struct {
	Enabled      bool              `mapstructure:"enabled"`
	OPAURL       string            `mapstructure:"opaURL"`
	Timeout      time.Duration     `mapstructure:"timeout"`
	DecisionPath AuthzDecisionPath `mapstructure:"decisionPath"`
	Headers      AuthzHeaders      `mapstructure:"headers"`
	Input        AuthzInput        `mapstructure:"input"`
}

AuthzConfig configures the OPA sidecar used as the tool-call PDP. Disabled (Enabled: false) by default, preserving prior behavior.

func (AuthzConfig) ValidateWithContext added in v1.11.0

func (c AuthzConfig) ValidateWithContext(ctx context.Context) error

func (AuthzConfig) WithDefaults added in v1.11.0

func (c AuthzConfig) WithDefaults() AuthzConfig

WithDefaults returns a copy of c with zero-value fields replaced by the documented defaults.

type AuthzDecisionPath added in v1.11.0

type AuthzDecisionPath struct {
	List    string `mapstructure:"list"`
	Call    string `mapstructure:"call"`
	Catalog string `mapstructure:"catalog"`
}

AuthzDecisionPath is the OPA data path queried for each decision kind (see docs/design/opa-tool-authorization-plan.ja.md「動作」).

func (AuthzDecisionPath) ValidateWithContext added in v1.11.0

func (c AuthzDecisionPath) ValidateWithContext(ctx context.Context) error

type AuthzHeaders added in v1.11.0

type AuthzHeaders struct {
	UserID     string `mapstructure:"userID"`
	UserGroups string `mapstructure:"userGroups"`
	Bypass     string `mapstructure:"bypass"`
}

AuthzHeaders names the inbound HTTP headers an upstream identity/authn layer is expected to inject before Manifold sees the request. AuthzHeaders.Bypass is checked against the literal string "true" (see authz.BypassRequested); it exists so a fronting proxy can disable authz per-request for tenants that opt out, without flipping Enabled globally.

func (AuthzHeaders) ValidateWithContext added in v1.11.0

func (c AuthzHeaders) ValidateWithContext(ctx context.Context) error

type AuthzInput added in v1.12.0

type AuthzInput struct {
	User     string `mapstructure:"user"`
	Groups   string `mapstructure:"groups"`
	Server   string `mapstructure:"server"`
	Tool     string `mapstructure:"tool"`
	Tools    string `mapstructure:"tools"`
	ToolName string `mapstructure:"toolName"`

	// FromHeaders maps a decision-input field name to the inbound HTTP
	// header it is read from. Resolved values are added as top-level
	// fields to every decision input, typed per AuthzInputHeaderField.Type.
	// Empty (the default) adds nothing; a required header missing or empty
	// on a request denies (authz.ErrMissingInputHeader), while an optional
	// one is simply left out of the input.
	FromHeaders map[string]AuthzInputHeaderField `mapstructure:"fromHeaders"`
}

AuthzInput names the JSON keys Manifold uses when building the OPA decision input (see OPADecider.Allow / AllowedTools / AllowCatalog). Configurable so a policy author can match an existing input contract instead of Manifold's defaults.

func (AuthzInput) ValidateWithContext added in v1.12.0

func (c AuthzInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext rejects collisions between keys that appear together in the same OPA input object: user/groups/server/tool (tools/call), user/groups/tools (tools/list), and server/toolName (each tools/list array element). Empty keys are not rejected here: like headers.*, decisionPath.*, opaURL and timeout, a zero value means "unset" and is backfilled by WithDefaults before validation runs.

type AuthzInputHeaderField added in v1.12.0

type AuthzInputHeaderField struct {
	Header   string `mapstructure:"header"`
	Required *bool  `mapstructure:"required"`
	Type     string `mapstructure:"type"`
}

AuthzInputHeaderField describes one entry of AuthzInput.FromHeaders: the inbound header to read, whether the request is denied when it is absent, and how the raw value is turned into a JSON value.

func (AuthzInputHeaderField) IsRequired added in v1.12.0

func (f AuthzInputHeaderField) IsRequired() bool

IsRequired reports whether a missing or empty header denies the request. Unset (nil) means required, so omitting the key stays fail-closed while still letting an explicit false through.

type Config

type Config struct {
	Gateway   Gateway `mapstructure:"gateway"`
	MCPServer Servers `mapstructure:"mcpServers"`

	Redis  *RedisConfig  `mapstructure:"redis"`
	SQLite *SQLiteConfig `mapstructure:"sqlite"`
	Memory *MemoryConfig `mapstructure:"memory"`

	Telemetry telemetry.Config `mapstructure:"telemetry"`

	FileFetch FileFetchConfig `mapstructure:"fileFetch"`

	Storage Storage `mapstructure:"storage"`

	Identities map[string]*IdentityProfile `mapstructure:"identities"`

	Authz AuthzConfig `mapstructure:"authz"`
}

func Load

func Load(ctx context.Context, configName string) (*Config, error)

Load reads the configuration from the config.yaml file and environment variables.

func (*Config) ValidateWithContext added in v1.2.0

func (c *Config) ValidateWithContext(ctx context.Context) error

type EdgeAuth added in v1.7.0

type EdgeAuth string
const (
	EdgeAuthPairing     EdgeAuth = "pairing"
	EdgeAuthForwardAuth EdgeAuth = "forwardAuth"
)

type EdgeConfig added in v1.7.0

type EdgeConfig struct {
	Auth    EdgeAuth      `mapstructure:"auth"`
	Pairing PairingConfig `mapstructure:"pairing"`

	// TrustCloudflare, when true, additionally trusts Cloudflare's published
	// edge IP ranges as /edge/pair rate-limit forwarders. Only enable this
	// when Manifold is actually deployed behind Cloudflare — see
	// docs/design/webmcp-reverse-gateway-phase2.ja.md「Phase 1 からの持ち越し判断事項」.
	TrustCloudflare bool `mapstructure:"trustCloudflare"`

	// TrustedForwarders adds extra CIDR prefixes to trust as /edge/pair
	// rate-limit forwarders, alongside the RFC1918 default and (if enabled)
	// Cloudflare's ranges — e.g. an ALB/Ingress subnet outside RFC1918.
	TrustedForwarders []string `mapstructure:"trustedForwarders"`
}

EdgeConfig selects how the reverse-connection browser extension binds its WebSocket connection to an identityKey (see docs/design/webmcp-reverse-gateway.ja.md).

func (EdgeConfig) IsStaticPairing added in v1.7.0

func (c EdgeConfig) IsStaticPairing() bool

IsStaticPairing reports whether this deployment binds the edge connection to a fixed identityKey instead of deriving one per agent request.

func (EdgeConfig) ValidateWithContext added in v1.7.0

func (c EdgeConfig) ValidateWithContext(ctx context.Context) error

func (EdgeConfig) WithDefaults added in v1.7.0

func (c EdgeConfig) WithDefaults() EdgeConfig

WithDefaults returns a copy of c with zero-value fields replaced by the documented defaults (pairing/remote — forwardAuth remains config structure only, see docs/design/webmcp-reverse-gateway.ja.md「拡張と identity の紐づけ」).

type FileFetchConfig added in v1.3.0

type FileFetchConfig struct {
	// AllowLocal allows connecting to private/loopback/link-local IP addresses and
	// using the http:// scheme. Intended for local development/testing against a
	// local stack (e.g. ministack). Defaults to false.
	AllowLocal bool `mapstructure:"allowLocal"`

	// AllowedHosts, when non-empty, restricts URL downloads to these hosts only
	// (exact match against the URL host, with or without port). Empty means all
	// hosts are allowed, subject to the private-IP block unless AllowLocal is true.
	AllowedHosts []string `mapstructure:"allowedHosts"`

	// MaxSize is the maximum number of bytes accepted for a single file value,
	// whether downloaded from a URL or provided as base64/text content.
	// 0 (or unset) falls back to DefaultFileFetchMaxSize.
	MaxSize int64 `mapstructure:"maxSize"`
}

FileFetchConfig controls how outbound file-fetch requests behave — e.g. when an MCP tool caller passes a URL for a file-input field and manifold downloads it on their behalf. This exists to mitigate SSRF: by default, downloads only allow https:// and refuse to connect to private/loopback/link-local IP addresses.

func (FileFetchConfig) WithDefaults added in v1.3.0

func (c FileFetchConfig) WithDefaults() FileFetchConfig

WithDefaults returns a copy of c with zero-value fields replaced by defaults.

type Gateway

type Gateway struct {
	Port int `mapstructure:"port"`

	Key  string `mapstructure:"key"`
	Cert string `mapstructure:"cert"`

	EncryptKey string `mapstructure:"encryptKey"`

	Edge EdgeConfig `mapstructure:"edge"`

	SpecRefresh SpecRefreshConfig `mapstructure:"specRefresh"`
}

func (Gateway) ValidateWithContext added in v1.2.0

func (c Gateway) ValidateWithContext(ctx context.Context) error

type IdentityProfile added in v1.8.0

type IdentityProfile struct {
	Source IdentitySource `mapstructure:"source"`

	// source: jwt. Claim defaults to DefaultIdentityClaim; Audience is optional.
	Claim    string `mapstructure:"claim"`
	Issuer   string `mapstructure:"issuer"`
	JWKSURL  string `mapstructure:"jwksURL"`
	Audience string `mapstructure:"audience"`

	// source: header
	Header string `mapstructure:"header"`
	Hash   bool   `mapstructure:"hash"`

	// source: introspection. CacheTTL defaults to DefaultIntrospectionCacheTTL.
	URL              string        `mapstructure:"url"`
	CredentialHeader string        `mapstructure:"credentialHeader"`
	CacheTTL         time.Duration `mapstructure:"cacheTTL"`
}

IdentityProfile is a named "how to derive an identityKey from an agent request" rule, referenced by reverse Server.Identity (see the "ユーザー識別 (identity プロファイル)" section of docs/design/webmcp-reverse-gateway.ja.md). Only the fields for the selected Source are set; ValidateWithContext rejects fields belonging to another source as a config mistake.

func (IdentityProfile) CacheTTLOrDefault added in v1.8.0

func (p IdentityProfile) CacheTTLOrDefault() time.Duration

CacheTTLOrDefault returns CacheTTL, falling back to DefaultIntrospectionCacheTTL when unset (<= 0).

func (IdentityProfile) ClaimOrDefault added in v1.8.0

func (p IdentityProfile) ClaimOrDefault() string

ClaimOrDefault returns Claim, falling back to DefaultIdentityClaim when unset.

func (IdentityProfile) ValidateWithContext added in v1.8.0

func (p IdentityProfile) ValidateWithContext(ctx context.Context) error

type IdentitySource added in v1.8.0

type IdentitySource string
const (
	IdentitySourceJWT           IdentitySource = "jwt"
	IdentitySourceHeader        IdentitySource = "header"
	IdentitySourceIntrospection IdentitySource = "introspection"
)

type MCPTransport

type MCPTransport string
const (
	MCPTransportHTTP    MCPTransport = "http"
	MCPTransportStdio   MCPTransport = "stdio"
	MCPTransportReverse MCPTransport = "reverse"
)

type MemoryConfig added in v1.3.0

type MemoryConfig struct {
	// Enabled が true の場合、インメモリストレージを使用する。
	Enabled bool `mapstructure:"enabled"`
}

MemoryConfig はインメモリストレージの設定。

type OAuth2

type OAuth2 struct {
	ClientID     string   `mapstructure:"clientID"`
	ClientSecret string   `mapstructure:"clientSecret"`
	AuthURL      string   `mapstructure:"authURL"`
	TokenURL     string   `mapstructure:"tokenURL"`
	Scopes       []string `mapstructure:"scopes"`
}

func (*OAuth2) ValidateWithContext added in v1.3.0

func (c *OAuth2) ValidateWithContext(ctx context.Context) error

type PairingConfig added in v1.7.0

type PairingConfig struct {
	Type PairingType `mapstructure:"type"`
}

func (PairingConfig) ValidateWithContext added in v1.7.0

func (c PairingConfig) ValidateWithContext(ctx context.Context) error

type PairingType added in v1.7.0

type PairingType string
const (
	PairingTypeRemote PairingType = "remote"
	PairingTypeStatic PairingType = "static"
)

type RedisConfig

type RedisConfig struct {
	URL         string   `mapstructure:"url"`
	Addrs       []string `mapstructure:"addrs"`
	User        string   `mapstructure:"user"`
	Password    string   `mapstructure:"password"`
	DB          int      `mapstructure:"db"`
	MasterName  string   `mapstructure:"master_name"`
	TLS         bool     `mapstructure:"tls"`
	ClusterMode bool     `mapstructure:"cluster_mode"`
}

type S3 added in v1.3.0

type S3 struct {
	Bucket    string `mapstructure:"bucket"`
	KeyPrefix string `mapstructure:"keyPrefix"`
}

func (*S3) ValidateWithContext added in v1.3.0

func (c *S3) ValidateWithContext(ctx context.Context) error

type SQLiteConfig added in v1.1.0

type SQLiteConfig struct {
	// Path はSQLiteデータベースファイルのパス。
	// ":memory:" を指定するとインメモリDBとして動作する。
	Path string `mapstructure:"path"`
}

SQLiteConfig はSQLiteストレージの設定。

type Server

type Server struct {
	Name         string
	Description  string            `mapstructure:"description"`
	BaseURL      string            `mapstructure:"baseURL"`
	Spec         string            `mapstructure:"spec"` // ファイル or http(s)(OpenAPI モード)
	ExtraHeaders map[string]string `mapstructure:"headers"`

	// nil は gateway.specRefresh.interval を使う、0 はこのサーバーのみリフレッシュ無効。
	SpecRefreshInterval *time.Duration `mapstructure:"specRefreshInterval"`

	// Tools は静的ツールカタログ(生成物)関連の設定。File が指定されると、
	// 起動・リフレッシュで spec を取得せず生成物ファイルからツールを読み込む。
	Tools *ToolsConfig `mapstructure:"tools"`

	AuthValue     *AuthValue     `mapstructure:"authValue"`
	OAuth2        *OAuth2        `mapstructure:"oauth2"`
	TokenExchange *TokenExchange `mapstructure:"tokenExchange"`

	// MCP バックエンドモード用(Spec が空のとき有効)
	Transport MCPTransport      `mapstructure:"transport"`
	URL       string            `mapstructure:"url"`     // streamable_http 用
	Command   string            `mapstructure:"command"` // stdio 用
	Args      []string          `mapstructure:"args"`
	Env       map[string]string `mapstructure:"env"`

	// reverse トランスポート用(WebMCP reverse connection gateway)
	Origin      string        `mapstructure:"origin"`      // ブリッジ対象タブの許可 origin
	Identity    string        `mapstructure:"identity"`    // identities プロファイル名の参照
	CallTimeout time.Duration `mapstructure:"callTimeout"` // 未設定/0以下は DefaultCallTimeout
}

func (Server) CallTimeoutOrDefault added in v1.7.0

func (s Server) CallTimeoutOrDefault() time.Duration

CallTimeoutOrDefault returns CallTimeout, falling back to DefaultCallTimeout when unset.

func (Server) EffectiveSpecRefreshInterval added in v1.10.0

func (s Server) EffectiveSpecRefreshInterval(global time.Duration) time.Duration

EffectiveSpecRefreshInterval returns the refresh interval for this server, falling back to the gateway-wide default. Only OpenAPI mode servers refresh; others always return 0. A server with tools.file set never refreshes (it starts from the generated file, not the live spec), regardless of the gateway-wide default.

func (Server) GeneratedToolsFile added in v1.14.0

func (s Server) GeneratedToolsFile() string

GeneratedToolsFile returns tools.file, or "" when unset (or Tools itself is unset).

func (*Server) IsMCPBackend

func (s *Server) IsMCPBackend() bool

IsMCPBackend はこの Server が MCP バックエンドモードかどうかを返す。 Spec が空で Transport が指定されている場合に MCP バックエンドモードとなる。 reverse は別経路(エッジレジストリ)で扱うため除く。

func (*Server) IsReverseBackend added in v1.7.0

func (s *Server) IsReverseBackend() bool

IsReverseBackend はこの Server が WebMCP reverse connection gateway 経由かどうかを返す。

func (Server) ValidateWithContext added in v1.2.0

func (s Server) ValidateWithContext(ctx context.Context) error

type Servers

type Servers map[string]*Server

type SpecRefreshConfig added in v1.10.0

type SpecRefreshConfig struct {
	Interval time.Duration `mapstructure:"interval"`
}

SpecRefreshConfig is the gateway-wide default for re-fetching OpenAPI mode specs after startup, overridable per server with mcpServers.<name>.specRefreshInterval. Interval 0 (unset) disables refreshing.

func (SpecRefreshConfig) ValidateWithContext added in v1.10.0

func (c SpecRefreshConfig) ValidateWithContext(ctx context.Context) error

type Storage added in v1.3.0

type Storage struct {
	Type    string `mapstructure:"type"`
	HostURL string `mapstructure:"hostURL"`
	S3      *S3    `mapstructure:"s3"`
}

func (*Storage) ValidateWithContext added in v1.3.0

func (c *Storage) ValidateWithContext(ctx context.Context) error

type TokenExchange added in v1.3.0

type TokenExchange struct {
	URL string `mapstructure:"url"`
}

func (*TokenExchange) ValidateWithContext added in v1.3.0

func (c *TokenExchange) ValidateWithContext(ctx context.Context) error

type ToolsConfig added in v1.14.0

type ToolsConfig struct {
	File string `mapstructure:"file"`
}

ToolsConfig groups static tool catalog (生成物) settings under mcpServers.<name>.tools. File is the only field in Phase 1; it is an object (rather than tools.file directly) so overrides (exclude/rename/ description) can be added alongside it later without a breaking change.

Jump to

Keyboard shortcuts

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