Postgres
Postgres
The Postgres store uses kysely
to provide a type-safe database interface for your MCPAuth instance. It is designed to work with a standard Postgres database and is a great choice for production environments.
Installation
To get started, install the required packages:
npm install @mcpauth/auth pg
Setup
Configure your MCPAuth instance to use the Postgres store.
import { McpAuth } from "@mcpauth/auth";
import { PostgresAdapter } from "@mcpauth/auth/stores/postgres";
export const { handlers, auth } = McpAuth({
PostgresAdapter({
connectionString: process.env.DATABASE_URL,
}),
// ... other options
});
Your DATABASE_URL
should be a standard Postgres connection string, e.g., postgresql://user:pass@host:port/db
.
Migrations
MCPAuth provides a CLI tool to manage your database schema. To run migrations for the Postgres 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:migrate
This 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
.
Then, 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 codegen tool.
Run the script to generate your schema types:
npm run mcpauth:generate
You can now use the generated SQL schema to create your database tables.