google

package
v0.0.75 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package google provides OAuth2 authentication and token management for Google APIs.

This package handles both file-based token storage (for STDIO transport) and OAuth store-based token management (for HTTP/SSE transports with OAuth authentication).

The TokenProvider interface allows different token sources to be plugged in, enabling seamless integration between MCP OAuth authentication and Google API access.

Index

Constants

This section is empty.

Variables

View Source
var DefaultOAuthScopes = []string{

	"openid",
	"https://www.googleapis.com/auth/userinfo.email",

	"https://mail.google.com/",
	"https://www.googleapis.com/auth/gmail.readonly",
	"https://www.googleapis.com/auth/gmail.modify",
	"https://www.googleapis.com/auth/gmail.send",
	"https://www.googleapis.com/auth/gmail.settings.basic",

	"https://www.googleapis.com/auth/documents.readonly",

	"https://www.googleapis.com/auth/drive",

	"https://www.googleapis.com/auth/calendar",

	"https://www.googleapis.com/auth/meetings.space.readonly",
	"https://www.googleapis.com/auth/meetings.space.settings",

	"https://www.googleapis.com/auth/tasks",

	"https://www.googleapis.com/auth/contacts.readonly",
	"https://www.googleapis.com/auth/contacts.other.readonly",
	"https://www.googleapis.com/auth/directory.readonly",
}

DefaultOAuthScopes are the Google OAuth scopes required for full MCP functionality. These scopes are used consistently across the application for OAuth configurations.

The scopes provide access to:

  • Gmail: read, modify, send, settings
  • Google Docs: read-only
  • Google Drive: full access
  • Google Calendar: full access
  • Google Meet: read spaces and settings
  • Google Tasks: full access
  • Contacts: read-only (including other contacts and directory)

Functions

func ForceHTTP11 added in v0.0.27

func ForceHTTP11(client *http.Client)

ForceHTTP11 configures an HTTP client to use HTTP/1.1 instead of HTTP/2. This is needed because some Google APIs have issues with HTTP/2. If the client's transport is not an *oauth2.Transport, this is a no-op.

func GetAuthenticationErrorMessage added in v0.0.27

func GetAuthenticationErrorMessage(account string) string

GetAuthenticationErrorMessage returns a user-friendly error message when authentication is required

func GetHTTPClient

func GetHTTPClient(ctx context.Context) (*http.Client, error)

GetHTTPClient returns an HTTP client configured with OAuth2 authentication for the default account The client is configured to use HTTP/1.1 to avoid HTTP/2 protocol errors

func GetHTTPClientForAccount added in v0.0.8

func GetHTTPClientForAccount(ctx context.Context, account string) (*http.Client, error)

GetHTTPClientForAccount returns an HTTP client configured with OAuth2 authentication for a specific account The client is configured to use HTTP/1.1 to avoid HTTP/2 protocol errors

func GetOAuthConfig added in v0.0.27

func GetOAuthConfig() *oauth2.Config

GetOAuthConfig returns the OAuth2 configuration for all Google services (exported for use by clients)

func GetTokenSource

func GetTokenSource(ctx context.Context) (oauth2.TokenSource, error)

GetTokenSource returns an OAuth2 token source for the stored token for the default account Returns nil if no valid token exists

func GetTokenSourceForAccount added in v0.0.8

func GetTokenSourceForAccount(ctx context.Context, account string) (oauth2.TokenSource, error)

GetTokenSourceForAccount returns an OAuth2 token source for the stored token for a specific account Returns nil if no valid token exists

func HasToken

func HasToken() bool

HasToken checks if a valid OAuth token exists for the default account

func HasTokenForAccount added in v0.0.8

func HasTokenForAccount(account string) bool

HasTokenForAccount checks if a valid OAuth token exists for the specified account

func MigrateDefaultToken added in v0.0.8

func MigrateDefaultToken() error

MigrateDefaultToken migrates the old google.token to google-default.token if needed This ensures backward compatibility for existing users

func SaveTokenForAccount added in v0.0.8

func SaveTokenForAccount(ctx context.Context, account string, token *oauth2.Token) error

SaveTokenForAccount saves a Google OAuth token for a specific account This is called by the OAuth middleware after validating the user's token

Types

type FileTokenProvider added in v0.0.27

type FileTokenProvider struct{}

FileTokenProvider provides tokens from disk files (for STDIO transport)

func NewFileTokenProvider added in v0.0.27

func NewFileTokenProvider() *FileTokenProvider

NewFileTokenProvider creates a new file-based token provider

func (*FileTokenProvider) GetTokenForAccount added in v0.0.27

func (p *FileTokenProvider) GetTokenForAccount(ctx context.Context, account string) (*oauth2.Token, error)

GetTokenForAccount retrieves a token from disk for the specified account

func (*FileTokenProvider) HasTokenForAccount added in v0.0.27

func (p *FileTokenProvider) HasTokenForAccount(account string) bool

HasTokenForAccount checks if a token file exists for the specified account

type TokenProvider added in v0.0.27

type TokenProvider interface {
	// GetTokenForAccount retrieves an OAuth token for the specified account
	GetTokenForAccount(ctx context.Context, account string) (*oauth2.Token, error)

	// HasTokenForAccount checks if a token exists for the specified account
	HasTokenForAccount(account string) bool
}

TokenProvider is an interface for providing OAuth tokens for Google APIs This abstraction allows different token sources (file-based, OAuth store, etc.)

Jump to

Keyboard shortcuts

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