URL: https://gofastmcp.com/clients/auth/bearer
Title: Bearer Token Authentication - FastMCP

Documentation Index
Fetch the complete documentation index at:
/llms.txt
Use this file to discover all available pages before exploring further.
Skip to main content
Meet
Prefect Horizon
, the enterprise MCP gateway built by the team behind FastMCP
FastMCP
home page
v3
Prefect Horizon
PrefectHQ/fastmcp
25,596
PrefectHQ/fastmcp
25,596
Search...
Navigation
Authentication
Bearer Token Authentication
Search the docs...
Ctrl
K
Documentation
Get Started
Welcome!
Installation
Quickstart
Servers
Overview
Core Components
Working with Tools
MCP Providers
Interactivity
Extensibility
Auth
Deployment
Apps
Overview
Quickstart
NEW
FastMCPApp
NEW
Interactive Tools
NEW
Generative UI
NEW
Custom HTML
Reference
Clients
Overview
Client-Only Package
Transports
fastmcp-remote
Operations
UPDATED
Authentication
UPDATED
OAuth
CIMD
NEW
Bearer Auth
Integrations
Auth
Web Frameworks
AI Assistants
AI SDKs
MCP.json
More
Settings
CLI
Upgrading
Development
What's New
FAQ
On this page
Client Usage
BearerAuth Helper
Custom Headers
Authentication
Bearer Token Authentication
Copy page
Authenticate your FastMCP client with a Bearer token.
Copy page
New in version
2.6.0
Bearer Token authentication is only relevant for HTTP-based transports.
You can configure your FastMCP client to use
bearer authentication
by supplying a valid access token. This is most appropriate for service accounts, long-lived API keys, CI/CD, applications where authentication is managed separately, or other non-interactive authentication methods.
A Bearer token is a JSON Web Token (JWT) that is used to authenticate a request. It is most commonly used in the
Authorization
header of an HTTP request, using the
Bearer
scheme:
Authorization
:
Bearer <token>
​
Client Usage
The most straightforward way to use a pre-existing Bearer token is to provide it as a string to the
auth
parameter of the
fastmcp.Client
or transport instance. FastMCP will automatically format it correctly for the
Authorization
header and bearer scheme.
If you’re using a string token, do not include the
Bearer
prefix. FastMCP will add it for you.
from
fastmcp
import
Client
async
with
Client
(
"
https://your-server.fastmcp.app/mcp
"
,
auth
=
"
<your-token>
"
,
)
as
client
:
await
client
.
ping
()
You can also supply a Bearer token to a transport instance, such as
StreamableHttpTransport
or
SSETransport
:
from
fastmcp
import
Client
from
fastmcp
.
client
.
transports
import
StreamableHttpTransport
transport
=
StreamableHttpTransport
(
"
http://your-server.fastmcp.app/mcp
"
,
auth
=
"
<your-token>
"
,
)
async
with
Client
(
transport
)
as
client
:
await
client
.
ping
()
​
BearerAuth
Helper
If you prefer to be more explicit and not rely on FastMCP to transform your string token, you can use the
BearerAuth
class yourself, which implements the
httpx.Auth
interface.
from
fastmcp
import
Client
from
fastmcp
.
client
.
auth
import
BearerAuth
async
with
Client
(
"
https://your-server.fastmcp.app/mcp
"
,
auth
=
BearerAuth
(
token
=
"
<your-token>
"
),
)
as
client
:
await
client
.
ping
()
​
Custom Headers
If the MCP server expects a custom header or token scheme, you can manually set the client’s
headers
instead of using the
auth
parameter by setting them on your transport:
from
fastmcp
import
Client
from
fastmcp
.
client
.
transports
import
StreamableHttpTransport
async
with
Client
(
transport
=
StreamableHttpTransport
(
"
https://your-server.fastmcp.app/mcp
"
,
headers
={
"
X-API-Key
"
:
"
<your-token>
"
},
),
)
as
client
:
await
client
.
ping
()
CIMD Authentication
Previous
Auth0 OAuth 🤝 FastMCP
Next
Ctrl
+I
discord
github
website
x
Powered by
This documentation is built and hosted on Mintlify, a developer documentation platform
Assistant
Responses are generated using AI and may contain mistakes.
\n\n
\n
\n \n
\n
