On this page

MCP and direct connections

Use an agent key as the MCP token for Claude, ChatGPT, Cursor and other AI tools, or as a direct Postgres connection.

#MCP

JSON
{
  "mcpServers": {
    "stitchdb": {
      "url": "https://stitchdb.com/platform/mcp",
      "headers": { "Authorization": "Bearer sdb_agt_..." }
    }
  }
}

With an agent key the MCP server offers the agent tools: execute_sql (through the firewall), list_tables, describe_table, get_approval, get_session, undo_session, check_exposure and, for keys with direct connections, get_db_credentials. Each MCP session is an undo session.

#Direct Postgres connection

Read-only and app developer keys can have a connection string for the key's own role through the connection pooler. Postgres grants and Row Level Security apply, but the firewall, approvals and the query log do not; changes are still recorded for undo.

Terminal
postgresql://p_<ref>_agt_<id>:<password>@<db-host>:6543/p_<ref>?sslmode=require

#Temporary database logins

For tools that need a real Postgres connection only for a while (psql, an ORM, a migration runner), a key with direct connections can hand out a login that ends by itself. It has exactly the key's rights (Row Level Security applies, read-only keys stay read-only), and Postgres refuses it after the time you choose: 5 minutes to 24 hours, default 1 hour, never past the key's own expiry. When it ends, open sessions are closed and the role is dropped. Revoking the key ends all of its logins at once.

  • Dashboard: AI agents → Agent keys → Temporary login. The connection string is shown once; the list shows every login of the key with End now.
  • MCP: the agent calls get_db_credentials with an optional ttl_minutes.
  • API: POST /platform/v1/agent/db-credentials with the agent key, body { "ttl_minutes": 30 }.
JSON
{
  "username": "p_<ref>_tmp_1a2b3c4d",
  "password": "…",
  "host": "<db-host>",
  "port": 6543,
  "session_port": 5432,
  "database": "p_<ref>",
  "expires_at": "2026-10-26T18:18:00.000Z",
  "connection_string": "postgresql://p_<ref>_tmp_1a2b3c4d:…@<db-host>:6543/p_<ref>?sslmode=require"
}

Up to 5 live logins per key and 30 per hour. Network restrictions apply. Migrations keys and keys with direct connections turned off get none. Like the key's own connection string, these logins skip the firewall, approvals and the query log, so prefer execute_sql when it is enough.