MySQL
MySQL
The MySQL store uses kysely to provide a type-safe database interface for your MCPAuth instance. It is designed for use with MySQL-compatible databases.
Installation
To get started, install the required packages:
npm install @mcpauth/auth mysql2Setup
Configure your MCPAuth instance to use the MySQL store.
import { McpAuth } from "@mcpauth/auth";
import { MySQLAdapter } from "@mcpauth/auth/stores/mysql";
export const { handlers, auth } = McpAuth({
MySQLAdapter({
connectionString: process.env.DATABASE_URL,
}),
// ... other options
});Your DATABASE_URL should be a standard MySQL connection string, e.g., mysql://user:pass@host:port/db.
Migrations
MCPAuth provides a CLI tool to manage your database schema. To run migrations for the MySQL store, add the following script to your package.json:
{
"scripts": {
"mcpauth:migrate": "mcpauth-migrate --run"
}
}Then, run the command to apply the migrations:
npm run mcpauth:migrateThis command will create the necessary tables (oauth_client, oauth_token, etc.) in your database.
Schema
To generate a SQL schema for your database, you can use mcpauth-generate.
Add a mcpauth:generate script to your package.json:
{
"scripts": {
"mcpauth:generate": "mcpauth-generate sql ./schema.sql"
}
}We recommend creating a .env file in your project root with your DATABASE_URL to make it accessible to the generate tool.
Run the script to generate your schema file:
npm run mcpauth:generateYou can now use the generated SQL schema to create your database tables.