Database
Store OAuth tokens and triggers in your database with ORM adapters
The Integrate SDK can persist OAuth provider tokens and scheduled triggers in your database instead of relying on hand-written callbacks for every CRUD operation. This enables:
- Multi-device sync: Access tokens across devices and sessions
- Server-side usage: Use tokens in API routes and background jobs
- Long-term persistence: Tokens survive browser clears and device changes
- Trigger storage: Schedule tool executions with database-backed triggers
Adapters vs callbacks
You can configure persistence in two ways:
| Approach | When to use |
|---|---|
| Database adapter (recommended) | Drizzle, Prisma, or MongoDB. Same callback shape as hand-written token storage |
| Raw callbacks | Custom storage, legacy setups, or non-standard schemas |
With adapters, pass database to createMCPServer. Token and trigger CRUD are handled for you. You still provide getSessionContext to map requests to a userId (session cookie, Clerk, service headers, etc.).
import { createMCPServer, githubIntegration } from "integrate-sdk/server";
import { drizzleAdapter } from "integrate-sdk/adapters/drizzle";
import { db } from "./db";
import { providerToken, trigger } from "./db/schema";
export const { client } = createMCPServer({
apiKey: process.env.INTEGRATE_API_KEY,
integrations: [githubIntegration({ scopes: ["repo"] })],
database: drizzleAdapter(db, {
provider: "pg",
schema: { providerToken, trigger },
}),
getSessionContext: async (req) => {
const session = await auth.api.getSession({ headers: req.headers });
return session?.user?.id ? { userId: session.user.id } : undefined;
},
});Explicit callbacks on createMCPServer still work and override adapter defaults when both are set.
Connected-provider tool loading
When using a database adapter, pair token storage with connected-only tool discovery:
import { getVercelAITools } from "integrate-sdk/server";
const tools = await getVercelAITools(serverClient, {
context: { userId: session.user.id },
connectedOnly: true,
mode: "code",
});Use listConnectedProviders from integrate-sdk/server when you need the connected provider list outside AI helpers.
Guides
- Drizzle: PostgreSQL, MySQL, SQLite
- Prisma:
@prisma/client - MongoDB: native driver collections
- Schema: canonical tables and indexes
- Triggers: composing
onCompleteandgetCallbackUrl - Hooks: cache invalidation, identity resolution, trigger authorization
Examples
Runnable Next.js examples for each database adapter live in the examples repository:
| Adapter | Example |
|---|---|
| Drizzle | database/drizzle-example |
| Prisma | database/prisma-example |
| MongoDB | database/mongodb-example |
Each example connects GitHub OAuth, persists tokens with the adapter, and lists repositories from the browser.
What stays app-specific
getSessionContext cannot be fully abstracted. Each app wires its auth library or internal service headers. Optional hooks cover app-specific behavior (cache revalidation, GitHub email resolution, trigger ownership repair) without forking the adapter.