Registry / database / mcp-authkit-store-postgres

mcp-authkit-store-postgres

JSON →
library0.2.1jsnpmunverified

Postgres-backed TokenStore for mcp-authkit, providing durable storage for Personal Access Tokens, refresh tokens, and upstream credential caches. Current stable version is 0.2.1, released as part of the mcp-authkit ecosystem. It wraps node-postgres (pg) and supports PostgreSQL 13+. Key differentiator: pools are consumer-owned, and store.close() does not close the pool to avoid ownership conflicts. Ships TypeScript types and uses ESM-only imports. Release cadence is tied to mcp-authkit releases.

npm install mcp-authkit-store-postgres
INSTALL
IMPORT
SIG · MCP-AUTHKIT-STORE-
M
mcp-authkit-store-postgres
databasejavascriptv0.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

postgresTokenStore
import { postgresTokenStore } from 'mcp-authkit/stores/postgres'
import { postgresTokenStore } from 'mcp-authkit-store-postgres'
The store is re-exported from the core mcp-authkit package at that subpath. Do not install mcp-authkit-store-postgres directly.
Pool
import { Pool } from 'pg'
const Pool = require('pg').Pool
pg 8.13 ships TypeScript definitions; use ESM import for best type inference.
TokenStore
import type { TokenStore } from 'mcp-authkit/stores/postgres'
import { TokenStore } from 'mcp-authkit/stores/postgres'
TokenStore is a TypeScript interface type, not a runtime export. Use 'import type' to avoid tree-shaking issues.

Shows how to create a Postgres-backed token store, run schema migrations, and store/retrieve tokens.

import { postgresTokenStore } from 'mcp-authkit/stores/postgres'; import { Pool } from 'pg'; const pool = new Pool({ connectionString: process.env.DATABASE_URL ?? 'postgres://user:pass@localhost:5432/mcp_auth' }); const store = postgresTokenStore({ pool, schema: 'mcp_auth', // optional, defaults to 'public' }); await store.init(); // runs CREATE TABLE IF NOT EXISTS // Store a token await store.set({ key: 'user:123', value: { accessToken: 'abc', refreshToken: 'def' }, ttl: 3600 }); // Retrieve a token const token = await store.get('user:123'); console.log(token); // Do NOT close the pool here; the consumer owns it.
Debug
Known issues
breakingstore.close() does NOT close the database pool; the consumer owns it and must close it separately.
fix
Always close the Pool yourself: await pool.end(). Never rely on store.close() to release connections.
affects: >=0.1.0
deprecatedImporting from 'mcp-authkit-store-postgres' is deprecated. Use 'mcp-authkit/stores/postgres' instead.
fix
Change imports to 'mcp-authkit/stores/postgres' and uninstall the standalone package.
affects: <0.2.0
gotchaThe store.init() method is idempotent but not atomic; concurrent calls during startup may cause transient deadlocks if multiple processes call it simultaneously.
fix
Run init() once during deployment via migration scripts, or use an advisory lock to serialize calls.
affects: >=0.1.0
gotchaToken TTL is enforced at application level, not by database row expiration. Expired tokens are only cleaned up on read operations (lazy eviction).
fix
Optionally schedule a background task to DELETE expired rows. Otherwise stale tokens accumulate.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Must use import to load ES Module: /path/to/node_modules/mcp-authkit-store-postgres/index.mjs
Using require() to import an ESM-only package in a CommonJS file.
fix
Switch your project to ESM ("type": "module" in package.json) or use dynamic import (const m = await import('mcp-authkit/stores/postgres')).
error: relation "tokens" does not exist
Forgetting to call store.init() before using the store, or using a different schema name.
fix
Ensure store.init() is awaited before any get/set call. Check that the schema option matches database schema.
TypeError: Cannot read properties of undefined (reading 'Pool')
pg is not installed or incorrectly imported.
fix
Run npm install pg@^8.13.0 and make sure you import { Pool } from 'pg' (not 'pg-pool').
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies
pgrequiredPeer dependency. Node-postgres client used for all database operations.
Agent activity
6 hits · last 30 days
node
6
Resources
mcp-authkit-store-postgres — npm install mcp-authkit-store-postgres · libregistry