Overview
Every tool handler receives aToolContext as its second argument. It carries the current session ID, resolved authentication headers, provider token, and an abort signal for cancellation.
Properties
The current MCP session ID. Generated by the server on the
initialize
handshake. Use this to correlate tool calls to a specific client session in
logs or external systems.An
AbortSignal for cooperative cancellation. When the MCP client sends a
notifications/cancelled message, the server aborts the signal. Pass this to
fetch or other async operations so they stop early when the client cancels.Request metadata forwarded from the MCP JSON-RPC layer.
progressToken— opaque token the client uses to track progress notifications.requestId— the JSON-RPC request ID for this call.
The active authentication strategy for this server instance.
| Value | Description |
|---|---|
oauth | Full OAuth 2.1 PKCE flow; providerToken is the mapped provider access token |
bearer | Static bearer token from BEARER_TOKEN env var |
api_key | Static API key from API_KEY env var |
custom | Arbitrary headers from CUSTOM_HEADERS env var |
none | No authentication configured |
The resolved access token for the authenticated user.
- OAuth: the provider access token mapped from the RS token (e.g., a Google or GitHub token).
- Bearer: the value of the
BEARER_TOKENenvironment variable. - API key: the value of the
API_KEYenvironment variable. - Custom / none:
undefined.
resolvedHeaders for making API calls instead of constructing the
Authorization header yourself.OAuth provider details. Only populated when
authStrategy is oauth.Ready-to-use HTTP headers for forwarding authentication to external APIs.
The exact headers depend on the active strategy:
Spread or pass this object directly to
| Strategy | Header |
|---|---|
oauth | Authorization: Bearer <provider-token> |
bearer | Authorization: Bearer <BEARER_TOKEN> |
api_key | <API_KEY_HEADER>: <API_KEY> (default header: x-api-key) |
custom | All headers from CUSTOM_HEADERS env var |
fetch:Raw authorization headers from the incoming MCP request (before resolution).
Use
resolvedHeaders instead — it contains the correct auth headers for
forwarding to external services regardless of the active strategy.AuthenticatedToolContext
AuthenticatedToolContext extends ToolContext and guarantees that
providerToken is a non-optional string. The dispatcher populates this
automatically for tools that declare requiresAuth: true.
assertProviderToken to narrow the type manually: