mcp

package
v1.30.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

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

func GenerateState() (string, error)

GenerateState generates a random state parameter for OAuth CSRF protection

func RegisterClient

func RegisterClient(ctx context.Context, authMetadata *AuthorizationServerMetadata, redirectURI string, scopes []string) (clientID, clientSecret string, err error)

RegisterClient performs dynamic client registration

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) Shutdown

func (cs *CallbackServer) Shutdown(ctx context.Context) error

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

func NewGatewayToolset(ctx context.Context, name, mcpServerName string, config any, envProvider environment.Provider, cwd string) (*GatewayToolset, error)

func (*GatewayToolset) Stop

func (t *GatewayToolset) Stop(ctx context.Context) error

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 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"`
}

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 (*OAuthToken) IsExpired

func (t *OAuthToken) IsExpired() bool

IsExpired checks if the token is expired

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

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

func NewRemoteToolset(name, urlString, transport string, headers map[string]string) *Toolset

NewRemoteToolset creates a new MCP toolset from a remote MCP Server.

func NewToolsetCommand

func NewToolsetCommand(name, command string, args, env []string, cwd string) *Toolset

NewToolsetCommand creates a new MCP toolset from a command.

func (*Toolset) Describe

func (ts *Toolset) Describe() string

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 (ts *Toolset) Instructions() string

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 (ts *Toolset) SetManagedOAuth(managed bool)

func (*Toolset) SetOAuthSuccessHandler

func (ts *Toolset) SetOAuthSuccessHandler(handler func())

func (*Toolset) SetToolsChangedHandler

func (ts *Toolset) SetToolsChangedHandler(handler func())

func (*Toolset) Start

func (ts *Toolset) Start(ctx context.Context) error

func (*Toolset) Stop

func (ts *Toolset) Stop(ctx context.Context) error

func (*Toolset) Tools

func (ts *Toolset) Tools(ctx context.Context) ([]tools.Tool, error)

Jump to

Keyboard shortcuts

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