Documentation
¶
Index ¶
- func ConnectAll(ctx context.Context, logger slog.Logger, configs []database.MCPServerConfig, ...) ([]fantasy.AgentTool, func())
- func IsPermanentRefreshError(err error) bool
- func RedactURL(rawURL string) string
- func RefreshFailureReason(err error) string
- func RevokeOAuth2Token(ctx context.Context, httpClient *http.Client, cfg database.MCPServerConfig, ...) (bool, error)
- func ValidateRevocationEndpoint(rawURL string) error
- type MCPToolIdentifier
- type RefreshResult
- type UserOIDCTokenSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConnectAll ¶
func ConnectAll( ctx context.Context, logger slog.Logger, configs []database.MCPServerConfig, tokens []database.MCPServerUserToken, userID uuid.UUID, oidcSrc UserOIDCTokenSource, coderHeaders map[string]string, ) ([]fantasy.AgentTool, func())
ConnectAll connects to all configured MCP servers, discovers their tools, and returns them as fantasy.AgentTool values. Tools are sorted by their prefixed name so callers receive a deterministic order. It skips servers that fail to connect and logs warnings. The returned cleanup function must be called to close all connections.
func IsPermanentRefreshError ¶ added in v2.36.0
IsPermanentRefreshError reports whether an OAuth2 token refresh error means the user's grant is permanently unusable (for example the upstream grant was revoked) rather than a transient provider failure. Only error codes tied to the grant itself count: client or config problems (invalid_client, unauthorized_client, ...) affect every user of the server and cannot be fixed by the user reconnecting, so they are treated as transient here. See RFC 6749 section 5.2.
func RedactURL ¶
RedactURL strips userinfo and query parameters from a URL to avoid logging embedded credentials. Query params are removed because API keys are sometimes passed as ?api_key=sk-... in server URLs.
func RefreshFailureReason ¶ added in v2.36.0
RefreshFailureReason converts a refresh error into a bounded string safe to persist as oauth_refresh_failure_reason. It is stored for operator debugging only and is never returned through the API.
func RevokeOAuth2Token ¶ added in v2.36.0
func RevokeOAuth2Token( ctx context.Context, httpClient *http.Client, cfg database.MCPServerConfig, tok database.MCPServerUserToken, ) (bool, error)
RevokeOAuth2Token revokes the user's token at the provider's RFC 7009 endpoint. It prefers the refresh token, retrying with the access token only on unsupported_token_type; other failures do not fall back, since an access-token success would hide a possibly live refresh token. Returns false without error when there is no revocation endpoint or no stored token. Errors carry only the HTTP status because provider bodies may echo secrets.
func ValidateRevocationEndpoint ¶ added in v2.36.0
ValidateRevocationEndpoint enforces the RFC 7009 HTTPS requirement; the request carries token material and the client secret. Plain HTTP is allowed only for loopback hosts.
Types ¶
type MCPToolIdentifier ¶
MCPToolIdentifier is implemented by tools that originate from an MCP server config and can report the config's database ID.
type RefreshResult ¶
type RefreshResult struct {
// AccessToken is the new (or unchanged) access token.
AccessToken string
// RefreshToken is the new (or preserved original) refresh
// token. Providers that don't rotate refresh tokens return
// an empty value; in that case the original is kept.
RefreshToken string
// TokenType is the token type (usually "Bearer").
TokenType string
// Expiry is the new token expiry. Zero value means no expiry
// was provided by the provider.
Expiry time.Time
// Refreshed is true when the access token actually changed,
// meaning a refresh occurred. When false the token was still
// valid and no network call was made.
Refreshed bool
}
RefreshResult contains the outcome of an OAuth2 token refresh attempt.
func RefreshOAuth2Token ¶
func RefreshOAuth2Token( ctx context.Context, cfg database.MCPServerConfig, tok database.MCPServerUserToken, ) (RefreshResult, error)
RefreshOAuth2Token checks whether the given MCP user token is expired (or within 10 seconds of expiry) and refreshes it using the OAuth2 credentials from the server config. If the token is still valid, no network call is made and Refreshed is false.
The caller is responsible for persisting the result when Refreshed is true.
type UserOIDCTokenSource ¶ added in v2.34.0
type UserOIDCTokenSource interface {
OIDCAccessToken(ctx context.Context, userID uuid.UUID) (string, error)
}
UserOIDCTokenSource resolves the OIDC access token for the calling user. Implementations attempt to refresh tokens that are expired or close to expiring and MUST return ("", nil) when the user has no OIDC link or a refresh attempt failed for any reason. A non-nil error is reserved for unexpected infrastructure failures (e.g. database errors) and skips header construction entirely. The empty-token-on-refresh-failure behavior matches provisionerdserver.ObtainOIDCAccessToken.