state

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 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

View Source
const DefaultPath = ".mcp-oauth-cli/state.json"

Variables

This section is empty.

Functions

func ClearSecrets added in v0.2.0

func ClearSecrets(path string, st *State, store secretstore.Store) error

ClearSecrets removes stored secrets (primary and per-entry history) from store and clears tokens, client secrets, and authorization codes from st before saving to disk. If st.SecretID is set, store must be non-nil and keyring deletion must succeed before st.SecretID is cleared on disk.

func Fingerprint

func Fingerprint(secret string) string

func Redacted

func Redacted(secret string) string

func Save

func Save(path string, st *State) error

func SaveWithSecrets added in v0.2.0

func SaveWithSecrets(path string, st *State, store secretstore.Store) error

SaveWithSecrets writes state to disk. When store is non-nil, current token and client secrets are stored under st.SecretID, historical refresh tokens are stored in separate <secret_id>/prev/<index> entries so the primary item stays bounded in size, and raw secrets are stripped from disk while preserving metadata and SHA-256 fingerprints.

func SetServerInstructions

func SetServerInstructions(st *State, instructions string)

func SetToken

func SetToken(st *State, tok TokenState)

func SetTools

func SetTools(st *State, tools []*mcp.Tool)

Types

type AuthorizationState

type AuthorizationState struct {
	AuthURL    string    `json:"auth_url,omitempty"`
	Code       string    `json:"code,omitempty"`
	State      string    `json:"state,omitempty"`
	ReceivedAt time.Time `json:"received_at,omitempty"`
}

type CallRecord

type CallRecord struct {
	Method    string    `json:"method"`
	OK        bool      `json:"ok"`
	Summary   string    `json:"summary,omitempty"`
	Error     string    `json:"error,omitempty"`
	CreatedAt time.Time `json:"created_at"`
}

type ClientState

type ClientState struct {
	Mode                    string                              `json:"mode,omitempty"`
	ClientID                string                              `json:"client_id,omitempty"`
	ClientSecret            string                              `json:"client_secret,omitempty"`
	TokenEndpointAuthMethod string                              `json:"token_endpoint_auth_method,omitempty"`
	Registration            *oauthex.ClientRegistrationResponse `json:"registration,omitempty"`
}

type DiscoveryState

type DiscoveryState struct {
	ServerURL  string                  `json:"server_url,omitempty"`
	Protected  *ProtectedResourceState `json:"protected_resource,omitempty"`
	AuthServer *oauthex.AuthServerMeta `json:"auth_server,omitempty"`
}

type OldRefreshTokenCheck

type OldRefreshTokenCheck struct {
	HistoryIndex          int       `json:"history_index"`
	OriginalReceivedAt    time.Time `json:"original_received_at,omitempty"`
	RefreshFingerprint    string    `json:"refresh_fingerprint,omitempty"`
	Usable                bool      `json:"usable"`
	NewAccessFingerprint  string    `json:"new_access_fingerprint,omitempty"`
	NewRefreshFingerprint string    `json:"new_refresh_fingerprint,omitempty"`
	RefreshTokenRotated   bool      `json:"refresh_token_rotated"`
	RefreshTokenReused    bool      `json:"refresh_token_reused"`
	Error                 string    `json:"error,omitempty"`
	CheckedAt             time.Time `json:"checked_at"`
}

type ProtectedResourceState

type ProtectedResourceState struct {
	MetadataURL string                             `json:"metadata_url,omitempty"`
	Metadata    *oauthex.ProtectedResourceMetadata `json:"metadata,omitempty"`
}

type RotationAttempt

type RotationAttempt struct {
	Iteration         int       `json:"iteration"`
	BeforeFingerprint string    `json:"before_fingerprint,omitempty"`
	AfterFingerprint  string    `json:"after_fingerprint,omitempty"`
	Rotated           bool      `json:"rotated"`
	Error             string    `json:"error,omitempty"`
	CreatedAt         time.Time `json:"created_at"`
}

type SecretBundle added in v0.2.0

type SecretBundle struct {
	ClientSecret             string        `json:"client_secret,omitempty"`
	RegistrationClientSecret string        `json:"registration_client_secret,omitempty"`
	CurrentToken             *TokenSecrets `json:"current_token,omitempty"`
}

type State

type State struct {
	SecretID             string                 `json:"secret_id,omitempty"`
	RedirectURL          string                 `json:"redirect_url,omitempty"`
	Discovery            *DiscoveryState        `json:"discovery,omitempty"`
	Client               *ClientState           `json:"client,omitempty"`
	Authorization        *AuthorizationState    `json:"authorization,omitempty"`
	CurrentToken         *TokenState            `json:"current_token,omitempty"`
	PreviousTokens       []TokenState           `json:"previous_tokens,omitempty"`
	Tools                []*mcp.Tool            `json:"tools,omitempty"`
	ToolsListedAt        time.Time              `json:"tools_listed_at,omitempty"`
	ServerInstructions   string                 `json:"server_instructions,omitempty"`
	ServerInstructionsAt time.Time              `json:"server_instructions_at,omitempty"`
	Calls                []CallRecord           `json:"calls,omitempty"`
	RotationAttempts     []RotationAttempt      `json:"rotation_attempts,omitempty"`
	OldRefreshChecks     []OldRefreshTokenCheck `json:"old_refresh_checks,omitempty"`
}

func Load

func Load(path string) (*State, error)

func LoadWithHistorySecrets added in v0.2.0

func LoadWithHistorySecrets(path string, store secretstore.Store) (*State, error)

LoadWithHistorySecrets loads the state file, current secrets, and per-entry historical refresh tokens stored under <secret_id>/prev/<index>.

func LoadWithSecrets added in v0.2.0

func LoadWithSecrets(path string, store secretstore.Store) (*State, error)

LoadWithSecrets loads the state file and, when store is non-nil and SecretID is set, hydrates the current token and client secrets from store.

func RedactState

func RedactState(st *State) *State

func (*State) RequireAuthServer

func (s *State) RequireAuthServer() error

func (*State) RequireClient

func (s *State) RequireClient() error

func (*State) RequireServer

func (s *State) RequireServer() error

func (*State) RequireToken

func (s *State) RequireToken() error

type TokenSecrets added in v0.2.0

type TokenSecrets struct {
	AccessToken  string `json:"access_token,omitempty"`
	RefreshToken string `json:"refresh_token,omitempty"`
}

type TokenState

type TokenState struct {
	AccessToken        string          `json:"access_token,omitempty"`
	TokenType          string          `json:"token_type,omitempty"`
	RefreshToken       string          `json:"refresh_token,omitempty"`
	Expiry             time.Time       `json:"expiry,omitempty"`
	Scope              string          `json:"scope,omitempty"`
	AccessFingerprint  string          `json:"access_fingerprint,omitempty"`
	RefreshFingerprint string          `json:"refresh_fingerprint,omitempty"`
	ReceivedAt         time.Time       `json:"received_at,omitempty"`
	Raw                json.RawMessage `json:"raw,omitempty"`
}

func RedactToken

func RedactToken(tok *TokenState) *TokenState

func (*TokenState) EffectiveAccessFingerprint

func (t *TokenState) EffectiveAccessFingerprint() string

func (*TokenState) EffectiveRefreshFingerprint

func (t *TokenState) EffectiveRefreshFingerprint() string

Jump to

Keyboard shortcuts

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