MCP
OAuth
MCP
The MCP plugin lets your app act as an OAuth provider for MCP clients. It handles authentication and makes it easy to issue and manage access tokens for MCP applications.
Installation
Add the Plugin
Add the MCP plugin to your auth configuration and specify the login page path.
This doesn't have a client plugin, so you don't need to make any changes to your authClient.
Generate Schema
Run the migration or generate the schema to add the necessary fields and tables to the database.
The MCP plugin uses the same schema as the OIDC Provider plugin. See the OIDC Provider Schema section for details.
Usage
OAuth Discovery Metadata
Add a route to expose OAuth metadata for MCP clients:
MCP Session Handling
You can use the helper function withMcpAuth
to get the session and handle unauthenticated calls automatically.
You can also use auth.api.getMCPSession
to get the session using the access token sent from the MCP client:
Configuration
The MCP plugin accepts the following configuration options:
Prop | Type | Default |
---|---|---|
loginPage | string | - |
oidcConfig? | object | - |
OIDC Configuration
The plugin supports additional OIDC configuration options through the oidcConfig
parameter:
Prop | Type | Default |
---|---|---|
codeExpiresIn? | number | 600 |
accessTokenExpiresIn? | number | 3600 |
refreshTokenExpiresIn? | number | 604800 |
defaultScope? | string | openid |
scopes? | string[] | ["openid", "profile", "email", "offline_access"] |
Schema
The MCP plugin uses the same schema as the OIDC Provider plugin. See the OIDC Provider Schema section for details.