Skip to main content
FastMCP defines session types for authentication and authorization in MCP servers.

FastMCPSession

Session class representing a connected MCP client session.

Properties

boolean
Whether the session is ready (connected and initialized)
ClientCapabilities | null
Client capabilities negotiated during initialization
LoggingLevel
Current logging level set by client
Root[]
Root directories provided by the client
Server
Underlying MCP SDK server instance
string | undefined
Session ID from Mcp-Session-Id header (HTTP transports only)

Methods

connect()

Connect the session with a transport.
Transport
required
MCP transport instance (StdioServerTransport, WebStreamableHTTPServerTransport, etc.)

close()

Close the session and clean up resources.

requestSampling()

Request LLM sampling from the client (if supported).
CreateMessageRequest['params']
required
Sampling request parameters
RequestOptions
Request options (timeout, etc.)
SamplingResponse

waitForReady()

Wait for session to be ready.

updateAuth()

Update the session’s authentication context.
T
required
New authentication data

Events

The session emits events that you can listen to:
() => void
Emitted when session is connected and ready
(event: { error: Error }) => void
Emitted when an error occurs
(event: { roots: Root[] }) => void
Emitted when client roots change

OAuthSession

Standard session type for OAuth providers.
string
The upstream OAuth access token
string[]
Scopes granted by the OAuth provider
number
Token expiration time (Unix timestamp in seconds)
string
ID token from OIDC providers
string
Refresh token (if available)
Record<string, unknown>
Additional claims extracted from the token (if customClaimsPassthrough enabled)

Usage

Provider-Specific Sessions

Each OAuth provider extends OAuthSession with provider-specific fields.

GoogleSession

Usage:

GitHubSession

Usage:

AzureSession

Usage:

Custom Session Types

Define custom session types for your authentication:

FastMCP Events

FastMCP server emits connection events:
(event: { session: FastMCPSession<T> }) => void
Emitted when a client connects
(event: { session: FastMCPSession<T> }) => void
Emitted when a client disconnects