mcp

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodexClientName    = "Codex"
	OpenCodeClientName = "OpenCode"
)
View Source
const (
	ClientName       = "SuperPlane"
	OAuthTimeout     = 15 * time.Second
	MaxMetadataBytes = 1 << 20
	DefaultTokenTTL  = time.Hour
)

Variables

This section is empty.

Functions

func AuthorizationURL

func AuthorizationURL(authEndpoint, clientID, redirectURI, state, resource string, pkce PKCE) (string, error)

func CallbackURL

func CallbackURL(baseURL string) string

func ClientDisplayName

func ClientDisplayName(storedName, clientID, fallback string) string

ClientDisplayName returns the label shown for an MCP OAuth client. A stored name that is not a known metadata URL wins. A known client label is used when that stored name is empty or is a metadata URL and the client id is a metadata URL for that client. Otherwise fallback is returned.

func ClientMetadataDocument

func ClientMetadataDocument(clientMetadataURL, redirectURI string) map[string]any

func ClientMetadataURL

func ClientMetadataURL(baseURL string) string

func DecryptResourceSecret

func DecryptResourceSecret(ctx context.Context, encryptor crypto.Encryptor, resourceID uuid.UUID, value []byte) (string, error)

DecryptResourceSecret decrypts a workspace MCP secret with the resource ID as AAD.

func DecryptedResourceSecret

func DecryptedResourceSecret(
	ctx context.Context,
	encryptor crypto.Encryptor,
	db *gorm.DB,
	resource *models.FactoryAgentResource,
	name string,
) (string, error)

DecryptedResourceSecret returns a named secret or an empty string when missing.

func EncryptResourceSecret

func EncryptResourceSecret(ctx context.Context, encryptor crypto.Encryptor, resourceID uuid.UUID, plaintext string) ([]byte, error)

EncryptResourceSecret encrypts a workspace MCP secret with the resource ID as AAD.

func GetJSON

func GetJSON(ctx context.Context, httpClient HTTPDoer, rawURL string, dest any) error

func MintFactoryAgentResourceAccessToken

func MintFactoryAgentResourceAccessToken(
	ctx context.Context,
	encryptor crypto.Encryptor,
	httpClient HTTPDoer,
	db *gorm.DB,
	resource *models.FactoryAgentResource,
) (string, error)

MintFactoryAgentResourceAccessToken returns a usable OAuth access token for a workspace MCP server. It reuses the stored access token until shortly before expiry, and refreshes under a database lock.

func MintFactoryAgentResourceAccessTokenWithLifetime

func MintFactoryAgentResourceAccessTokenWithLifetime(
	ctx context.Context,
	encryptor crypto.Encryptor,
	httpClient HTTPDoer,
	db *gorm.DB,
	resource *models.FactoryAgentResource,
	minRemaining time.Duration,
) (string, error)

MintFactoryAgentResourceAccessTokenWithLifetime returns a token that remains valid for at least minRemaining. Agent runs pass the execution timeout because they copy the token into fixed headers for the whole run.

func RandomState

func RandomState() (string, error)

func RandomToken

func RandomToken() (string, error)

func RevokeToken

func RevokeToken(ctx context.Context, httpClient HTTPDoer, revocationEndpoint, clientID, token string)

func S256Challenge

func S256Challenge(verifier string) string

func StoreOAuthTokens

func StoreOAuthTokens(
	ctx context.Context,
	encryptor crypto.Encryptor,
	db *gorm.DB,
	resource *models.FactoryAgentResource,
	tokens *TokenResponse,
) error

StoreOAuthTokens encrypts and persists the access token and optional refresh token. The refresh token is written first. A provider that rotates tokens has already invalidated the previous refresh token by the time this runs.

func TimeoutContext

func TimeoutContext(parent context.Context) (context.Context, context.CancelFunc)

func TokenTTL

func TokenTTL(tokens *TokenResponse) time.Duration

func UserFacingOAuthError

func UserFacingOAuthError(err error) string

UserFacingOAuthError returns a short error for the MCP servers page.

func ValidatePublicHTTPSURL

func ValidatePublicHTTPSURL(raw string) error

ValidatePublicHTTPSURL rejects empty, non-https, and private MCP endpoints.

func VerifyS256

func VerifyS256(verifier, challenge string) bool

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"`
	RevocationEndpoint                string   `json:"revocation_endpoint"`
	CodeChallengeMethodsSupported     []string `json:"code_challenge_methods_supported"`
	ClientIDMetadataDocumentSupported bool     `json:"client_id_metadata_document_supported"`
}

type ClientRegistration

type ClientRegistration struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
}

func RegisterClient

func RegisterClient(ctx context.Context, httpClient HTTPDoer, registrationEndpoint, redirectURI, clientMetadataURL string) (*ClientRegistration, error)

type Discovery

type Discovery struct {
	Resource      string
	Protected     ProtectedResourceMetadata
	AuthServer    AuthorizationServerMetadata
	AuthServerURL string
}

func Discover

func Discover(ctx context.Context, httpClient HTTPDoer, mcpURL string) (*Discovery, error)

func (*Discovery) SelectClientID

func (d *Discovery) SelectClientID(clientMetadataURL string) (clientID string, useDCR bool, err error)

type HTTPDoer

type HTTPDoer interface {
	Do(*http.Request) (*http.Response, error)
}

func DoerFromCore

func DoerFromCore(httpCtx core.HTTPContext) HTTPDoer

type PKCE

type PKCE struct {
	Verifier        string
	Challenge       string
	ChallengeMethod string
}

func NewPKCE

func NewPKCE() (PKCE, error)

type ProtectedResourceMetadata

type ProtectedResourceMetadata struct {
	Resource             string   `json:"resource"`
	AuthorizationServers []string `json:"authorization_servers"`
}

type TokenEndpointError

type TokenEndpointError struct {
	StatusCode  int
	Code        string
	Description string
	Body        string
}

TokenEndpointError is a non-success response from an OAuth token endpoint. Code is the OAuth error name, such as invalid_grant, when the body is JSON.

func (*TokenEndpointError) Error

func (e *TokenEndpointError) Error() string

func (*TokenEndpointError) RejectsGrant

func (e *TokenEndpointError) RejectsGrant() bool

RejectsGrant reports whether the authorization server refused the grant. Timeouts and server errors are not a rejected grant.

type TokenResponse

type TokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int    `json:"expires_in"`
	TokenType    string `json:"token_type"`
}

func ExchangeCode

func ExchangeCode(ctx context.Context, httpClient HTTPDoer, tokenEndpoint, clientID, clientSecret, redirectURI, code, verifier, resource string) (*TokenResponse, error)

func RefreshAccessToken

func RefreshAccessToken(ctx context.Context, httpClient HTTPDoer, tokenEndpoint, clientID, clientSecret, refreshToken, resource string) (*TokenResponse, error)

type Tool

type Tool struct {
	Name        string
	Description string
	ReadOnly    bool
}

Tool is one MCP tools/list entry. Schema is omitted on purpose.

func ListTools

func ListTools(ctx context.Context, httpClient HTTPDoer, mcpURL string, headers map[string]string) ([]Tool, error)

ListTools initializes a Streamable HTTP MCP session and returns tools/list.

Jump to

Keyboard shortcuts

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