Documentation
¶
Index ¶
- func BuildAuthorizationURL(authEndpoint, clientID, redirectURI, state, codeChallenge, resourceURL string) string
- func GeneratePKCEVerifier() string
- func GenerateState() (string, error)
- func PerformOAuthLogin(ctx context.Context, serverURL string) error
- func RegisterClient(ctx context.Context, authMetadata *AuthorizationServerMetadata, ...) (clientID, clientSecret string, err error)
- func RemoveOAuthToken(resourceURL string) error
- func RequestAuthorizationCode(ctx context.Context, authURL string, callbackServer *CallbackServer, ...) (string, string, error)
- type AuthorizationServerMetadata
- type CallbackServer
- func (cs *CallbackServer) GetRedirectURI() string
- func (cs *CallbackServer) SetExpectedState(state string)
- func (cs *CallbackServer) Shutdown(ctx context.Context) error
- func (cs *CallbackServer) Start() error
- func (cs *CallbackServer) WaitForCallback(ctx context.Context) (code, state string, err error)
- type GatewayToolset
- type InMemoryTokenStore
- type KeyringTokenStore
- type OAuthToken
- type OAuthTokenEntry
- type OAuthTokenStore
- type PromptArgument
- type PromptInfo
- type Toolset
- func (ts *Toolset) Describe() string
- func (ts *Toolset) GetPrompt(ctx context.Context, name string, arguments map[string]string) (*mcp.GetPromptResult, error)
- func (ts *Toolset) Instructions() string
- func (ts *Toolset) ListPrompts(ctx context.Context) ([]PromptInfo, error)
- func (ts *Toolset) SetElicitationHandler(handler tools.ElicitationHandler)
- func (ts *Toolset) SetManagedOAuth(managed bool)
- func (ts *Toolset) SetOAuthSuccessHandler(handler func())
- func (ts *Toolset) SetToolsChangedHandler(handler func())
- func (ts *Toolset) Start(ctx context.Context) error
- func (ts *Toolset) Stop(ctx context.Context) error
- func (ts *Toolset) Tools(ctx context.Context) ([]tools.Tool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildAuthorizationURL ¶
func BuildAuthorizationURL(authEndpoint, clientID, redirectURI, state, codeChallenge, resourceURL string) string
BuildAuthorizationURL builds the OAuth authorization URL with PKCE
func GeneratePKCEVerifier ¶
func GeneratePKCEVerifier() string
GeneratePKCEVerifier generates a PKCE code verifier using oauth2 library
func GenerateState ¶
GenerateState generates a random state parameter for OAuth CSRF protection
func PerformOAuthLogin ¶ added in v1.44.0
PerformOAuthLogin performs a standalone OAuth flow for the given MCP server URL. It discovers the authorization server metadata, performs dynamic client registration, opens the browser for user authorization, and stores the resulting token in the keyring.
func RegisterClient ¶
func RegisterClient(ctx context.Context, authMetadata *AuthorizationServerMetadata, redirectURI string, scopes []string) (clientID, clientSecret string, err error)
RegisterClient performs dynamic client registration
func RemoveOAuthToken ¶ added in v1.44.0
RemoveOAuthToken opens the OS keyring and removes the token for the given resource URL.
func RequestAuthorizationCode ¶
func RequestAuthorizationCode(ctx context.Context, authURL string, callbackServer *CallbackServer, expectedState string) (string, string, error)
RequestAuthorizationCode requests the user to open the authorization URL and waits for the callback
Types ¶
type AuthorizationServerMetadata ¶
type AuthorizationServerMetadata struct {
Issuer string `json:"issuer"`
AuthorizationEndpoint string `json:"authorization_endpoint"`
TokenEndpoint string `json:"token_endpoint"`
RegistrationEndpoint string `json:"registration_endpoint,omitempty"`
RevocationEndpoint string `json:"revocation_endpoint,omitempty"`
IntrospectionEndpoint string `json:"introspection_endpoint,omitempty"`
JwksURI string `json:"jwks_uri,omitempty"`
ScopesSupported []string `json:"scopes_supported,omitempty"`
ResponseTypesSupported []string `json:"response_types_supported"`
ResponseModesSupported []string `json:"response_modes_supported,omitempty"`
GrantTypesSupported []string `json:"grant_types_supported,omitempty"`
TokenEndpointAuthMethodsSupported []string `json:"token_endpoint_auth_methods_supported,omitempty"`
RevocationEndpointAuthMethodsSupported []string `json:"revocation_endpoint_auth_methods_supported,omitempty"`
CodeChallengeMethodsSupported []string `json:"code_challenge_methods_supported,omitempty"`
}
AuthorizationServerMetadata represents OAuth 2.0 Authorization Server Metadata (RFC 8414)
type CallbackServer ¶
type CallbackServer struct {
// contains filtered or unexported fields
}
CallbackServer handles OAuth callback requests
func NewCallbackServer ¶
func NewCallbackServer() (*CallbackServer, error)
NewCallbackServer creates a new OAuth callback server
func (*CallbackServer) GetRedirectURI ¶
func (cs *CallbackServer) GetRedirectURI() string
func (*CallbackServer) SetExpectedState ¶
func (cs *CallbackServer) SetExpectedState(state string)
func (*CallbackServer) Start ¶
func (cs *CallbackServer) Start() error
func (*CallbackServer) WaitForCallback ¶
func (cs *CallbackServer) WaitForCallback(ctx context.Context) (code, state string, err error)
type GatewayToolset ¶
type GatewayToolset struct {
*Toolset
// contains filtered or unexported fields
}
func NewGatewayToolset ¶
type InMemoryTokenStore ¶
type InMemoryTokenStore struct {
// contains filtered or unexported fields
}
InMemoryTokenStore implements OAuthTokenStore in memory
func (*InMemoryTokenStore) GetToken ¶
func (s *InMemoryTokenStore) GetToken(resourceURL string) (*OAuthToken, error)
func (*InMemoryTokenStore) RemoveToken ¶
func (s *InMemoryTokenStore) RemoveToken(resourceURL string) error
func (*InMemoryTokenStore) StoreToken ¶
func (s *InMemoryTokenStore) StoreToken(resourceURL string, token *OAuthToken) error
type KeyringTokenStore ¶ added in v1.44.0
type KeyringTokenStore struct {
// contains filtered or unexported fields
}
KeyringTokenStore implements OAuthTokenStore using the OS-native credential store (macOS Keychain, Windows Credential Manager, Linux Secret Service).
func (*KeyringTokenStore) GetToken ¶ added in v1.44.0
func (s *KeyringTokenStore) GetToken(resourceURL string) (*OAuthToken, error)
func (*KeyringTokenStore) RemoveToken ¶ added in v1.44.0
func (s *KeyringTokenStore) RemoveToken(resourceURL string) error
func (*KeyringTokenStore) StoreToken ¶ added in v1.44.0
func (s *KeyringTokenStore) StoreToken(resourceURL string, token *OAuthToken) error
type OAuthToken ¶
type OAuthToken struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
Scope string `json:"scope,omitempty"`
ExpiresAt time.Time `json:"expires_at"`
ClientID string `json:"client_id,omitempty"`
ClientSecret string `json:"client_secret,omitempty"`
}
func ExchangeCodeForToken ¶
func ExchangeCodeForToken(ctx context.Context, tokenEndpoint, code, codeVerifier, clientID, clientSecret, redirectURI string) (*OAuthToken, error)
ExchangeCodeForToken exchanges an authorization code for an access token
func RefreshAccessToken ¶ added in v1.44.0
func RefreshAccessToken(ctx context.Context, tokenEndpoint, refreshToken, clientID, clientSecret string) (*OAuthToken, error)
RefreshAccessToken uses a refresh token to obtain a new access token without user interaction.
func (*OAuthToken) IsExpired ¶
func (t *OAuthToken) IsExpired() bool
IsExpired checks if the token is expired
type OAuthTokenEntry ¶ added in v1.44.0
type OAuthTokenEntry struct {
ResourceURL string
Token *OAuthToken
}
OAuthTokenEntry represents a stored OAuth token along with its resource URL.
func ListOAuthTokens ¶ added in v1.44.0
func ListOAuthTokens() ([]OAuthTokenEntry, error)
ListOAuthTokens opens the OS keyring and returns all stored OAuth tokens. It reads a stored index to discover resource URLs, then fetches each token. This results in only Get() calls (no Keys()), so the user is prompted for keychain access at most once.
type OAuthTokenStore ¶
type OAuthTokenStore interface {
// GetToken retrieves a token for the given resource URL
GetToken(resourceURL string) (*OAuthToken, error)
// StoreToken stores a token for the given resource URL
StoreToken(resourceURL string, token *OAuthToken) error
// RemoveToken removes a token for the given resource URL
RemoveToken(resourceURL string) error
}
OAuthTokenStore manages OAuth tokens
func NewInMemoryTokenStore ¶
func NewInMemoryTokenStore() OAuthTokenStore
NewInMemoryTokenStore creates a new in-memory token store
func NewKeyringTokenStore ¶ added in v1.44.0
func NewKeyringTokenStore() OAuthTokenStore
NewKeyringTokenStore creates a token store backed by the OS keychain. Falls back to InMemoryTokenStore if no keyring backend is available.
type PromptArgument ¶
type PromptArgument struct {
Name string `json:"name"` // The name of the argument
Description string `json:"description"` // Human-readable description of the argument
Required bool `json:"required"` // Whether this argument is required
}
PromptArgument represents a single argument for an MCP prompt
type PromptInfo ¶
type PromptInfo struct {
Name string `json:"name"` // The prompt name/identifier
Description string `json:"description"` // Human-readable description of what this prompt does
Arguments []PromptArgument `json:"arguments"` // List of arguments this prompt accepts
}
PromptInfo contains metadata about an available MCP prompt
type Toolset ¶
type Toolset struct {
// contains filtered or unexported fields
}
Toolset represents a set of MCP tools
func NewRemoteToolset ¶
NewRemoteToolset creates a new MCP toolset from a remote MCP Server.
func NewToolsetCommand ¶
NewToolsetCommand creates a new MCP toolset from a command.
func (*Toolset) Describe ¶
Describe returns a short, user-visible description of this toolset instance. It never includes secrets.
func (*Toolset) GetPrompt ¶
func (ts *Toolset) GetPrompt(ctx context.Context, name string, arguments map[string]string) (*mcp.GetPromptResult, error)
GetPrompt retrieves a specific prompt with provided arguments from the MCP server. This method executes the prompt and returns the result content.
func (*Toolset) Instructions ¶
func (*Toolset) ListPrompts ¶
func (ts *Toolset) ListPrompts(ctx context.Context) ([]PromptInfo, error)
ListPrompts retrieves available prompts from the MCP server. Returns a slice of PromptInfo containing metadata about each available prompt including name, description, and argument specifications.
func (*Toolset) SetElicitationHandler ¶
func (ts *Toolset) SetElicitationHandler(handler tools.ElicitationHandler)
func (*Toolset) SetManagedOAuth ¶
func (*Toolset) SetOAuthSuccessHandler ¶
func (ts *Toolset) SetOAuthSuccessHandler(handler func())
func (*Toolset) SetToolsChangedHandler ¶
func (ts *Toolset) SetToolsChangedHandler(handler func())